summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2014-12-25 19:12:45 +0200
committerYakov Goldberg <yakov.g@samsung.com>2014-12-28 15:58:08 +0200
commit20dffebd1e5ea0cf97e0d8ed36b5fc9cdc1adc36 (patch)
tree03e3217fc9ea111818ab4bdc7afefb817aa14831 /src/bin
parent6de136c0c7d708f33e912cc1909f687aaded953f (diff)
filtering
Signed-off-by: Yakov Goldberg <yakov.g@samsung.com>
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/egui_gui/egui_logic.c13
-rw-r--r--src/bin/egui_gui/objtree.c128
2 files changed, 124 insertions, 17 deletions
diff --git a/src/bin/egui_gui/egui_logic.c b/src/bin/egui_gui/egui_logic.c
index ed454ec..d6884d9 100644
--- a/src/bin/egui_gui/egui_logic.c
+++ b/src/bin/egui_gui/egui_logic.c
@@ -783,16 +783,9 @@ _factory_vertical_pack(Eina_Bool vertical_pack)
783 783
784/* Filter function to be called, when Filter entry is changed. */ 784/* Filter function to be called, when Filter entry is changed. */
785static void 785static void
786_entry_changed_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) 786_objtree_filter_entry_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
787{ 787{
788 const char *str = elm_entry_entry_get(obj); 788 objtree_build(_active_context_get());
789 if (!str)
790 {
791 objtree_item_selected_set(NULL);
792 return;
793 }
794 Gui_Widget *wdg = wdg_first_find(_active_context_get(), str);
795 objtree_item_selected_set(wdg);
796} 789}
797 790
798Eina_Bool 791Eina_Bool
@@ -881,7 +874,7 @@ egui_start()
881 key_binding_new(_key_binding_save_cb, (void *) (intptr_t) ITEM_SAVE, "ctrl", "s", NULL); 874 key_binding_new(_key_binding_save_cb, (void *) (intptr_t) ITEM_SAVE, "ctrl", "s", NULL);
882 key_binding_new(_key_binding_save_cb, (void *) (intptr_t) ITEM_SAVEAS, "shift", "ctrl", "s", NULL); 875 key_binding_new(_key_binding_save_cb, (void *) (intptr_t) ITEM_SAVEAS, "shift", "ctrl", "s", NULL);
883 876
884 evas_object_smart_callback_add(g_main_wdgs->main_win->objtree_filter_entry, "changed,user", _entry_changed_cb, NULL); 877 evas_object_smart_callback_add(g_main_wdgs->main_win->objtree_filter_entry, "changed,user", _objtree_filter_entry_changed_cb, NULL);
885 878
886 _idle_enterer = ecore_idle_enterer_add(_canvas_bg_show_on_idle, NULL); 879 _idle_enterer = ecore_idle_enterer_add(_canvas_bg_show_on_idle, NULL);
887 /* Toolbar */ 880 /* Toolbar */
diff --git a/src/bin/egui_gui/objtree.c b/src/bin/egui_gui/objtree.c
index 492bc55..f4fcc47 100644
--- a/src/bin/egui_gui/objtree.c
+++ b/src/bin/egui_gui/objtree.c
@@ -5,6 +5,10 @@
5#include "egui_layout.h" 5#include "egui_layout.h"
6 6
7static Eo *lst = NULL; 7static Eo *lst = NULL;
8/*List to keep filtered widgets.
9 * Cleared each time when objtree is built. */
10static Eina_List *filter_list = NULL;
11
8static const Gui_Context *active_ctx = NULL; 12static const Gui_Context *active_ctx = NULL;
9 13
10static ObjTreeViewCbs *_view_cbs = NULL; 14static ObjTreeViewCbs *_view_cbs = NULL;
@@ -17,6 +21,16 @@ static Eina_Hash *_widgets_to_items_hash_table = NULL;
17/* Hash table to keep track of which items are oppened and which not */ 21/* Hash table to keep track of which items are oppened and which not */
18static Eina_Hash *_openned_items_set = NULL; 22static Eina_Hash *_openned_items_set = NULL;
19 23
24static const char *
25_objtree_filter_entry_string_get()
26{
27 Egui_Layout_Widgets *g = egui_layout_gui_get();
28 const char *str = elm_entry_entry_get(g->main_win->objtree_filter_entry);
29 //Trim from left
30 while (*str == ' ') str++;
31 return strlen(str) ? str : NULL;
32}
33
20static char * 34static char *
21_item_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part) 35_item_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
22{ 36{
@@ -71,27 +85,50 @@ _item_expand(Gui_Widget *wdg, Elm_Object_Item *parent)
71 Elm_Object_Item *nitem; 85 Elm_Object_Item *nitem;
72 const Eina_List *w_list, *l; 86 const Eina_List *w_list, *l;
73 87
74 if (wdg) eina_hash_set(_openned_items_set, wdg_name_get(wdg), (void*)1); 88 if (wdg) eina_hash_set(_openned_items_set, wdg_name_get(wdg), (void *) 1);
75 89
76 /* if wdg == NULL, this is root item, so add items for windows; 90 /* if wdg == NULL, this is root item, so add items for windows;
77 * or add items for child widgets. */ 91 * or add items for child widgets. */
78 w_list = wdg ? wdg_children_list_get(wdg) : 92 w_list = wdg ? wdg_children_list_get(wdg) :
79 gui_context_main_widgets_get(active_ctx); 93 gui_context_main_widgets_get(active_ctx);
80 94
95 /* If filter_entry in not empty, we are in filter mode*/
96 const char *filter_str = _objtree_filter_entry_string_get();
81 /* Addind child's items into objtree view. */ 97 /* Addind child's items into objtree view. */
82 EINA_LIST_FOREACH(w_list, l, wid) 98 EINA_LIST_FOREACH(w_list, l, wid)
83 { 99 {
100 Eina_Bool filtered = EINA_FALSE;
84 Gui_Widget *w = wdg_get(wid); 101 Gui_Widget *w = wdg_get(wid);
85 if (!w) continue; 102 if (!w) continue;
103 /* This condition is needed to add items when filtering by typing. */
104 if (filter_list)
105 {
106 if (!eina_list_data_find(filter_list, w)) continue;
107 filtered = EINA_TRUE;
108 filter_list = eina_list_remove(filter_list, w);
109 }
110 /* This condition is needed to filter items when expand/contract items. */
111 else
112 {
113 if (filter_str && strstr(wdg_name_get(w), filter_str))
114 {
115 filtered = EINA_TRUE;
116 }
117 }
86 118
87 const char *wdgname = wdg_name_get(w); 119 const char *wdgname = wdg_name_get(w);
88 type = (wdg_children_list_get(w)) ? ELM_GENLIST_ITEM_TREE : ELM_GENLIST_ITEM_NONE; 120 type = (wdg_children_list_get(w)) ? ELM_GENLIST_ITEM_TREE : ELM_GENLIST_ITEM_NONE;
89 nitem = elm_genlist_item_append(lst, _itc, w, parent, 121 if (!filter_str || (filter_str && filtered))
90 type, _view_cbs->item_selection_cb_func, NULL); 122 {
91 eina_hash_set(_widgets_to_items_hash_table, wdgname, nitem); 123 nitem = elm_genlist_item_append(lst, _itc, w, parent,
92 124 type, _view_cbs->item_selection_cb_func, NULL);
93 if (eina_hash_find(_openned_items_set, wdgname)) 125 eina_hash_set(_widgets_to_items_hash_table, wdgname, nitem);
94 elm_genlist_item_expanded_set(nitem, EINA_TRUE); 126
127 /* Expand item if it is in _opened_hash or if item meets filter condition. */
128 if ((eina_hash_find(_openned_items_set, wdgname)) ||
129 (filter_str && filtered))
130 elm_genlist_item_expanded_set(nitem, EINA_TRUE);
131 }
95 } 132 }
96} 133}
97 134
@@ -180,6 +217,17 @@ void
180objtree_item_selected_set(const Gui_Widget *wdg) 217objtree_item_selected_set(const Gui_Widget *wdg)
181{ 218{
182 Elm_Object_Item *item = NULL; 219 Elm_Object_Item *item = NULL;
220
221 /* If filter was active, need to drop filter and clear open items hash. */
222 if (_objtree_filter_entry_string_get())
223 {
224 Egui_Layout_Widgets *g = egui_layout_gui_get();
225 eo_do(g->main_win->objtree_filter_entry, elm_obj_layout_text_set(NULL, NULL));
226 /* There is no function, that clears hash, so recreate it. */
227 if (_openned_items_set) eina_hash_free(_openned_items_set);
228 _openned_items_set = eina_hash_string_superfast_new(NULL);
229 }
230
183 elm_genlist_clear(lst); 231 elm_genlist_clear(lst);
184 _item_expand(NULL, NULL); 232 _item_expand(NULL, NULL);
185 233
@@ -200,6 +248,72 @@ objtree_item_selected_set(const Gui_Widget *wdg)
200 elm_genlist_item_selected_set(item, EINA_TRUE); 248 elm_genlist_item_selected_set(item, EINA_TRUE);
201} 249}
202 250
251/* This function builds a list of items which meet filter condition. */
252void
253objtree_build(const Gui_Context *ctx)
254{
255 elm_genlist_clear(lst);
256
257 Eid *wid;
258 Eina_Bool can_merge = EINA_TRUE;
259 const Eina_List *itr;
260 Eina_List *tmp_list = NULL;
261
262 const char *filter_str = _objtree_filter_entry_string_get();
263 /* Cleate list of widgets, whose names contain filter str.
264 * Parents of these widgets are also in this list. */
265 if (filter_str)
266 {
267 Eina_List *wdg_lst = wdg_lst_get(ctx);
268 EINA_LIST_FOREACH(wdg_lst, itr, wid)
269 {
270 can_merge = EINA_TRUE;
271 const Gui_Widget *wdg = wdg_get(wid), *wdg_parent;
272 if (!wdg) continue;
273 const char *wdg_name = wdg_name_get(wdg);
274 if (strstr(wdg_name, filter_str))
275 {
276 if (!eina_list_data_find(filter_list, wdg))
277 tmp_list = eina_list_append(tmp_list, wdg);
278
279 while (wdg)
280 {
281 if (IS_MAIN(wdg)) break;
282 wdg_parent = wdg_parent_get(wdg);
283 if (!IS_MAIN(wdg) && !wdg_parent)
284 {
285 can_merge = EINA_FALSE;
286 break;
287 }
288 wdg_name = wdg_name_get(wdg_parent);
289 if (!eina_list_data_find(filter_list, wdg_parent))
290 tmp_list = eina_list_append(tmp_list, wdg_parent);
291 wdg = wdg_parent;
292 }
293 }
294 if (can_merge)
295 {
296 Eina_List *llst = eina_list_merge(filter_list, tmp_list);
297 filter_list = eina_list_clone(llst);
298 }
299 else
300 {
301 eina_list_free(tmp_list);
302 }
303 tmp_list = NULL;
304 }
305 }
306 else
307 {
308 /* During typing in entry filter, clear hash when sting is empty. */
309 if (_openned_items_set) eina_hash_free(_openned_items_set);
310 _openned_items_set = eina_hash_string_superfast_new(NULL);
311 }
312
313 _item_expand(NULL, NULL);
314}
315
316
203/* Remove an item */ 317/* Remove an item */
204void 318void
205objtree_item_remove(const Gui_Widget *wdg) 319objtree_item_remove(const Gui_Widget *wdg)