yakov pushed a commit to branch master.

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

commit c7bdfc14567d3152f794eff9eb79daf36d5057ec
Author: Yakov Goldberg <yako...@samsung.com>
Date:   Sun Nov 29 13:32:05 2015 +0200

    Refactoring/fixing content packing/unpacking flows
    
    Create proper flow for objects packing/repacking through
    content view and DnD.
    Reorder memento creations in these flows.
---
 src/bin/gui/editor.c | 363 +++++++++++++++++++++++++++++----------------------
 src/lib/gui_widget.c |  22 +++-
 src/lib/gui_widget.h |   5 +
 3 files changed, 232 insertions(+), 158 deletions(-)

diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c
index e4962cd..84e6af8 100644
--- a/src/bin/gui/editor.c
+++ b/src/bin/gui/editor.c
@@ -1884,7 +1884,6 @@ _drop_target_drop(Gui_Widget *drop_target_wdg, Eo 
*canvas_drop_target, const cha
      }
    else if (drop_to_wdg == DROP_TO_NAVIFRAME)
      {
-        ERR("implement drop to naviframe");
         if (di->drop_instead_item_obj)
           {
              Item_Container_Item *wit = di->drop_item_cont_item, *new_wit;
@@ -1909,7 +1908,6 @@ _drop_target_drop(Gui_Widget *drop_target_wdg, Eo 
*canvas_drop_target, const cha
                   if ((gui_value_type_get(val) == GUI_TYPE_OBJECT) &&
                       (di->drop_instead_item_obj == EID_ID_GET(val)))
                     {
-                       ERR("Found val to drop item: %s", 
eid_name_get(di->drop_instead_item_obj));
                        break;
                     }
                }
@@ -2583,6 +2581,112 @@ _drop_target_pos(void *data, Eo *obj, Evas_Coord x, 
Evas_Coord y, Elm_Xdnd_Actio
      }
 }
 
+static Gui_Widget*
+_dummy_widget_create(const Gui_Context *ctx, const Gui_Widget *parent_wdg)
+{
+   Gui_Widget *_dummy_wdg = wdg_get(gui_context_eid_get_by_name(NULL, 
"__dummy"));
+   char *new_dummy_name = gui_context_free_name_get(ctx, 
wdg_class_name_get(_dummy_wdg));
+   Eid *new_dummy_eid = eid_new((Gui_Context *)ctx, new_dummy_name, 
EID_TYPE_WIDGET);
+   free(new_dummy_name);
+   Gui_Widget *new_dummy_wdg = wdg_copy(_dummy_wdg, new_dummy_eid, EINA_TRUE);
+   wdg_parent_set(new_dummy_wdg, wdg_name_get(parent_wdg));
+   return new_dummy_wdg;
+}
+
+/* Helper to remove 'item name' widget from container
+ * and create such memento.
+ * For LAYOUT container, dummy object will be created */
+static void
+_obj_container_item_remove_helper(Gui_Widget *wdg_container, const char 
*item_name)
+{
+   const Gui_Context *ctx = wdg_context_get(wdg_container);
+   Object_Container *_old_container, *_new_container;
+   _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) 
wdg_container);
+   _new_container = obj_container_copy(_old_container);
+
+   obj_container_ref(_old_container);
+   wdg_obj_container_unset((Gui_Widget *) wdg_container);
+   wdg_obj_container_set((Gui_Widget *) wdg_container, _new_container);
+
+   /* Take old container's class name from content-property. */
+   Object_Container_Item *_ci = wdg_obj_container_item_get(wdg_container, -1, 
item_name);
+
+   int idx = 0;
+   Object_Container_Item *dummy_ci = NULL;
+   Gui_Widget *new_dummy_wdg = NULL;
+   if (!strcmp(wdg_class_name_get(wdg_container), DB_DEF_LAYOUT_CLASS))
+     {
+        new_dummy_wdg = _dummy_widget_create(ctx, wdg_container);
+        Eid *new_dummy_eid = wdg_eid_get(new_dummy_wdg);
+        memento_command_add(new_dummy_eid, MEMENTO_WIDGET,  (void *) 
(intptr_t) EINA_FALSE, (void *) (intptr_t) EINA_TRUE);
+
+        /* Creating new dummy item */
+        Gui_Widget_Property *i_prop = obj_container_item_prop_get(_ci);
+
+        idx = wdg_obj_container_item_idx_get(wdg_container, 
obj_container_item_eid_get(_ci), EINA_FALSE);
+
+        Gui_Widget_Property *new_dummy_prop = prop_copy(i_prop);
+        Gui_Value *dummy_val = prop_value_nth_get(new_dummy_prop, 1);
+        gui_value_name_id_set(dummy_val, GUI_TYPE_OBJECT, new_dummy_eid);
+        dummy_ci = obj_container_item_new(new_dummy_prop, new_dummy_eid);
+     }
+
+   wdg_obj_container_item_remove(wdg_container, _ci);
+
+   /* If dummy item was created, add it into container, create Eo and pack it. 
*/
+   if (dummy_ci)
+     {
+        wdg_obj_container_item_add(wdg_container, dummy_ci, idx);
+     }
+   memento_command_add(wdg_eid_get(wdg_container),
+                       MEMENTO_OBJ_CONTAINER,
+                       _old_container, _new_container);
+   obj_container_unref(_old_container);
+}
+
+/* If same_container param is true, new item and new memento will not be 
created. */
+static void
+_item_container_item_null_helper(const Gui_Widget *wdg_container, Eina_Bool 
same_container, const Item_Container_Item *it_to_change, const 
Gui_Widget_Property *prop_to_change, int val_idx_to_change)
+{
+   if (!wdg_container) return;
+   if (!it_to_change) return;
+   const Gui_Context *ctx = wdg_context_get(wdg_container);
+
+   Item_Container_Item *new_wit = NULL;
+   Gui_Widget_Property *new_it_prop = NULL;
+   if (same_container)
+     {
+        new_wit = (Item_Container_Item *) it_to_change;
+        new_it_prop = (Gui_Widget_Property *) prop_to_change;
+     }
+   else
+     {
+        new_wit = item_container_item_copy(it_to_change);
+        new_it_prop = prop_copy(prop_to_change);
+     }
+
+   Gui_Value *it_val = prop_value_nth_get(new_it_prop, val_idx_to_change);
+
+   if (!strcmp(wdg_class_name_get(wdg_container), DB_DEF_NAVIFRAME_CLASS))
+     {
+        Gui_Widget *dummy_wdg = _dummy_widget_create(ctx, wdg_container);
+        Eid *dummy_eid = wdg_eid_get(dummy_wdg);
+        memento_command_add(dummy_eid, MEMENTO_WIDGET,  (void *) (intptr_t) 
EINA_FALSE, (void *) (intptr_t) EINA_TRUE);
+        gui_value_name_id_set(it_val, GUI_TYPE_OBJECT, dummy_eid);
+     }
+   else
+     {
+        gui_value_name_id_set(it_val, GUI_TYPE_OBJECT, 0);
+     }
+
+   if (!same_container)
+     {
+        memento_command_add(wdg_eid_get(wdg_container), 
MEMENTO_ITEM_CONTAINER_ITEM, (Item_Container_Item *) it_to_change, new_wit);
+        item_container_item_prop_set(new_wit, new_it_prop);
+        
item_container_item_set_on_id(item_container_item_eid_get(it_to_change), 
new_wit);
+     }
+}
+
 /*********************************************************/
 
 /* This callback is called only when widget is dragged,
@@ -2627,71 +2731,60 @@ _drag_start_post(const Gui_Widget *wdg, const Eo 
*_wdg_eo)
    /* Unpack Eo object if dragging from container. */
    if (wdg_container)
      {
-        /* If container is layout, need to create new dummy instead of dragged 
widget. */
-        Eid *new_dummy_eid = NULL;
-        if (!strcmp(wdg_class_name_get(wdg_container), DB_DEF_LAYOUT_CLASS))
+        if (wdg_container_type_get(wdg_container) == OBJ_CONTAINER)
           {
-             Gui_Widget *_dummy_wdg = 
wdg_get(gui_context_eid_get_by_name(NULL, "__dummy"));
-             char *new_dummy_name = gui_context_free_name_get(ctx, 
wdg_class_name_get(_dummy_wdg));
-             new_dummy_eid = eid_new((Gui_Context *)ctx, new_dummy_name, 
EID_TYPE_WIDGET);
-             Gui_Widget *new_dummy_wdg = wdg_copy(_dummy_wdg, new_dummy_eid, 
EINA_TRUE);
-             free(new_dummy_name);
-             wdg_parent_set(new_dummy_wdg, wdg_name_get(wdg_container));
-             memento_command_add(new_dummy_eid, MEMENTO_WIDGET,  (void *) 
(intptr_t) EINA_FALSE, (void *) (intptr_t) EINA_TRUE);
-          }
-
-        Eo *wdg_cont_eo = session_eo_get(session, wdg_container);
+             /* If container is layout, need to get part of edje object and 
index within Obj Container. */
+             int idx = 0;
+             const char *part = NULL;
+             if (!strcmp(wdg_class_name_get(wdg_container), 
DB_DEF_LAYOUT_CLASS))
+               {
+                  /* Creating new dummy item */
+                  Object_Container_Item *_it = 
wdg_obj_container_item_get(wdg_container, -1, wdg_name_get(wdg));
+                  Gui_Widget_Property *i_prop = 
obj_container_item_prop_get(_it);
 
-        Object_Container *_old_prev_container, *_new_prev_container;
-        _old_prev_container = (Object_Container *) 
wdg_obj_container_get((Gui_Widget *) wdg_container);
-        _new_prev_container = obj_container_copy(_old_prev_container);
-        memento_command_add(wdg_eid_get(wdg_container),
-                            MEMENTO_OBJ_CONTAINER,
-                            _old_prev_container, _new_prev_container);
+                  idx = wdg_obj_container_item_idx_get(wdg_container, 
obj_container_item_eid_get(_it), EINA_FALSE);
+                  part = STRING_GET(prop_value_nth_get(i_prop, 0));
+               }
 
-        wdg_obj_container_unset((Gui_Widget *) wdg_container);
-        wdg_obj_container_set((Gui_Widget *) wdg_container, 
_new_prev_container);
+             _obj_container_item_remove_helper(wdg_container, 
wdg_name_get(wdg));
 
-        /* If container is layout, create, fill in property and create 
Container Item. */
-        Object_Container_Item *_ci = wdg_obj_container_item_get(wdg_container, 
-1, wdg_name_get(wdg));
-        int idx = wdg_obj_container_item_idx_get(wdg_container, 
obj_container_item_eid_get(_ci), EINA_FALSE);
-        Object_Container_Item *dummy_ci = NULL;
-        const char *part = NULL;
-        if (!strcmp(wdg_class_name_get(wdg_container), DB_DEF_LAYOUT_CLASS))
-          {
-             Gui_Widget_Property *i_prop = obj_container_item_prop_get(_ci);
-             Gui_Widget_Property *new_prop = prop_copy(i_prop);
+             /* If dummy widget was created, create Eo and pack it. */
+             Object_Container_Item *dummy_ci = 
wdg_obj_container_item_get(wdg_container, idx, NULL);
+             Eo *wdg_cont_eo = session_eo_get(session, wdg_container);
+             if (dummy_ci)
+               {
+                  Gui_Widget *dummy_wdg = 
wdg_get(obj_container_item_eid_get(dummy_ci));
+                  manager_widget_create((Gui_Session *) session, dummy_wdg, 
NULL);
+                  Eo *dummy_eo = session_eo_get(session, dummy_wdg);
+                  eo_do(wdg_cont_eo, elm_obj_container_content_unset(part));
+                  eo_do(wdg_cont_eo, elm_obj_container_content_set(part, 
dummy_eo));
+               }
 
-             Gui_Value *val = prop_value_nth_get(new_prop, 1);
-             gui_value_name_id_set(val, GUI_TYPE_OBJECT, new_dummy_eid);
-             dummy_ci = obj_container_item_new(new_prop, new_dummy_eid);
-             val = prop_value_nth_get(new_prop, 0);
-             part = STRING_GET(val);
+             /* FIXME: wdg_eo is NULL when dragging from objtree. It can be 
changed but should be?*/
+             if (wdg_eo)
+               {
+                  if (!strcmp(wdg_class_name_get(wdg_container), 
DB_DEF_BOX_CLASS))
+                    {
+                       eo_do(wdg_cont_eo, elm_obj_box_unpack(wdg_eo));
+                    }
+                  else if (!strcmp(wdg_class_name_get(wdg_container), 
DB_DEF_TABLE_CLASS))
+                    {
+                       eo_do(wdg_cont_eo, elm_obj_table_unpack(wdg_eo));
+                    }
+               }
           }
-
-        wdg_obj_container_item_remove(wdg_container, _ci);
-        /* If dummy item was created, add it into container, create Eo and 
pack it. */
-        if (dummy_ci)
+        else if (wdg_container_type_get(wdg_container) == ITEM_CONTAINER)
           {
-             wdg_obj_container_item_add(wdg_container, dummy_ci, idx);
-             Gui_Widget *wi = wdg_get(new_dummy_eid);
-
-             manager_widget_create((Gui_Session *) session, wi, NULL);
-             Eo *dummy_eo = session_eo_get(session, wi);
-             eo_do(wdg_cont_eo, elm_obj_container_content_unset(part));
-             eo_do(wdg_cont_eo, elm_obj_container_content_set(part, dummy_eo));
-          }
+             const Item_Container_Item *it = NULL;
+             const Gui_Widget_Property *it_prop = NULL;
+             int val_idx = 0;
 
-        /* FIXME: wdg_eo is NULL when dragging from objtree. It can be changed 
but should be?*/
-        if (wdg_eo)
-          {
-             if (!strcmp(wdg_class_name_get(wdg_container), DB_DEF_BOX_CLASS))
+             /* Find item, prop and value index of new_param_wdg */
+             wdg_item_container_item_get(wdg_container, (Gui_Widget *) wdg, 
&it, &it_prop, NULL, &val_idx);
+             if (it)
                {
-                  eo_do(wdg_cont_eo, elm_obj_box_unpack(wdg_eo));
-               }
-             else if (!strcmp(wdg_class_name_get(wdg_container), 
DB_DEF_TABLE_CLASS))
-               {
-                  eo_do(wdg_cont_eo, elm_obj_table_unpack(wdg_eo));
+                  /* Need to handle case when repacking inside the same 
container, so pass boolean it this is the same. */
+                  _item_container_item_null_helper(wdg_container, EINA_FALSE, 
it, it_prop, val_idx);
                }
           }
      }
@@ -3250,7 +3343,28 @@ _editor_selected_wdg_del_cb()
    if (!wdg) return;
    _editor_wdg_selected_set(NULL);
 
-   //_editor_widget_clear(wdg);
+   Eid *wdg_cont_eid = wdg_parent_container_eid_get(wdg);
+   Gui_Widget *wdg_container = wdg_cont_eid ? wdg_get(wdg_cont_eid) : NULL;
+   if (wdg_container)
+     {
+        if (wdg_container_type_get(wdg_container) == OBJ_CONTAINER)
+          {
+             _obj_container_item_remove_helper(wdg_container, 
wdg_name_get(wdg));
+          }
+        else if (wdg_container_type_get(wdg_container) == ITEM_CONTAINER)
+          {
+             const Item_Container_Item *it;
+             const Gui_Widget_Property *it_prop;
+             int val_idx = 0;
+
+             /* Find item, prop and value index of new_param_wdg */
+             wdg_item_container_item_get(wdg_container, wdg, &it, &it_prop, 
NULL, &val_idx);
+             if (it)
+               {
+                  _item_container_item_null_helper(wdg_container, EINA_FALSE, 
it, it_prop, val_idx);
+               }
+          }
+     }
 
    eid_active_set(wdg_eid_get(wdg), EINA_FALSE);
    memento_command_add(wdg_eid_get(wdg), MEMENTO_WIDGET,  (void *) (intptr_t) 
EINA_TRUE, (void *) (intptr_t) EINA_FALSE);
@@ -3686,42 +3800,41 @@ _field_update_from_itemview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Desc
           }
         else
           {
-             Eid *name_id = gui_context_eid_get_by_name(_active_context_get(), 
new_value);
-             gui_value_name_id_set(val, type, name_id);
+             Eid *new_name_id = 
gui_context_eid_get_by_name(_active_context_get(), new_value);
              if (type == GUI_TYPE_OBJECT)
                {
-                  Gui_Widget *w = wdg_get(name_id);
+                  Gui_Widget *new_param_wdg = wdg_get(new_name_id);
                   /* Check if new_widget was packed previously: take it's 
parent and check
                    * if widget is packed into it's parent.
                    * If so, we need to unpack widget and delete from contents*/
 
-                  Eid *prev_parent_cont_eid = wdg_parent_container_eid_get(w);
+                  Eid *prev_parent_cont_eid = 
wdg_parent_container_eid_get(new_param_wdg);
                   Gui_Widget *prev_wdg_container = prev_parent_cont_eid ? 
wdg_get(prev_parent_cont_eid) : NULL;
-                  if (prev_wdg_container && 
(wdg_container_type_get(prev_wdg_container) == OBJ_CONTAINER))
+
+                  if (prev_wdg_container)
                     {
-                       Object_Container *_old_prev_container, 
*_new_prev_container;
-                       _old_prev_container = (Object_Container *) 
wdg_obj_container_get((Gui_Widget *) prev_wdg_container);
-                       _new_prev_container = 
obj_container_copy(_old_prev_container);
-
-                       memento_command_add(wdg_eid_get(prev_wdg_container),
-                                           MEMENTO_OBJ_CONTAINER,
-                                           _old_prev_container, 
_new_prev_container);
-                       wdg_obj_container_unset((Gui_Widget *) 
prev_wdg_container);
-                       wdg_obj_container_set((Gui_Widget *) 
prev_wdg_container, _new_prev_container);
-
-                       /* Take old container's class name from 
content-property. */
-                       Object_Container_Item *_ci = 
wdg_obj_container_item_get(prev_wdg_container, -1, new_value);
-                       Gui_Widget_Property *old_prop = 
obj_container_item_prop_get(_ci);
-
-                       const Op_Desc *old_op_desc = prop_op_desc_get(old_prop);
-                       const char *old_container_name = 
db_op_desc_class_name_get(old_op_desc);
-
-                       Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
-                       manager_widget_content_unset(session, 
prev_wdg_container, old_container_name, old_prop, NULL);
-                       wdg_obj_container_item_remove(prev_wdg_container, _ci);
+                       if (wdg_container_type_get(prev_wdg_container) == 
OBJ_CONTAINER)
+                         {
+                            
_obj_container_item_remove_helper(prev_wdg_container, new_value);
+                         }
+                       else if (wdg_container_type_get(prev_wdg_container) == 
ITEM_CONTAINER)
+                         {
+                            const Item_Container_Item *it = NULL;
+                            const Gui_Widget_Property *it_prop = NULL;
+                            int val_idx = 0;
+
+                            /* Find item, prop and value index of 
new_param_wdg */
+                            wdg_item_container_item_get(prev_wdg_container, 
new_param_wdg, &it, &it_prop, NULL, &val_idx);
+                            if (it)
+                              {
+                                 /* Need to handle case when repacking inside 
the same container, so pass boolean it this is the same. */
+                                 
_item_container_item_null_helper(prev_wdg_container, prev_wdg_container == wdg, 
it, it_prop, val_idx);
+                              }
+                         }
                     }
-                  memento_command_add(wdg_eid_get(w), MEMENTO_WIDGET_PARENT, 
wdg_eid_get(wdg_parent_get(w)), wdg_eid_get(wdg));
-                  wdg_parent_set(w, wdg_name_get(wdg));
+                  gui_value_name_id_set(val, type, new_name_id);
+                  memento_command_add(new_name_id, MEMENTO_WIDGET_PARENT, 
prev_wdg_container ? wdg_eid_get(prev_wdg_container) : 
wdg_eid_get(wdg_parent_get(new_param_wdg)), wdg_eid_get(wdg));
+                  wdg_parent_set(new_param_wdg, wdg_name_get(wdg));
                }
           }
         /* If old_value is some widget, set main_obj as it's parent. */
@@ -3890,7 +4003,7 @@ _itemview_item_do_(unsigned int type)
               itemview_item_del(wit);
               wdg_item_remove(selected_item_id);
               break;
- }
+           }
       case ITEM_ADD:
       case ITEM_ADD_NESTED:
       case SEPARATOR_ADD:
@@ -3938,6 +4051,8 @@ _content_del_from_propview(void *data, Eo *obj 
EINA_UNUSED, const Eo_Event_Descr
    Object_Container_Item *ci = wdg_obj_container_item_get(wdg, idx, NULL);
    Eid *name_id = obj_container_item_eid_get(ci);
 
+   _obj_container_item_remove_helper((Gui_Widget *) wdg, 
eid_name_get(name_id));
+
    Gui_Widget *param_wdg = wdg_get(name_id);
    /* Need to change parent for content being unset from container.
     * Set parent window as parent for widget. */
@@ -3947,18 +4062,9 @@ _content_del_from_propview(void *data, Eo *obj 
EINA_UNUSED, const Eo_Event_Descr
         /* Do it to update list. */
         wdg_parent_set(param_wdg, wdg_name_get(parent_win));
         objtree_item_selected_set(wdg);
+        memento_command_add(name_id, MEMENTO_WIDGET_PARENT, wdg_eid_get(wdg), 
wdg_eid_get(parent_win));
      }
-   Object_Container *_old_container, *_new_container;
-   _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) 
wdg);
-   _new_container = obj_container_copy(_old_container);
 
-   memento_command_add(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER, 
_old_container, _new_container);
-
-   wdg_obj_container_unset((Gui_Widget *) wdg);
-   wdg_obj_container_set((Gui_Widget *) wdg, _new_container);
-
-   /* Delete content from container data. */
-   wdg_obj_container_item_remove(wdg, ci);
    /* Reload window when unpacking something. */
    _editor_wdg_selected_set(wdg);
    objtree_item_selected_set(wdg);
@@ -4185,72 +4291,19 @@ _content_change_from_propview(void *data EINA_UNUSED, 
Eo *obj, const Eo_Event_De
                {
                   if (wdg_container_type_get(prev_wdg_container) == 
OBJ_CONTAINER)
                     {
-                       Object_Container *_old_prev_container, 
*_new_prev_container;
-                       _old_prev_container = (Object_Container *) 
wdg_obj_container_get((Gui_Widget *) prev_wdg_container);
-                       _new_prev_container = 
obj_container_copy(_old_prev_container);
-
-                       memento_command_add(wdg_eid_get(prev_wdg_container),
-                                           MEMENTO_OBJ_CONTAINER,
-                                           _old_prev_container, 
_new_prev_container);
-                       wdg_obj_container_unset((Gui_Widget *) 
prev_wdg_container);
-                       wdg_obj_container_set((Gui_Widget *) 
prev_wdg_container, _new_prev_container);
-
-                       /* Take old container's class name from 
content-property. */
-                       Object_Container_Item *_ci = 
wdg_obj_container_item_get(prev_wdg_container, -1, new_value);
-                       Gui_Widget_Property *old_prop = 
obj_container_item_prop_get(_ci);
-
-                       const Op_Desc *old_op_desc = prop_op_desc_get(old_prop);
-                       const char *old_container_name = 
db_op_desc_class_name_get(old_op_desc);
-
-                       Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
-                       manager_widget_content_unset(session, 
prev_wdg_container, old_container_name, old_prop, NULL);
-                       wdg_obj_container_item_remove(prev_wdg_container, _ci);
+                       _obj_container_item_remove_helper(prev_wdg_container, 
new_value);
                     }
                   else if (wdg_container_type_get(prev_wdg_container) == 
ITEM_CONTAINER)
                     {
-                       const Eina_List *items_lst = 
item_container_item_subitems_get(wdg_item_container_root_get(prev_wdg_container)),
 *itr;
-                       /* Detect if cursor is inside swallow object.*/
-                       Eid *eid_itr;
-                       Item_Container_Item *cit;
+                       const Item_Container_Item *cit;
                        const Gui_Widget_Property *it_prop;
                        int val_idx = 0;
-                       Eina_Bool stop = EINA_FALSE;
-                       EINA_LIST_FOREACH(items_lst, itr, eid_itr)
-                         {
-                            cit = item_container_item_get_from_id(eid_itr);
-                            it_prop = item_container_item_prop_get(cit);
-                            Eina_List *values = prop_value_get(it_prop), *itr2;
-                            Gui_Value *it_val;
-                            EINA_LIST_FOREACH(values, itr2, it_val)
-                              {
-                                 if (gui_value_type_get(it_val) == 
GUI_TYPE_OBJECT)
-                                   {
-                                      if (new_name_id == EID_ID_GET(it_val))
-                                        {
-                                           stop = EINA_TRUE;
-                                           break;
-                                        }
-                                   }
-                                 val_idx++;
-                              }
-                            if (stop) break;
-                            val_idx = 0;
-                            cit = NULL;
-                            eid_itr = NULL;
-                            it_prop = NULL;
-                         }
 
+                       /* Find item, prop and value index of new_param_wdg */
+                       wdg_item_container_item_get(prev_wdg_container, 
new_param_wdg, &cit, &it_prop, NULL, &val_idx);
                        if (cit)
                          {
-                            Item_Container_Item *new_wit = 
item_container_item_copy(cit);
-                            
memento_command_add(wdg_eid_get(prev_wdg_container), 
MEMENTO_ITEM_CONTAINER_ITEM, cit, new_wit);
-
-                            Gui_Widget_Property *new_it_prop = 
prop_copy(it_prop);
-                            Gui_Value *it_val = 
prop_value_nth_get(new_it_prop, val_idx);
-                            gui_value_name_id_set(it_val, GUI_TYPE_OBJECT, 0);
-
-                            item_container_item_prop_set(new_wit, new_it_prop);
-                            
item_container_item_set_on_id(item_container_item_eid_get(cit), new_wit);
+                            
_item_container_item_null_helper(prev_wdg_container, EINA_FALSE, cit, it_prop, 
val_idx);
                          }
                     }
                }
diff --git a/src/lib/gui_widget.c b/src/lib/gui_widget.c
index 9f67ac4..8f4f5d1 100644
--- a/src/lib/gui_widget.c
+++ b/src/lib/gui_widget.c
@@ -1830,7 +1830,7 @@ wdg_data_get(const Gui_Widget *wdg, const char *key)
 /************************************************************/
 
 static Eina_Bool
-_item_container_items_iterate(const Item_Container_Item *item, Eid 
*wdg_eid_search)
+_item_container_items_iterate(const Item_Container_Item *item, Eid 
*wdg_eid_search, const Item_Container_Item **_it, const Gui_Widget_Property 
**_prop, const Gui_Value **_val, int *_val_idx)
 {
    const Eina_List *items_lst = item_container_item_subitems_get(item), *itr;
    /* Detect if cursor is inside swallow object.*/
@@ -1841,22 +1841,38 @@ _item_container_items_iterate(const Item_Container_Item 
*item, Eid *wdg_eid_sear
         const Gui_Widget_Property *prop = item_container_item_prop_get(cit);
         Eina_List *values = prop_value_get(prop), *itr2;
         Gui_Value *val;
+        int val_idx = 0;
         EINA_LIST_FOREACH(values, itr2, val)
           {
              if (gui_value_type_get(val) == GUI_TYPE_OBJECT)
                {
                   if (wdg_eid_search == EID_ID_GET(val))
                     {
+                       if (_it) *_it = cit;
+                       if (_prop) *_prop = prop;
+                       if (_val) *_val = val;
+                       if (_val_idx) *_val_idx = val_idx;
                        return EINA_TRUE;
                     }
                }
+             val_idx++;
           }
-        Eina_Bool found = _item_container_items_iterate(cit, wdg_eid_search);
+        Eina_Bool found = _item_container_items_iterate(cit, wdg_eid_search, 
_it, _prop, _val, _val_idx);
         if (found) return EINA_TRUE;
      }
    return EINA_FALSE;
 }
 
+/* Returns item, property, value and value index
+ * if wdg is packed into container. */
+void
+wdg_item_container_item_get(const Gui_Widget *container, Gui_Widget *wdg, 
const Item_Container_Item **_it, const Gui_Widget_Property **_prop, const 
Gui_Value **_val, int *_val_idx)
+{
+   Eid *wdg_eid = wdg_eid_get(wdg);
+   const Item_Container_Item *root_item = 
wdg_item_container_root_get(container);
+   _item_container_items_iterate(root_item, wdg_eid, _it, _prop, _val, 
_val_idx);
+}
+
 Eid *
 wdg_parent_container_eid_get(const Gui_Widget *wdg)
 {
@@ -1876,7 +1892,7 @@ wdg_parent_container_eid_get(const Gui_Widget *wdg)
      {
         Eid *wdg_eid = wdg_eid_get(wdg);
         const Item_Container_Item *root_item = 
wdg_item_container_root_get(wdg_parent);
-        if (_item_container_items_iterate(root_item, wdg_eid))
+        if (_item_container_items_iterate(root_item, wdg_eid, NULL, NULL, 
NULL, NULL))
           return wdg_eid_get(wdg_parent);
      }
 
diff --git a/src/lib/gui_widget.h b/src/lib/gui_widget.h
index 6974f96..537e5fd 100644
--- a/src/lib/gui_widget.h
+++ b/src/lib/gui_widget.h
@@ -570,6 +570,11 @@ wdg_is_container(const Gui_Widget *wdg, const char 
*container_class_name);
 const Item_Container_Item *
 wdg_item_container_root_get(const Gui_Widget *wdg);
 
+/* Returns item, property, value and value index
+ * if wdg is packed into container. */
+void
+wdg_item_container_item_get(const Gui_Widget *container, Gui_Widget *wdg, 
const Item_Container_Item **_it, const Gui_Widget_Property **_prop, const 
Gui_Value **_val, int *_val_idx);
+
 /* Add item to widget.
  * If parent_item is NULL, item will be added to Widget. */
 Eina_Bool

-- 


Reply via email to