hermet pushed a commit to branch master. http://git.enlightenment.org/tools/enventor.git/commit/?id=fb1b4d861f82888ab86a6cc1047f9b5f78f6e20f
commit fb1b4d861f82888ab86a6cc1047f9b5f78f6e20f Author: ChunEon Park <her...@hermet.pe.kr> Date: Wed Feb 26 10:36:53 2014 +0900 search - on implementing search function. --- data/themes/default/images/hotkeys_open.png | Bin 480 -> 481 bytes src/bin/edc_editor.c | 12 +++++++ src/bin/main.c | 2 +- src/bin/search.c | 53 ++++++++++++++++++++++++++-- src/include/common.h | 1 + 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/data/themes/default/images/hotkeys_open.png b/data/themes/default/images/hotkeys_open.png index 625c9ed..bd18568 100644 Binary files a/data/themes/default/images/hotkeys_open.png and b/data/themes/default/images/hotkeys_open.png differ diff --git a/src/bin/edc_editor.c b/src/bin/edc_editor.c index ecbb3c2..e4bb235 100644 --- a/src/bin/edc_editor.c +++ b/src/bin/edc_editor.c @@ -863,3 +863,15 @@ edit_font_size_update(edit_data *ed, Eina_Bool msg) snprintf(buf, sizeof(buf), "Font Size: %1.1fx", config_font_size_get()); stats_info_msg_update(buf); } + +void +edit_search(edit_data *ed, const char *word) +{ + Eina_Bool found; + static search_data *sd = NULL; + + sd = search_word(sd, ed->en_edit, word, &found); +// search_stop(sd); + printf("word(%s) found(%d)\n", word, found); + fflush(stdout); +} diff --git a/src/bin/main.c b/src/bin/main.c index 021e3ea..20df508 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -165,7 +165,7 @@ ctrl_func(app_data *ad, const char *key) //Find/Replace if (!strcmp(key, "f") || !strcmp(key, "F")) { - search_edit_word(ad->ed, "RECT"); + edit_search(ad->ed, "part"); return ECORE_CALLBACK_DONE; } //Template Code diff --git a/src/bin/search.c b/src/bin/search.c index c465349..345961f 100644 --- a/src/bin/search.c +++ b/src/bin/search.c @@ -1,9 +1,56 @@ #include <Elementary.h> #include "common.h" +struct search_s +{ + int order; +}; + +search_data * +search_word(search_data *sd, Evas_Object *entry, const char *word, + Eina_Bool *found) +{ + *found = EINA_FALSE; + + if (!word) return NULL; + + const char *text = elm_entry_entry_get(entry); + const char *utf8 = elm_entry_markup_to_utf8(text); + + if (!sd) sd = calloc(1, sizeof(search_data)); + + //There is no word in the text + char *s = strstr(utf8, word); + if (!s) + { + free(sd); + return sd; + } + + int order = sd->order; + + //No more next word found + if ((order > 0) && (strlen(s) <= 1)) return sd; + + while (order > 0) + { + s++; + s = strstr(s, word); + if (!s) return sd; + order--; + } + + //Got you! + int len = strlen(word); + elm_entry_select_region_set(entry, (s - utf8), (s - utf8) + len); + sd->order++; + *found = EINA_TRUE; + + return sd; +} + void -search_edit_word(edit_data *ed, const char *word) +search_stop(search_data *sd) { -printf("search word - %s\n", word); -fflush(stdout); + if (sd) free(sd); } diff --git a/src/include/common.h b/src/include/common.h index a530df2..4627b04 100644 --- a/src/include/common.h +++ b/src/include/common.h @@ -9,6 +9,7 @@ typedef struct parser_s parser_data; typedef struct attr_value_s attr_value; typedef struct syntax_helper_s syntax_helper; typedef struct indent_s indent_data; +typedef struct search_s search_data; #include "edc_editor.h" #include "menu.h" --