jaehwan pushed a commit to branch master.

http://git.enlightenment.org/tools/eflete.git/commit/?id=89bf1d6eaed56507eafae9ee57df56f8100b7be4

commit 89bf1d6eaed56507eafae9ee57df56f8100b7be4
Author: Jaehwan Kim <jae.hwan....@samsung.com>
Date:   Wed Apr 27 19:54:26 2016 +0900

    import_edj: compose the widget list by existing widget in edj
    
    When the edj path is set, it reads widget list from edj.
    If the widget list doesn't exist, it can create without checking the widget.
    But if not, it should be chosen at least one widget.
---
 src/bin/common/string_common.c          |  22 +++
 src/bin/common/string_common.h          |   3 +
 src/bin/project_manager/group_manager.c |  24 +---
 src/bin/ui/tab_home_import_edj.c        | 248 +++++++++++++++++---------------
 4 files changed, 155 insertions(+), 142 deletions(-)

diff --git a/src/bin/common/string_common.c b/src/bin/common/string_common.c
index d5de437..ea14527 100644
--- a/src/bin/common/string_common.c
+++ b/src/bin/common/string_common.c
@@ -59,3 +59,25 @@ string_char_replace(char *str, char src, char rep)
         str++;
      }
 }
+
+const char *
+widget_name_get(const Eina_Stringshare *group_name)
+{
+    int len = strlen(group_name);
+    int i;
+    char str[32];
+
+    if (group_name[0] != 'e') return NULL;
+    if (group_name[1] != 'l') return NULL;
+    if (group_name[2] != 'm') return NULL;
+    if (group_name[3] != '/') return NULL;
+
+    for (i = 4; i < len; i++)
+    {
+        if (group_name[i] == '/') break;
+        str[i - 4] = group_name[i];
+    }
+    str[i - 4] = '\0';
+
+    return strdup(str);
+}
diff --git a/src/bin/common/string_common.h b/src/bin/common/string_common.h
index f49b20b..47e2058 100644
--- a/src/bin/common/string_common.h
+++ b/src/bin/common/string_common.h
@@ -58,4 +58,7 @@ state_name_split(Eina_Stringshare *name, Eina_Stringshare 
**name_out, double *va
 void
 string_char_replace(char *str, char src, char rep);
 
+const char *
+widget_name_get(const Eina_Stringshare *group_name);
+
 #endif /* STRING_MACRO_H */
diff --git a/src/bin/project_manager/group_manager.c 
b/src/bin/project_manager/group_manager.c
index c9bdb00..4eb7d21 100644
--- a/src/bin/project_manager/group_manager.c
+++ b/src/bin/project_manager/group_manager.c
@@ -425,28 +425,6 @@ gm_group_del(Project *pro, Group *group)
    free(group);
 }
 
-char *
-_get_widget_name(const Eina_Stringshare *group_name)
-{
-    int len = strlen(group_name);
-    int i;
-    char str[32];
-
-    if (group_name[0] != 'e') return NULL;
-    if (group_name[1] != 'l') return NULL;
-    if (group_name[2] != 'm') return NULL;
-    if (group_name[3] != '/') return NULL;
-
-    for (i = 4; i < len; i++)
-    {
-        if (group_name[i] == '/') break;
-        str[i - 4] = group_name[i];
-    }
-    str[i - 4] = '\0';
-
-    return strdup(str);
-}
-
 void
 gm_groups_load(Project *pro)
 {
@@ -473,7 +451,7 @@ gm_groups_load(Project *pro)
 
         if (pro->widgets)
           {
-             widget_name = _get_widget_name(group_name);
+             widget_name = widget_name_get(group_name);
              if (!widget_name) continue;
              EINA_LIST_FOREACH(pro->widgets, wl, checked_widget)
                {
diff --git a/src/bin/ui/tab_home_import_edj.c b/src/bin/ui/tab_home_import_edj.c
index 4a07d5a..9221974 100644
--- a/src/bin/ui/tab_home_import_edj.c
+++ b/src/bin/ui/tab_home_import_edj.c
@@ -33,64 +33,8 @@ struct _Widget_Item_Data
 };
 typedef struct _Widget_Item_Data Widget_Item_Data;
 
-static Widget_Item_Data widget_item_data[] =
-   {
-     { N_("access"),           false },
-     { N_("actionslider"),     false },
-     { N_("bg"),               false },
-     { N_("border"),           false },
-     { N_("bubble"),           false },
-     { N_("button"),           false },
-     { N_("calendar"),         false },
-     { N_("check"),            false },
-     { N_("clock"),            false },
-     { N_("colorsel"),         false },
-     { N_("conform"),          false },
-     { N_("ctxpopup"),         false },
-     { N_("cursor"),           false },
-     { N_("datetime"),         false },
-     { N_("dayselector"),      false },
-     { N_("diskselector"),     false },
-     { N_("entry"),            false },
-     { N_("fileselector"),     false },
-     { N_("flipselector"),     false },
-     { N_("focus"),            false },
-     { N_("frame"),            false },
-     { N_("gengrid"),          false },
-     { N_("genlist"),          false },
-     { N_("hover"),            false },
-     { N_("icon"),             false },
-     { N_("index"),            false },
-     { N_("label"),            false },
-     { N_("layout"),           false },
-     { N_("list"),             false },
-     { N_("map"),              false },
-     { N_("menu"),             false },
-     { N_("multibuttonentry"), false },
-     { N_("naviframe"),        false },
-     { N_("notify"),           false },
-     { N_("panel"),            false },
-     { N_("panes"),            false },
-     { N_("photo"),            false },
-     { N_("photocam"),         false },
-     { N_("player"),           false },
-     { N_("pointer"),          false },
-     { N_("popup"),            false },
-     { N_("progress"),         false },
-     { N_("radio"),            false },
-     { N_("scroller"),         false },
-     { N_("segment_control"),  false },
-     { N_("separator"),        false },
-     { N_("slider"),           false },
-     { N_("slideshow"),        false },
-     { N_("spinner"),          false },
-     { N_("thumb"),            false },
-     { N_("toolbar"),          false },
-     { N_("tooltip"),          false },
-     { N_("video"),            false },
-     { N_("win"),              false },
-     { NULL,                   false }
-   };
+Eina_List *widget_list = NULL;
+const char *prev_edj_path = NULL;
 
 struct _Tab_Home_Edj
 {
@@ -111,17 +55,26 @@ struct _Tab_Home_Edj
 typedef struct _Tab_Home_Edj Tab_Home_Edj;
 static Tab_Home_Edj tab_edj;
 
+static char *_genlist_label_get(void *data,
+                                Evas_Object *obj,
+                                const char  *part);
+
+static Evas_Object *_genlist_content_get(void *data,
+                                         Evas_Object *obj,
+                                         const char *part);
+
+
 /* CHECK ALL AND NOT ALL */
 static void
 _checks_set(Eina_Bool check_val)
 {
-   Widget_Item_Data *widget_item_data_iterator = widget_item_data;
+   Widget_Item_Data *widget = NULL;
+   Eina_List *l;
 
-   while (widget_item_data_iterator->name)
+   EINA_LIST_FOREACH(widget_list, l, widget)
      {
-        if (widget_item_data_iterator->check != check_val)
-          widget_item_data_iterator->check = check_val;
-        widget_item_data_iterator++;
+        if (widget->check != check_val)
+          widget->check = check_val;
      }
    elm_genlist_realized_items_update(tab_edj.genlist);
 }
@@ -129,51 +82,121 @@ _checks_set(Eina_Bool check_val)
 static Eina_Bool
 _checked_get(void)
 {
-   Widget_Item_Data *widget_item_data_iterator = widget_item_data;
+   Widget_Item_Data *widget = NULL;
+   Eina_List *l;
 
-   while (widget_item_data_iterator->name)
+   EINA_LIST_FOREACH(widget_list, l, widget)
      {
-        if (widget_item_data_iterator->check == EINA_TRUE)
-           return EINA_TRUE;
-        widget_item_data_iterator++;
+        if (widget->check)
+          return EINA_TRUE;
      }
    return EINA_FALSE;
 }
 
+static int
+_string_compare(const void *data1, const void *data2)
+{
+   Widget_Item_Data *d1, *d2;
+   d1 = (Widget_Item_Data *)data1;
+   d2 = (Widget_Item_Data *)data2;
+
+   if (!strcmp(d1->name, d2->name)) return 0;
+
+   return -1;
+}
+
 static void
-_validate(void *data __UNUSED__,
-          Evas_Object *obj __UNUSED__,
-          void *event_info __UNUSED__)
+_validate()
 {
    if ((elm_validator_regexp_status_get(tab_edj.name_validator) != 
ELM_REG_NOERROR) ||
-       ((!eina_str_has_extension(elm_entry_entry_get(tab_edj.edj), ".edj") ||
-       !ecore_file_exists(elm_entry_entry_get(tab_edj.edj))) &&
-       !_checked_get()))
+       !eina_str_has_extension(elm_entry_entry_get(tab_edj.edj), ".edj") ||
+       !ecore_file_exists(elm_entry_entry_get(tab_edj.edj)) ||
+       (widget_list && !_checked_get()))
      elm_object_disabled_set(tab_edj.btn_create, true);
    else
      elm_object_disabled_set(tab_edj.btn_create, false);
+}
 
+static void
+_name_changed_cb(void *data __UNUSED__,
+                 Evas_Object *obj __UNUSED__,
+                 void *event_info __UNUSED__)
+{
+   _validate();
 }
 
 static void
-_edj_set()
+_edj_changed_cb(void *data __UNUSED__,
+                Evas_Object *obj __UNUSED__,
+                void *event_info __UNUSED__)
 {
-   Eina_Bool checked = _checked_get();
+   const char *widget_name;
+   Eina_List *collections, *l;
+   Eina_Stringshare *group_name;
+   Widget_Item_Data *widget = NULL;
+   Elm_Genlist_Item_Class *itc = NULL;
+
+   if (prev_edj_path && !strcmp(prev_edj_path, 
elm_entry_entry_get(tab_edj.edj))) return;
+   prev_edj_path = elm_entry_entry_get(tab_edj.edj);
+
+   elm_genlist_clear(tab_edj.genlist);
 
-   if (checked)
+   EINA_LIST_FREE(widget_list, widget)
      {
-        Ewe_Combobox_Item *item = ewe_combobox_select_item_get(tab_edj.themes);
-        char buf[256];
-        if (item)
+        free(widget);
+     }
+   widget_list = NULL;
+
+   if (eina_str_has_extension(elm_entry_entry_get(tab_edj.edj), ".edj") &&
+       ecore_file_exists(elm_entry_entry_get(tab_edj.edj)))
+     {
+        collections = 
edje_file_collection_list(elm_entry_entry_get(tab_edj.edj));
+
+        assert(collections != NULL);
+
+        collections = eina_list_sort(collections, 
eina_list_count(collections), (Eina_Compare_Cb) strcmp);
+        EINA_LIST_FOREACH(collections, l, group_name)
           {
-             snprintf(buf, sizeof(buf), "%s/%s", EFLETE_TEMPLATE_EDJ_PATH, 
item->title);
-             elm_entry_entry_set(tab_edj.edj, buf);
+             if (!strcmp(group_name, EFLETE_INTERNAL_GROUP_NAME)) continue;
+             widget_name = widget_name_get(group_name);
+             if (!widget_name) continue;
+
+             widget = mem_calloc(1, sizeof(Widget_Item_Data));
+             widget->name = widget_name;
+             widget->check = false;
+             if (!eina_list_search_unsorted(widget_list, _string_compare, 
(void *)widget))
+               widget_list = eina_list_append(widget_list, widget);
           }
+
+        itc = elm_genlist_item_class_new();
+        itc->item_style = "default";
+        itc->func.text_get = _genlist_label_get;
+        itc->func.content_get = _genlist_content_get;
+
+        EINA_LIST_FOREACH(widget_list, l, widget)
+          {
+             elm_genlist_item_append(tab_edj.genlist, itc, widget,
+                                     NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
+          }
+        elm_genlist_item_class_free(itc);
+     }
+
+   _validate();
+}
+
+static void
+_edj_set()
+{
+   Ewe_Combobox_Item *item = ewe_combobox_select_item_get(tab_edj.themes);
+   char buf[256];
+   if (item)
+     {
+        snprintf(buf, sizeof(buf), "%s/%s", EFLETE_TEMPLATE_EDJ_PATH, 
item->title);
+        elm_entry_entry_set(tab_edj.edj, buf);
      }
    else elm_entry_entry_set(tab_edj.edj, "");
-   elm_object_disabled_set(tab_edj.edj, checked);
 
-   _validate(NULL, NULL, NULL);
+   _validate();
 }
 
 static void
@@ -182,7 +205,7 @@ _on_check_all(void *data __UNUSED__,
               void *event_info __UNUSED__)
 {
    _checks_set(elm_check_state_get(obj));
-   _edj_set();
+   _validate();
 }
 
 /*  GENLIST  */
@@ -194,7 +217,7 @@ _check_widget(void *data,
    Widget_Item_Data *widget_data = (Widget_Item_Data *)data;
    assert(widget_data != NULL);
    widget_data->check = elm_check_state_get(obj);
-   _edj_set();
+   _validate();
 }
 
 static char *
@@ -269,19 +292,16 @@ _progress_end(void *data, PM_Project_Result result)
 Eina_List *
 _checked_widget_list_get()
 {
-   Widget_Item_Data *widget_item_data_iterator = widget_item_data;
-   Eina_List *list = NULL;
+   Widget_Item_Data *widget = NULL;
+   Eina_List *list = NULL, *l;
 
-   while (widget_item_data_iterator->name)
+   EINA_LIST_FOREACH(widget_list, l, widget)
      {
-        if (widget_item_data_iterator->check)
-          {
-             list = eina_list_append(list, widget_item_data_iterator->name);
-          }
-        widget_item_data_iterator++;
+        if (widget->check)
+          list = eina_list_append(list, widget->name);
      }
 
-     return list;
+   return list;
 }
 
 static Eina_Bool
@@ -393,8 +413,6 @@ _elipsis_edj(void *data __UNUSED__,
 Evas_Object *
 _tab_import_edj_add(void)
 {
-   Elm_Genlist_Item_Class *itc = NULL;
-   Widget_Item_Data *widget_item_data_iterator = widget_item_data;
    Eina_List *themes = NULL, *l = NULL;
    char *theme;
 
@@ -412,7 +430,7 @@ _tab_import_edj_add(void)
    elm_object_part_text_set(tab_edj.layout, "label.name", _("Project name:"));
    ENTRY_ADD(tab_edj.layout, tab_edj.name, true)
    eo_event_callback_add(tab_edj.name, ELM_ENTRY_EVENT_VALIDATE, 
elm_validator_regexp_helper, tab_edj.name_validator);
-   evas_object_smart_callback_add(tab_edj.name, "changed", _validate, NULL);
+   evas_object_smart_callback_add(tab_edj.name, "changed", _name_changed_cb, 
NULL);
    elm_object_part_content_set(tab_edj.layout, "swallow.name", tab_edj.name);
    /* label.path */
    elm_object_part_text_set(tab_edj.layout, "label.path", _("Path to 
project:"));
@@ -424,7 +442,7 @@ _tab_import_edj_add(void)
    /* label.path */
    elm_object_part_text_set(tab_edj.layout, "label.edj", _("Path to 
edj-file:"));
    ENTRY_ADD(tab_edj.layout, tab_edj.edj, true)
-   evas_object_smart_callback_add(tab_edj.edj, "changed", _validate, NULL);
+   evas_object_smart_callback_add(tab_edj.edj, "changed", _edj_changed_cb, 
NULL);
    elm_object_part_content_set(tab_edj.layout, "swallow.edj", tab_edj.edj);
    elipsis_btn_add(tab_edj.edj, _elipsis_edj, NULL);
 
@@ -450,18 +468,7 @@ _tab_import_edj_add(void)
    /* genlist */
    tab_edj.genlist = elm_genlist_add(ap.win);
    evas_object_smart_callback_add(tab_edj.genlist, "activated", 
_on_item_activated, NULL);
-   itc = elm_genlist_item_class_new();
-   itc->item_style = "default";
-   itc->func.text_get = _genlist_label_get;
-   itc->func.content_get = _genlist_content_get;
 
-   while (widget_item_data_iterator->name)
-     {
-        elm_genlist_item_append(tab_edj.genlist, itc, 
widget_item_data_iterator,
-                                NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
-        widget_item_data_iterator++;
-     }
-   elm_genlist_item_class_free(itc);
    elm_object_part_content_set(tab_edj.layout, "swallow.widgets", 
tab_edj.genlist);
 
    return tab_edj.layout;
@@ -478,11 +485,12 @@ _delayed_popup(void *data)
 void
 _tab_import_edj_data_set(const char *name, const char *path, const char *edj, 
const Eina_List *widgets)
 {
-   const Eina_List *l;
+   const Eina_List *l, *wl;
    const char *str;
    Widget_Item_Data *widget_item_data_iterator;
    Eina_Strbuf *buf = eina_strbuf_new();
    Eina_Bool first_not_found = true;
+   Widget_Item_Data *widget = NULL;
 
    assert(tab_edj.layout != NULL);
 
@@ -492,19 +500,19 @@ _tab_import_edj_data_set(const char *name, const char 
*path, const char *edj, co
    else elm_entry_entry_set(tab_edj.path, 
profile_get()->general.projects_folder);
 
    elm_entry_entry_set(tab_edj.edj, edj);
+   edje_message_signal_process();
 
    EINA_LIST_FOREACH(widgets, l, str)
      {
-        widget_item_data_iterator = widget_item_data;
-        while (widget_item_data_iterator->name)
+        EINA_LIST_FOREACH(widget_list, wl, widget)
           {
-             if (!strcasecmp(str, widget_item_data_iterator->name))
-               break;
-             widget_item_data_iterator++;
+             if (!strcasecmp(str, widget->name))
+               {
+                  widget->check = true;
+                  break;
+               }
           }
-        if (widget_item_data_iterator->name)
-          widget_item_data_iterator->check = true;
-        else
+        if (!widget)
           {
              eina_strbuf_append_printf(buf, first_not_found ? "%s" : ", %s", 
str);
              first_not_found = false;
@@ -518,4 +526,6 @@ _tab_import_edj_data_set(const char *name, const char 
*path, const char *edj, co
         ecore_job_add(_delayed_popup, eina_strbuf_string_steal(buf));
      }
    eina_strbuf_free(buf);
+
+   _validate();
 }

-- 


Reply via email to