yakov pushed a commit to branch master.

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

commit 3e2133a3ab3bade692cfe9abc2b06de02b5db7b9
Author: Yakov Goldberg <yako...@samsung.com>
Date:   Tue Oct 27 14:08:01 2015 +0200

    Added updater support
    
    Updater integrated with property/content changes, DnD, and undo/redo.
    All Eo updates go through updater
---
 src/bin/gui/dnd.c    |  50 +++---
 src/bin/gui/dnd.h    |   2 +-
 src/bin/gui/editor.c | 444 ++++++++++++++++++---------------------------------
 src/lib/gui_widget.c |  19 ++-
 src/lib/gui_widget.h |   4 +
 src/lib/undoredo.c   |  44 ++++-
 src/lib/undoredo.h   |   3 +-
 src/lib/updater.c    | 103 ++++++++++--
 8 files changed, 340 insertions(+), 329 deletions(-)

diff --git a/src/bin/gui/dnd.c b/src/bin/gui/dnd.c
index 04d02bb..8943fee 100644
--- a/src/bin/gui/dnd.c
+++ b/src/bin/gui/dnd.c
@@ -27,8 +27,7 @@ typedef struct
    Eo *drag_window_obj_wref;
 
    Eina_Bool drag_accept;
-   void (*dragdone_post_cb)(Eina_Bool accept);
-
+   void (*dragdone_post_cb)(Eina_Bool accept, const Eo *wdg_eo);
 } Drag_Info;
 
 /* Information about Drop Target*/
@@ -44,7 +43,7 @@ typedef struct
    Elm_Drag_Pos drop_target_pos;
    void *posdata;
 
-   Eo *obj; /* This obj is used only to properly call elm_drop_target_del() */
+   Eo *drop_target_eo; /* This obj is used only to properly call 
elm_drop_target_del() */
    const Gui_Widget *drop_target;
 } Drop_Target_Info;
 
@@ -62,11 +61,11 @@ static _Drop_Info_Global _drop_info_global = {0, NULL, 
EINA_FALSE};
 typedef struct
 {
    Drag_Info *drag_info;
-   const Gui_Widget *wdg_src;
+   Eina_Bool canvas_is_source;
    char *_drag_data; /*Allocated on drag_start and deleted in dragdone*/
 } _Drag_Info_Global;
 
-static _Drag_Info_Global _drag_info_global = {NULL, NULL, NULL};
+static _Drag_Info_Global _drag_info_global = {NULL, EINA_FALSE, NULL};
 
 static Ecore_Timer *_drag_factory_timer = NULL;
 
@@ -118,7 +117,7 @@ dnd_drag_window_object_visibility_set(Eina_Bool visibility)
 Eina_Bool
 dnd_is_source()
 {
-   return !!dnd_drag_wdg_get();
+   return _drag_info_global.canvas_is_source;
 }
 
 Eina_Bool
@@ -130,7 +129,9 @@ dnd_is_destination()
 const Gui_Widget *
 dnd_drag_wdg_get()
 {
-   return _drag_info_global.wdg_src;
+   if (_drag_info_global.canvas_is_source)
+     return wdg_get(_drag_info_global.drag_info->wdg_id);
+   return NULL;
 }
 
 static void
@@ -148,6 +149,9 @@ _dragaccept(void *data, Evas_Object *obj EINA_UNUSED, 
Eina_Bool doaccept EINA_UN
        di->drag_accept = doaccept;
 }
 
+static Eina_Bool
+_drag_data_free(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description 
*desc EINA_UNUSED, void *event_info EINA_UNUSED);
+
 static void
 _dragdone(void *data, Evas_Object *obj EINA_UNUSED)
 {
@@ -159,13 +163,18 @@ _dragdone(void *data, Evas_Object *obj EINA_UNUSED)
      {
         if (di->dragdone_post_cb)
           {
-             di->dragdone_post_cb(di->drag_accept);
+             di->dragdone_post_cb(di->drag_accept, di->obj);
           }
      }
 
    /* if dropping outside, NULL this pointer*/
+   if (_drag_info_global.canvas_is_source)
+     _drag_data_free(_drag_info_global.drag_info, NULL, NULL, NULL);
+
    if (!dnd_is_destination())
-     _drag_info_global.wdg_src = NULL;
+     {
+        _drag_info_global.canvas_is_source = EINA_FALSE;
+     }
 }
 
 /* This callback is called only for a window object.
@@ -235,7 +244,7 @@ _dropcb(void *data, Evas_Object *obj, Elm_Selection_Data 
*ev)
 
    if (ti->drop_target_drop)
      ti->drop_target_drop(ti->dropdata, obj, ev);
-   _drag_info_global.wdg_src = NULL;
+   _drag_info_global.canvas_is_source = EINA_FALSE;
 
    _drop_info_global._enter_leave_counter = 0;
    _drop_data_free();
@@ -474,7 +483,7 @@ _drag_start_from_factory(void *data)
 
    _drag_factory_timer = NULL;
    _drag_info_global.drag_info = di;
-   _drag_info_global.wdg_src = NULL;
+   _drag_info_global.canvas_is_source = EINA_FALSE;
 
    char *wdg_data = json_widget_generate(di->wdg_id);
    _drag_info_global._drag_data = wdg_data;
@@ -537,7 +546,7 @@ drag_add(Eo *obj, const char *image_path, Eid *wdg_id)
 /* Function to start dragging, when mouse down/up are handled outside.
  * Dragging widgets on canvas */
 void
-drag_start(Eo *obj, Eid *wdg_id, void (*_post_cb)(const Gui_Widget *, const Eo 
*), void (*_dragdone_post_cb)(Eina_Bool accept))
+drag_start(Eo *obj, Eid *wdg_id, void (*_drag_start_post_cb)(const Gui_Widget 
*, const Eo *), void (*_dragdone_post_cb)(Eina_Bool accept, const Eo *))
 {
    Drag_Info *di = calloc(1, sizeof(Drag_Info));
    di->image_path = NULL;
@@ -546,8 +555,7 @@ drag_start(Eo *obj, Eid *wdg_id, void (*_post_cb)(const 
Gui_Widget *, const Eo *
    di->dragdone_post_cb = _dragdone_post_cb;
 
    _drag_info_global.drag_info = di;
-   _drag_info_global.wdg_src = wdg_get(di->wdg_id);
-   eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_DEL, _drag_data_free, 
di));
+   _drag_info_global.canvas_is_source = EINA_TRUE;
 
    Eo *drag_object = obj;
 
@@ -579,9 +587,9 @@ drag_start(Eo *obj, Eid *wdg_id, void (*_post_cb)(const 
Gui_Widget *, const Eo *
                   _dragdone, di);
    free(wdg_data);
 
-   if (_post_cb)
+   if (_drag_start_post_cb)
      {
-        _post_cb(wdg_get(di->wdg_id), di->obj);
+        _drag_start_post_cb(wdg_get(di->wdg_id), di->obj);
      }
 }
 
@@ -632,7 +640,7 @@ drop_target_wdg_set(Gui_Widget *wdg, Eo *obj,
 
    if (!wdg || IS_MAIN(wdg))
      {
-        ti->obj = obj;
+        ti->drop_target_eo = obj;
         elm_drop_target_add(obj, ELM_SEL_FORMAT_TEXT,
               _dropenter, ti,
               _dropleave, ti,
@@ -718,7 +726,7 @@ _drag_item_container_dragstart_cb(void *data EINA_UNUSED, 
Evas_Object *obj EINA_
    di->image_path = NULL;
    di->wdg_id = wdg_eid_get(wdg);
    _drag_info_global.drag_info = di;
-   _drag_info_global.wdg_src = wdg;
+   _drag_info_global.canvas_is_source = EINA_TRUE;
 
    if (_dici && _dici->dragstart)
      {
@@ -737,7 +745,7 @@ _drag_item_container_dragdone_cb(void *data, Evas_Object 
*obj, Eina_Bool accepte
      }
    /* if dropping outside, NULL this pointer*/
    if (!dnd_is_destination())
-     _drag_info_global.wdg_src = NULL;
+     _drag_info_global.canvas_is_source = EINA_FALSE;
 }
 
 static Eina_Bool
@@ -811,9 +819,9 @@ drop_target_wdg_del(Gui_Widget *wdg, Eo *obj)
 
    if (!ti) return;
    /* call elm_drop_target_del() only for main objects, t.e. if obj exists. */
-   if (ti->obj)
+   if (ti->drop_target_eo)
      {
-        elm_drop_target_del(ti->obj, ELM_SEL_FORMAT_TEXT,
+        elm_drop_target_del(ti->drop_target_eo, ELM_SEL_FORMAT_TEXT,
                             _dropenter, ti,
                             _dropleave, ti,
                             _droppos, ti,
diff --git a/src/bin/gui/dnd.h b/src/bin/gui/dnd.h
index 5aee0f8..d618368 100644
--- a/src/bin/gui/dnd.h
+++ b/src/bin/gui/dnd.h
@@ -5,7 +5,7 @@ void
 drag_add(Eo *obj, const char *image_path, Eid *wdg_id);
 
 void
-drag_start(Eo *obj, Eid *wdg_id, void (*_post_cb)(const Gui_Widget *, const Eo 
*), void (*_dragdone_post_cb)(Eina_Bool accept));
+drag_start(Eo *obj, Eid *wdg_id, void (*_post_cb)(const Gui_Widget *, const Eo 
*), void (*_dragdone_post_cb)(Eina_Bool accept, const Eo *wdg_eo));
 
 void
 drop_target_wdg_set(Gui_Widget *wdg, Eo *obj,
diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c
index 935c07c..4033bbf 100644
--- a/src/bin/gui/editor.c
+++ b/src/bin/gui/editor.c
@@ -14,6 +14,7 @@
 #include "cbview.h"
 #include "key_bindings.h"
 #include "settings.h"
+#include "updater.h"
 
 #include "dnd.h"
 
@@ -58,11 +59,6 @@ typedef struct
 }
 DnD_Main_Obj_Info;
 
-/* Function to call in the end of undo/redo in order to update view.
- * Update is made according to head memento. */
-static void
-_editor_undo_redo_post(const Memento *memento);
-
 static void
 _wdg_parent_win_reload(const Gui_Widget *wdg);
 
@@ -530,7 +526,7 @@ void
 _drag_start_post_cb(const Gui_Widget *wdg, const Eo *_wdg_eo);
 
 static void
-_dragdone_post_cb(Eina_Bool accept);
+_dragdone_post_cb(Eina_Bool accept, const Eo *wdg_eo);
 
 static Ecore_Timer *_drag_timer_start = NULL;
 static Eina_Bool drag_started = EINA_FALSE;
@@ -1158,16 +1154,6 @@ _frame_mouse_up(void *data EINA_UNUSED, Eo *obj, const 
Eo_Event_Description *des
    return EO_CALLBACK_CONTINUE;
 }
 
-/* Second parameter is used only as parent for INLINED windows*/
-static void
-_iter_widget_create(Gui_Widget *wdg, const Eo *parent_win)
-{
-   Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
-   if (parent_win) wdg_data_set(wdg, "_eo_parent", parent_win);
-   manager_widget_create(session, wdg, NULL);
-   wdg_data_set(wdg, "_eo_parent", NULL);
-}
-
 static Eina_Bool
 _wdg_resize(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc 
EINA_UNUSED, void *event_info EINA_UNUSED)
 {
@@ -1469,7 +1455,7 @@ _widget_item_add(Gui_Session *session, const Gui_Widget 
*wdg, const Item_Contain
              if (w && !session_wdg_exists(session, w))
                {
                   /* Creation of the child widgets of the item. */
-                  _iter_widget_create(w, session_eo_get(session, wdg));
+                  manager_widget_create(session, wdg, NULL);
                }
           }
      }
@@ -1673,11 +1659,16 @@ _drop_target_leave(void *data, Evas_Object *obj)
              di->packed = EINA_FALSE;
           }
      }
-   if (di->eo_cur && IS_MAIN(drop_target_wdg))
+
+   if (di->eo_cur && IS_MAIN(drop_target_wdg) && (di->eo_cur != 
session_eo_get(session, dnd_drag_wdg_get())))
      {
         eo_del(di->eo_cur);
         di->eo_cur = NULL;
      }
+   else
+     {
+        if (di->eo_cur) eo_do(di->eo_cur, efl_gfx_visible_set(EINA_FALSE));
+     }
 
    if (!dnd_counter_get())
      {
@@ -1705,16 +1696,16 @@ enum
 
 /* canvas_drop_target != NULL when dropping on canvas. */
 static Eina_Bool
-_drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char 
*drag_data EINA_UNUSED, Eina_Bool dropped_to_objtree)
+_drop_target_drop(Gui_Widget *drop_target_wdg, Eo *canvas_drop_target, const 
char *drag_data, Eina_Bool dropped_to_objtree)
 {
    DnD_Main_Obj_Info *di = NULL;
    const Gui_Widget *new_wdg = NULL;
    int drop_to_wdg = NO_DROP;
 
    _wdg_border_draw(NULL, EINA_FALSE, BORDER_DROP_TARGET);
-   if (wdg)
+   if (drop_target_wdg)
      {
-        di = wdg_data_get(wdg_main_wdg_get(wdg), EDITOR_DND_DATA);
+        di = wdg_data_get(wdg_main_wdg_get(drop_target_wdg), EDITOR_DND_DATA);
      }
    else if (canvas_drop_target != NULL)
      {
@@ -1725,23 +1716,23 @@ _drop_target_drop(Gui_Widget *wdg, Eo 
*canvas_drop_target, const char *drag_data
         ERR("Drop target is wrong. If you see this message something is 
terribly wrong!");
      }
 
-   if (!wdg)
+   if (!drop_target_wdg)
      {
         drop_to_wdg = DROP_TO_CANVAS;
      }
-   else if (IS_WIN(wdg))
+   else if (IS_WIN(drop_target_wdg))
      {
         drop_to_wdg = DROP_TO_WIN;
      }
-   else if (!strcmp(wdg_class_name_get(wdg), DB_DEF_BOX_CLASS))
+   else if (!strcmp(wdg_class_name_get(drop_target_wdg), DB_DEF_BOX_CLASS))
      {
         drop_to_wdg = DROP_TO_BOX;
      }
-   else if (!strcmp(wdg_class_name_get(wdg), DB_DEF_TABLE_CLASS))
+   else if (!strcmp(wdg_class_name_get(drop_target_wdg), DB_DEF_TABLE_CLASS))
      {
         drop_to_wdg = DROP_TO_TABLE;
      }
-   else if (IS_MAIN(wdg))
+   else if (IS_MAIN(drop_target_wdg))
      {
         drop_to_wdg = DROP_TO_MAIN;
      }
@@ -1762,27 +1753,41 @@ _drop_target_drop(Gui_Widget *wdg, Eo 
*canvas_drop_target, const char *drag_data
      _dragged_wdg = _editor_wdg_create(_active_context_get(), drag_data);
 
    new_wdg = _dragged_wdg;
+   /* If dragging not from canvas, add MEMENTO_WIDGET and set parent */
    if (!dnd_is_source())
-      memento_command_add(wdg_eid_get(new_wdg), MEMENTO_WIDGET,
-            (void *) (intptr_t) EINA_FALSE, (void *) (intptr_t) EINA_TRUE);
+     {
+        memento_command_add(wdg_eid_get(new_wdg), MEMENTO_WIDGET,
+                            (void *) (intptr_t) EINA_FALSE, (void *) 
(intptr_t) EINA_TRUE);
+        wdg_parent_set((Gui_Widget *) new_wdg, drop_target_wdg ? 
wdg_name_get(drop_target_wdg) : NULL);
+     }
+   /* if dragging on canvas, change parent if parent is different. */
+   else
+     {
+        if (!(drop_target_wdg && (wdg_parent_id_get(new_wdg) == 
wdg_eid_get(drop_target_wdg))))
+          {
+             memento_command_add(wdg_eid_get(new_wdg), MEMENTO_WIDGET_PARENT, 
wdg_parent_id_get(new_wdg), drop_target_wdg ? wdg_eid_get(drop_target_wdg) : 
NULL);
+             wdg_parent_set((Gui_Widget *) new_wdg, drop_target_wdg ? 
wdg_name_get(drop_target_wdg) : NULL);
+          }
+     }
 
    /* Where to drop. */
    if (drop_to_wdg == DROP_TO_CANVAS)
      {
-        memento_command_add(wdg_eid_get(new_wdg),
-              MEMENTO_WIDGET_PARENT,
-              wdg_parent_id_get(new_wdg), NULL);
-        wdg_parent_set((Gui_Widget *) new_wdg, NULL);
         wdg_data_set(new_wdg, CURSOR_DROP_X, (void *) (intptr_t) 
di->pointer_x);
         wdg_data_set(new_wdg, CURSOR_DROP_Y, (void *) (intptr_t) 
di->pointer_y);
+
+        Main_Wdg_Info *wi = wdg_data_get(new_wdg, MAIN_WDG_INFO);
+        if (wi)
+          {
+             Eo *fr = main_wdg_info_frame_get(wi);
+             Evas_Coord w, h;
+             elm_grid_pack_get(fr, NULL, NULL, &w, &h);
+             eo_do(canvas_get(), elm_obj_grid_pack(fr, di->pointer_x, 
di->pointer_y, w, h));
+          }
      }
    /* Dragging into win */
    else if (drop_to_wdg == DROP_TO_WIN)
      {
-        memento_command_add(wdg_eid_get(new_wdg),
-              MEMENTO_WIDGET_PARENT,
-              wdg_parent_id_get(new_wdg), wdg_eid_get(wdg));
-        wdg_parent_set((Gui_Widget *) new_wdg, wdg_name_get(wdg));
         if (new_wdg)
           {
              Gui_Widget_Property *old_prop, *prop;
@@ -1819,46 +1824,44 @@ _drop_target_drop(Gui_Widget *wdg, Eo 
*canvas_drop_target, const char *drag_data
          * or to memento unpacking from previous container
          * in order to correctly manage internals. */
         Object_Container *_old_container, *_new_container;
-        _old_container = (Object_Container *) wdg_obj_container_get(wdg);
+        _old_container = (Object_Container *) 
wdg_obj_container_get(drop_target_wdg);
         _new_container = obj_container_copy(_old_container);
 
-        memento_command_add(wdg_eid_get(wdg),
+        memento_command_add(wdg_eid_get(drop_target_wdg),
               MEMENTO_OBJ_CONTAINER_ITEM,
               _old_container, _new_container);
         /* Current memento is a memento created, during _factory 
_widget_create earlier in this func. */
-        wdg_obj_container_unset(wdg);
-        wdg_obj_container_set(wdg, _new_container);
+        wdg_obj_container_unset(drop_target_wdg);
+        wdg_obj_container_set(drop_target_wdg, _new_container);
 
-        const Op_Desc *op_desc = 
db_container_desc_op_desc_get(db_container_desc_get(wdg_class_name_get(wdg)), 
CONTAINER_PACK);
+        const Op_Desc *op_desc = 
db_container_desc_op_desc_get(db_container_desc_get(wdg_class_name_get(drop_target_wdg)),
 CONTAINER_PACK);
         Gui_Widget_Property *prop = prop_create_for_op(op_desc);
         Gui_Value *val = prop_value_nth_get(prop, 0);
         gui_value_name_id_set(val, GUI_TYPE_OBJECT, wdg_eid_get(new_wdg));
 
         Object_Container_Item *ci = obj_container_item_new(prop, 
wdg_eid_get(new_wdg));
-        wdg_obj_container_item_add(wdg, ci, di->box_pack_idx);
-        wdg_parent_set((Gui_Widget *) new_wdg, wdg_name_get(wdg));
+        wdg_obj_container_item_add(drop_target_wdg, ci, di->box_pack_idx);
      }
    else if (drop_to_wdg == DROP_TO_TABLE)
      {
-        Eo *wdg_eo = session_eo_get(session, wdg);
+        Eo *wdg_eo = session_eo_get(session, drop_target_wdg);
         Object_Container_Item *it;
 
         Object_Container *_old_container, *_new_container;
-        _old_container = (Object_Container *) wdg_obj_container_get(wdg);
+        _old_container = (Object_Container *) 
wdg_obj_container_get(drop_target_wdg);
         _new_container = obj_container_copy(_old_container);
 
-        memento_command_add(wdg_eid_get(wdg),
+        memento_command_add(wdg_eid_get(drop_target_wdg),
               MEMENTO_OBJ_CONTAINER_ITEM,
               _old_container, _new_container);
         /* Current memento is a memento created, during _factory 
_widget_create earlier in this func. */
 
-        const Eina_List *old_lst = wdg_obj_container_contents_list_get(wdg), 
*l;
-        wdg_obj_container_unset(wdg);
-        wdg_obj_container_set(wdg, _new_container);
-        wdg_parent_set((Gui_Widget *) new_wdg, wdg_name_get(wdg));
+        const Eina_List *old_lst = 
wdg_obj_container_contents_list_get(drop_target_wdg), *l;
+        wdg_obj_container_unset(drop_target_wdg);
+        wdg_obj_container_set(drop_target_wdg, _new_container);
 
         /* Delete everything in new_container */
-        wdg_obj_container_item_remove_all(wdg);
+        wdg_obj_container_item_remove_all(drop_target_wdg);
 
         /* Iterate over old list and create new container items and properties.
          * Also get packing coordinates from Eo object and put it into 
property. */
@@ -1875,11 +1878,11 @@ _drop_target_drop(Gui_Widget *wdg, Eo 
*canvas_drop_target, const char *drag_data
              gui_value_int_set(prop_value_nth_get(new_prop, 2), iy);
 
              Object_Container_Item *ci = obj_container_item_new(new_prop, eid);
-             wdg_obj_container_item_add((Gui_Widget *) wdg, ci, -1);
+             wdg_obj_container_item_add((Gui_Widget *) drop_target_wdg, ci, 
-1);
           }
 
         /* Add new element into the container */
-        const Op_Desc *op_desc = 
db_container_desc_op_desc_get(db_container_desc_get(wdg_class_name_get(wdg)), 
CONTAINER_PACK);
+        const Op_Desc *op_desc = 
db_container_desc_op_desc_get(db_container_desc_get(wdg_class_name_get(drop_target_wdg)),
 CONTAINER_PACK);
         Gui_Widget_Property *prop = prop_create_for_op(op_desc);
 
         gui_value_name_id_set(prop_value_nth_get(prop, 0), GUI_TYPE_OBJECT, 
wdg_eid_get(new_wdg));
@@ -1889,20 +1892,12 @@ _drop_target_drop(Gui_Widget *wdg, Eo 
*canvas_drop_target, const char *drag_data
         gui_value_int_set(prop_value_nth_get(prop, 4), 1);
 
         Object_Container_Item *ci = obj_container_item_new(prop, 
wdg_eid_get(new_wdg));
-        wdg_obj_container_item_add(wdg, ci, -1);
-     }
-   /* When drop into main object which is not window, only update parent. */
-   else if (drop_to_wdg == DROP_TO_MAIN)
-     {
-        memento_command_add(wdg_eid_get(new_wdg),
-              MEMENTO_WIDGET_PARENT,
-              wdg_parent_id_get(new_wdg), wdg_eid_get(wdg));
-        wdg_parent_set((Gui_Widget *) new_wdg, wdg_name_get(wdg));
+        wdg_obj_container_item_add(drop_target_wdg, ci, -1);
      }
 
 end:
 
-   if (!dnd_is_source() && di->eo_cur)
+   if (di->eo_cur && (di->eo_cur != session_eo_get(session, _dragged_wdg)))
      {
         eo_del(di->eo_cur);
      }
@@ -1910,7 +1905,6 @@ end:
 
    if (new_wdg)
      {
-        _wdg_parent_win_reload(new_wdg);
         _editor_wdg_selected_set(new_wdg);
         objtree_build();
         objtree_item_selected_set(new_wdg);
@@ -1998,7 +1992,7 @@ _objtree_drag_start_cb(void *data EINA_UNUSED, 
Evas_Object *obj EINA_UNUSED)
 static void
 _objtree_dragdone_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, 
Eina_Bool accepted)
 {
-   _dragdone_post_cb(accepted);
+   _dragdone_post_cb(accepted, NULL);
 }
 
 static void
@@ -2072,6 +2066,7 @@ _drop_target_pos(void *data, Eo *obj, Evas_Coord x, 
Evas_Coord y, Elm_Xdnd_Actio
           }
      }
 
+   const Gui_Session *session = gui_context_editor_session_get(ctx);
    if (_dragged_wdg && !di->eo_cur && (!IS_WIN(_dragged_wdg)))
      {
         di->eo_cur = dnd_drag_obj_create(_dragged_wdg, drop_target_wdg_eo);
@@ -2250,7 +2245,6 @@ _drop_target_pos(void *data, Eo *obj, Evas_Coord x, 
Evas_Coord y, Elm_Xdnd_Actio
                        /* Don't pack widget which is currently dragged. */
                        if (dnd_drag_wdg_get() == wdg_get(eid))
                          continue;
-                       const Gui_Session *session = 
gui_context_editor_session_get(wdg_context_get(drop_target_wdg));
                        Eo *c = session_eo_get(session, wdg_get(eid));
                        eo_do(drop_target_wdg_eo, elm_obj_table_pack_set(c, ix, 
iy, iw, ih));
                     }
@@ -2262,7 +2256,6 @@ _drop_target_pos(void *data, Eo *obj, Evas_Coord x, 
Evas_Coord y, Elm_Xdnd_Actio
                   Gui_Widget_Property *prop = obj_container_item_prop_get(it);
                   int ix, iy, iw, ih;
                   Eid *eid = EID_ID_GET(prop_value_nth_get(prop, 0));
-                  const Gui_Session *session = 
gui_context_editor_session_get(wdg_context_get(drop_target_wdg));
                   Eo *c = session_eo_get(session, wdg_get(eid));
 
                   eo_do(drop_target_wdg_eo, elm_obj_table_pack_get(c, &ix, 
&iy, &iw, &ih));
@@ -2332,6 +2325,14 @@ _drag_start_post_cb(const Gui_Widget *wdg, const Eo 
*_wdg_eo)
              eo_do(fr, efl_gfx_visible_set(EINA_FALSE));
           }
      }
+   else
+     {
+        DnD_Main_Obj_Info *di = wdg_data_get(wdg_main_wdg_get(wdg), 
EDITOR_DND_DATA);
+        /* If we dragging around window where drag started, use real object.
+         * Use weak ref, to automatically NULL this pointer if object dropped 
into other place. */
+        eo_do(wdg_eo, eo_wref_add(&(di->eo_cur)));
+     }
+
    /* Unpack Eo object if dragging from container. */
    if (wdg_container)
      {
@@ -2361,25 +2362,13 @@ _drag_start_post_cb(const Gui_Widget *wdg, const Eo 
*_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));
-                  /* Object will be deleted automatically by evas*/
-                  session_wdg_existence_set((Gui_Session *) session, wdg, 
EINA_FALSE);
                }
           }
      }
-   /* If dragging from a widget(window), unset parent*/
-   else if (wdg_parent)
-     {
-        memento_command_add(wdg_eid_get(wdg),
-              MEMENTO_WIDGET_PARENT,
-              wdg_parent_id_get(wdg), NULL);
-        wdg_parent_set((Gui_Widget *) wdg, NULL);
-     }
-   else if (!wdg_parent)
-     {
-        memento_command_add(wdg_eid_get(wdg),
-              MEMENTO_WIDGET_PARENT,
-              NULL, NULL);
-     }
+
+   /* Need to change parent to NULL, because parent is also changed in 
container unset. */
+   memento_command_add(wdg_eid_get(wdg), MEMENTO_WIDGET_PARENT, wdg_parent ? 
wdg_eid_get(wdg_parent) : NULL, NULL);
+   wdg_parent_set((Gui_Widget *) wdg, NULL);
 }
 
 static Eina_Bool
@@ -2387,52 +2376,71 @@ __undo_no_update(const Gui_Context *ctx);
 
 /* This callback is added only for dragging of objects on canvas. */
 static void
-_dragdone_post_cb(Eina_Bool accept)
+_dragdone_post_cb(Eina_Bool accept, const Eo *wdg_eo)
 {
-   const Gui_Widget *wdg = dnd_drag_wdg_get();
-   if (!wdg) return;
-   Gui_Context *ctx = (Gui_Context *) wdg_context_get(wdg);
+   const Gui_Widget *drag_wdg = dnd_drag_wdg_get();
+   if (!drag_wdg) return;
+   Gui_Context *ctx = (Gui_Context *) wdg_context_get(drag_wdg);
+   if (wdg_eo) eo_do(wdg_eo, efl_gfx_visible_set(EINA_TRUE));
 
    /* If dragged object was not accepted, or was accepted outside Erigo,
     * drop memento created on drag start. */
    if (!accept ||
        (accept && !dnd_is_destination()))
      {
-        __undo_no_update(ctx);
+        const Memento *head_memento = context_current_memento_get(ctx);
+        Memento_Command *cmd;
+        const Eina_List *cmds_list = memento_commands_get(head_memento), *itr;
+        Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
+        EINA_LIST_REVERSE_FOREACH(cmds_list, itr, cmd)
+          {
+             Memento_Type type = memento_command_type_get(cmd);
+             Eid *eid = memento_command_wdg_get(cmd);
+             Gui_Widget *wdg = wdg_get(eid);
+             switch (type)
+               {
+                case MEMENTO_OBJ_CONTAINER_ITEM:
+                     {
+                        Object_Container *old_container = 
memento_command_old_pointer_get(cmd);
+
+                        manager_widget_content_unset_all(session, wdg, 
wdg_obj_container_class_name_get(wdg), NULL);
+                        wdg_obj_container_unset(wdg);
+                        wdg_obj_container_set(wdg, old_container);
+                        manager_widget_content_add(session, wdg, NULL);
+                        break;
+                     }
+                case MEMENTO_WIDGET_PARENT:
+                     {
+                        manager_widget_delete(session, wdg, NULL);
+                        Eid *old_parent_id = (Eid *) 
memento_command_old_pointer_get(cmd);
+                        wdg_parent_set(wdg, eid_name_get(old_parent_id));
+                        manager_widget_create(session, wdg, NULL);
+                        break;
+                     }
+                default:
+                   ERR("case - default");
+               }
+          }
+
         context_memento_move_to_prev(ctx);
         context_memento_discard(ctx);
 
         eo_do(g->main_win->toolbar_redo_it, 
elm_wdg_item_disabled_set(context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE));
         eo_do(g->main_win->toolbar_undo_it, 
elm_wdg_item_disabled_set(context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE));
 
-        _wdg_parent_win_reload(wdg);
-        _editor_wdg_selected_set(wdg);
+        _editor_wdg_selected_set(drag_wdg);
         objtree_build();
-        objtree_item_selected_set(wdg);
-
-        /* If dropping memento, make obj visible */
-        const Gui_Session *session = gui_context_editor_session_get(ctx);
-        Eo *wdg_eo = session_eo_get(session, wdg);
-
-        eo_do(wdg_eo, efl_gfx_visible_set(EINA_TRUE));
-
-        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
-        if (wi)
-          {
-             Eo *fr = main_wdg_info_frame_get(wi);
-             eo_do(fr, efl_gfx_visible_set(EINA_TRUE));
-          }
+        objtree_item_selected_set(drag_wdg);
 
         _dragged_wdg = NULL;
      }
-   else
+   /* Make main wdg visible.
+    * If it was only dragged - making it visible is Ok. If parent was changed 
- it will be deleted in updater. */
+   Main_Wdg_Info *wi = wdg_data_get(drag_wdg, MAIN_WDG_INFO);
+   if (wi)
      {
-        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
-        if (wi)
-          {
-             Eo *fr = main_wdg_info_frame_get(wi);
-             eo_del(fr);
-          }
+        Eo *fr = main_wdg_info_frame_get(wi);
+        eo_do(fr, efl_gfx_visible_set(EINA_TRUE));
      }
 }
 
@@ -2474,8 +2482,10 @@ _main_wdg_eo_del(void *data, Eo *obj EINA_UNUSED, const 
Eo_Event_Description *de
         if (fr)
           {
              eo_do(fr, elm_obj_container_content_unset(NULL));
-             eo_do(fr, efl_gfx_visible_set(EINA_FALSE));
+             eo_del(fr);
           }
+        free(wi);
+        wdg_data_set(wdg, MAIN_WDG_INFO, NULL);
      }
    return EINA_TRUE;
 }
@@ -2512,7 +2522,8 @@ _widget_add(Gui_Session *session, const Gui_Widget *wdg, 
void *data EINA_UNUSED)
    else
      {
         Eo *fr;
-        Eo *parent_win = wdg_data_get(wdg, "_eo_parent");
+        /* Canvas is always parent of main widgets*/
+        Eo *parent_win = canvas_get();
 
         Eo *win = eo_add(ELM_WIN_CLASS, parent_win, 
elm_obj_win_name_set(NULL), elm_obj_win_type_set(ELM_WIN_INLINED_IMAGE));
         if (!win) return EINA_FALSE;
@@ -2655,13 +2666,12 @@ _widget_add(Gui_Session *session, const Gui_Widget 
*wdg, void *data EINA_UNUSED)
 static Eina_Bool
 _widget_del(Gui_Session *session, const Gui_Widget *wdg, void *data 
EINA_UNUSED)
 {
-   Eo *o = session_eo_get(session, wdg), *del_obj;
-   del_obj = o;
+   Eo *o = session_eo_get(session, wdg), *del_obj = NULL;
 
-   if (IS_MAIN(wdg) && !IS_WIN(wdg))
-     {
-        eo_do(o, del_obj = eo_key_data_get("__editor_win"));
-     }
+   /* If no data "__editor_win" delete object,
+    * else - its editor win. */
+   eo_do(o, del_obj = eo_key_data_get("__editor_win"));
+   if (!del_obj) del_obj = o;
 
    eo_del(del_obj);
    return EINA_TRUE;
@@ -2706,32 +2716,12 @@ _wdg_parent_win_reload(const Gui_Widget *wdg)
    /* Remove all Eo of current window. */
    _editor_widget_clear(pwin);
    /* Create window from beginning. */
-   _iter_widget_create(pwin, canvas_get());
+   Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
+   manager_widget_create(session, pwin, NULL);
    /* Hide border of window, which is drawn when win is recreated and resized 
*/
    _editor_wdg_selected_set(NULL);
 }
 
-static void
-_update_widget_on_undoredo(Eid *wdg_id, Eina_Bool state)
-{
-   const Gui_Widget *parent = NULL; /* We need the parent to reload the win */
-   Gui_Widget *wdg = wdg_get(wdg_id);
-   if (wdg) /* On widget deletion, we delete the Eo object first */
-     {
-        parent = (Gui_Widget *) wdg_parent_get(wdg);
-        _editor_widget_clear(wdg);
-     }
-   eid_active_set(wdg_id, state);
-
-   wdg = wdg_get(wdg_id);
-   if (wdg) parent = wdg_main_wdg_get(wdg);
-   if (parent) _wdg_parent_win_reload(parent);
-   objtree_build();
-   objtree_item_selected_set(wdg ? wdg : parent);
-   _editor_wdg_selected_set(wdg ? wdg : parent);
-   proplayout_build(wdg ? wdg : parent);
-}
-
 /* Undo last action */
 static Eina_Bool
 __undo_no_update(const Gui_Context *ctx)
@@ -2748,6 +2738,7 @@ __undo_no_update(const Gui_Context *ctx)
      {
         Memento_Type type = memento_command_type_get(cmd);
         Eid *eid = memento_command_wdg_get(cmd);
+        Gui_Widget *wdg = wdg_get(eid);
         switch (type)
           {
            case MEMENTO_PROPERTY:
@@ -2755,7 +2746,6 @@ __undo_no_update(const Gui_Context *ctx)
                    Gui_Widget_Property *old_prop, *new_prop;
                    const Op_Desc *op_desc = NULL;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -2776,8 +2766,6 @@ __undo_no_update(const Gui_Context *ctx)
                      {
                         op_desc = prop_op_desc_get(old_prop);
                         wdg_prop_add(wdg, old_prop);
-                        Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
-                        manager_widget_property_add(session, wdg, old_prop, 
NULL);
                         if (_editor_wdg_selected_get() != wdg)
                           {
                              objtree_item_selected_set(wdg);
@@ -2787,7 +2775,6 @@ __undo_no_update(const Gui_Context *ctx)
                    /* If old_property == NULL, need to reload widget. */
                    else
                      {
-                        _wdg_parent_win_reload(wdg);
                         objtree_build();
                         objtree_item_selected_set(wdg);
                      }
@@ -2799,7 +2786,6 @@ __undo_no_update(const Gui_Context *ctx)
                 {
                    Object_Container *old_container;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -2816,7 +2802,6 @@ __undo_no_update(const Gui_Context *ctx)
                 {
                    Item_Container_Item *old_it;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -2832,7 +2817,6 @@ __undo_no_update(const Gui_Context *ctx)
                 {
                    Gui_Widget_Callback *old_cb;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -2853,7 +2837,6 @@ __undo_no_update(const Gui_Context *ctx)
                 {
                    Callback_Container *old_cc;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -2867,32 +2850,11 @@ __undo_no_update(const Gui_Context *ctx)
            case MEMENTO_WIDGET:
                 {
                    Eina_Bool old_state = (intptr_t) 
memento_command_old_pointer_get(cmd);
-                   _update_widget_on_undoredo(eid, old_state);
+                   eid_active_set(eid, old_state);
                    break;
                 }
            case MEMENTO_WIDGET_PARENT:
                 {
-                   Gui_Widget *wdg = wdg_get(eid);
-                   _wdg_border_draw(wdg, EINA_FALSE, BORDER_SELECTION);
-                   /* According to current scenario, widget can be dragged 
from another and dropped to canvas.
-                    * Thus here can be only main_wdg which is going to be 
undoed.
-                    * So it's frame and editor window must be deleted and 
Main_Wdg_Info data must be freed. */
-                   if (IS_MAIN(wdg) && !IS_WIN(wdg))
-                     {
-                        Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
-                        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
-                        wdg_data_set(wdg, MAIN_WDG_INFO, NULL);
-                        if (wi)
-                          {
-                             Eo *fr = main_wdg_info_frame_get(wi);
-                             Eo *o = session_eo_get(session, wdg);
-                             Eo *optional_win = eo_do_ret(o, optional_win, 
eo_key_data_get("__editor_win"));
-                             eo_del(optional_win);
-                             eo_del(fr);
-                             free(wi);
-                             session_wdg_existence_set(session, wdg, 
EINA_FALSE);
-                          }
-                     }
                    Eid *old_parent_id = (Eid *) 
memento_command_old_pointer_get(cmd);
                    wdg_parent_set(wdg, eid_name_get(old_parent_id));
                    break;
@@ -2949,7 +2911,7 @@ _editor_undo(const Gui_Context *ctx)
 
   if (! __undo_no_update(ctx)) return EINA_FALSE;
    /* Update propview. */
-   _editor_undo_redo_post(head_memento);
+   context_memento_not_updated_add((Gui_Context *) ctx, head_memento, 
EINA_FALSE);
 
    context_memento_move_to_prev((Gui_Context *) ctx);
 
@@ -2973,13 +2935,13 @@ _editor_redo(const Gui_Context *ctx)
      {
         Memento_Type type = memento_command_type_get(cmd);
         Eid *eid = memento_command_wdg_get(cmd);
+        Gui_Widget *wdg = wdg_get(eid);
         switch (type)
           {
            case MEMENTO_PROPERTY:
                 {
                    const Op_Desc *op_desc = NULL;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -3001,8 +2963,6 @@ _editor_redo(const Gui_Context *ctx)
                      {
                         op_desc = prop_op_desc_get(new_prop);
                         wdg_prop_add(wdg, new_prop);
-                        Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
-                        manager_widget_property_add(session, wdg, new_prop, 
NULL);
                         if (_editor_wdg_selected_get() != wdg)
                           {
                              objtree_item_selected_set(wdg);
@@ -3011,7 +2971,6 @@ _editor_redo(const Gui_Context *ctx)
                      }
                    else
                      {
-                        _wdg_parent_win_reload(wdg);
                         objtree_build();
                         objtree_item_selected_set(wdg);
                      }
@@ -3023,7 +2982,6 @@ _editor_redo(const Gui_Context *ctx)
                 {
                    Gui_Widget_Callback *new_cb;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -3044,7 +3002,6 @@ _editor_redo(const Gui_Context *ctx)
                 {
                    Callback_Container *new_cc;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -3062,7 +3019,6 @@ _editor_redo(const Gui_Context *ctx)
                 {
                    Object_Container *new_container;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -3079,7 +3035,6 @@ _editor_redo(const Gui_Context *ctx)
                 {
                    Item_Container_Item *new_it;
 
-                   Gui_Widget *wdg = wdg_get(eid);
                    if (!wdg)
                      {
                         ERR("wdg not found");
@@ -3094,32 +3049,11 @@ _editor_redo(const Gui_Context *ctx)
            case MEMENTO_WIDGET:
                 {
                    Eina_Bool new_state = (intptr_t) 
memento_command_new_pointer_get(cmd);
-                   _update_widget_on_undoredo(eid, new_state);
+                   eid_active_set(eid, new_state);
                    break;
                 }
            case MEMENTO_WIDGET_PARENT:
                 {
-                   Gui_Widget *wdg = wdg_get(eid);
-                   _wdg_border_draw(wdg, EINA_FALSE, BORDER_SELECTION);
-                   /* According to current scenario, widget can be dragged 
from canvas and dropped into object.
-                    * Thus here can be only main_wdg which is going to be 
redoed.
-                    * So it's frame and editor window must be deleted and 
Main_Wdg_Info data must be freed. */
-                   if (IS_MAIN(wdg) && !IS_WIN(wdg))
-                     {
-                        Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
-                        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
-                        wdg_data_set(wdg, MAIN_WDG_INFO, NULL);
-                        if (wi)
-                          {
-                             Eo *fr = main_wdg_info_frame_get(wi);
-                             Eo *o = session_eo_get(session, wdg);
-                             Eo *optional_win = eo_do_ret(o, optional_win, 
eo_key_data_get("__editor_win"));
-                             eo_del(optional_win);
-                             eo_del(fr);
-                             free(wi);
-                             session_wdg_existence_set(session, wdg, 
EINA_FALSE);
-                          }
-                     }
                    Eid *new_parent_id = (Eid *) 
memento_command_new_pointer_get(cmd);
                    wdg_parent_set(wdg, eid_name_get(new_parent_id));
                    break;
@@ -3163,78 +3097,13 @@ _editor_redo(const Gui_Context *ctx)
           }
      }
    /* Update propview. */
-   _editor_undo_redo_post(head_memento);
+   context_memento_not_updated_add((Gui_Context *) ctx, head_memento, 
EINA_TRUE);
 
    eo_do(g->main_win->toolbar_redo_it, 
elm_wdg_item_disabled_set(context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE));
    eo_do(g->main_win->toolbar_undo_it, 
elm_wdg_item_disabled_set(context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE));
    return EINA_TRUE;
 }
 
-static void
-_editor_undo_redo_post(const Memento *memento)
-{
-   Memento_Command *cmd;
-   const Eina_List *cmds_list = memento_commands_get(memento), *itr;
-   EINA_LIST_FOREACH(cmds_list, itr, cmd)
-     {
-        Memento_Type type = memento_command_type_get(cmd);
-        Eid *eid = memento_command_wdg_get(cmd);
-        Gui_Widget *memento_wdg = wdg_get(eid);
-        switch (type)
-          {
-           case MEMENTO_PROPERTY:
-                {
-                   break;
-                }
-           case MEMENTO_OBJ_CONTAINER_ITEM:
-           case MEMENTO_ITEM_CONTAINER_ITEM:
-                {
-                   proplayout_view_switch(CONTENT_TYPE);
-                   _wdg_parent_win_reload(memento_wdg);
-                   _editor_wdg_selected_set(memento_wdg);
-                   objtree_build();
-                   objtree_item_selected_set(memento_wdg);
-                   break;
-                }
-           case MEMENTO_CALLBACK:
-                {
-                   break;
-                }
-           case MEMENTO_CALLBACK_ADD_DEL:
-                {
-                   proplayout_view_switch(CALLBACK_TYPE);
-                   _editor_wdg_selected_set(memento_wdg);
-                   break;
-                }
-           case MEMENTO_WIDGET:
-           case MEMENTO_WIDGET_PARENT:
-                {
-                   if (memento_wdg)
-                     {
-                        _wdg_parent_win_reload(memento_wdg);
-                        _editor_wdg_selected_set(memento_wdg);
-                        objtree_build();
-                        objtree_item_selected_set(memento_wdg);
-                     }
-                   break;
-                }
-           case MEMENTO_NONE:
-           case MEMENTO_ACTION:
-           case MEMENTO_WIDGET_NAME:
-                {
-                   break;
-                }
-           case MEMENTO_WIDGET_PUBLIC:
-                {
-                   proplayout_view_switch(DESCRIPTION_TYPE);
-                   break;
-                }
-           default:
-              ERR("case - default");
-          }
-     }
-}
-
 static Eina_Bool
 _editor_ctx_call(const Gui_Context *ctx)
 {
@@ -3256,8 +3125,8 @@ _editor_ctx_call(const Gui_Context *ctx)
              continue;
           }
 
-        /* All windows should be shown in main gui window. */
-        _iter_widget_create(wdg, canvas_get());
+        Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
+        manager_widget_create(session, wdg, NULL);
      }
    /* During context call _win_resize() will be called.
     * It will draw border around win, but widget was not selected yet.
@@ -3276,26 +3145,28 @@ _editor_selected_wdg_del_cb()
    Gui_Widget *wdg = (Gui_Widget *) _editor_wdg_selected_get();
    Gui_Context *ctx = _active_context_get();
    if (!wdg) return;
-   const Gui_Widget *parent_wdg = wdg_parent_get((Gui_Widget *) wdg);
    _editor_wdg_selected_set(NULL);
-   _editor_widget_clear(wdg);
+
+   //_editor_widget_clear(wdg);
 
    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);
 
    /* if parent_wdg is not NULL, it's not window, so it has parent.
     * if parent wdg is NULL, wdg is window, so just delete it. */
+#if 0
    if (parent_wdg)
      {
         _wdg_parent_win_reload(parent_wdg);
      }
-   proplayout_build(NULL);
+#endif
+//   proplayout_build(NULL);
 
    /* Set selected widget: t.e. if I delete button, box will be selected after.
     * If I delete window, main item will be selected. */
-   objtree_build();
-   objtree_item_selected_set(parent_wdg);
-   _editor_wdg_selected_set(parent_wdg);
+//   objtree_build();
+//   objtree_item_selected_set(parent_wdg);
+//   _editor_wdg_selected_set(parent_wdg);
    context_memento_finalize(ctx);
 }
 
@@ -3531,12 +3402,12 @@ _prop_update_from_propview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Descr
     * in order to update layout. */
    if (reload_win)
      {
-        _wdg_parent_win_reload(wdg);
         proplayout_build(NULL);
         _editor_wdg_selected_set(wdg);
         objtree_build();
         objtree_item_selected_set(wdg);
      }
+#if 0
    else
      {
         /* Don't do anything with win if prop is VISIBILITY*/
@@ -3546,9 +3417,10 @@ _prop_update_from_propview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Descr
         else
           {
              Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
-             manager_widget_property_add(session, wdg, prop, NULL);
+             //manager_widget_property_add(session, wdg, prop, NULL);
           }
      }
+#endif
    context_memento_finalize(ctx);
    return EO_CALLBACK_CONTINUE;
    /* FIXME: add return here? */
@@ -3578,7 +3450,6 @@ _drop_property_cb(void *data, Evas_Object *obj, void 
*event_info EINA_UNUSED)
              memento_command_add(wdg_eid_get(wdg), MEMENTO_PROPERTY, prop, 
NULL);
 
              wdg_prop_remove((Gui_Widget *) wdg, (Gui_Widget_Property *) prop);
-             _wdg_parent_win_reload(wdg);
              proplayout_build(NULL);
              _editor_wdg_selected_set(wdg);
              objtree_build();
@@ -3671,7 +3542,6 @@ _field_update_from_itemview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Desc
    memento_command_add(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, (void *) 
wit, new_wit);
 
    /* Change item in Dep_Data*/
-
    item_container_item_set_on_id(item_container_item_eid_get(wit), new_wit);
 
    /* Get value which need to be changed.*/
@@ -3690,7 +3560,6 @@ _field_update_from_itemview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Desc
              gui_value_string_set(val, entry_data);
 
              /* Reloading all window. */
-             _wdg_parent_win_reload(wdg);
              proplayout_build(NULL);
              _editor_wdg_selected_set(wdg);
              objtree_build();
@@ -3886,7 +3755,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:
@@ -3910,7 +3779,6 @@ _itemview_item_do_(unsigned int type)
 
    if (reload)
      {
-        _wdg_parent_win_reload(wdg);
         proplayout_build(NULL);
         _editor_wdg_selected_set(wdg);
         objtree_build();
@@ -3958,7 +3826,6 @@ _content_del_from_propview(void *data, Eo *obj 
EINA_UNUSED, const Eo_Event_Descr
    /* Delete content from container data. */
    wdg_obj_container_item_remove(wdg, ci);
    /* Reload window when unpacking something. */
-   _wdg_parent_win_reload(wdg);
    _editor_wdg_selected_set(wdg);
    objtree_build();
    objtree_item_selected_set(wdg);
@@ -3994,8 +3861,6 @@ _content_reorder_from_propview(void *data, Eo *obj 
EINA_UNUSED, const Eo_Event_D
           {
              memento_command_add(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, 
_old_container, _new_container);
 
-             /* Reload all the win when content reordered */
-              _wdg_parent_win_reload(wdg);
              /* Update propview. */
              _editor_wdg_selected_set(wdg);
              objtree_build();
@@ -4126,7 +3991,6 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_De
              ci = obj_container_item_new(new_prop, eid);
              wdg_obj_container_item_add((Gui_Widget *) wdg, ci, 
pfd->it_data->idx);
 
-             _wdg_parent_win_reload(wdg);
              _editor_wdg_selected_set(wdg);
              objtree_build();
              objtree_item_selected_set(wdg);
@@ -4221,8 +4085,6 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_De
              ci = obj_container_item_new(new_prop, eid);
              wdg_obj_container_item_add((Gui_Widget *) wdg, ci, 
pfd->it_data->idx);
 
-             /* Need to reload all window, because previously packed widgets 
will stay at their places. */
-              _wdg_parent_win_reload(wdg);
              /* Update propview. */
              _editor_wdg_selected_set(wdg);
              objtree_build();
@@ -4418,7 +4280,9 @@ _project_new(const char *filename)
    objtree_context_set(ctx);
 
    /* Assign new editor session to context */
-   gui_context_editor_session_set(_active_context_get(), 
session_new(MODE_EDITOR, EINA_TRUE));
+   Gui_Session *session = session_new(MODE_EDITOR, EINA_TRUE);
+   gui_context_editor_session_set(ctx, session);
+   updater_session_add(ctx, session);
 
    _editor_ctx_call(ctx);
 
diff --git a/src/lib/gui_widget.c b/src/lib/gui_widget.c
index 71c949e..501db7b 100644
--- a/src/lib/gui_widget.c
+++ b/src/lib/gui_widget.c
@@ -3956,7 +3956,15 @@ void
 context_memento_finalize(Gui_Context *ctx)
 {
    const Memento *mem = context_current_memento_get(ctx);
-   if (mem) memento_finalize((Memento *)mem);
+   if (mem)
+     {
+        if (!memento_finalize((Memento *) mem))
+          {
+             context_memento_move_to_prev(ctx);
+             context_memento_discard(ctx);
+             return;
+          }
+     }
    if (_new_memento_cb) _new_memento_cb(_new_memento_data);
    // add changes on ctx HERE
    ctx->not_updated_mementos = eina_list_append(ctx->not_updated_mementos, 
mem);
@@ -3964,6 +3972,15 @@ context_memento_finalize(Gui_Context *ctx)
    updater_wake(ctx);
 }
 
+/* FIXME: remove this func, when editor_undo will move to gui_widget. */
+void
+context_memento_not_updated_add(Gui_Context *ctx, const Memento *mem, 
Eina_Bool dir)
+{
+   ctx->not_updated_mementos = eina_list_append(ctx->not_updated_mementos, 
mem);
+   ctx->not_updated_mementos_direction = dir;
+   updater_wake(ctx);
+}
+
 Eina_List *
 context_memento_not_updated_list_steal(Gui_Context *ctx, Eina_Bool *dir)
 {
diff --git a/src/lib/gui_widget.h b/src/lib/gui_widget.h
index e96df91..b48e532 100644
--- a/src/lib/gui_widget.h
+++ b/src/lib/gui_widget.h
@@ -992,6 +992,10 @@ context_current_memento_get(const Gui_Context *ctx);
 void
 context_memento_finalize(Gui_Context *ctx);
 
+/* FIXME: remove this func, when editor_undo will move to gui_widget. */
+void
+context_memento_not_updated_add(Gui_Context *ctx, const Memento *mem, 
Eina_Bool dir);
+
 Eina_List *
 context_memento_not_updated_list_steal(Gui_Context *ctx, Eina_Bool *dir);
 
diff --git a/src/lib/undoredo.c b/src/lib/undoredo.c
index 9ec6ef0..42c7302 100644
--- a/src/lib/undoredo.c
+++ b/src/lib/undoredo.c
@@ -6,6 +6,7 @@ struct _Memento_Command
 {
    Eid *eid; // wdg, action...
    Memento_Type type;
+   Eina_Bool delete_me : 1;
    union
      {
         struct
@@ -273,10 +274,11 @@ memento_is_finalized(const Memento *memento)
    return memento->finalized;
 }
 
-void
+/* Return EINA_FALSE if memento is empty after finalize and should be deleted 
*/
+Eina_Bool
 memento_finalize(Memento *memento)
 {
-   Eina_List *itr;
+   Eina_List *itr, *itr2;
    Memento_Command *cmd, *cmd_next;
    memento->finalized = EINA_TRUE;
    Eina_Bool change = EINA_TRUE;
@@ -286,6 +288,7 @@ memento_finalize(Memento *memento)
         change = EINA_FALSE;
         EINA_LIST_FOREACH(memento->cmds, itr, cmd)
           {
+             if (cmd->delete_me) continue;
              Eina_List *next = eina_list_next(itr);
              if (next)
                {
@@ -298,13 +301,46 @@ memento_finalize(Memento *memento)
                        void *tmp = cmd->new_ptr;
                        cmd->new_ptr = cmd_next->new_ptr;
                        cmd_next->new_ptr = tmp;
-                       memento->cmds = eina_list_remove_list(memento->cmds, 
next);
-                       _cmd_del(cmd_next);
+                       cmd_next->delete_me = EINA_TRUE;
                        change = EINA_TRUE;
                     }
                }
+             if (cmd->old_ptr == cmd->new_ptr)
+               {
+                  cmd->delete_me = EINA_TRUE;
+               }
+             if (cmd->type == MEMENTO_OBJ_CONTAINER_ITEM)
+               {
+                  const Eina_List *from_list, *to_list;
+                  from_list = obj_container_contents_list_get(cmd->old_ptr);
+                  to_list = obj_container_contents_list_get(cmd->new_ptr);
+                  if (eina_list_count(from_list) != eina_list_count(to_list)) 
continue;
+                  cmd->delete_me = EINA_TRUE;
+                  while (from_list)
+                    {
+                       if 
(obj_container_item_eid_get(eina_list_data_get(from_list)) !=
+                           
obj_container_item_eid_get(eina_list_data_get(to_list)))
+                         {
+                            cmd->delete_me = EINA_FALSE;
+                            break;
+                         }
+
+                       from_list = eina_list_next(from_list);
+                       to_list = eina_list_next(to_list);
+                    }
+
+               }
+          }
+        EINA_LIST_FOREACH_SAFE(memento->cmds, itr, itr2, cmd)
+          {
+             if (cmd->delete_me)
+               {
+                  memento->cmds = eina_list_remove_list(memento->cmds, itr);
+                  _cmd_del(cmd);
+               }
           }
      }
+   return !!memento->cmds;
 }
 
 /* Get last Memento command */
diff --git a/src/lib/undoredo.h b/src/lib/undoredo.h
index 64da3c6..2290230 100644
--- a/src/lib/undoredo.h
+++ b/src/lib/undoredo.h
@@ -39,7 +39,8 @@ memento_del(Memento *memento);
 Eina_Bool
 memento_is_finalized(const Memento *memento);
 
-void
+/* Return EINA_FALSE if memento is empty after finalize and should be deleted 
*/
+Eina_Bool
 memento_finalize(Memento *memento);
 
 const Eina_List *
diff --git a/src/lib/updater.c b/src/lib/updater.c
index a695a4e..3603784 100644
--- a/src/lib/updater.c
+++ b/src/lib/updater.c
@@ -1,5 +1,6 @@
 #include <Ecore.h>
 
+#include "egui_log.h"
 #include "gui_widget.h"
 #include "ffi_glue.h"
 #include "updater.h"
@@ -54,7 +55,6 @@ _update_check(void *data EINA_UNUSED)
 {
    Gui_Context *ctx;
    if (!_ctxs_to_update) return EINA_TRUE;
-   printf("Checking contexts\n");
    EINA_LIST_FREE(_ctxs_to_update, ctx)
      {
         Eina_Bool mem_dir = EINA_TRUE;
@@ -63,11 +63,21 @@ _update_check(void *data EINA_UNUSED)
         Memento *mem;
         EINA_LIST_FREE(mementos, mem)
           {
-             const Eina_List *itr;
+             const Eina_List *itr, *commands;
              Memento_Command *cmd;
-             EINA_LIST_FOREACH(memento_commands_get(mem), itr, cmd)
+
+             commands = memento_commands_get(mem);
+             itr = mem_dir ? commands : eina_list_last(commands);
+
+             /* According to direction we must iterate forward/backward 
through commands.
+              * Following for loop is opened EINA_LIST_FOREACH and 
EINA_LIST_REVERSE_FOREACH */
+             for (cmd = eina_list_data_get(itr);
+                  itr;
+                  itr = (mem_dir ? eina_list_next(itr) : eina_list_prev(itr)),
+                  cmd = eina_list_data_get(itr))
                {
                   Eid *eid = memento_command_wdg_get(cmd);
+                  Gui_Widget *wdg = wdg_get(eid);
                   Memento_Type type = memento_command_type_get(cmd);
                   void *from, *to;
                   if (mem_dir)
@@ -84,23 +94,94 @@ _update_check(void *data EINA_UNUSED)
                     {
                      case MEMENTO_WIDGET:
                           {
-                             printf("Widget %d state %p -> %p\n", eid, from, 
to);
-                             if (from) _eo_del_apply(sessions, eid);
-                             else _eo_add_apply(sessions, eid);
+                             if (from)
+                               {
+                                  eid_active_set(eid, EINA_TRUE);
+                                  _eo_del_apply(sessions, eid);
+                                  eid_active_set(eid, EINA_FALSE);
+                               }
+                             else
+                               {
+                                  _eo_add_apply(sessions, eid);
+                                  Eid *parent_container_id = 
wdg_parent_container_eid_get(wdg);
+                                  if (parent_container_id)
+                                    {
+                                       Gui_Widget *cont = 
wdg_get(parent_container_id);
+                                       Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
+                                       
manager_widget_content_unset_all(session, cont, 
wdg_obj_container_class_name_get(cont), NULL);
+                                       manager_widget_content_add(session, 
cont, NULL);
+                                    }
+                               }
                              break;
                           }
                      case MEMENTO_PROPERTY:
-                     case MEMENTO_ACTION:
-                     case MEMENTO_CALLBACK:
-                     case MEMENTO_CALLBACK_ADD_DEL:
+                          {
+                             Gui_Widget_Property *prop = to;
+
+                             if (prop)
+                               {
+                                  Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
+                                  manager_widget_property_add(session, wdg, 
prop, NULL);
+                               }
+                             else
+                               {
+                                  _eo_del_apply(sessions, eid);
+                                  _eo_add_apply(sessions, eid);
+                                  /* Here separate algorithm for each kind of 
container can be implemented. */
+                                  Eid *parent_container_id = 
wdg_parent_container_eid_get(wdg);
+                                  if (parent_container_id)
+                                    {
+                                       Gui_Widget *cont = 
wdg_get(parent_container_id);
+                                       Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
+                                       
manager_widget_content_unset_all(session, cont, 
wdg_obj_container_class_name_get(cont), NULL);
+                                       manager_widget_content_add(session, 
cont, NULL);
+                                    }
+                               }
+                             break;
+                          }
                      case MEMENTO_OBJ_CONTAINER_ITEM:
+                          {
+                             Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
+                             manager_widget_content_unset_all(session, wdg, 
wdg_obj_container_class_name_get(wdg), NULL);
+                             manager_widget_content_add(session, wdg, NULL);
+                             break;
+                          }
+                     case MEMENTO_WIDGET_PARENT:
+                          {
+                             _eo_del_apply(sessions, eid);
+                             _eo_add_apply(sessions, eid);
+                             break;
+                          }
                      case MEMENTO_OBJ_CONTAINER_PROPERTY:
                      case MEMENTO_ITEM_CONTAINER_ITEM:
-                     case MEMENTO_WIDGET_PARENT:
+                          {
+                             if (strstr(wdg_name_get(wdg), "main_menu"))
+                               {
+                                  Eid *parent_eid = wdg_parent_id_get(wdg);
+                                  _eo_del_apply(sessions, parent_eid);
+                                  _eo_add_apply(sessions, parent_eid);
+                                  break;
+                              }
+                             _eo_del_apply(sessions, eid);
+                             _eo_add_apply(sessions, eid);
+                             /* Here separate algorithm for each kind of 
container can be implemented. */
+                             Eid *parent_container_id = 
wdg_parent_container_eid_get(wdg);
+                             if (parent_container_id)
+                               {
+                                  Gui_Widget *cont = 
wdg_get(parent_container_id);
+                                  Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(ctx);
+                                  manager_widget_content_unset_all(session, 
cont, wdg_obj_container_class_name_get(cont), NULL);
+                                  manager_widget_content_add(session, cont, 
NULL);
+                               }
+                             break;
+                          }
+                     case MEMENTO_ACTION:
+                     case MEMENTO_CALLBACK:
+                     case MEMENTO_CALLBACK_ADD_DEL:
                      case MEMENTO_WIDGET_NAME:
                      case MEMENTO_WIDGET_PUBLIC:
                      default:
-                        printf("%s - Apply %d\n", __FUNCTION__, 
memento_command_type_get(cmd));
+                        printf("%s - Apply %d\n", __FUNCTION__, type);
                         break;
                     }
                }

-- 


Reply via email to