summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2015-10-10 22:04:15 +0300
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2015-10-10 22:54:17 +0300
commit31d6e210e76d07343e6310758065dc0c3523a0de (patch)
tree295324bec67a6c8c4d952a0fd1a7128ea34ed72f
parented8ca8140df6109ce069f4132be02abc2ab0d2a7 (diff)
Mementos: refactoring.devs/yakov/erigo_1_15
Before, a memento command had to know if it has to be appended to a previous memento, which is wrong. Now, the memento is added independently. A finalization function needs to be invoked, so all the mementos added between two finalizations are considered atomic (always applied together).
-rw-r--r--src/bin/gui/cbview.c40
-rw-r--r--src/bin/gui/descview.c12
-rw-r--r--src/bin/gui/editor.c309
-rw-r--r--src/lib/gui_widget.c90
-rw-r--r--src/lib/gui_widget.h32
-rw-r--r--src/lib/undoredo.c237
-rw-r--r--src/lib/undoredo.h39
7 files changed, 344 insertions, 415 deletions
diff --git a/src/bin/gui/cbview.c b/src/bin/gui/cbview.c
index 4cbbfde..d98db3e 100644
--- a/src/bin/gui/cbview.c
+++ b/src/bin/gui/cbview.c
@@ -63,8 +63,7 @@ _action_type_changed(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description
63 const Callback_Container *cc_old = wdg_cb_container_get(wdg); 63 const Callback_Container *cc_old = wdg_cb_container_get(wdg);
64 Callback_Container *cc_new = cc_old?cb_container_copy(cc_old):cb_container_new(); 64 Callback_Container *cc_new = cc_old?cb_container_copy(cc_old):cb_container_new();
65 cb_container_cb_add(cc_new, cb); 65 cb_container_cb_add(cc_new, cb);
66 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_CALLBACK_ADD_DEL, (void *)cc_old, cc_new); 66 memento_command_add(wdg_eid_get(wdg), MEMENTO_CALLBACK_ADD_DEL, (void *)cc_old, cc_new);
67 gui_context_memento_add(ctx, memento);
68 67
69 wdg_cb_container_unset(wdg); 68 wdg_cb_container_unset(wdg);
70 wdg_cb_container_set(wdg, cc_new); 69 wdg_cb_container_set(wdg, cc_new);
@@ -72,9 +71,8 @@ _action_type_changed(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description
72 else 71 else
73 { 72 {
74 new_action = action_copy(action_id); 73 new_action = action_copy(action_id);
75 Memento *memento = memento_new(action_id, MEMENTO_ACTION, old_action, new_action); 74 memento_command_add(action_id, MEMENTO_ACTION, old_action, new_action);
76 action_set(action_id, new_action); 75 action_set(action_id, new_action);
77 gui_context_memento_add(ctx, memento);
78 } 76 }
79 77
80 Action_Type action_type = action_type_get_from_string(type_as_string); 78 Action_Type action_type = action_type_get_from_string(type_as_string);
@@ -100,6 +98,7 @@ _action_type_changed(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description
100 98
101 cbview_build(it_data->wdg); 99 cbview_build(it_data->wdg);
102 cbview_item_selected_set(cb_eid_get(cb)); 100 cbview_item_selected_set(cb_eid_get(cb));
101 context_memento_finalize(ctx);
103 102
104 return EO_CALLBACK_CONTINUE; 103 return EO_CALLBACK_CONTINUE;
105} 104}
@@ -117,9 +116,8 @@ _action_wdg_selected(void *data, Eo *obj EINA_UNUSED, void *event_info)
117 if (action) 116 if (action)
118 { 117 {
119 Gui_Action *new_action = action_copy(action_id); 118 Gui_Action *new_action = action_copy(action_id);
120 Memento *memento = memento_new(action_id, MEMENTO_ACTION, action, new_action); 119 memento_command_add(action_id, MEMENTO_ACTION, action, new_action);
121 action_set(action_id, new_action); 120 action_set(action_id, new_action);
122 gui_context_memento_add(ctx, memento);
123 121
124 const char *wdg_name = elm_object_item_part_text_get(event_info, NULL); 122 const char *wdg_name = elm_object_item_part_text_get(event_info, NULL);
125 Eid *wdg_id = gui_context_eid_get_by_name(ctx, wdg_name); 123 Eid *wdg_id = gui_context_eid_get_by_name(ctx, wdg_name);
@@ -132,6 +130,7 @@ _action_wdg_selected(void *data, Eo *obj EINA_UNUSED, void *event_info)
132 130
133 cbview_build(it_data->wdg); 131 cbview_build(it_data->wdg);
134 cbview_item_selected_set(cb_eid_get(cb)); 132 cbview_item_selected_set(cb_eid_get(cb));
133 context_memento_finalize(ctx);
135} 134}
136 135
137static Eina_Bool 136static Eina_Bool
@@ -147,9 +146,8 @@ _action_parent_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descript
147 if (action) 146 if (action)
148 { 147 {
149 Gui_Action *new_action = action_copy(action_id); 148 Gui_Action *new_action = action_copy(action_id);
150 Memento *memento = memento_new(action_id, MEMENTO_ACTION, action, new_action); 149 memento_command_add(action_id, MEMENTO_ACTION, action, new_action);
151 action_set(action_id, new_action); 150 action_set(action_id, new_action);
152 gui_context_memento_add(ctx, memento);
153 151
154 const char *parent_name = elm_object_item_part_text_get(event_info, NULL); 152 const char *parent_name = elm_object_item_part_text_get(event_info, NULL);
155 Eid *parent_id = gui_context_eid_get_by_name(ctx, parent_name); 153 Eid *parent_id = gui_context_eid_get_by_name(ctx, parent_name);
@@ -158,6 +156,7 @@ _action_parent_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descript
158 156
159 cbview_build(it_data->wdg); 157 cbview_build(it_data->wdg);
160 cbview_item_selected_set(cb_eid_get(cb)); 158 cbview_item_selected_set(cb_eid_get(cb));
159 context_memento_finalize(ctx);
161 return EO_CALLBACK_CONTINUE; 160 return EO_CALLBACK_CONTINUE;
162} 161}
163 162
@@ -174,9 +173,8 @@ _action_user_cb_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descrip
174 if (action) 173 if (action)
175 { 174 {
176 Gui_Action *new_action = action_copy(action_id); 175 Gui_Action *new_action = action_copy(action_id);
177 Memento *memento = memento_new(action_id, MEMENTO_ACTION, action, new_action); 176 memento_command_add(action_id, MEMENTO_ACTION, action, new_action);
178 action_set(action_id, new_action); 177 action_set(action_id, new_action);
179 gui_context_memento_add(ctx, memento);
180 178
181 const char *cb_name = elm_object_item_part_text_get(event_info, NULL); 179 const char *cb_name = elm_object_item_part_text_get(event_info, NULL);
182 Eid *cb_id = gui_context_eid_get_by_name(ctx, cb_name); 180 Eid *cb_id = gui_context_eid_get_by_name(ctx, cb_name);
@@ -185,6 +183,7 @@ _action_user_cb_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descrip
185 183
186 cbview_build(it_data->wdg); 184 cbview_build(it_data->wdg);
187 cbview_item_selected_set(cb_eid_get(cb)); 185 cbview_item_selected_set(cb_eid_get(cb));
186 context_memento_finalize(ctx);
188 return EO_CALLBACK_CONTINUE; 187 return EO_CALLBACK_CONTINUE;
189} 188}
190 189
@@ -193,7 +192,6 @@ _action_prop_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descriptio
193{ 192{
194 It_Data *it_data = data; 193 It_Data *it_data = data;
195 Gui_Widget_Callback *cb = it_data->cb; 194 Gui_Widget_Callback *cb = it_data->cb;
196 Gui_Context *ctx = (Gui_Context *) wdg_context_get(it_data->wdg);
197 195
198 Eid *action_id = cb_action_id_get(cb); 196 Eid *action_id = cb_action_id_get(cb);
199 Gui_Action *action = action_get(action_id); 197 Gui_Action *action = action_get(action_id);
@@ -226,8 +224,7 @@ _action_prop_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descriptio
226 Gui_Widget_Property *prop = prop_create_for_op(op); 224 Gui_Widget_Property *prop = prop_create_for_op(op);
227 225
228 Gui_Action *new_action = action_copy(action_id); 226 Gui_Action *new_action = action_copy(action_id);
229 Memento *memento = memento_new(action_id, MEMENTO_ACTION, action, new_action); 227 memento_command_add(action_id, MEMENTO_ACTION, action, new_action);
230 gui_context_memento_add(ctx, memento);
231 228
232 action_modif_set(new_action, wdg_id, prop); 229 action_modif_set(new_action, wdg_id, prop);
233 action_set(action_id, new_action); 230 action_set(action_id, new_action);
@@ -238,6 +235,7 @@ _action_prop_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descriptio
238 cbview_build(it_data->wdg); 235 cbview_build(it_data->wdg);
239 cbview_item_selected_set(cb_eid_get(cb)); 236 cbview_item_selected_set(cb_eid_get(cb));
240 } 237 }
238 context_memento_finalize(_active_context_get());
241 return EO_CALLBACK_CONTINUE; 239 return EO_CALLBACK_CONTINUE;
242} 240}
243 241
@@ -270,11 +268,11 @@ _action_item_selected(void *data, Eo *obj, const Eo_Event_Description *desc EINA
270 268
271 Eid *wdg_id = action_widget_id_get(action); 269 Eid *wdg_id = action_widget_id_get(action);
272 Gui_Action *new_action = action_copy(action_id); 270 Gui_Action *new_action = action_copy(action_id);
273 Memento *memento = memento_new(action_id, MEMENTO_ACTION, action, new_action); 271 memento_command_add(action_id, MEMENTO_ACTION, action, new_action);
274 gui_context_memento_add(ctx, memento);
275 272
276 action_modif_set(new_action, wdg_id, new_prop); 273 action_modif_set(new_action, wdg_id, new_prop);
277 action_set(action_id, new_action); 274 action_set(action_id, new_action);
275 context_memento_finalize(ctx);
278 return EO_CALLBACK_CONTINUE; 276 return EO_CALLBACK_CONTINUE;
279} 277}
280 278
@@ -387,8 +385,8 @@ _action_prop_update(void *data, Eo *obj, void *event_info)
387 } 385 }
388 Eid *wdg_id = action_widget_id_get(action); 386 Eid *wdg_id = action_widget_id_get(action);
389 Gui_Action *new_action = action_copy(action_id); 387 Gui_Action *new_action = action_copy(action_id);
390 Memento *memento = memento_new(action_id, MEMENTO_ACTION, action, new_action); 388 memento_command_add(action_id, MEMENTO_ACTION, action, new_action);
391 gui_context_memento_add(ctx, memento); 389 context_memento_finalize(_active_context_get());
392 390
393 action_modif_set(new_action, wdg_id, new_prop); 391 action_modif_set(new_action, wdg_id, new_prop);
394 action_set(action_id, new_action); 392 action_set(action_id, new_action);
@@ -709,8 +707,7 @@ _selected_callback_move(int dir)
709 cc_new = cb_container_copy(cc_old); 707 cc_new = cb_container_copy(cc_old);
710 if (cb_container_cb_move(cc_new, cb, dir)) 708 if (cb_container_cb_move(cc_new, cb, dir))
711 { 709 {
712 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_CALLBACK_ADD_DEL, (void *)cc_old, cc_new); 710 memento_command_add(wdg_eid_get(wdg), MEMENTO_CALLBACK_ADD_DEL, (void *)cc_old, cc_new);
713 gui_context_memento_add((Gui_Context *) wdg_context_get(wdg), memento);
714 711
715 wdg_cb_container_unset((Gui_Widget *) wdg); 712 wdg_cb_container_unset((Gui_Widget *) wdg);
716 wdg_cb_container_set((Gui_Widget *) wdg, cc_new); 713 wdg_cb_container_set((Gui_Widget *) wdg, cc_new);
@@ -727,6 +724,7 @@ _selected_callback_move(int dir)
727 } 724 }
728 } 725 }
729 } 726 }
727 context_memento_finalize(_active_context_get());
730} 728}
731 729
732Eina_Bool 730Eina_Bool
@@ -758,14 +756,14 @@ _callbacksview_del_btn_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, cons
758 cc_old = wdg_cb_container_get(wdg); 756 cc_old = wdg_cb_container_get(wdg);
759 cc_new = cb_container_copy(cc_old); 757 cc_new = cb_container_copy(cc_old);
760 cb_container_cb_remove(cc_new, cb); 758 cb_container_cb_remove(cc_new, cb);
761 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_CALLBACK_ADD_DEL, (void *)cc_old, cc_new); 759 memento_command_add(wdg_eid_get(wdg), MEMENTO_CALLBACK_ADD_DEL, (void *)cc_old, cc_new);
762 gui_context_memento_add((Gui_Context *) wdg_context_get(wdg), memento);
763 760
764 wdg_cb_container_unset((Gui_Widget *) wdg); 761 wdg_cb_container_unset((Gui_Widget *) wdg);
765 wdg_cb_container_set((Gui_Widget *) wdg, cc_new); 762 wdg_cb_container_set((Gui_Widget *) wdg, cc_new);
766 763
767 cbview_build(wdg); 764 cbview_build(wdg);
768 cbview_item_selected_set(cb_eid_get(cb)); 765 cbview_item_selected_set(cb_eid_get(cb));
766 context_memento_finalize(_active_context_get());
769 } 767 }
770 return EO_CALLBACK_CONTINUE; 768 return EO_CALLBACK_CONTINUE;
771} 769}
diff --git a/src/bin/gui/descview.c b/src/bin/gui/descview.c
index d3bfd11..1ef36e8 100644
--- a/src/bin/gui/descview.c
+++ b/src/bin/gui/descview.c
@@ -38,10 +38,8 @@ _wdg_public_change_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA
38 old_state = wdg_public_get(wdg); 38 old_state = wdg_public_get(wdg);
39 wdg_public_set(wdg, new_state); 39 wdg_public_set(wdg, new_state);
40 40
41 const Gui_Context *ctx = wdg_context_get(wdg); 41 memento_command_add(wdg_eid_get(wdg), MEMENTO_WIDGET_PUBLIC, (void *) (intptr_t) old_state, (void *) (intptr_t) new_state);
42 Memento *memento = NULL; 42 context_memento_finalize(_active_context_get());
43 memento = memento_new(wdg_eid_get(wdg), MEMENTO_WIDGET_PUBLIC, (void *) (intptr_t) old_state, (void *) (intptr_t) new_state);
44 gui_context_memento_add((Gui_Context *) ctx, memento);
45 43
46 return EO_CALLBACK_CONTINUE; 44 return EO_CALLBACK_CONTINUE;
47} 45}
@@ -57,10 +55,8 @@ _wdg_name_change_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_U
57 /* If name change was successful, save memento. */ 55 /* If name change was successful, save memento. */
58 if (widget_name_change(wdg, new_name)) 56 if (widget_name_change(wdg, new_name))
59 { 57 {
60 const Gui_Context *ctx = wdg_context_get(wdg); 58 memento_command_add(wdg_eid_get(wdg), MEMENTO_WIDGET_NAME, (void *) old_name, (void *) new_name);
61 Memento *memento = NULL; 59 context_memento_finalize(_active_context_get());
62 memento = memento_new(wdg_eid_get(wdg), MEMENTO_WIDGET_NAME, (void *) old_name, (void *) new_name);
63 gui_context_memento_add((Gui_Context *) ctx, memento);
64 } 60 }
65 free(old_name); 61 free(old_name);
66 return EO_CALLBACK_CONTINUE; 62 return EO_CALLBACK_CONTINUE;
diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c
index f6950d5..864ec10 100644
--- a/src/bin/gui/editor.c
+++ b/src/bin/gui/editor.c
@@ -988,9 +988,7 @@ _marker_mouse_up(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *de
988 { 988 {
989 goto end; 989 goto end;
990 } 990 }
991 Memento *memento = NULL; 991 memento_command_add(wdg_eid_get(wdg), MEMENTO_PROPERTY, _mmd.prop_size, prop);
992 memento = memento_new(wdg_eid_get(wdg), MEMENTO_PROPERTY, _mmd.prop_size, prop);
993 gui_context_memento_add(_active_context_get(), memento);
994 } 992 }
995 993
996 /* For non Main widget save position in memento. */ 994 /* For non Main widget save position in memento. */
@@ -1013,9 +1011,7 @@ _marker_mouse_up(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *de
1013 { 1011 {
1014 goto end; 1012 goto end;
1015 } 1013 }
1016 Memento *memento = NULL; 1014 memento_command_add(wdg_eid_get(wdg), MEMENTO_PROPERTY, _mmd.prop_pos, prop);
1017 memento = memento_new(wdg_eid_get(wdg), MEMENTO_PROPERTY, _mmd.prop_pos, prop);
1018 memento_append((Memento *) gui_context_current_memento_get(_active_context_get()), memento);
1019 } 1015 }
1020 } 1016 }
1021 1017
@@ -1044,6 +1040,7 @@ end:
1044 _mmd.object_y = 0; 1040 _mmd.object_y = 0;
1045 _mmd.delta_x = 0; 1041 _mmd.delta_x = 0;
1046 _mmd.delta_y = 0; 1042 _mmd.delta_y = 0;
1043 context_memento_finalize(_active_context_get());
1047 return EO_CALLBACK_CONTINUE; 1044 return EO_CALLBACK_CONTINUE;
1048} 1045}
1049 1046
@@ -1890,7 +1887,7 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
1890 } 1887 }
1891 if (drop_to_wdg == NO_DROP) goto end; 1888 if (drop_to_wdg == NO_DROP) goto end;
1892 1889
1893 const Gui_Context *ctx = _active_context_get(); 1890 Gui_Context *ctx = _active_context_get();
1894 const Gui_Session *session = gui_context_editor_session_get(ctx); 1891 const Gui_Session *session = gui_context_editor_session_get(ctx);
1895 /* Drop when dragging from factory. */ 1892 /* Drop when dragging from factory. */
1896 int drop_x = di->pointer_x, drop_y = di->pointer_y; 1893 int drop_x = di->pointer_x, drop_y = di->pointer_y;
@@ -1900,6 +1897,9 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
1900 } 1897 }
1901 1898
1902 new_wdg = di->wdg_cur; 1899 new_wdg = di->wdg_cur;
1900 if (!dnd_is_source())
1901 memento_command_add(wdg_eid_get(new_wdg), MEMENTO_WIDGET,
1902 (void *) (intptr_t) EINA_FALSE, (void *) (intptr_t) EINA_TRUE);
1903 1903
1904 /* Check if new_widget was packed previously: take it's parent and check 1904 /* Check if new_widget was packed previously: take it's parent and check
1905 * if widget is packed into it's parent. 1905 * if widget is packed into it's parent.
@@ -1929,8 +1929,7 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
1929 /* If anything was reordered, need to reload content. */ 1929 /* If anything was reordered, need to reload content. */
1930 if (wdg_obj_container_content_reorder(wdg, cur_visual_idx, reorder_delta)) 1930 if (wdg_obj_container_content_reorder(wdg, cur_visual_idx, reorder_delta))
1931 { 1931 {
1932 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container); 1932 memento_command_add(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
1933 gui_context_memento_add(_active_context_get(), memento);
1934 } 1933 }
1935 obj_container_unref(_old_container); 1934 obj_container_unref(_old_container);
1936 } 1935 }
@@ -1946,8 +1945,7 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
1946 _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg); 1945 _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg);
1947 _new_container = obj_container_copy(_old_container); 1946 _new_container = obj_container_copy(_old_container);
1948 1947
1949 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container); 1948 memento_command_add(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
1950 gui_context_memento_add((Gui_Context *) ctx, memento);
1951 1949
1952 const Eina_List *old_lst = wdg_obj_container_contents_list_get(wdg); 1950 const Eina_List *old_lst = wdg_obj_container_contents_list_get(wdg);
1953 wdg_obj_container_unset((Gui_Widget *) wdg); 1951 wdg_obj_container_unset((Gui_Widget *) wdg);
@@ -2009,18 +2007,9 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
2009 gui_value_int_set(val, drop_y); 2007 gui_value_int_set(val, drop_y);
2010 propview_item_update(prop); 2008 propview_item_update(prop);
2011 2009
2012 Memento *memento = NULL; 2010 memento_command_add(wdg_eid_get(new_wdg), MEMENTO_PROPERTY, old_prop, prop);
2013 memento = memento_new(wdg_eid_get(new_wdg), MEMENTO_PROPERTY, old_prop, prop);
2014 2011
2015 /* If new widget was dragged from the factory, memento must be added to the previous one. */ 2012 /* If new widget was dragged from the factory, memento must be added to the previous one. */
2016 if (!dnd_is_source())
2017 {
2018 memento_append((Memento *) gui_context_current_memento_get(ctx), memento);
2019 }
2020 else
2021 {
2022 gui_context_memento_add((Gui_Context *) ctx, memento);
2023 }
2024 if (old_prop) 2013 if (old_prop)
2025 { 2014 {
2026 wdg_prop_remove((Gui_Widget *) new_wdg, old_prop); 2015 wdg_prop_remove((Gui_Widget *) new_wdg, old_prop);
@@ -2043,10 +2032,9 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
2043 Object_Container *_old_prev_container, *_new_prev_container; 2032 Object_Container *_old_prev_container, *_new_prev_container;
2044 _old_prev_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) prev_wdg_container); 2033 _old_prev_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) prev_wdg_container);
2045 _new_prev_container = obj_container_copy(_old_prev_container); 2034 _new_prev_container = obj_container_copy(_old_prev_container);
2046 Memento *memento = memento_new(wdg_eid_get(prev_wdg_container), 2035 memento_command_add(wdg_eid_get(prev_wdg_container),
2047 MEMENTO_OBJ_CONTAINER_ITEM, 2036 MEMENTO_OBJ_CONTAINER_ITEM,
2048 _old_prev_container, _new_prev_container); 2037 _old_prev_container, _new_prev_container);
2049 gui_context_memento_add((Gui_Context *) ctx, memento);
2050 wdg_obj_container_unset((Gui_Widget *) prev_wdg_container); 2038 wdg_obj_container_unset((Gui_Widget *) prev_wdg_container);
2051 wdg_obj_container_set((Gui_Widget *) prev_wdg_container, _new_prev_container); 2039 wdg_obj_container_set((Gui_Widget *) prev_wdg_container, _new_prev_container);
2052 2040
@@ -2057,27 +2045,24 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
2057 /* If dragging from a widget(window), unset parent*/ 2045 /* If dragging from a widget(window), unset parent*/
2058 else if (wdg_parent && (wdg_parent != wdg)) 2046 else if (wdg_parent && (wdg_parent != wdg))
2059 { 2047 {
2060 Memento *memento = memento_new(wdg_eid_get(new_wdg), 2048 memento_command_add(wdg_eid_get(new_wdg),
2061 MEMENTO_WIDGET_PARENT, 2049 MEMENTO_WIDGET_PARENT,
2062 wdg_parent_id_get(new_wdg), NULL); 2050 wdg_parent_id_get(new_wdg), NULL);
2063 gui_context_memento_add((Gui_Context *) ctx, memento);
2064 wdg_parent_set((Gui_Widget *) new_wdg, NULL); 2051 wdg_parent_set((Gui_Widget *) new_wdg, NULL);
2065 } 2052 }
2066 else if (!wdg_parent) 2053 else if (!wdg_parent)
2067 { 2054 {
2068 Memento *memento = memento_new(wdg_eid_get(new_wdg), 2055 memento_command_add(wdg_eid_get(new_wdg),
2069 MEMENTO_WIDGET_PARENT, 2056 MEMENTO_WIDGET_PARENT,
2070 NULL, NULL); 2057 NULL, NULL);
2071 gui_context_memento_add((Gui_Context *) ctx, memento);
2072 } 2058 }
2073 2059
2074 /* Where to drop. */ 2060 /* Where to drop. */
2075 if (drop_to_wdg == DROP_TO_CANVAS) 2061 if (drop_to_wdg == DROP_TO_CANVAS)
2076 { 2062 {
2077 Memento *memento_next = memento_new(wdg_eid_get(new_wdg), 2063 memento_command_add(wdg_eid_get(new_wdg),
2078 MEMENTO_WIDGET_PARENT, 2064 MEMENTO_WIDGET_PARENT,
2079 wdg_parent_id_get(new_wdg), NULL); 2065 wdg_parent_id_get(new_wdg), NULL);
2080 memento_append((Memento *) gui_context_current_memento_get(ctx), memento_next);
2081 wdg_parent_set((Gui_Widget *) new_wdg, NULL); 2066 wdg_parent_set((Gui_Widget *) new_wdg, NULL);
2082 wdg_data_set(new_wdg, CURSOR_DROP_X, (void *) (intptr_t) di->pointer_x); 2067 wdg_data_set(new_wdg, CURSOR_DROP_X, (void *) (intptr_t) di->pointer_x);
2083 wdg_data_set(new_wdg, CURSOR_DROP_Y, (void *) (intptr_t) di->pointer_y); 2068 wdg_data_set(new_wdg, CURSOR_DROP_Y, (void *) (intptr_t) di->pointer_y);
@@ -2085,11 +2070,9 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
2085 /* Dragging into win */ 2070 /* Dragging into win */
2086 else if (drop_to_wdg == DROP_TO_WIN) 2071 else if (drop_to_wdg == DROP_TO_WIN)
2087 { 2072 {
2088 Memento *memento_next = memento_new(wdg_eid_get(new_wdg), 2073 memento_command_add(wdg_eid_get(new_wdg),
2089 MEMENTO_WIDGET_PARENT, 2074 MEMENTO_WIDGET_PARENT,
2090 wdg_parent_id_get(new_wdg), wdg_eid_get(wdg)); 2075 wdg_parent_id_get(new_wdg), wdg_eid_get(wdg));
2091 Memento *memento_last = memento_next;
2092 memento_append((Memento *) gui_context_current_memento_get(ctx), memento_next);
2093 wdg_parent_set((Gui_Widget *) new_wdg, wdg_name_get(wdg)); 2076 wdg_parent_set((Gui_Widget *) new_wdg, wdg_name_get(wdg));
2094 if (new_wdg) 2077 if (new_wdg)
2095 { 2078 {
@@ -2112,8 +2095,7 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
2112 gui_value_int_set(val, drop_y); 2095 gui_value_int_set(val, drop_y);
2113 propview_item_update(prop); 2096 propview_item_update(prop);
2114 2097
2115 memento_next = memento_new(wdg_eid_get(new_wdg), MEMENTO_PROPERTY, old_prop, prop); 2098 memento_command_add(wdg_eid_get(new_wdg), MEMENTO_PROPERTY, old_prop, prop);
2116 memento_append(memento_last, memento_next);
2117 2099
2118 if (old_prop) 2100 if (old_prop)
2119 { 2101 {
@@ -2131,11 +2113,10 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
2131 _old_container = (Object_Container *) wdg_obj_container_get(wdg); 2113 _old_container = (Object_Container *) wdg_obj_container_get(wdg);
2132 _new_container = obj_container_copy(_old_container); 2114 _new_container = obj_container_copy(_old_container);
2133 2115
2134 Memento *memento_next = memento_new(wdg_eid_get(wdg), 2116 memento_command_add(wdg_eid_get(wdg),
2135 MEMENTO_OBJ_CONTAINER_ITEM, 2117 MEMENTO_OBJ_CONTAINER_ITEM,
2136 _old_container, _new_container); 2118 _old_container, _new_container);
2137 /* Current memento is a memento created, during _factory _widget_create earlier in this func. */ 2119 /* Current memento is a memento created, during _factory _widget_create earlier in this func. */
2138 memento_append((Memento *) gui_context_current_memento_get(ctx), memento_next);
2139 wdg_obj_container_unset(wdg); 2120 wdg_obj_container_unset(wdg);
2140 wdg_obj_container_set(wdg, _new_container); 2121 wdg_obj_container_set(wdg, _new_container);
2141 2122
@@ -2157,11 +2138,10 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
2157 _old_container = (Object_Container *) wdg_obj_container_get(wdg); 2138 _old_container = (Object_Container *) wdg_obj_container_get(wdg);
2158 _new_container = obj_container_copy(_old_container); 2139 _new_container = obj_container_copy(_old_container);
2159 2140
2160 Memento *memento_next = memento_new(wdg_eid_get(wdg), 2141 memento_command_add(wdg_eid_get(wdg),
2161 MEMENTO_OBJ_CONTAINER_ITEM, 2142 MEMENTO_OBJ_CONTAINER_ITEM,
2162 _old_container, _new_container); 2143 _old_container, _new_container);
2163 /* Current memento is a memento created, during _factory _widget_create earlier in this func. */ 2144 /* Current memento is a memento created, during _factory _widget_create earlier in this func. */
2164 memento_append((Memento *) gui_context_current_memento_get(ctx), memento_next);
2165 2145
2166 const Eina_List *old_lst = wdg_obj_container_contents_list_get(wdg), *l; 2146 const Eina_List *old_lst = wdg_obj_container_contents_list_get(wdg), *l;
2167 wdg_obj_container_unset(wdg); 2147 wdg_obj_container_unset(wdg);
@@ -2205,10 +2185,9 @@ _drop_target_drop(Gui_Widget *wdg, Eo *canvas_drop_target, const char *drag_data
2205 /* When drop into main object which is not window, only update parent. */ 2185 /* When drop into main object which is not window, only update parent. */
2206 else if (drop_to_wdg == DROP_TO_MAIN) 2186 else if (drop_to_wdg == DROP_TO_MAIN)
2207 { 2187 {
2208 Memento *memento_next = memento_new(wdg_eid_get(new_wdg), 2188 memento_command_add(wdg_eid_get(new_wdg),
2209 MEMENTO_WIDGET_PARENT, 2189 MEMENTO_WIDGET_PARENT,
2210 wdg_parent_id_get(new_wdg), wdg_eid_get(wdg)); 2190 wdg_parent_id_get(new_wdg), wdg_eid_get(wdg));
2211 memento_append((Memento *) gui_context_current_memento_get(ctx), memento_next);
2212 wdg_parent_set((Gui_Widget *) new_wdg, wdg_name_get(wdg)); 2191 wdg_parent_set((Gui_Widget *) new_wdg, wdg_name_get(wdg));
2213 } 2192 }
2214end: 2193end:
@@ -2233,6 +2212,7 @@ end:
2233 objtree_item_selected_set(new_wdg); 2212 objtree_item_selected_set(new_wdg);
2234 } 2213 }
2235 2214
2215 context_memento_finalize(ctx);
2236 return EINA_TRUE; 2216 return EINA_TRUE;
2237} 2217}
2238 2218
@@ -2925,39 +2905,33 @@ static Eina_Bool
2925_editor_undo(const Gui_Context *ctx) 2905_editor_undo(const Gui_Context *ctx)
2926{ 2906{
2927 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE); 2907 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
2928 const Memento *memento, *head_memento, *tmp; 2908 const Memento *memento, *head_memento;
2909 const Memento_Command *cmd;
2929 /* Save head memento for post function. */ 2910 /* Save head memento for post function. */
2930 head_memento = memento = gui_context_current_memento_get(ctx); 2911 head_memento = memento = context_current_memento_get(ctx);
2931 if (!memento) return EINA_FALSE; 2912 if (!memento) return EINA_FALSE;
2932 2913
2933 /* Find last element of the list */ 2914 const Eina_List *cmds_list = memento_commands_get(memento), *itr;
2934 tmp = memento_next(memento); 2915 EINA_LIST_REVERSE_FOREACH(cmds_list, itr, cmd)
2935 while (tmp)
2936 { 2916 {
2937 memento = tmp; 2917 Memento_Type type = memento_command_type_get(cmd);
2938 tmp = memento_next(memento); 2918 Eid *eid = memento_command_wdg_get(cmd);
2939 }
2940
2941 while (memento)
2942 {
2943 Memento_Type type = memento_type_get(memento);
2944 switch (type) 2919 switch (type)
2945 { 2920 {
2946 case MEMENTO_PROPERTY: 2921 case MEMENTO_PROPERTY:
2947 { 2922 {
2948 Gui_Widget_Property *old_prop, *new_prop; 2923 Gui_Widget_Property *old_prop, *new_prop;
2949 Eid *wdg_id = memento_wdg_get(memento);
2950 const Op_Desc *op_desc = NULL; 2924 const Op_Desc *op_desc = NULL;
2951 2925
2952 Gui_Widget *wdg = wdg_get(wdg_id); 2926 Gui_Widget *wdg = wdg_get(eid);
2953 if (!wdg) 2927 if (!wdg)
2954 { 2928 {
2955 ERR("wdg not found"); 2929 ERR("wdg not found");
2956 return EINA_FALSE; 2930 return EINA_FALSE;
2957 } 2931 }
2958 2932
2959 old_prop = memento_old_pointer_get(memento); 2933 old_prop = memento_command_old_pointer_get(cmd);
2960 new_prop = memento_new_pointer_get(memento); 2934 new_prop = memento_command_new_pointer_get(cmd);
2961 /* If last action was 'Drop prop', new_prop is NULL. */ 2935 /* If last action was 'Drop prop', new_prop is NULL. */
2962 if (new_prop) 2936 if (new_prop)
2963 { 2937 {
@@ -2992,16 +2966,15 @@ _editor_undo(const Gui_Context *ctx)
2992 case MEMENTO_OBJ_CONTAINER_ITEM: 2966 case MEMENTO_OBJ_CONTAINER_ITEM:
2993 { 2967 {
2994 Object_Container *old_container; 2968 Object_Container *old_container;
2995 Eid *wdg_id = memento_wdg_get(memento);
2996 2969
2997 Gui_Widget *wdg = wdg_get(wdg_id); 2970 Gui_Widget *wdg = wdg_get(eid);
2998 if (!wdg) 2971 if (!wdg)
2999 { 2972 {
3000 ERR("wdg not found"); 2973 ERR("wdg not found");
3001 return EINA_FALSE; 2974 return EINA_FALSE;
3002 } 2975 }
3003 2976
3004 old_container = memento_old_pointer_get(memento); 2977 old_container = memento_command_old_pointer_get(cmd);
3005 2978
3006 wdg_obj_container_unset(wdg); 2979 wdg_obj_container_unset(wdg);
3007 wdg_obj_container_set(wdg, old_container); 2980 wdg_obj_container_set(wdg, old_container);
@@ -3010,16 +2983,15 @@ _editor_undo(const Gui_Context *ctx)
3010 case MEMENTO_ITEM_CONTAINER_ITEM: 2983 case MEMENTO_ITEM_CONTAINER_ITEM:
3011 { 2984 {
3012 Item_Container_Item *old_it; 2985 Item_Container_Item *old_it;
3013 Eid *wdg_id = memento_wdg_get(memento);
3014 2986
3015 Gui_Widget *wdg = wdg_get(wdg_id); 2987 Gui_Widget *wdg = wdg_get(eid);
3016 if (!wdg) 2988 if (!wdg)
3017 { 2989 {
3018 ERR("wdg not found"); 2990 ERR("wdg not found");
3019 return EINA_FALSE; 2991 return EINA_FALSE;
3020 } 2992 }
3021 2993
3022 old_it = memento_old_pointer_get(memento); 2994 old_it = memento_command_old_pointer_get(cmd);
3023 2995
3024 item_container_item_set_on_id(item_container_item_eid_get(old_it), old_it); 2996 item_container_item_set_on_id(item_container_item_eid_get(old_it), old_it);
3025 break; 2997 break;
@@ -3027,16 +2999,15 @@ _editor_undo(const Gui_Context *ctx)
3027 case MEMENTO_CALLBACK: 2999 case MEMENTO_CALLBACK:
3028 { 3000 {
3029 Gui_Widget_Callback *old_cb; 3001 Gui_Widget_Callback *old_cb;
3030 Eid *wdg_id = memento_wdg_get(memento);
3031 3002
3032 Gui_Widget *wdg = wdg_get(wdg_id); 3003 Gui_Widget *wdg = wdg_get(eid);
3033 if (!wdg) 3004 if (!wdg)
3034 { 3005 {
3035 ERR("wdg not found"); 3006 ERR("wdg not found");
3036 return EINA_FALSE; 3007 return EINA_FALSE;
3037 } 3008 }
3038 3009
3039 old_cb = memento_old_pointer_get(memento); 3010 old_cb = memento_command_old_pointer_get(cmd);
3040 Eid *cb_eid = cb_eid_get(old_cb); 3011 Eid *cb_eid = cb_eid_get(old_cb);
3041 3012
3042 cb_set_on_id(cb_eid, old_cb); 3013 cb_set_on_id(cb_eid, old_cb);
@@ -3049,30 +3020,27 @@ _editor_undo(const Gui_Context *ctx)
3049 case MEMENTO_CALLBACK_ADD_DEL: 3020 case MEMENTO_CALLBACK_ADD_DEL:
3050 { 3021 {
3051 Callback_Container *old_cc; 3022 Callback_Container *old_cc;
3052 Eid *wdg_id = memento_wdg_get(memento);
3053 3023
3054 Gui_Widget *wdg = wdg_get(wdg_id); 3024 Gui_Widget *wdg = wdg_get(eid);
3055 if (!wdg) 3025 if (!wdg)
3056 { 3026 {
3057 ERR("wdg not found"); 3027 ERR("wdg not found");
3058 return EINA_FALSE; 3028 return EINA_FALSE;
3059 } 3029 }
3060 old_cc = memento_old_pointer_get(memento); 3030 old_cc = memento_command_old_pointer_get(cmd);
3061 wdg_cb_container_unset(wdg); 3031 wdg_cb_container_unset(wdg);
3062 wdg_cb_container_set(wdg, old_cc); 3032 wdg_cb_container_set(wdg, old_cc);
3063 break; 3033 break;
3064 } 3034 }
3065 case MEMENTO_WIDGET: 3035 case MEMENTO_WIDGET:
3066 { 3036 {
3067 Eid *wdg_id = memento_wdg_get(memento); 3037 Eina_Bool old_state = (intptr_t) memento_command_old_pointer_get(cmd);
3068 Eina_Bool old_state = (intptr_t) memento_old_pointer_get(memento); 3038 _update_widget_on_undoredo(eid, old_state);
3069 _update_widget_on_undoredo(wdg_id, old_state);
3070 break; 3039 break;
3071 } 3040 }
3072 case MEMENTO_WIDGET_PARENT: 3041 case MEMENTO_WIDGET_PARENT:
3073 { 3042 {
3074 Eid *wdg_id = memento_wdg_get(memento); 3043 Gui_Widget *wdg = wdg_get(eid);
3075 Gui_Widget *wdg = wdg_get(wdg_id);
3076 /* According to current scenario, widget can be dragged from another and dropped to canvas. 3044 /* According to current scenario, widget can be dragged from another and dropped to canvas.
3077 * Thus here can be only main_wdg which is going to be undoed. 3045 * Thus here can be only main_wdg which is going to be undoed.
3078 * So it's frame and editor window must be deleted and Main_Wdg_Info data must be freed. */ 3046 * So it's frame and editor window must be deleted and Main_Wdg_Info data must be freed. */
@@ -3092,37 +3060,34 @@ _editor_undo(const Gui_Context *ctx)
3092 session_wdg_existence_set(session, wdg, EINA_FALSE); 3060 session_wdg_existence_set(session, wdg, EINA_FALSE);
3093 } 3061 }
3094 } 3062 }
3095 Eid *old_parent_id = (Eid *) memento_old_pointer_get(memento); 3063 Eid *old_parent_id = (Eid *) memento_command_old_pointer_get(cmd);
3096 wdg_parent_set(wdg, eid_name_get(old_parent_id)); 3064 wdg_parent_set(wdg, eid_name_get(old_parent_id));
3097 break; 3065 break;
3098 } 3066 }
3099 case MEMENTO_WIDGET_NAME: 3067 case MEMENTO_WIDGET_NAME:
3100 { 3068 {
3101 Eid *wdg_id = memento_wdg_get(memento); 3069 if (eid)
3102 if (wdg_id)
3103 { 3070 {
3104 const char *old_name = (const char *)memento_old_pointer_get(memento); 3071 const char *old_name = (const char *)memento_command_old_pointer_get(cmd);
3105 widget_name_change(wdg_get(wdg_id), old_name); 3072 widget_name_change(wdg_get(eid), old_name);
3106 } 3073 }
3107 break; 3074 break;
3108 } 3075 }
3109 case MEMENTO_WIDGET_PUBLIC: 3076 case MEMENTO_WIDGET_PUBLIC:
3110 { 3077 {
3111 Eid *wdg_id = memento_wdg_get(memento); 3078 if (eid)
3112 if (wdg_id)
3113 { 3079 {
3114 Eina_Bool old_public_state = (Eina_Bool) (intptr_t) memento_old_pointer_get(memento); 3080 Eina_Bool old_public_state = (Eina_Bool) (intptr_t) memento_command_old_pointer_get(cmd);
3115 wdg_public_set(wdg_get(wdg_id), old_public_state); 3081 wdg_public_set(wdg_get(eid), old_public_state);
3116 } 3082 }
3117 break; 3083 break;
3118 } 3084 }
3119 case MEMENTO_ACTION: 3085 case MEMENTO_ACTION:
3120 { 3086 {
3121 Eid *action_id = memento_wdg_get(memento); 3087 if (eid)
3122 if (action_id)
3123 { 3088 {
3124 Gui_Action *old_action = (Gui_Action *)memento_old_pointer_get(memento); 3089 Gui_Action *old_action = (Gui_Action *)memento_command_old_pointer_get(cmd);
3125 action_set(action_id, old_action); 3090 action_set(eid, old_action);
3126 } 3091 }
3127 3092
3128 proplayout_view_switch(CALLBACK_TYPE); 3093 proplayout_view_switch(CALLBACK_TYPE);
@@ -3136,16 +3101,15 @@ _editor_undo(const Gui_Context *ctx)
3136 default: 3101 default:
3137 ERR("case - default"); 3102 ERR("case - default");
3138 } 3103 }
3139 memento = memento_prev(memento);
3140 } 3104 }
3141 3105
3142 /* Update propview. */ 3106 /* Update propview. */
3143 _editor_undo_redo_post(head_memento); 3107 _editor_undo_redo_post(head_memento);
3144 3108
3145 gui_context_memento_prev((Gui_Context *) ctx); 3109 context_memento_move_to_prev((Gui_Context *) ctx);
3146 3110
3147 eo_do(g->main_win->toolbar_redo_it, elm_wdg_item_disabled_set(gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE)); 3111 eo_do(g->main_win->toolbar_redo_it, elm_wdg_item_disabled_set(context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE));
3148 eo_do(g->main_win->toolbar_undo_it, elm_wdg_item_disabled_set(gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE)); 3112 eo_do(g->main_win->toolbar_undo_it, elm_wdg_item_disabled_set(context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE));
3149 return EINA_TRUE; 3113 return EINA_TRUE;
3150} 3114}
3151 3115
@@ -3155,19 +3119,22 @@ _editor_redo(const Gui_Context *ctx)
3155{ 3119{
3156 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE); 3120 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
3157 const Memento *memento, *head_memento; 3121 const Memento *memento, *head_memento;
3158 head_memento = memento = gui_context_memento_next((Gui_Context *) ctx); 3122 const Memento_Command *cmd;
3123 context_memento_move_to_next((Gui_Context *) ctx);
3124 head_memento = memento = context_current_memento_get(ctx);
3159 3125
3160 while (memento) 3126 const Eina_List *cmds_list = memento_commands_get(memento), *itr;
3127 EINA_LIST_FOREACH(cmds_list, itr, cmd)
3161 { 3128 {
3162 Memento_Type type = memento_type_get(memento); 3129 Memento_Type type = memento_command_type_get(cmd);
3130 Eid *eid = memento_command_wdg_get(cmd);
3163 switch (type) 3131 switch (type)
3164 { 3132 {
3165 case MEMENTO_PROPERTY: 3133 case MEMENTO_PROPERTY:
3166 { 3134 {
3167 Eid *wdg_id = memento_wdg_get(memento);
3168 const Op_Desc *op_desc = NULL; 3135 const Op_Desc *op_desc = NULL;
3169 3136
3170 Gui_Widget *wdg = wdg_get(wdg_id); 3137 Gui_Widget *wdg = wdg_get(eid);
3171 if (!wdg) 3138 if (!wdg)
3172 { 3139 {
3173 ERR("wdg not found"); 3140 ERR("wdg not found");
@@ -3175,8 +3142,8 @@ _editor_redo(const Gui_Context *ctx)
3175 } 3142 }
3176 3143
3177 Gui_Widget_Property *new_prop, *old_prop; 3144 Gui_Widget_Property *new_prop, *old_prop;
3178 old_prop = memento_old_pointer_get(memento); 3145 old_prop = memento_command_old_pointer_get(cmd);
3179 new_prop = memento_new_pointer_get(memento); 3146 new_prop = memento_command_new_pointer_get(cmd);
3180 3147
3181 if (old_prop) 3148 if (old_prop)
3182 { 3149 {
@@ -3210,16 +3177,15 @@ _editor_redo(const Gui_Context *ctx)
3210 case MEMENTO_CALLBACK: 3177 case MEMENTO_CALLBACK:
3211 { 3178 {
3212 Gui_Widget_Callback *new_cb; 3179 Gui_Widget_Callback *new_cb;
3213 Eid *wdg_id = memento_wdg_get(memento);
3214 3180
3215 Gui_Widget *wdg = wdg_get(wdg_id); 3181 Gui_Widget *wdg = wdg_get(eid);
3216 if (!wdg) 3182 if (!wdg)
3217 { 3183 {
3218 ERR("wdg not found"); 3184 ERR("wdg not found");
3219 return EINA_FALSE; 3185 return EINA_FALSE;
3220 } 3186 }
3221 3187
3222 new_cb = memento_new_pointer_get(memento); 3188 new_cb = memento_command_new_pointer_get(cmd);
3223 Eid *cb_eid = cb_eid_get(new_cb); 3189 Eid *cb_eid = cb_eid_get(new_cb);
3224 3190
3225 cb_set_on_id(cb_eid, new_cb); 3191 cb_set_on_id(cb_eid, new_cb);
@@ -3232,15 +3198,14 @@ _editor_redo(const Gui_Context *ctx)
3232 case MEMENTO_CALLBACK_ADD_DEL: 3198 case MEMENTO_CALLBACK_ADD_DEL:
3233 { 3199 {
3234 Callback_Container *new_cc; 3200 Callback_Container *new_cc;
3235 Eid *wdg_id = memento_wdg_get(memento);
3236 3201
3237 Gui_Widget *wdg = wdg_get(wdg_id); 3202 Gui_Widget *wdg = wdg_get(eid);
3238 if (!wdg) 3203 if (!wdg)
3239 { 3204 {
3240 ERR("wdg not found"); 3205 ERR("wdg not found");
3241 return EINA_FALSE; 3206 return EINA_FALSE;
3242 } 3207 }
3243 new_cc = memento_new_pointer_get(memento); 3208 new_cc = memento_command_new_pointer_get(cmd);
3244 wdg_cb_container_unset(wdg); 3209 wdg_cb_container_unset(wdg);
3245 wdg_cb_container_set(wdg, new_cc); 3210 wdg_cb_container_set(wdg, new_cc);
3246 3211
@@ -3251,16 +3216,15 @@ _editor_redo(const Gui_Context *ctx)
3251 case MEMENTO_OBJ_CONTAINER_ITEM: 3216 case MEMENTO_OBJ_CONTAINER_ITEM:
3252 { 3217 {
3253 Object_Container *new_container; 3218 Object_Container *new_container;
3254 Eid *wdg_id = memento_wdg_get(memento);
3255 3219
3256 Gui_Widget *wdg = wdg_get(wdg_id); 3220 Gui_Widget *wdg = wdg_get(eid);
3257 if (!wdg) 3221 if (!wdg)
3258 { 3222 {
3259 ERR("wdg not found"); 3223 ERR("wdg not found");
3260 return EINA_FALSE; 3224 return EINA_FALSE;
3261 } 3225 }
3262 3226
3263 new_container = memento_new_pointer_get(memento); 3227 new_container = memento_command_new_pointer_get(cmd);
3264 3228
3265 wdg_obj_container_unset(wdg); 3229 wdg_obj_container_unset(wdg);
3266 wdg_obj_container_set(wdg, new_container); 3230 wdg_obj_container_set(wdg, new_container);
@@ -3269,31 +3233,28 @@ _editor_redo(const Gui_Context *ctx)
3269 case MEMENTO_ITEM_CONTAINER_ITEM: 3233 case MEMENTO_ITEM_CONTAINER_ITEM:
3270 { 3234 {
3271 Item_Container_Item *new_it; 3235 Item_Container_Item *new_it;
3272 Eid *wdg_id = memento_wdg_get(memento);
3273 3236
3274 Gui_Widget *wdg = wdg_get(wdg_id); 3237 Gui_Widget *wdg = wdg_get(eid);
3275 if (!wdg) 3238 if (!wdg)
3276 { 3239 {
3277 ERR("wdg not found"); 3240 ERR("wdg not found");
3278 return EINA_FALSE; 3241 return EINA_FALSE;
3279 } 3242 }
3280 3243
3281 new_it = memento_new_pointer_get(memento); 3244 new_it = memento_command_new_pointer_get(cmd);
3282 3245
3283 item_container_item_set_on_id(item_container_item_eid_get(new_it), new_it); 3246 item_container_item_set_on_id(item_container_item_eid_get(new_it), new_it);
3284 break; 3247 break;
3285 } 3248 }
3286 case MEMENTO_WIDGET: 3249 case MEMENTO_WIDGET:
3287 { 3250 {
3288 Eid *wdg_id = memento_wdg_get(memento); 3251 Eina_Bool new_state = (intptr_t) memento_command_new_pointer_get(cmd);
3289 Eina_Bool new_state = (intptr_t) memento_new_pointer_get(memento); 3252 _update_widget_on_undoredo(eid, new_state);
3290 _update_widget_on_undoredo(wdg_id, new_state);
3291 break; 3253 break;
3292 } 3254 }
3293 case MEMENTO_WIDGET_PARENT: 3255 case MEMENTO_WIDGET_PARENT:
3294 { 3256 {
3295 Eid *wdg_id = memento_wdg_get(memento); 3257 Gui_Widget *wdg = wdg_get(eid);
3296 Gui_Widget *wdg = wdg_get(wdg_id);
3297 /* According to current scenario, widget can be dragged from canvas and dropped into object. 3258 /* According to current scenario, widget can be dragged from canvas and dropped into object.
3298 * Thus here can be only main_wdg which is going to be redoed. 3259 * Thus here can be only main_wdg which is going to be redoed.
3299 * So it's frame and editor window must be deleted and Main_Wdg_Info data must be freed. */ 3260 * So it's frame and editor window must be deleted and Main_Wdg_Info data must be freed. */
@@ -3313,37 +3274,34 @@ _editor_redo(const Gui_Context *ctx)
3313 session_wdg_existence_set(session, wdg, EINA_FALSE); 3274 session_wdg_existence_set(session, wdg, EINA_FALSE);
3314 } 3275 }
3315 } 3276 }
3316 Eid *new_parent_id = (Eid *) memento_new_pointer_get(memento); 3277 Eid *new_parent_id = (Eid *) memento_command_new_pointer_get(cmd);
3317 wdg_parent_set(wdg, eid_name_get(new_parent_id)); 3278 wdg_parent_set(wdg, eid_name_get(new_parent_id));
3318 break; 3279 break;
3319 } 3280 }
3320 case MEMENTO_WIDGET_NAME: 3281 case MEMENTO_WIDGET_NAME:
3321 { 3282 {
3322 Eid *wdg_id = memento_wdg_get(memento); 3283 if (eid)
3323 if (wdg_id)
3324 { 3284 {
3325 const char *new_name = (const char *) memento_new_pointer_get(memento); 3285 const char *new_name = (const char *) memento_command_new_pointer_get(cmd);
3326 widget_name_change(wdg_get(wdg_id), new_name); 3286 widget_name_change(wdg_get(eid), new_name);
3327 } 3287 }
3328 break; 3288 break;
3329 } 3289 }
3330 case MEMENTO_WIDGET_PUBLIC: 3290 case MEMENTO_WIDGET_PUBLIC:
3331 { 3291 {
3332 Eid *wdg_id = memento_wdg_get(memento); 3292 if (eid)
3333 if (wdg_id)
3334 { 3293 {
3335 Eina_Bool new_public_state = (Eina_Bool) (intptr_t) memento_new_pointer_get(memento); 3294 Eina_Bool new_public_state = (Eina_Bool) (intptr_t) memento_command_new_pointer_get(cmd);
3336 wdg_public_set(wdg_get(wdg_id), new_public_state); 3295 wdg_public_set(wdg_get(eid), new_public_state);
3337 } 3296 }
3338 break; 3297 break;
3339 } 3298 }
3340 case MEMENTO_ACTION: 3299 case MEMENTO_ACTION:
3341 { 3300 {
3342 Eid *action_id = memento_wdg_get(memento); 3301 if (eid)
3343 if (action_id)
3344 { 3302 {
3345 Gui_Action *new_action = (Gui_Action *)memento_new_pointer_get(memento); 3303 Gui_Action *new_action = (Gui_Action *)memento_command_new_pointer_get(cmd);
3346 action_set(action_id, new_action); 3304 action_set(eid, new_action);
3347 } 3305 }
3348 3306
3349 proplayout_view_switch(CALLBACK_TYPE); 3307 proplayout_view_switch(CALLBACK_TYPE);
@@ -3357,23 +3315,26 @@ _editor_redo(const Gui_Context *ctx)
3357 default: 3315 default:
3358 ERR("case - default"); 3316 ERR("case - default");
3359 } 3317 }
3360 memento = memento_next(memento);
3361 } 3318 }
3362 /* Update propview. */ 3319 /* Update propview. */
3363 _editor_undo_redo_post(head_memento); 3320 _editor_undo_redo_post(head_memento);
3364 3321
3365 eo_do(g->main_win->toolbar_redo_it, elm_wdg_item_disabled_set(gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE)); 3322 eo_do(g->main_win->toolbar_redo_it, elm_wdg_item_disabled_set(context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE));
3366 eo_do(g->main_win->toolbar_undo_it, elm_wdg_item_disabled_set(gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE)); 3323 eo_do(g->main_win->toolbar_undo_it, elm_wdg_item_disabled_set(context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE));
3367 return EINA_TRUE; 3324 return EINA_TRUE;
3368} 3325}
3369 3326
3370static void 3327static void
3371_editor_undo_redo_post(const Memento *memento) 3328_editor_undo_redo_post(const Memento *memento)
3372{ 3329{
3373 while (memento) 3330 Memento_Command *cmd;
3331 const Eina_List *cmds_list = memento_commands_get(memento), *itr;
3332 EINA_LIST_FOREACH(cmds_list, itr, cmd)
3374 { 3333 {
3375 Memento_Type memento_type = memento_type_get(memento); 3334 Memento_Type type = memento_command_type_get(cmd);
3376 switch (memento_type) 3335 Eid *eid = memento_command_wdg_get(cmd);
3336 Gui_Widget *memento_wdg = wdg_get(eid);
3337 switch (type)
3377 { 3338 {
3378 case MEMENTO_PROPERTY: 3339 case MEMENTO_PROPERTY:
3379 { 3340 {
@@ -3382,7 +3343,6 @@ _editor_undo_redo_post(const Memento *memento)
3382 case MEMENTO_OBJ_CONTAINER_ITEM: 3343 case MEMENTO_OBJ_CONTAINER_ITEM:
3383 case MEMENTO_ITEM_CONTAINER_ITEM: 3344 case MEMENTO_ITEM_CONTAINER_ITEM:
3384 { 3345 {
3385 Gui_Widget *memento_wdg = wdg_get(memento_wdg_get(memento));
3386 proplayout_view_switch(CONTENT_TYPE); 3346 proplayout_view_switch(CONTENT_TYPE);
3387 _wdg_parent_win_reload(memento_wdg); 3347 _wdg_parent_win_reload(memento_wdg);
3388 _editor_wdg_selected_set(memento_wdg); 3348 _editor_wdg_selected_set(memento_wdg);
@@ -3396,7 +3356,6 @@ _editor_undo_redo_post(const Memento *memento)
3396 } 3356 }
3397 case MEMENTO_CALLBACK_ADD_DEL: 3357 case MEMENTO_CALLBACK_ADD_DEL:
3398 { 3358 {
3399 Gui_Widget *memento_wdg = wdg_get(memento_wdg_get(memento));
3400 proplayout_view_switch(CALLBACK_TYPE); 3359 proplayout_view_switch(CALLBACK_TYPE);
3401 _editor_wdg_selected_set(memento_wdg); 3360 _editor_wdg_selected_set(memento_wdg);
3402 break; 3361 break;
@@ -3404,7 +3363,6 @@ _editor_undo_redo_post(const Memento *memento)
3404 case MEMENTO_WIDGET: 3363 case MEMENTO_WIDGET:
3405 case MEMENTO_WIDGET_PARENT: 3364 case MEMENTO_WIDGET_PARENT:
3406 { 3365 {
3407 Gui_Widget *memento_wdg = wdg_get(memento_wdg_get(memento));
3408 if (memento_wdg) 3366 if (memento_wdg)
3409 { 3367 {
3410 _wdg_parent_win_reload(memento_wdg); 3368 _wdg_parent_win_reload(memento_wdg);
@@ -3428,7 +3386,6 @@ _editor_undo_redo_post(const Memento *memento)
3428 default: 3386 default:
3429 ERR("case - default"); 3387 ERR("case - default");
3430 } 3388 }
3431 memento = memento_next(memento);
3432 } 3389 }
3433} 3390}
3434 3391
@@ -3478,9 +3435,7 @@ _editor_selected_wdg_del_cb()
3478 _editor_widget_clear(wdg); 3435 _editor_widget_clear(wdg);
3479 3436
3480 eid_active_set(wdg_eid_get(wdg), EINA_FALSE); 3437 eid_active_set(wdg_eid_get(wdg), EINA_FALSE);
3481 Memento *memento; 3438 memento_command_add(wdg_eid_get(wdg), MEMENTO_WIDGET, (void *) (intptr_t) EINA_TRUE, (void *) (intptr_t) EINA_FALSE);
3482 memento = memento_new(wdg_eid_get(wdg), MEMENTO_WIDGET, (void *) (intptr_t) EINA_TRUE, (void *) (intptr_t) EINA_FALSE);
3483 gui_context_memento_add((Gui_Context *) ctx, memento);
3484 3439
3485 /* if parent_wdg is not NULL, it's not window, so it has parent. 3440 /* if parent_wdg is not NULL, it's not window, so it has parent.
3486 * if parent wdg is NULL, wdg is window, so just delete it. */ 3441 * if parent wdg is NULL, wdg is window, so just delete it. */
@@ -3495,6 +3450,7 @@ _editor_selected_wdg_del_cb()
3495 objtree_build(ctx); 3450 objtree_build(ctx);
3496 objtree_item_selected_set(parent_wdg); 3451 objtree_item_selected_set(parent_wdg);
3497 _editor_wdg_selected_set(parent_wdg); 3452 _editor_wdg_selected_set(parent_wdg);
3453 context_memento_finalize(ctx);
3498} 3454}
3499 3455
3500static Gui_Widget * 3456static Gui_Widget *
@@ -3527,9 +3483,7 @@ _editor_factory_wdg_create(const char *drag_data, const Gui_Widget *focused_wdg,
3527 3483
3528 wdg_parent_set(wdg, parent_name); 3484 wdg_parent_set(wdg, parent_name);
3529 3485
3530 Memento *memento; 3486 memento_command_add(wdg_eid_get(wdg), MEMENTO_WIDGET, (void *) (intptr_t) EINA_FALSE, (void *) (intptr_t) EINA_TRUE);
3531 memento = memento_new(wdg_eid_get(wdg), MEMENTO_WIDGET, (void *) (intptr_t) EINA_FALSE, (void *) (intptr_t) EINA_TRUE);
3532 gui_context_memento_add(ctx, memento);
3533 3487
3534 /*Add default visibility property*/ 3488 /*Add default visibility property*/
3535 Gui_Widget_Property *prop; 3489 Gui_Widget_Property *prop;
@@ -3800,12 +3754,11 @@ _prop_update_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Descr
3800 eo_do(obj, elm_obj_widget_part_text_set(NULL, new_enum_value)); 3754 eo_do(obj, elm_obj_widget_part_text_set(NULL, new_enum_value));
3801 } 3755 }
3802 3756
3803 Memento *memento = NULL;
3804 /* If new property was previously assigned to widget, delete it from widget. 3757 /* If new property was previously assigned to widget, delete it from widget.
3805 * I need to write memento_new twice, because wdg_prop_remove will do unref and prop will be deleted. */ 3758 * I need to write memento_new twice, because wdg_prop_remove will do unref and prop will be deleted. */
3806 if (prop_wdg_get(old_property)) 3759 if (prop_wdg_get(old_property))
3807 { 3760 {
3808 memento = memento_new(wdg_eid_get(wdg), MEMENTO_PROPERTY, old_property, prop); 3761 memento_command_add(wdg_eid_get(wdg), MEMENTO_PROPERTY, old_property, prop);
3809 wdg_prop_remove((Gui_Widget *) wdg, old_property); 3762 wdg_prop_remove((Gui_Widget *) wdg, old_property);
3810 } 3763 }
3811 /* If not, this prop is default property which was fetched from _ffi_eo_do, don't need to save it, 3764 /* If not, this prop is default property which was fetched from _ffi_eo_do, don't need to save it,
@@ -3817,9 +3770,8 @@ _prop_update_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Descr
3817 prop_ref(old_property); 3770 prop_ref(old_property);
3818 prop_unref(old_property); 3771 prop_unref(old_property);
3819 old_property = NULL; 3772 old_property = NULL;
3820 memento = memento_new(wdg_eid_get(wdg), MEMENTO_PROPERTY, old_property, prop); 3773 memento_command_add(wdg_eid_get(wdg), MEMENTO_PROPERTY, old_property, prop);
3821 } 3774 }
3822 gui_context_memento_add(ctx, memento);
3823 3775
3824 /* Assign new prop to widget */ 3776 /* Assign new prop to widget */
3825 wdg_prop_add((Gui_Widget *) wdg, prop); 3777 wdg_prop_add((Gui_Widget *) wdg, prop);
@@ -3848,6 +3800,7 @@ _prop_update_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Descr
3848 manager_widget_property_add(session, wdg, prop, MODE_EDITOR, NULL); 3800 manager_widget_property_add(session, wdg, prop, MODE_EDITOR, NULL);
3849 } 3801 }
3850 } 3802 }
3803 context_memento_finalize(ctx);
3851 return EO_CALLBACK_CONTINUE; 3804 return EO_CALLBACK_CONTINUE;
3852 /* FIXME: add return here? */ 3805 /* FIXME: add return here? */
3853end: 3806end:
@@ -3891,8 +3844,7 @@ _drop_property_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
3891 const Gui_Widget *wdg = prop_wdg_get(prop); 3844 const Gui_Widget *wdg = prop_wdg_get(prop);
3892 if (wdg) 3845 if (wdg)
3893 { 3846 {
3894 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_PROPERTY, prop, NULL); 3847 memento_command_add(wdg_eid_get(wdg), MEMENTO_PROPERTY, prop, NULL);
3895 gui_context_memento_add(ctx, memento);
3896 3848
3897 wdg_prop_remove((Gui_Widget *) wdg, (Gui_Widget_Property *) prop); 3849 wdg_prop_remove((Gui_Widget *) wdg, (Gui_Widget_Property *) prop);
3898 _wdg_parent_win_reload(wdg); 3850 _wdg_parent_win_reload(wdg);
@@ -3903,6 +3855,7 @@ _drop_property_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
3903 } 3855 }
3904 } 3856 }
3905 eo_do(obj, elm_obj_ctxpopup_dismiss()); 3857 eo_do(obj, elm_obj_ctxpopup_dismiss());
3858 context_memento_finalize(ctx);
3906} 3859}
3907 3860
3908/* callback to provide Context menu, when "..." button clicked for property. */ 3861/* callback to provide Context menu, when "..." button clicked for property. */
@@ -3937,7 +3890,6 @@ static Eina_Bool
3937_item_public_update_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) 3890_item_public_update_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
3938{ 3891{
3939 Eina_Bool state; 3892 Eina_Bool state;
3940 const Gui_Context *ctx = _active_context_get();
3941 Gui_Widget *wdg = (Gui_Widget *) _editor_wdg_selected_get(); 3893 Gui_Widget *wdg = (Gui_Widget *) _editor_wdg_selected_get();
3942 3894
3943 Item_Container_Item *item = data, *new_item; 3895 Item_Container_Item *item = data, *new_item;
@@ -3945,10 +3897,10 @@ _item_public_update_cb(void *data, Eo *obj, const Eo_Event_Description *desc EIN
3945 new_item = item_container_item_copy(item); 3897 new_item = item_container_item_copy(item);
3946 item_container_item_public_set(new_item, state); 3898 item_container_item_public_set(new_item, state);
3947 3899
3948 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, item, new_item); 3900 memento_command_add(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, item, new_item);
3949 gui_context_memento_add((Gui_Context *) ctx, memento);
3950 3901
3951 item_container_item_set_on_id(item_container_item_eid_get(item), new_item); 3902 item_container_item_set_on_id(item_container_item_eid_get(item), new_item);
3903 context_memento_finalize(_active_context_get());
3952 return EO_CALLBACK_CONTINUE; 3904 return EO_CALLBACK_CONTINUE;
3953} 3905}
3954 3906
@@ -3986,8 +3938,7 @@ _field_update_from_itemview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Desc
3986 item_container_item_prop_set(new_wit, new_prop); 3938 item_container_item_prop_set(new_wit, new_prop);
3987 3939
3988 /* Create memento. */ 3940 /* Create memento. */
3989 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, (void *) wit, new_wit); 3941 memento_command_add(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, (void *) wit, new_wit);
3990 gui_context_memento_add((Gui_Context *) ctx, memento);
3991 3942
3992 /* Change item in Dep_Data*/ 3943 /* Change item in Dep_Data*/
3993 3944
@@ -4054,6 +4005,7 @@ _field_update_from_itemview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Desc
4054 } 4005 }
4055 objtree_item_selected_set(wdg); 4006 objtree_item_selected_set(wdg);
4056 } 4007 }
4008 context_memento_finalize(_active_context_get());
4057 return EO_CALLBACK_CONTINUE; 4009 return EO_CALLBACK_CONTINUE;
4058} 4010}
4059 4011
@@ -4115,8 +4067,7 @@ _itemview_item_do_(unsigned int type)
4115 /* create Id for new parent item. */ 4067 /* create Id for new parent item. */
4116 new_parent_item = item_container_item_copy(parent_it); 4068 new_parent_item = item_container_item_copy(parent_it);
4117 4069
4118 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, parent_it, new_parent_item); 4070 memento_command_add(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, parent_it, new_parent_item);
4119 gui_context_memento_add((Gui_Context *) ctx, memento);
4120 4071
4121 item_container_item_set_on_id(item_container_item_eid_get(parent_it), new_parent_item); 4072 item_container_item_set_on_id(item_container_item_eid_get(parent_it), new_parent_item);
4122 4073
@@ -4173,8 +4124,7 @@ _itemview_item_do_(unsigned int type)
4173 4124
4174 new_parent_item = item_container_item_copy(parent_it); 4125 new_parent_item = item_container_item_copy(parent_it);
4175 4126
4176 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, parent_it, new_parent_item); 4127 memento_command_add(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, parent_it, new_parent_item);
4177 gui_context_memento_add((Gui_Context *) ctx, memento);
4178 4128
4179 item_container_item_set_on_id(item_container_item_eid_get(parent_it), new_parent_item); 4129 item_container_item_set_on_id(item_container_item_eid_get(parent_it), new_parent_item);
4180 } 4130 }
@@ -4192,8 +4142,7 @@ _itemview_item_do_(unsigned int type)
4192 intptr_t dir = (type == ITEM_MOVE_UP) ? UP : DOWN; 4142 intptr_t dir = (type == ITEM_MOVE_UP) ? UP : DOWN;
4193 if ((reload = item_container_item_reorder(wit, dir))) 4143 if ((reload = item_container_item_reorder(wit, dir)))
4194 { 4144 {
4195 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, parent_it, new_parent_item); 4145 memento_command_add(wdg_eid_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, parent_it, new_parent_item);
4196 gui_context_memento_add((Gui_Context *) ctx, memento);
4197 } 4146 }
4198 item_container_item_unref(parent_it); 4147 item_container_item_unref(parent_it);
4199 } 4148 }
@@ -4239,6 +4188,7 @@ _itemview_item_do_(unsigned int type)
4239 itemview_item_selected_set(it); 4188 itemview_item_selected_set(it);
4240 } 4189 }
4241 4190
4191 context_memento_finalize(_active_context_get());
4242 return EO_CALLBACK_CONTINUE; 4192 return EO_CALLBACK_CONTINUE;
4243} 4193}
4244 4194
@@ -4270,8 +4220,7 @@ _content_del_from_propview(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descr
4270 _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg); 4220 _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg);
4271 _new_container = obj_container_copy(_old_container); 4221 _new_container = obj_container_copy(_old_container);
4272 4222
4273 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container); 4223 memento_command_add(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
4274 gui_context_memento_add(ctx, memento);
4275 4224
4276 wdg_obj_container_unset((Gui_Widget *) wdg); 4225 wdg_obj_container_unset((Gui_Widget *) wdg);
4277 wdg_obj_container_set((Gui_Widget *) wdg, _new_container); 4226 wdg_obj_container_set((Gui_Widget *) wdg, _new_container);
@@ -4284,6 +4233,7 @@ _content_del_from_propview(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descr
4284 objtree_build(ctx); 4233 objtree_build(ctx);
4285 objtree_item_selected_set(wdg); 4234 objtree_item_selected_set(wdg);
4286 4235
4236 context_memento_finalize(ctx);
4287 return EO_CALLBACK_CONTINUE; 4237 return EO_CALLBACK_CONTINUE;
4288} 4238}
4289 4239
@@ -4312,8 +4262,7 @@ _content_reorder_from_propview(void *data, Eo *obj EINA_UNUSED, const Eo_Event_D
4312 /* If anything was reordered, need to reload content. */ 4262 /* If anything was reordered, need to reload content. */
4313 if (wdg_obj_container_content_reorder(wdg, idx, button_dir)) 4263 if (wdg_obj_container_content_reorder(wdg, idx, button_dir))
4314 { 4264 {
4315 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container); 4265 memento_command_add(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
4316 gui_context_memento_add(_active_context_get(), memento);
4317 4266
4318 /* Reload all the win when content reordered */ 4267 /* Reload all the win when content reordered */
4319 _wdg_parent_win_reload(wdg); 4268 _wdg_parent_win_reload(wdg);
@@ -4324,6 +4273,7 @@ _content_reorder_from_propview(void *data, Eo *obj EINA_UNUSED, const Eo_Event_D
4324 } 4273 }
4325 obj_container_unref(_old_container); 4274 obj_container_unref(_old_container);
4326 } 4275 }
4276 context_memento_finalize(_active_context_get());
4327 return EO_CALLBACK_CONTINUE; 4277 return EO_CALLBACK_CONTINUE;
4328} 4278}
4329 4279
@@ -4387,8 +4337,7 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_De
4387 _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg); 4337 _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg);
4388 _new_container = obj_container_copy(_old_container); 4338 _new_container = obj_container_copy(_old_container);
4389 4339
4390 Memento *memento = memento_new(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container); 4340 memento_command_add(wdg_eid_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
4391 gui_context_memento_add(ctx, memento);
4392 4341
4393 wdg_obj_container_unset((Gui_Widget *) wdg); 4342 wdg_obj_container_unset((Gui_Widget *) wdg);
4394 wdg_obj_container_set((Gui_Widget *) wdg, _new_container); 4343 wdg_obj_container_set((Gui_Widget *) wdg, _new_container);
@@ -4515,10 +4464,9 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_De
4515 _old_prev_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) prev_wdg_container); 4464 _old_prev_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) prev_wdg_container);
4516 _new_prev_container = obj_container_copy(_old_prev_container); 4465 _new_prev_container = obj_container_copy(_old_prev_container);
4517 4466
4518 Memento *memento_next = memento_new(wdg_eid_get(prev_wdg_container), 4467 memento_command_add(wdg_eid_get(prev_wdg_container),
4519 MEMENTO_OBJ_CONTAINER_ITEM, 4468 MEMENTO_OBJ_CONTAINER_ITEM,
4520 _old_prev_container, _new_prev_container); 4469 _old_prev_container, _new_prev_container);
4521 memento_append(memento, memento_next);
4522 wdg_obj_container_unset((Gui_Widget *) prev_wdg_container); 4470 wdg_obj_container_unset((Gui_Widget *) prev_wdg_container);
4523 wdg_obj_container_set((Gui_Widget *) prev_wdg_container, _new_prev_container); 4471 wdg_obj_container_set((Gui_Widget *) prev_wdg_container, _new_prev_container);
4524 4472
@@ -4551,6 +4499,7 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_De
4551 objtree_item_selected_set(wdg); 4499 objtree_item_selected_set(wdg);
4552 } 4500 }
4553 } 4501 }
4502 context_memento_finalize(ctx);
4554 4503
4555 return EO_CALLBACK_CONTINUE; 4504 return EO_CALLBACK_CONTINUE;
4556} 4505}
@@ -4605,8 +4554,8 @@ _switch_to_context(Gui_Context *ctx)
4605 _active_context_set(ctx); 4554 _active_context_set(ctx);
4606 objtree_context_set(ctx); 4555 objtree_context_set(ctx);
4607 4556
4608 eo_do(g->main_win->toolbar_redo_it, elm_wdg_item_disabled_set(gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE)); 4557 eo_do(g->main_win->toolbar_redo_it, elm_wdg_item_disabled_set(context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE));
4609 eo_do(g->main_win->toolbar_undo_it, elm_wdg_item_disabled_set(gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE)); 4558 eo_do(g->main_win->toolbar_undo_it, elm_wdg_item_disabled_set(context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE));
4610 4559
4611 Gui_Widget *wdg = gui_context_data_get(ctx, SELECTED_WDG); 4560 Gui_Widget *wdg = gui_context_data_get(ctx, SELECTED_WDG);
4612 _editor_wdg_selected_set(wdg); 4561 _editor_wdg_selected_set(wdg);
diff --git a/src/lib/gui_widget.c b/src/lib/gui_widget.c
index 841db53..132cb72 100644
--- a/src/lib/gui_widget.c
+++ b/src/lib/gui_widget.c
@@ -3851,19 +3851,19 @@ memento_cb_add(New_Memento_Cb cb, void *data)
3851 3851
3852/* Add memento item to the state list */ 3852/* Add memento item to the state list */
3853void 3853void
3854gui_context_memento_add(Gui_Context *ctx, const Memento *memento) 3854_context_memento_add(Gui_Context *ctx, const Memento *memento)
3855{ 3855{
3856 EINA_SAFETY_ON_NULL_RETURN(ctx); 3856 EINA_SAFETY_ON_NULL_RETURN(ctx);
3857 EINA_SAFETY_ON_NULL_RETURN(memento); 3857 EINA_SAFETY_ON_NULL_RETURN(memento);
3858 /* If we are trying to add new memento in the middle of Undo/Redo, 3858 /* If we are trying to add new memento in the middle of Undo/Redo,
3859 * everything after current state will be dropped.*/ 3859 * everything after current state will be dropped.*/
3860 gui_context_memento_discard(ctx); 3860 context_memento_discard(ctx);
3861 ctx->memento_list = eina_list_append(ctx->memento_list, memento); 3861 ctx->memento_list = eina_list_append(ctx->memento_list, memento);
3862 ctx->current_memento = eina_list_last(ctx->memento_list); 3862 ctx->current_memento = eina_list_last(ctx->memento_list);
3863 if (_new_memento_cb) _new_memento_cb(_new_memento_data); 3863 if (_new_memento_cb) _new_memento_cb(_new_memento_data);
3864// gui_context_memento_squash(ctx);
3865} 3864}
3866 3865
3866#if 0
3867void 3867void
3868gui_context_memento_squash(Gui_Context *ctx) 3868gui_context_memento_squash(Gui_Context *ctx)
3869{ 3869{
@@ -3894,79 +3894,48 @@ gui_context_memento_squash(Gui_Context *ctx)
3894 } 3894 }
3895 ctx->current_memento = eina_list_last(ctx->memento_list); 3895 ctx->current_memento = eina_list_last(ctx->memento_list);
3896} 3896}
3897#endif
3897 3898
3898/* Get current Memento*/ 3899/* Get current Memento*/
3899const Memento * 3900const Memento *
3900gui_context_current_memento_get(const Gui_Context *ctx) 3901context_current_memento_get(const Gui_Context *ctx)
3901{
3902 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
3903 if (ctx->current_memento)
3904 return eina_list_data_get(ctx->current_memento);
3905 return NULL;
3906}
3907/* Move pointer to the next item in list and returns it.
3908 * Returns NULL, if current item is the last. */
3909const Memento*
3910gui_context_memento_next(Gui_Context *ctx)
3911{ 3902{
3912 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL); 3903 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
3913 if (ctx->current_memento == eina_list_last(ctx->memento_list)) return NULL;
3914 /* This is a state when undo was pressed until the end. */
3915 if (!ctx->current_memento && ctx->memento_list)
3916 {
3917 ctx->current_memento = ctx->memento_list;
3918 }
3919 else
3920 {
3921 ctx->current_memento = eina_list_next(ctx->current_memento);
3922 }
3923 return eina_list_data_get(ctx->current_memento); 3904 return eina_list_data_get(ctx->current_memento);
3924} 3905}
3925 3906
3926/* Move pointer to the previous item in list. Returns NULL, if current item is the first. */ 3907void
3927const Memento* 3908context_memento_finalize(Gui_Context *ctx)
3928gui_context_memento_prev(Gui_Context *ctx)
3929{ 3909{
3930 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL); 3910 const Memento *mem = context_current_memento_get(ctx);
3931 if (!ctx->current_memento) return NULL; 3911 if (mem) memento_finalize((Memento *)mem);
3932 ctx->current_memento = eina_list_prev(ctx->current_memento); 3912 // add changes on ctx HERE
3933 if (!ctx->current_memento) return NULL;
3934 return eina_list_data_get(ctx->current_memento);
3935} 3913}
3936 3914
3937/* Discard all stack items which are after the current state. */ 3915/* Discard all stack items which are after the current state. */
3938void 3916void
3939gui_context_memento_discard(Gui_Context *ctx) 3917context_memento_discard(Gui_Context *ctx)
3940{ 3918{
3941 EINA_SAFETY_ON_NULL_RETURN(ctx); 3919 EINA_SAFETY_ON_NULL_RETURN(ctx);
3942 Memento *memento; 3920 Eina_List *last;
3943 Eina_List *itr1, *itr2; 3921 while ((last = eina_list_last(ctx->memento_list)) && last != ctx->current_memento)
3944 if (ctx->current_memento != eina_list_last(ctx->memento_list))
3945 { 3922 {
3946 /* if current_memento == NULL, remove all memnto list. 3923 memento_del(eina_list_data_get(last));
3947 * if not, remove everything after current_memento */ 3924 ctx->memento_list = eina_list_remove_list(ctx->memento_list, last);
3948 Eina_List *lst = (ctx->current_memento) ? eina_list_next(ctx->current_memento) : ctx->memento_list;
3949 EINA_LIST_FOREACH_SAFE(lst, itr1, itr2, memento)
3950 {
3951 ctx->memento_list = eina_list_remove_list(ctx->memento_list, itr1);
3952 memento_del(memento);
3953 }
3954 } 3925 }
3955} 3926}
3956 3927
3957/* Check whenether current state can be undo'ed */ 3928/* Check whenether current state can be undo'ed */
3958Eina_Bool 3929Eina_Bool
3959gui_context_can_undo(const Gui_Context *ctx) 3930context_can_undo(const Gui_Context *ctx)
3960{ 3931{
3961 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE); 3932 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
3962 if (ctx->current_memento) 3933 return !!ctx->current_memento;
3963 return EINA_TRUE;
3964 return EINA_FALSE;
3965} 3934}
3966 3935
3967/* Check whenether current state can be redo'ed */ 3936/* Check whenether current state can be redo'ed */
3968Eina_Bool 3937Eina_Bool
3969gui_context_can_redo(const Gui_Context *ctx) 3938context_can_redo(const Gui_Context *ctx)
3970{ 3939{
3971 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE); 3940 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
3972 if (ctx->memento_list) 3941 if (ctx->memento_list)
@@ -3976,3 +3945,26 @@ gui_context_can_redo(const Gui_Context *ctx)
3976 } 3945 }
3977 return EINA_FALSE; 3946 return EINA_FALSE;
3978} 3947}
3948
3949void
3950context_memento_move_to_prev(Gui_Context *ctx)
3951{
3952 EINA_SAFETY_ON_NULL_RETURN(ctx);
3953 ctx->current_memento = eina_list_prev(ctx->current_memento);
3954}
3955
3956void
3957context_memento_move_to_next(Gui_Context *ctx)
3958{
3959 EINA_SAFETY_ON_NULL_RETURN(ctx);
3960 if (ctx->current_memento == eina_list_last(ctx->memento_list)) return;
3961 /* This is a state when undo was pressed until the end. */
3962 if (!ctx->current_memento && ctx->memento_list)
3963 {
3964 ctx->current_memento = ctx->memento_list;
3965 }
3966 else
3967 {
3968 ctx->current_memento = eina_list_next(ctx->current_memento);
3969 }
3970}
diff --git a/src/lib/gui_widget.h b/src/lib/gui_widget.h
index feacff8..6f291d5 100644
--- a/src/lib/gui_widget.h
+++ b/src/lib/gui_widget.h
@@ -961,24 +961,14 @@ resource_context_get(const Gui_Resource *res);
961 961
962/* Add memento item to the state list */ 962/* Add memento item to the state list */
963void 963void
964gui_context_memento_add(Gui_Context *ctx, const Memento *memento); 964_context_memento_add(Gui_Context *ctx, const Memento *memento);
965
966/* Iterate all memento and squash according to condition. */
967void
968gui_context_memento_squash(Gui_Context *ctx);
969 965
970/* Get current Memento*/ 966/* Get current Memento*/
971const Memento * 967const Memento *
972gui_context_current_memento_get(const Gui_Context *ctx); 968context_current_memento_get(const Gui_Context *ctx);
973 969
974/* Move pointer to the next item in list and returns it. 970void
975 * Returns NULL, if current item is the last. */ 971context_memento_finalize(Gui_Context *ctx);
976const Memento*
977gui_context_memento_next(Gui_Context *ctx);
978
979/* Move pointer to the previous item in list. */
980const Memento*
981gui_context_memento_prev(Gui_Context *ctx);
982 972
983/* Assign a function to call when a memento is added */ 973/* Assign a function to call when a memento is added */
984void 974void
@@ -986,19 +976,21 @@ memento_cb_add(New_Memento_Cb cb, void *data);
986 976
987/* Check whenether current state can be undo'ed */ 977/* Check whenether current state can be undo'ed */
988Eina_Bool 978Eina_Bool
989gui_context_can_undo(const Gui_Context *ctx); 979context_can_undo(const Gui_Context *ctx);
990 980
991/* Check whenether current state can be redo'ed */ 981/* Check whenether current state can be redo'ed */
992Eina_Bool 982Eina_Bool
993gui_context_can_redo(const Gui_Context *ctx); 983context_can_redo(const Gui_Context *ctx);
984
985void
986context_memento_move_to_prev(Gui_Context *ctx);
994 987
995/* Discard all stack items which are after the current state. */
996void 988void
997gui_context_memento_discard(Gui_Context *ctx); 989context_memento_move_to_next(Gui_Context *ctx);
998 990
999/* Discard all stack items. */ 991/* Discard all stack items which are after the current state. */
1000void 992void
1001gui_context_memento_discard_all(Gui_Context *ctx); 993context_memento_discard(Gui_Context *ctx);
1002 994
1003void 995void
1004gui_context_edit_theme_name_set(Gui_Context *ctx, const char *theme_name); 996gui_context_edit_theme_name_set(Gui_Context *ctx, const char *theme_name);
diff --git a/src/lib/undoredo.c b/src/lib/undoredo.c
index 1768cc3..8858185 100644
--- a/src/lib/undoredo.c
+++ b/src/lib/undoredo.c
@@ -2,11 +2,9 @@
2#include "egui_log.h" 2#include "egui_log.h"
3#include "gui_widget.h" 3#include "gui_widget.h"
4 4
5struct _Memento 5struct _Memento_Command
6{ 6{
7 /* Inlist to keep a list of depended mementos. */ 7 Eid *eid; // wdg, action...
8 EINA_INLIST;
9 Eid *id; // wdg, action...
10 Memento_Type type; 8 Memento_Type type;
11 union 9 union
12 { 10 {
@@ -63,13 +61,20 @@ struct _Memento
63 }; 61 };
64}; 62};
65 63
64struct _Memento
65{
66 Eina_List *cmds; /* List of Memento commands */
67 Eina_Bool finalized : 1;
68};
69
66/* Create new Memento Item */ 70/* Create new Memento Item */
67Memento* 71Eina_Bool
68memento_new(Eid *id, Memento_Type type, void *old_pointer, void *new_pointer) 72memento_command_add(Eid *eid, Memento_Type type, void *old_pointer, void *new_pointer)
69{ 73{
70 Memento *memento = calloc(1, sizeof(Memento)); 74 const Gui_Context *ctx = gui_context_get_by_eid(eid);
71 memento->type = type; 75 Memento_Command *cmd = calloc(1, sizeof(*cmd));
72 memento->id = id; 76 cmd->type = type;
77 cmd->eid = eid;
73 switch (type) 78 switch (type)
74 { 79 {
75 case MEMENTO_PROPERTY: 80 case MEMENTO_PROPERTY:
@@ -77,17 +82,17 @@ memento_new(Eid *id, Memento_Type type, void *old_pointer, void *new_pointer)
77 /* old_pointer can be NULL only when property was never set. */ 82 /* old_pointer can be NULL only when property was never set. */
78 if (old_pointer) 83 if (old_pointer)
79 prop_ref((Gui_Widget_Property *) old_pointer); 84 prop_ref((Gui_Widget_Property *) old_pointer);
80 memento->old_property = old_pointer; 85 cmd->old_property = old_pointer;
81 if (new_pointer) 86 if (new_pointer)
82 prop_ref((Gui_Widget_Property *) new_pointer); 87 prop_ref((Gui_Widget_Property *) new_pointer);
83 memento->new_property = new_pointer; 88 cmd->new_property = new_pointer;
84 break; 89 break;
85 } 90 }
86 case MEMENTO_ACTION: 91 case MEMENTO_ACTION:
87 { 92 {
88 memento->old_action = old_pointer; 93 cmd->old_action = old_pointer;
89 if (old_pointer) action_ref(old_pointer); 94 if (old_pointer) action_ref(old_pointer);
90 memento->new_action = new_pointer; 95 cmd->new_action = new_pointer;
91 if (new_pointer) action_ref(new_pointer); 96 if (new_pointer) action_ref(new_pointer);
92 break; 97 break;
93 } 98 }
@@ -96,64 +101,64 @@ memento_new(Eid *id, Memento_Type type, void *old_pointer, void *new_pointer)
96 /* old_pointer can be NULL only when property was never set. */ 101 /* old_pointer can be NULL only when property was never set. */
97 if (old_pointer) 102 if (old_pointer)
98 cb_ref((Gui_Widget_Callback *) old_pointer); 103 cb_ref((Gui_Widget_Callback *) old_pointer);
99 memento->old_callback = old_pointer; 104 cmd->old_callback = old_pointer;
100 if (new_pointer) 105 if (new_pointer)
101 cb_ref((Gui_Widget_Callback *) new_pointer); 106 cb_ref((Gui_Widget_Callback *) new_pointer);
102 memento->new_callback = new_pointer; 107 cmd->new_callback = new_pointer;
103 break; 108 break;
104 } 109 }
105 case MEMENTO_CALLBACK_ADD_DEL: 110 case MEMENTO_CALLBACK_ADD_DEL:
106 { 111 {
107 if (old_pointer) 112 if (old_pointer)
108 cb_container_ref((Callback_Container *) old_pointer); 113 cb_container_ref((Callback_Container *) old_pointer);
109 memento->old_cb_container = old_pointer; 114 cmd->old_cb_container = old_pointer;
110 if (new_pointer) 115 if (new_pointer)
111 cb_container_ref((Callback_Container *) new_pointer); 116 cb_container_ref((Callback_Container *) new_pointer);
112 memento->new_cb_container = new_pointer; 117 cmd->new_cb_container = new_pointer;
113 break; 118 break;
114 } 119 }
115 case MEMENTO_OBJ_CONTAINER_ITEM: 120 case MEMENTO_OBJ_CONTAINER_ITEM:
116 { 121 {
117 memento->old_obj_container = old_pointer; 122 cmd->old_obj_container = old_pointer;
118 if (memento->old_obj_container) 123 if (cmd->old_obj_container)
119 obj_container_ref((Object_Container *) memento->old_obj_container); 124 obj_container_ref((Object_Container *) cmd->old_obj_container);
120 memento->new_obj_container = new_pointer; 125 cmd->new_obj_container = new_pointer;
121 if (memento->new_obj_container) 126 if (cmd->new_obj_container)
122 obj_container_ref((Object_Container *) memento->new_obj_container); 127 obj_container_ref((Object_Container *) cmd->new_obj_container);
123 break; 128 break;
124 } 129 }
125 case MEMENTO_ITEM_CONTAINER_ITEM: 130 case MEMENTO_ITEM_CONTAINER_ITEM:
126 { 131 {
127 memento->old_item = old_pointer; 132 cmd->old_item = old_pointer;
128 if (memento->old_item) 133 if (cmd->old_item)
129 item_container_item_ref((Item_Container_Item *) memento->old_item); 134 item_container_item_ref((Item_Container_Item *) cmd->old_item);
130 memento->new_item = new_pointer; 135 cmd->new_item = new_pointer;
131 if (memento->new_item) 136 if (cmd->new_item)
132 item_container_item_ref((Item_Container_Item *) memento->new_item); 137 item_container_item_ref((Item_Container_Item *) cmd->new_item);
133 break; 138 break;
134 } 139 }
135 case MEMENTO_WIDGET: 140 case MEMENTO_WIDGET:
136 { 141 {
137 memento->old_state = (intptr_t) old_pointer; 142 cmd->old_state = (intptr_t) old_pointer;
138 memento->new_state = (intptr_t) new_pointer; 143 cmd->new_state = (intptr_t) new_pointer;
139 break; 144 break;
140 } 145 }
141 case MEMENTO_WIDGET_PARENT: 146 case MEMENTO_WIDGET_PARENT:
142 { 147 {
143 memento->old_parent = (Eid *) old_pointer; 148 cmd->old_parent = (Eid *) old_pointer;
144 memento->new_parent = (Eid *) new_pointer; 149 cmd->new_parent = (Eid *) new_pointer;
145 break; 150 break;
146 } 151 }
147 case MEMENTO_WIDGET_NAME: 152 case MEMENTO_WIDGET_NAME:
148 { 153 {
149 memento->old_name = strdup((char *) old_pointer); 154 cmd->old_name = strdup((char *) old_pointer);
150 memento->new_name = strdup((char *) new_pointer); 155 cmd->new_name = strdup((char *) new_pointer);
151 break; 156 break;
152 } 157 }
153 case MEMENTO_WIDGET_PUBLIC: 158 case MEMENTO_WIDGET_PUBLIC:
154 { 159 {
155 memento->old_public_state = (intptr_t) old_pointer; 160 cmd->old_public_state = (intptr_t) old_pointer;
156 memento->new_public_state = (intptr_t) new_pointer; 161 cmd->new_public_state = (intptr_t) new_pointer;
157 break; 162 break;
158 } 163 }
159 case MEMENTO_NONE: 164 case MEMENTO_NONE:
@@ -163,7 +168,14 @@ memento_new(Eid *id, Memento_Type type, void *old_pointer, void *new_pointer)
163 default: 168 default:
164 ERR("case - default"); 169 ERR("case - default");
165 } 170 }
166 return memento; 171 Memento *memento = (Memento *)context_current_memento_get(ctx);
172 if (!memento || memento->finalized)
173 {
174 memento = calloc(1, sizeof(*memento));
175 _context_memento_add((Gui_Context *)ctx, memento);
176 }
177 memento->cmds = eina_list_append(memento->cmds, cmd);
178 return EINA_TRUE;
167} 179}
168 180
169/* Delete Memento Object */ 181/* Delete Memento Object */
@@ -171,51 +183,50 @@ void
171memento_del(Memento *memento) 183memento_del(Memento *memento)
172{ 184{
173 EINA_SAFETY_ON_NULL_RETURN(memento); 185 EINA_SAFETY_ON_NULL_RETURN(memento);
174 Eina_Inlist *inlist = EINA_INLIST_GET(memento); 186 Memento_Command *cmd;
175 EINA_INLIST_FREE(inlist, memento) 187 EINA_LIST_FREE(memento->cmds, cmd)
176 { 188 {
177 inlist = eina_inlist_remove(inlist, EINA_INLIST_GET(memento)); 189 switch (cmd->type)
178 switch (memento->type)
179 { 190 {
180 case MEMENTO_PROPERTY: 191 case MEMENTO_PROPERTY:
181 { 192 {
182 /* old_pointer can be NULL only when property was never set. */ 193 /* old_pointer can be NULL only when property was never set. */
183 if (memento->old_property) 194 if (cmd->old_property)
184 prop_unref((Gui_Widget_Property *) memento->old_property); 195 prop_unref((Gui_Widget_Property *) cmd->old_property);
185 if (memento->new_property) 196 if (cmd->new_property)
186 prop_unref((Gui_Widget_Property *) memento->new_property); 197 prop_unref((Gui_Widget_Property *) cmd->new_property);
187 break; 198 break;
188 } 199 }
189 case MEMENTO_CALLBACK: 200 case MEMENTO_CALLBACK:
190 { 201 {
191 if (memento->old_callback) 202 if (cmd->old_callback)
192 cb_unref((Gui_Widget_Callback *) memento->old_callback); 203 cb_unref((Gui_Widget_Callback *) cmd->old_callback);
193 if (memento->new_callback) 204 if (cmd->new_callback)
194 cb_unref((Gui_Widget_Callback *) memento->new_callback); 205 cb_unref((Gui_Widget_Callback *) cmd->new_callback);
195 break; 206 break;
196 } 207 }
197 case MEMENTO_CALLBACK_ADD_DEL: 208 case MEMENTO_CALLBACK_ADD_DEL:
198 { 209 {
199 if (memento->old_cb_container) 210 if (cmd->old_cb_container)
200 cb_container_unref((Callback_Container *) memento->old_cb_container); 211 cb_container_unref((Callback_Container *) cmd->old_cb_container);
201 if (memento->new_cb_container) 212 if (cmd->new_cb_container)
202 cb_container_unref((Callback_Container *) memento->new_cb_container); 213 cb_container_unref((Callback_Container *) cmd->new_cb_container);
203 break; 214 break;
204 } 215 }
205 case MEMENTO_OBJ_CONTAINER_ITEM: 216 case MEMENTO_OBJ_CONTAINER_ITEM:
206 { 217 {
207 if (memento->old_obj_container) 218 if (cmd->old_obj_container)
208 obj_container_unref((Object_Container *) memento->old_obj_container); 219 obj_container_unref((Object_Container *) cmd->old_obj_container);
209 if (memento->new_obj_container) 220 if (cmd->new_obj_container)
210 obj_container_unref((Object_Container *) memento->new_obj_container); 221 obj_container_unref((Object_Container *) cmd->new_obj_container);
211 break; 222 break;
212 } 223 }
213 case MEMENTO_ITEM_CONTAINER_ITEM: 224 case MEMENTO_ITEM_CONTAINER_ITEM:
214 { 225 {
215 if (memento->old_item) 226 if (cmd->old_item)
216 item_container_item_unref((Item_Container_Item *) memento->old_item); 227 item_container_item_unref((Item_Container_Item *) cmd->old_item);
217 if (memento->new_item) 228 if (cmd->new_item)
218 item_container_item_unref((Item_Container_Item *) memento->new_item); 229 item_container_item_unref((Item_Container_Item *) cmd->new_item);
219 break; 230 break;
220 } 231 }
221 case MEMENTO_WIDGET: 232 case MEMENTO_WIDGET:
@@ -226,10 +237,10 @@ memento_del(Memento *memento)
226 } 237 }
227 case MEMENTO_WIDGET_NAME: 238 case MEMENTO_WIDGET_NAME:
228 { 239 {
229 if (memento->old_name) 240 if (cmd->old_name)
230 free(memento->old_name); 241 free(cmd->old_name);
231 if (memento->new_name) 242 if (cmd->new_name)
232 free(memento->new_name); 243 free(cmd->new_name);
233 break; 244 break;
234 } 245 }
235 case MEMENTO_NONE: 246 case MEMENTO_NONE:
@@ -243,95 +254,92 @@ memento_del(Memento *memento)
243 default: 254 default:
244 ERR("case - default"); 255 ERR("case - default");
245 } 256 }
246 free(memento); 257 free(cmd);
247 } 258 }
259 free(memento);
248} 260}
249 261
250/* Get next Memento */ 262Eina_Bool
251Memento* 263memento_is_finalized(const Memento *memento)
252memento_next(const Memento *memento)
253{ 264{
254 return EINA_INLIST_CONTAINER_GET(EINA_INLIST_GET(memento)->next, Memento); 265 return memento->finalized;
255} 266}
256 267
257/* Get prev Memento */ 268void
258Memento* 269memento_finalize(Memento *memento)
259memento_prev(const Memento *memento)
260{ 270{
261 return EINA_INLIST_CONTAINER_GET(EINA_INLIST_GET(memento)->prev, Memento); 271 memento->finalized = EINA_TRUE;
262} 272}
263 273
264/* Append memento to the list of mementos */ 274/* Get last Memento command */
265void 275const Eina_List *
266memento_append(Memento *head, Memento *in) 276memento_commands_get(const Memento *memento)
267{ 277{
268 Eina_Inlist *inlist = NULL; 278 return memento->cmds;
269 if (head) inlist = EINA_INLIST_GET(head);
270 inlist = eina_inlist_append(inlist, EINA_INLIST_GET(in));
271} 279}
272 280
273/* Get Memento type */ 281/* Get Memento type */
274Memento_Type 282Memento_Type
275memento_type_get(const Memento *memento) 283memento_command_type_get(const Memento_Command *cmd)
276{ 284{
277 EINA_SAFETY_ON_NULL_RETURN_VAL(memento, MEMENTO_NONE); 285 EINA_SAFETY_ON_NULL_RETURN_VAL(cmd, MEMENTO_NONE);
278 return memento->type; 286 return cmd->type;
279} 287}
280 288
281/* Get widget. */ 289/* Get widget. */
282Eid * 290Eid *
283memento_wdg_get(const Memento *memento) 291memento_command_wdg_get(const Memento_Command *cmd)
284{ 292{
285 EINA_SAFETY_ON_NULL_RETURN_VAL(memento, MEMENTO_NONE); 293 EINA_SAFETY_ON_NULL_RETURN_VAL(cmd, MEMENTO_NONE);
286 return memento->id; 294 return cmd->eid;
287} 295}
288 296
289/* Get old pointer to property/list. */ 297/* Get old pointer to property/list. */
290void * 298void *
291memento_old_pointer_get(const Memento *memento) 299memento_command_old_pointer_get(const Memento_Command *cmd)
292{ 300{
293 EINA_SAFETY_ON_NULL_RETURN_VAL(memento, NULL); 301 EINA_SAFETY_ON_NULL_RETURN_VAL(cmd, NULL);
294 switch (memento->type) 302 switch (cmd->type)
295 { 303 {
296 case MEMENTO_PROPERTY: 304 case MEMENTO_PROPERTY:
297 { 305 {
298 return (void *) memento->old_property; 306 return (void *) cmd->old_property;
299 } 307 }
300 case MEMENTO_ACTION: 308 case MEMENTO_ACTION:
301 { 309 {
302 return (void *) memento->old_action; 310 return (void *) cmd->old_action;
303 } 311 }
304 case MEMENTO_CALLBACK: 312 case MEMENTO_CALLBACK:
305 { 313 {
306 return (void *) memento->old_callback; 314 return (void *) cmd->old_callback;
307 } 315 }
308 case MEMENTO_CALLBACK_ADD_DEL: 316 case MEMENTO_CALLBACK_ADD_DEL:
309 { 317 {
310 return (void *) memento->old_cb_container; 318 return (void *) cmd->old_cb_container;
311 } 319 }
312 case MEMENTO_OBJ_CONTAINER_ITEM: 320 case MEMENTO_OBJ_CONTAINER_ITEM:
313 { 321 {
314 return (void *) memento->old_obj_container; 322 return (void *) cmd->old_obj_container;
315 } 323 }
316 case MEMENTO_ITEM_CONTAINER_ITEM: 324 case MEMENTO_ITEM_CONTAINER_ITEM:
317 { 325 {
318 return (void *) memento->old_item; 326 return (void *) cmd->old_item;
319 } 327 }
320 case MEMENTO_WIDGET: 328 case MEMENTO_WIDGET:
321 { 329 {
322 return (void *) (intptr_t) memento->old_state; 330 return (void *) (intptr_t) cmd->old_state;
323 } 331 }
324 case MEMENTO_WIDGET_PARENT: 332 case MEMENTO_WIDGET_PARENT:
325 { 333 {
326 return (void *) memento->old_parent; 334 return (void *) cmd->old_parent;
327 } 335 }
328 case MEMENTO_WIDGET_NAME: 336 case MEMENTO_WIDGET_NAME:
329 { 337 {
330 return (void *) memento->old_name; 338 return (void *) cmd->old_name;
331 } 339 }
332 case MEMENTO_WIDGET_PUBLIC: 340 case MEMENTO_WIDGET_PUBLIC:
333 { 341 {
334 return (void *) (intptr_t) memento->old_public_state; 342 return (void *) (intptr_t) cmd->old_public_state;
335 } 343 }
336 case MEMENTO_NONE: 344 case MEMENTO_NONE:
337 { 345 {
@@ -345,50 +353,50 @@ memento_old_pointer_get(const Memento *memento)
345 353
346/* Get new pointer to property/list. */ 354/* Get new pointer to property/list. */
347void * 355void *
348memento_new_pointer_get(const Memento *memento) 356memento_command_new_pointer_get(const Memento_Command *cmd)
349{ 357{
350 EINA_SAFETY_ON_NULL_RETURN_VAL(memento, NULL); 358 EINA_SAFETY_ON_NULL_RETURN_VAL(cmd, NULL);
351 switch (memento->type) 359 switch (cmd->type)
352 { 360 {
353 case MEMENTO_PROPERTY: 361 case MEMENTO_PROPERTY:
354 { 362 {
355 return (void *) memento->new_property; 363 return (void *) cmd->new_property;
356 } 364 }
357 case MEMENTO_ACTION: 365 case MEMENTO_ACTION:
358 { 366 {
359 return (void *) memento->new_action; 367 return (void *) cmd->new_action;
360 } 368 }
361 case MEMENTO_CALLBACK: 369 case MEMENTO_CALLBACK:
362 { 370 {
363 return (void *) memento->new_callback; 371 return (void *) cmd->new_callback;
364 } 372 }
365 case MEMENTO_CALLBACK_ADD_DEL: 373 case MEMENTO_CALLBACK_ADD_DEL:
366 { 374 {
367 return (void *) memento->new_cb_container; 375 return (void *) cmd->new_cb_container;
368 } 376 }
369 case MEMENTO_OBJ_CONTAINER_ITEM: 377 case MEMENTO_OBJ_CONTAINER_ITEM:
370 { 378 {
371 return (void *) memento->new_obj_container; 379 return (void *) cmd->new_obj_container;
372 } 380 }
373 case MEMENTO_ITEM_CONTAINER_ITEM: 381 case MEMENTO_ITEM_CONTAINER_ITEM:
374 { 382 {
375 return (void *) memento->new_item; 383 return (void *) cmd->new_item;
376 } 384 }
377 case MEMENTO_WIDGET: 385 case MEMENTO_WIDGET:
378 { 386 {
379 return (void *) (intptr_t) memento->new_state; 387 return (void *) (intptr_t) cmd->new_state;
380 } 388 }
381 case MEMENTO_WIDGET_PARENT: 389 case MEMENTO_WIDGET_PARENT:
382 { 390 {
383 return (void *) memento->new_parent; 391 return (void *) cmd->new_parent;
384 } 392 }
385 case MEMENTO_WIDGET_NAME: 393 case MEMENTO_WIDGET_NAME:
386 { 394 {
387 return (void *) memento->new_name; 395 return (void *) cmd->new_name;
388 } 396 }
389 case MEMENTO_WIDGET_PUBLIC: 397 case MEMENTO_WIDGET_PUBLIC:
390 { 398 {
391 return (void *) (intptr_t) memento->new_public_state; 399 return (void *) (intptr_t) cmd->new_public_state;
392 } 400 }
393 case MEMENTO_NONE: 401 case MEMENTO_NONE:
394 { 402 {
@@ -400,6 +408,7 @@ memento_new_pointer_get(const Memento *memento)
400 return NULL; 408 return NULL;
401} 409}
402 410
411#if 0
403/* Assigns source memento's new pointer to dest memento's new pointer. 412/* Assigns source memento's new pointer to dest memento's new pointer.
404 * Source memento must be deleted. 413 * Source memento must be deleted.
405 * 414 *
@@ -451,3 +460,5 @@ mementos_squash(Memento *dest, Memento *source)
451 } 460 }
452 } 461 }
453} 462}
463#endif
464
diff --git a/src/lib/undoredo.h b/src/lib/undoredo.h
index 62400fa..64da3c6 100644
--- a/src/lib/undoredo.h
+++ b/src/lib/undoredo.h
@@ -17,6 +17,7 @@ typedef enum
17 MEMENTO_WIDGET_PUBLIC 17 MEMENTO_WIDGET_PUBLIC
18} Memento_Type; 18} Memento_Type;
19 19
20typedef struct _Memento_Command Memento_Command;
20typedef struct _Memento Memento; 21typedef struct _Memento Memento;
21 22
22/* There is Design patten Memento, which defines three parts. 23/* There is Design patten Memento, which defines three parts.
@@ -27,47 +28,37 @@ typedef struct _Memento Memento;
27 * 28 *
28 * Gui_Context is also the Caretaker. */ 29 * Gui_Context is also the Caretaker. */
29 30
30/* Create new Memento Object */ 31/* Create new Memento command */
31Memento* 32Eina_Bool
32memento_new(Eid *wdg_id, Memento_Type type, void *old_pointer, void *new_pointer); 33memento_command_add(Eid *wdg_id, Memento_Type type, void *old_pointer, void *new_pointer);
33 34
34/* Delete Memento Object */ 35/* Delete Memento Object */
35void 36void
36memento_del(Memento *memento); 37memento_del(Memento *memento);
37 38
38/* Get Memento type */ 39Eina_Bool
39Memento_Type 40memento_is_finalized(const Memento *memento);
40memento_type_get(const Memento *memento);
41 41
42/* Append memento to the list of mementos */
43void 42void
44memento_append(Memento *head, Memento *in); 43memento_finalize(Memento *memento);
45 44
46/* Get next Memento */ 45const Eina_List *
47Memento* 46memento_commands_get(const Memento *memento);
48memento_next(const Memento *memento);
49 47
50/* Get prev Memento */ 48/* Get Memento type */
51Memento* 49Memento_Type
52memento_prev(const Memento *memento); 50memento_command_type_get(const Memento_Command *cmd);
53
54/* Functions to set/get state in Memento. */
55 51
56/* Get widget. */ 52/* Get widget. */
57Eid * 53Eid *
58memento_wdg_get(const Memento *memento); 54memento_command_wdg_get(const Memento_Command *cmd);
59 55
60/* Get old pointer to property/list. */ 56/* Get old pointer to property/list. */
61void * 57void *
62memento_old_pointer_get(const Memento *memento); 58memento_command_old_pointer_get(const Memento_Command *cmd);
63 59
64/* Get new pointer to property/list. */ 60/* Get new pointer to property/list. */
65void * 61void *
66memento_new_pointer_get(const Memento *memento); 62memento_command_new_pointer_get(const Memento_Command *cmd);
67
68/* Assigns source memento's new pointer to dest memento's new pointer.
69 * source memento must be deleted. */
70void
71mementos_squash(Memento *dest, Memento *source);
72 63
73#endif 64#endif