jackdanielz pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=d33b8783c8274f81e40d6e75c57c853b9e45d203

commit d33b8783c8274f81e40d6e75c57c853b9e45d203
Author: Daniel Zaoui <daniel.za...@samsung.com>
Date:   Thu Nov 5 11:32:44 2015 +0200

    Parser: fix parent in case DnD data is wrong
    
    If a dragged widget contains a parent that doesn't exist in the JSON
    data, we have to set its parent to prevent conflicts with widgets
    existing in the context.
---
 src/bin/gui/editor.c | 18 +++++-------------
 src/lib/gui_parser.c | 29 ++++++++++++++++++++---------
 2 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c
index c0691fe..935c07c 100644
--- a/src/bin/gui/editor.c
+++ b/src/bin/gui/editor.c
@@ -1527,7 +1527,7 @@ _table_borders_draw(Eo *table, int w, int h, Eina_List 
**_border_objects)
 }
 
 static Gui_Widget *
-_editor_wdg_create(Gui_Context *ctx, const char *json_data, const Gui_Widget 
*parent)
+_editor_wdg_create(Gui_Context *ctx, const char *json_data)
 {
    Eina_List *lst = NULL;
    if (!gui_parser_json_parse(ctx, json_data, EINA_TRUE, EINA_TRUE, &lst))
@@ -1535,16 +1535,8 @@ _editor_wdg_create(Gui_Context *ctx, const char 
*json_data, const Gui_Widget *pa
         ERR("Can not parse: \n%s", json_data);
         return NULL;
      }
-   if (eina_list_count(lst) != 1)
-     {
-        ERR("Number of main widgets in JSON data has to be 1, have: %d \n", 
eina_list_count(lst));
-        //return NULL;
-     }
    Eid *wdg_id = eina_list_data_get(lst);
-   Gui_Widget *wdg = wdg_get(wdg_id);
-   if (parent)
-      wdg_parent_set(wdg, wdg_name_get(parent));
-   return wdg;
+   return wdg_get(wdg_id);
 }
 
 static Gui_Widget *_dragged_wdg;
@@ -1767,7 +1759,7 @@ _drop_target_drop(Gui_Widget *wdg, Eo 
*canvas_drop_target, const char *drag_data
 
    /* FIXME: delete this, as wdg_cur must be created in _drop_target_pos()*/
    if (!_dragged_wdg)
-     _dragged_wdg = _editor_wdg_create(_active_context_get(), drag_data, NULL);
+     _dragged_wdg = _editor_wdg_create(_active_context_get(), drag_data);
 
    new_wdg = _dragged_wdg;
    if (!dnd_is_source())
@@ -1958,7 +1950,7 @@ _objtree_pos_cb(void *data EINA_UNUSED, Evas_Object *cont 
EINA_UNUSED, Elm_Objec
              //printf("Enter ZZZ%sZZZ\n", _drop_data);
              if (!_dragged_wdg)
                {
-                  _dragged_wdg = _editor_wdg_create(_active_context_get(), 
drop_data, NULL);
+                  _dragged_wdg = _editor_wdg_create(_active_context_get(), 
drop_data);
                }
           }
      }
@@ -2075,7 +2067,7 @@ _drop_target_pos(void *data, Eo *obj, Evas_Coord x, 
Evas_Coord y, Elm_Xdnd_Actio
              /* Creation of the wdg */
              if (!_dragged_wdg)
                {
-                  _dragged_wdg = _editor_wdg_create(_active_context_get(), 
drop_data, NULL);
+                  _dragged_wdg = _editor_wdg_create(_active_context_get(), 
drop_data);
                }
           }
      }
diff --git a/src/lib/gui_parser.c b/src/lib/gui_parser.c
index a79df07..b4d9996 100644
--- a/src/lib/gui_parser.c
+++ b/src/lib/gui_parser.c
@@ -467,9 +467,9 @@ _read_items_section(const Gui_Context *gui_ctx, Gui_Widget 
*wdg, Item_Container_
    eina_iterator_free(it);
 }
 
-/* if null_parent is EINA_TRUE, set parent to NULL*/
+/* if fix_parent is EINA_TRUE, set parent to NULL in case the parent doesn't 
exist */
 static Eina_Bool
-_widget_parse(Gui_Context *gui_ctx, Eid *eid, Eina_Json_Value *widget_js, 
Eina_Bool null_parent, const char *json_version EINA_UNUSED)
+_widget_parse(Gui_Context *gui_ctx, Eid *eid, Eina_Json_Value *widget_js, 
Eina_Bool fix_parent, Eina_List *local_wdg_names, const char *json_version 
EINA_UNUSED)
 {
    /* Creation of widget */
    const char *class_name = NULL, *parent_name = NULL;
@@ -494,7 +494,17 @@ _widget_parse(Gui_Context *gui_ctx, Eid *eid, 
Eina_Json_Value *widget_js, Eina_B
    if ((j) && (eina_json_type_get(j) == EINA_JSON_TYPE_STRING))
       parent_name = eina_json_string_get(j);
 
-   if (null_parent) parent_name = NULL;
+   if (fix_parent)
+     {
+        Eina_List *itr;
+        const char *local_name;
+        Eina_Bool found = EINA_FALSE;
+        EINA_LIST_FOREACH(local_wdg_names, itr, local_name)
+          {
+             if (!strcmp(local_name, widget_name)) found = EINA_TRUE;
+          }
+        if (!found) parent_name = NULL;
+     }
    if (!wdg_parent_set(wdg, parent_name))
      {
         goto bad_end;
@@ -995,16 +1005,16 @@ _erigo_settings_parse(Gui_Context *gui_ctx, 
Eina_Json_Value *res_js)
 
 /* Register name and save JSON in list.
  *
- * if null_parent is EINA_TRUE, set only first parent to NULL,
- * this is used to null parent, when generating DnD widget from widget */
+ * if fix_parent is EINA_TRUE, we set the parent to NULL in case the given 
parent doesn't exist in the given JSON,
+ * this is used during DnD */
 Eina_Bool
-gui_parser_json_parse(Gui_Context *gui_ctx, const char *_data, Eina_Bool 
rename, Eina_Bool null_parent, Eina_List **mains)
+gui_parser_json_parse(Gui_Context *gui_ctx, const char *_data, Eina_Bool 
rename, Eina_Bool fix_parent, Eina_List **mains)
 {
    Eina_Json_Context *ctx = eina_json_context_dom_new();
    Eina_Json_Type type;
    Eina_Bool err = eina_json_context_parse(ctx, _data);
    Eina_Bool parse_ret = EINA_TRUE;
-   Eina_List *wdgs, *itr;
+   Eina_List *wdgs, *itr, *local_wdg_names = NULL;
    Eid *wdg_id;
    if (!err)
      {
@@ -1055,6 +1065,7 @@ gui_parser_json_parse(Gui_Context *gui_ctx, const char 
*_data, Eina_Bool rename,
         const char *class_name = eina_json_string_get(j);
         char *realname = NULL;
 
+        if (fix_parent) local_wdg_names = eina_list_append(local_wdg_names, 
eina_stringshare_add(name));
         if (rename)
           {
              realname = gui_context_free_name_get(gui_ctx, class_name);
@@ -1104,8 +1115,7 @@ gui_parser_json_parse(Gui_Context *gui_ctx, const char 
*_data, Eina_Bool rename,
                   parse_ret = EINA_FALSE;
                   break;
                }
-             parse_ret = _widget_parse(gui_ctx, name_id, c, null_parent, 
json_version);
-             null_parent = EINA_FALSE;
+             parse_ret = _widget_parse(gui_ctx, name_id, c, fix_parent, 
local_wdg_names, json_version);
              if (!parse_ret)
                {
                   ERR("Can not parse widget: \"%s\"", name);
@@ -1124,6 +1134,7 @@ gui_parser_json_parse(Gui_Context *gui_ctx, const char 
*_data, Eina_Bool rename,
      }
 
 end:
+   EINA_LIST_FREE(local_wdg_names, name) eina_stringshare_del(name);
    gui_context_nicknames_clear(gui_ctx);
    eina_json_value_free(jv);
    eina_json_context_free(ctx);

-- 


Reply via email to