autosuggest: Change the variable name from 'autocomplete' to 'suggest' for readability.

Summary:
Change the variable name from 'autocomplete' to 'suggest'.
Because 'autocomplete' is too long.

Reviewers: ajwillia.ms

Reviewed By: ajwillia.ms

Differential Revision: https://phab.enlightenment.org/D4496
This commit is contained in:
YeongJong Lee 2016-12-19 23:25:01 +00:00 committed by Andy Williams
parent 21ae2bfebd
commit 284c7ff3ca
1 changed files with 65 additions and 72 deletions

View File

@ -27,7 +27,7 @@ typedef struct
} Edi_Range;
#if HAVE_LIBCLANG
static Evas_Object *_clang_autocomplete_popup_bg, *_clang_autocomplete_popup_genlist;
static Evas_Object *_suggest_popup_bg, *_suggest_popup_genlist;
#endif
void
@ -99,7 +99,7 @@ _edi_editor_current_word_get(Edi_Editor *editor, unsigned int row, unsigned int
}
static Evas_Object *
_autocomplete_list_content_get(void *data, Evas_Object *obj, const char *part)
_suggest_list_content_get(void *data, Evas_Object *obj, const char *part)
{
Edi_Editor *editor;
Edi_Mainview_Item *item;
@ -136,26 +136,26 @@ _autocomplete_list_content_get(void *data, Evas_Object *obj, const char *part)
}
static void
_autocomplete_list_update(char *word)
_suggest_list_update(char *word)
{
Eina_List *list, *l;
Elm_Genlist_Item_Class *ic;
Elm_Object_Item *item;
char *auto_str;
elm_genlist_clear(_clang_autocomplete_popup_genlist);
elm_genlist_clear(_suggest_popup_genlist);
list = (Eina_List *)evas_object_data_get(_clang_autocomplete_popup_genlist,
"autocomplete_list");
list = (Eina_List *)evas_object_data_get(_suggest_popup_genlist,
"suggest_list");
ic = elm_genlist_item_class_new();
ic->item_style = "full";
ic->func.content_get = _autocomplete_list_content_get;
ic->func.content_get = _suggest_list_content_get;
EINA_LIST_FOREACH(list, l, auto_str)
{
if (eina_str_has_prefix(auto_str, word))
{
elm_genlist_item_append(_clang_autocomplete_popup_genlist,
elm_genlist_item_append(_suggest_popup_genlist,
ic,
auto_str,
NULL,
@ -166,15 +166,15 @@ _autocomplete_list_update(char *word)
}
elm_genlist_item_class_free(ic);
item = elm_genlist_first_item_get(_clang_autocomplete_popup_genlist);
item = elm_genlist_first_item_get(_suggest_popup_genlist);
if (item)
elm_genlist_item_selected_set(item, EINA_TRUE);
else
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
}
static void
_autocomplete_list_set(Edi_Editor *editor)
_suggest_list_set(Edi_Editor *editor)
{
Elm_Code *code;
CXIndex idx;
@ -186,16 +186,15 @@ _autocomplete_list_set(Edi_Editor *editor)
unsigned int clang_argc, row, col;
Eina_List *list = NULL;
list = (Eina_List *)evas_object_data_get(_clang_autocomplete_popup_genlist,
"autocomplete_list");
list = (Eina_List *)evas_object_data_get(_suggest_popup_genlist,
"suggest_list");
if (list)
{
char *temp_str;
EINA_LIST_FREE(list, temp_str)
free(temp_str);
list = NULL;
evas_object_data_del(_clang_autocomplete_popup_genlist,
"autocomplete_list");
evas_object_data_del(_suggest_popup_genlist, "suggest_list");
}
elm_code_widget_cursor_position_get(editor->entry, &row, &col);
@ -248,37 +247,35 @@ _autocomplete_list_set(Edi_Editor *editor)
clang_disposeTranslationUnit(tx_unit);
clang_disposeIndex(idx);
evas_object_data_set(_clang_autocomplete_popup_genlist,
"autocomplete_list", list);
_autocomplete_list_update(curword);
evas_object_data_set(_suggest_popup_genlist, "suggest_list", list);
_suggest_list_update(curword);
free(curword);
}
static void
_autocomplete_bg_cb_hide(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
_suggest_bg_cb_hide(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Eina_List *list = NULL;
list = (Eina_List *)evas_object_data_get(_clang_autocomplete_popup_genlist,
"autocomplete_list");
list = (Eina_List *)evas_object_data_get(_suggest_popup_genlist,
"suggest_list");
if (list)
{
char *temp_str;
EINA_LIST_FREE(list, temp_str)
free(temp_str);
list = NULL;
evas_object_data_del(_clang_autocomplete_popup_genlist,
"autocomplete_list");
evas_object_data_del(_suggest_popup_genlist, "suggest_list");
}
evas_object_key_ungrab(_clang_autocomplete_popup_genlist, "Return", 0, 0);
evas_object_key_ungrab(_clang_autocomplete_popup_genlist, "Up", 0, 0);
evas_object_key_ungrab(_clang_autocomplete_popup_genlist, "Down", 0, 0);
evas_object_key_ungrab(_suggest_popup_genlist, "Return", 0, 0);
evas_object_key_ungrab(_suggest_popup_genlist, "Up", 0, 0);
evas_object_key_ungrab(_suggest_popup_genlist, "Down", 0, 0);
}
static void
_autocomplete_list_cb_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
Evas_Object *obj, void *event_info)
_suggest_list_cb_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
Evas_Object *obj, void *event_info)
{
Edi_Mainview_Item *m_it;
Elm_Object_Item *it;
@ -317,7 +314,7 @@ _autocomplete_list_cb_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
list_word, strlen(list_word));
elm_code_widget_cursor_position_set(editor->entry, row,
col - wordlen + strlen(list_word));
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
}
else if (!strcmp(ev->key, "Up"))
{
@ -338,50 +335,46 @@ _autocomplete_list_cb_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
}
static void
_autocomplete_list_cb_focus(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event_info)
_suggest_list_cb_focus(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info)
{
Elm_Object_Item *it = event_info;
elm_genlist_item_selected_set(it, EINA_TRUE);
}
static void
_clang_autocomplete_popup_show(Edi_Editor *editor)
_suggest_popup_show(Edi_Editor *editor)
{
unsigned int col, row;
Evas_Coord cx, cy, cw, ch;
if (elm_genlist_items_count(_clang_autocomplete_popup_genlist) <= 0)
if (elm_genlist_items_count(_suggest_popup_genlist) <= 0)
return;
elm_code_widget_cursor_position_get(editor->entry, &row, &col);
elm_code_widget_geometry_for_position_get(editor->entry, row, col,
&cx, &cy, &cw, &ch);
evas_object_move(_clang_autocomplete_popup_bg, cx, cy);
evas_object_show(_clang_autocomplete_popup_bg);
evas_object_move(_suggest_popup_bg, cx, cy);
evas_object_show(_suggest_popup_bg);
if (!evas_object_key_grab(_clang_autocomplete_popup_genlist, "Return", 0, 0,
EINA_TRUE))
if (!evas_object_key_grab(_suggest_popup_genlist, "Return", 0, 0, EINA_TRUE))
ERR("Failed to grab key - %s", "Return");
if (!evas_object_key_grab(_clang_autocomplete_popup_genlist, "Up", 0, 0,
EINA_TRUE))
if (!evas_object_key_grab(_suggest_popup_genlist, "Up", 0, 0, EINA_TRUE))
ERR("Failed to grab key - %s", "Up");
if (!evas_object_key_grab(_clang_autocomplete_popup_genlist, "Down", 0, 0,
EINA_TRUE))
if (!evas_object_key_grab(_suggest_popup_genlist, "Down", 0, 0, EINA_TRUE))
ERR("Failed to grab key - %s", "Down");
}
static void
_clang_autocomplete_popup_key_down_cb(Edi_Editor *editor, const char *key,
const char *string)
_suggest_popup_key_down_cb(Edi_Editor *editor, const char *key, const char *string)
{
Elm_Code *code;
Elm_Code_Line *line;
unsigned int col, row;
char *word;
if (!evas_object_visible_get(_clang_autocomplete_popup_bg))
if (!evas_object_visible_get(_suggest_popup_bg))
return;
elm_code_widget_cursor_position_get(editor->entry, &row, &col);
@ -393,17 +386,17 @@ _clang_autocomplete_popup_key_down_cb(Edi_Editor *editor, const char *key,
{
if (col - 1 <= 0)
{
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
return;
}
word = _edi_editor_current_word_get(editor, row, col - 1);
if (!strcmp(word, ""))
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
else
{
_autocomplete_list_update(word);
_clang_autocomplete_popup_show(editor);
_suggest_list_update(word);
_suggest_popup_show(editor);
}
free(word);
}
@ -411,17 +404,17 @@ _clang_autocomplete_popup_key_down_cb(Edi_Editor *editor, const char *key,
{
if (line->length < col)
{
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
return;
}
word = _edi_editor_current_word_get(editor, row, col + 1);
if (!strcmp(word, ""))
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
else
{
_autocomplete_list_update(word);
_clang_autocomplete_popup_show(editor);
_suggest_list_update(word);
_suggest_popup_show(editor);
}
free(word);
}
@ -429,23 +422,23 @@ _clang_autocomplete_popup_key_down_cb(Edi_Editor *editor, const char *key,
{
if (col - 1 <= 0)
{
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
return;
}
word = _edi_editor_current_word_get(editor, row, col - 1);
if (!strcmp(word, ""))
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
else
{
_autocomplete_list_update(word);
_clang_autocomplete_popup_show(editor);
_suggest_list_update(word);
_suggest_popup_show(editor);
}
free(word);
}
else if (!strcmp(key, "Escape"))
{
evas_object_hide(_clang_autocomplete_popup_bg);
evas_object_hide(_suggest_popup_bg);
}
else if (!strcmp(key, "Delete"))
{
@ -455,32 +448,32 @@ _clang_autocomplete_popup_key_down_cb(Edi_Editor *editor, const char *key,
{
word = _edi_editor_current_word_get(editor, row, col);
strncat(word, string, 1);
_autocomplete_list_update(word);
_clang_autocomplete_popup_show(editor);
_suggest_list_update(word);
_suggest_popup_show(editor);
free(word);
}
}
static void
_clang_autocomplete_popup_init(Edi_Editor *editor)
_suggest_popup_init(Edi_Editor *editor)
{
//Popup bg
Evas_Object *bg = elm_bubble_add(editor->entry);
_clang_autocomplete_popup_bg = bg;
_suggest_popup_bg = bg;
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_event_callback_add(bg, EVAS_CALLBACK_HIDE,
_autocomplete_bg_cb_hide, NULL);
_suggest_bg_cb_hide, NULL);
evas_object_resize(bg, 350, 200);
//Genlist
Evas_Object *genlist = elm_genlist_add(editor->entry);
_clang_autocomplete_popup_genlist = genlist;
_suggest_popup_genlist = genlist;
elm_object_focus_allow_set(genlist, EINA_FALSE);
evas_object_event_callback_add(genlist, EVAS_CALLBACK_KEY_DOWN,
_autocomplete_list_cb_key_down, NULL);
_suggest_list_cb_key_down, NULL);
evas_object_smart_callback_add(genlist, "item,focused",
_autocomplete_list_cb_focus, NULL);
_suggest_list_cb_focus, NULL);
elm_object_content_set(bg, genlist);
evas_object_show(genlist);
}
@ -531,14 +524,14 @@ _smart_cb_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
#if HAVE_LIBCLANG
else if (!strcmp(ev->key, "space"))
{
_autocomplete_list_set(editor);
_clang_autocomplete_popup_show(editor);
_suggest_list_set(editor);
_suggest_popup_show(editor);
}
#endif
}
#if HAVE_LIBCLANG
if ((!alt) && (!ctrl))
_clang_autocomplete_popup_key_down_cb(editor, ev->key, ev->string);
_suggest_popup_key_down_cb(editor, ev->key, ev->string);
#endif
}
@ -918,8 +911,8 @@ _mouse_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
event = (Evas_Event_Mouse_Up *)event_info;
#if HAVE_LIBCLANG
if (_clang_autocomplete_popup_bg)
evas_object_hide(_clang_autocomplete_popup_bg);
if (_suggest_popup_bg)
evas_object_hide(_suggest_popup_bg);
#endif
ctrl = evas_key_modifier_is_set(event->modifiers, "Control");
@ -1078,7 +1071,7 @@ edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item)
evas_object_event_callback_add(vbox, EVAS_CALLBACK_DEL, _editor_del_cb, ev_handler);
#if HAVE_LIBCLANG
_clang_autocomplete_popup_init(editor);
_suggest_popup_init(editor);
#endif
return vbox;
}