summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-07-24 12:41:33 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-07-24 12:41:33 +0900
commit8425af77686bace152e93d89d3ed5b872cd0b32e (patch)
tree18b7e2e701125514c69a50263ccef4785151e5a1 /src/bin
parent1857e0df0b29a19a6aea330c85ffed0482b58041 (diff)
fix genlist/grid search item patch to be simpler and just better
better - why? 1. no reliance on fnmatrch headers - have special enums for this so fnmatch is an internal detail (casefole may not exist) 2. don't leak strduped strings - free them when done 3. have the same code for genlist and grid (dup for now until an interface makes it the same search interface) 4. improve docs 5. get right @since version 6. use label get func in item class - providing a func won't work when multiple items of multiple classes exist in the list
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/test_gengrid.c16
-rw-r--r--src/bin/test_genlist.c29
2 files changed, 13 insertions, 32 deletions
diff --git a/src/bin/test_gengrid.c b/src/bin/test_gengrid.c
index a2ca6a08b..bfdd85fd0 100644
--- a/src/bin/test_gengrid.c
+++ b/src/bin/test_gengrid.c
@@ -1381,20 +1381,11 @@ static const char *_grid5_items_text[] = {
1381}; 1381};
1382 1382
1383static char * 1383static char *
1384_grid5_search_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
1385{
1386 char buf[32];
1387 Item_Data *id = data;
1388
1389 snprintf(buf, sizeof(buf), "%s", _grid5_items_text[id->mode]);
1390 return strdup(buf);
1391}
1392
1393static char *
1394_grid5_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED) 1384_grid5_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
1395{ 1385{
1386 Item_Data *id = data;
1396 char buf[64]; 1387 char buf[64];
1397 snprintf(buf, sizeof(buf), "%s", _grid5_search_text_get(data, NULL, NULL)); 1388 snprintf(buf, sizeof(buf), "%s", _grid5_items_text[id->mode]);
1398 return strdup(buf); 1389 return strdup(buf);
1399} 1390}
1400 1391
@@ -1405,7 +1396,8 @@ _grid5_search_item(grid5_Event_Data *event_data, Elm_Object_Item * it)
1405 if (!str || !strlen(str)) return; 1396 if (!str || !strlen(str)) return;
1406 1397
1407 printf("Looking for \"%s\". ", str); 1398 printf("Looking for \"%s\". ", str);
1408 event_data->last_item_found = elm_gengrid_search_by_text_item_get(event_data->grid_obj, it, _grid5_search_text_get, NULL, str, 0); 1399 event_data->last_item_found = elm_gengrid_search_by_text_item_get
1400 (event_data->grid_obj, it, NULL, str, 0);
1409 1401
1410 if (event_data->last_item_found) 1402 if (event_data->last_item_found)
1411 { 1403 {
diff --git a/src/bin/test_genlist.c b/src/bin/test_genlist.c
index d553be566..0d80d1c58 100644
--- a/src/bin/test_genlist.c
+++ b/src/bin/test_genlist.c
@@ -3508,8 +3508,8 @@ static const char *_gl20_items_text[] = {
3508 "Topeka", "Trenton" }; 3508 "Topeka", "Trenton" };
3509 3509
3510static char * 3510static char *
3511_gl20_search_text_get(void *data, Evas_Object *obj EINA_UNUSED, 3511_gl20_text_get(void *data, Evas_Object *obj EINA_UNUSED,
3512 const char *part EINA_UNUSED) 3512 const char *part EINA_UNUSED)
3513{ 3513{
3514 char buf[32]; 3514 char buf[32];
3515 int item_index = (int)(uintptr_t)data; 3515 int item_index = (int)(uintptr_t)data;
@@ -3530,29 +3530,18 @@ _gl20_search_text_get(void *data, Evas_Object *obj EINA_UNUSED,
3530 return NULL; 3530 return NULL;
3531} 3531}
3532 3532
3533static char *
3534_gl20_text_get(void *data, Evas_Object *obj EINA_UNUSED,
3535 const char *part EINA_UNUSED)
3536{
3537 char buf[64];
3538 snprintf(buf, sizeof(buf), "(this text is not uset for search) %s",
3539 _gl20_search_text_get(data, NULL, NULL));
3540 return strdup(buf);
3541}
3542
3543static void 3533static void
3544_gl20_searsh_item(gl20_Event_Data *event_data, Elm_Object_Item * it) 3534_gl20_search_item(gl20_Event_Data *event_data, Elm_Object_Item * it)
3545{ 3535{
3546 const char *str = elm_entry_entry_get(event_data->en_obj); 3536 const char *str = elm_entry_entry_get(event_data->en_obj);
3547 if (!str || !strlen(str)) return; 3537 if (!str || !strlen(str)) return;
3548 3538
3549 int flag = 0; 3539 Elm_Glob_Match_Flags flag = 0;
3550 if (!elm_check_state_get(event_data->tg_obj)) 3540 if (!elm_check_state_get(event_data->tg_obj)) flag = ELM_GLOB_MATCH_NOCASE;
3551 flag = FNM_CASEFOLD;
3552 3541
3553 printf("Looking for \"%s\". ", str); 3542 printf("Looking for \"%s\". ", str);
3554 event_data->last_item_found = elm_genlist_search_by_text_item_get(event_data->gl_obj, 3543 event_data->last_item_found = elm_genlist_search_by_text_item_get
3555 it, _gl20_search_text_get, NULL, str, flag); 3544 (event_data->gl_obj, it, NULL, str, flag);
3556 3545
3557 if (event_data->last_item_found) 3546 if (event_data->last_item_found)
3558 { 3547 {
@@ -3570,7 +3559,7 @@ static void
3570_gl20_search_settings_changed_cb(void *data, Evas_Object *obj EINA_UNUSED, 3559_gl20_search_settings_changed_cb(void *data, Evas_Object *obj EINA_UNUSED,
3571 void *einfo EINA_UNUSED) 3560 void *einfo EINA_UNUSED)
3572{ 3561{
3573 _gl20_searsh_item(data, NULL); 3562 _gl20_search_item(data, NULL);
3574} 3563}
3575 3564
3576static Elm_Genlist_Item_Class * 3565static Elm_Genlist_Item_Class *
@@ -3616,7 +3605,7 @@ static void _gl20_on_keydown(void *data, Evas *evas EINA_UNUSED,
3616 if (!strcmp(ev->key, "Return")) 3605 if (!strcmp(ev->key, "Return"))
3617 { 3606 {
3618 printf("Looking for next item\n"); 3607 printf("Looking for next item\n");
3619 _gl20_searsh_item(data, event_data->last_item_found); 3608 _gl20_search_item(data, event_data->last_item_found);
3620 } 3609 }
3621} 3610}
3622 3611