search - on implementing search function.

This commit is contained in:
ChunEon Park 2014-02-26 10:36:53 +09:00
parent c8e5b4d6c4
commit fb1b4d861f
5 changed files with 65 additions and 5 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 480 B

After

Width:  |  Height:  |  Size: 481 B

View File

@ -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);
}

View File

@ -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

View File

@ -1,9 +1,56 @@
#include <Elementary.h>
#include "common.h"
void
search_edit_word(edit_data *ed, const char *word)
struct search_s
{
printf("search word - %s\n", word);
fflush(stdout);
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_stop(search_data *sd)
{
if (sd) free(sd);
}

View File

@ -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"