summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2014-10-23 19:25:32 +0300
committerYakov Goldberg <yakov.g@samsung.com>2014-10-27 10:27:32 +0200
commit817f958bd84adc35f65e142e2eb62d226870e20a (patch)
tree4f1ce91c5ee77d5997b75fe55afc867a468d1259
parentfbb3ea5c4086e057f785185b07000a0822e444f4 (diff)
Fix undo/redo for containers
- Fix undo/redo for the case when an object was packed into container from another container
-rw-r--r--src/bin/egui_gui/editor.c557
-rw-r--r--src/lib/undoredo.c130
-rw-r--r--src/lib/undoredo.h8
3 files changed, 387 insertions, 308 deletions
diff --git a/src/bin/egui_gui/editor.c b/src/bin/egui_gui/editor.c
index e3ea3f3..25b8f35 100644
--- a/src/bin/egui_gui/editor.c
+++ b/src/bin/egui_gui/editor.c
@@ -18,6 +18,11 @@
18 18
19#define MAIN_WDG_INFO "main_wdg_info_key" 19#define MAIN_WDG_INFO "main_wdg_info_key"
20 20
21/* Function to call in the end of undo/redo in order to update view.
22 * Update is made according to head memento. */
23static void
24_editor_undo_redo_post(const Gui_Memento *memento);
25
21static Gui_Context *_active_ctx = NULL; 26static Gui_Context *_active_ctx = NULL;
22static const Egui_Layout_Widgets *g; 27static const Egui_Layout_Widgets *g;
23 28
@@ -1166,160 +1171,155 @@ static Eina_Bool
1166_editor_undo(const Gui_Context *ctx) 1171_editor_undo(const Gui_Context *ctx)
1167{ 1172{
1168 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE); 1173 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
1169 const Gui_Memento *memento; 1174 const Gui_Memento *memento, *head_memento;
1170 memento = gui_context_current_memento_get(ctx); 1175 /* Save head memento for post function. */
1176 head_memento = memento = gui_context_current_memento_get(ctx);
1171 1177
1172 Gui_Memento_Type type = gui_memento_type_get(memento); 1178 while (memento)
1173 switch (type)
1174 { 1179 {
1175 case MEMENTO_PROPERTY: 1180 Gui_Memento_Type type = gui_memento_type_get(memento);
1176 { 1181 switch (type)
1177 Gui_Widget_Property *old_prop, *new_prop; 1182 {
1178 Dep_Id *wdg_id = gui_memento_wdg_get(memento); 1183 case MEMENTO_PROPERTY:
1179 const Op_Desc *op_desc = NULL;
1180
1181 Gui_Widget *wdg = wdg_get(wdg_id);
1182 if (!wdg)
1183 { 1184 {
1184 ERR("wdg not found"); 1185 Gui_Widget_Property *old_prop, *new_prop;
1185 return EINA_FALSE; 1186 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1186 } 1187 const Op_Desc *op_desc = NULL;
1187 1188
1188 old_prop = gui_memento_old_pointer_get(memento); 1189 Gui_Widget *wdg = wdg_get(wdg_id);
1189 new_prop = gui_memento_new_pointer_get(memento); 1190 if (!wdg)
1190 /* If last action was 'Drop prop', new_prop is NULL. */ 1191 {
1191 if (new_prop) 1192 ERR("wdg not found");
1192 { 1193 return EINA_FALSE;
1193 op_desc = prop_op_desc_get(new_prop); 1194 }
1194 wdg_prop_remove(wdg, new_prop);
1195 }
1196 1195
1197 propsview_view_switch(PROPERTY_TYPE); 1196 old_prop = gui_memento_old_pointer_get(memento);
1198 if (old_prop) 1197 new_prop = gui_memento_new_pointer_get(memento);
1199 { 1198 /* If last action was 'Drop prop', new_prop is NULL. */
1200 op_desc = prop_op_desc_get(old_prop); 1199 if (new_prop)
1201 wdg_prop_add(wdg, old_prop); 1200 {
1202 Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx); 1201 op_desc = prop_op_desc_get(new_prop);
1203 manager_widget_property_add(session, wdg, old_prop, MODE_EDITOR, NULL); 1202 wdg_prop_remove(wdg, new_prop);
1204 if (_editor_wdg_selected_get() != wdg) 1203 }
1204
1205 propsview_view_switch(PROPERTY_TYPE);
1206 if (old_prop)
1207 {
1208 op_desc = prop_op_desc_get(old_prop);
1209 wdg_prop_add(wdg, old_prop);
1210 Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
1211 manager_widget_property_add(session, wdg, old_prop, MODE_EDITOR, NULL);
1212 if (_editor_wdg_selected_get() != wdg)
1213 {
1214 objtree_item_selected_set(wdg);
1215 }
1216 propview_item_update(old_prop);
1217 }
1218 /* If old_property == NULL, need to reload widget. */
1219 else
1205 { 1220 {
1221 _wdg_parent_win_reload(wdg);
1206 objtree_item_selected_set(wdg); 1222 objtree_item_selected_set(wdg);
1207 } 1223 }
1208 propview_item_update(old_prop); 1224 if (op_desc)
1225 propview_item_selected_set(op_desc);
1226 break;
1209 } 1227 }
1210 /* If old_property == NULL, need to reload widget. */ 1228 case MEMENTO_OBJ_CONTAINER_ITEM:
1211 else
1212 { 1229 {
1213 _wdg_parent_win_reload(wdg); 1230 Object_Container *old_container;
1214 objtree_item_selected_set(wdg); 1231 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1215 }
1216 if (op_desc)
1217 propview_item_selected_set(op_desc);
1218 break;
1219 }
1220 case MEMENTO_OBJ_CONTAINER_ITEM:
1221 {
1222 Object_Container *old_container;
1223 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1224 1232
1225 Gui_Widget *wdg = wdg_get(wdg_id); 1233 Gui_Widget *wdg = wdg_get(wdg_id);
1226 if (!wdg) 1234 if (!wdg)
1227 { 1235 {
1228 ERR("wdg not found"); 1236 ERR("wdg not found");
1229 return EINA_FALSE; 1237 return EINA_FALSE;
1230 } 1238 }
1231
1232 old_container = gui_memento_old_pointer_get(memento);
1233 1239
1234 wdg_obj_container_unset(wdg); 1240 old_container = gui_memento_old_pointer_get(memento);
1235 wdg_obj_container_set(wdg, old_container);
1236 1241
1237 propsview_view_switch(CONTENT_TYPE); 1242 wdg_obj_container_unset(wdg);
1238 _wdg_parent_win_reload(wdg); 1243 wdg_obj_container_set(wdg, old_container);
1239 _editor_wdg_selected_set(wdg); 1244 break;
1240 objtree_item_selected_set(wdg);
1241 break;
1242 }
1243 case MEMENTO_ITEM_CONTAINER_ITEM:
1244 {
1245 Item_Container_Item *old_it;
1246 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1247
1248 Gui_Widget *wdg = wdg_get(wdg_id);
1249 if (!wdg)
1250 {
1251 ERR("wdg not found");
1252 return EINA_FALSE;
1253 } 1245 }
1246 case MEMENTO_ITEM_CONTAINER_ITEM:
1247 {
1248 Item_Container_Item *old_it;
1249 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1254 1250
1255 old_it = gui_memento_old_pointer_get(memento); 1251 Gui_Widget *wdg = wdg_get(wdg_id);
1252 if (!wdg)
1253 {
1254 ERR("wdg not found");
1255 return EINA_FALSE;
1256 }
1256 1257
1257 Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(old_it)); 1258 old_it = gui_memento_old_pointer_get(memento);
1258 dep_data_item_set(dep_data, old_it);
1259 1259
1260 propsview_view_switch(CONTENT_TYPE); 1260 Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(old_it));
1261 _wdg_parent_win_reload(wdg); 1261 dep_data_item_set(dep_data, old_it);
1262 _editor_wdg_selected_set(wdg); 1262 break;
1263 objtree_item_selected_set(wdg);
1264 break;
1265 }
1266 case MEMENTO_CALLBACK:
1267 {
1268 Gui_Widget_Callback *old_cb;
1269 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1270
1271 Gui_Widget *wdg = wdg_get(wdg_id);
1272 if (!wdg)
1273 {
1274 ERR("wdg not found");
1275 return EINA_FALSE;
1276 } 1263 }
1264 case MEMENTO_CALLBACK:
1265 {
1266 Gui_Widget_Callback *old_cb;
1267 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1277 1268
1278 old_cb = gui_memento_old_pointer_get(memento); 1269 Gui_Widget *wdg = wdg_get(wdg_id);
1279 Dep_Id *cb_dep_id = cb_dep_id_get(old_cb); 1270 if (!wdg)
1271 {
1272 ERR("wdg not found");
1273 return EINA_FALSE;
1274 }
1280 1275
1281 Dep_Data *dep_data = gui_context_dep_data_get(cb_dep_id); 1276 old_cb = gui_memento_old_pointer_get(memento);
1282 dep_data_cb_set(dep_data, old_cb); 1277 Dep_Id *cb_dep_id = cb_dep_id_get(old_cb);
1283 1278
1284 propsview_view_switch(CALLBACK_TYPE); 1279 Dep_Data *dep_data = gui_context_dep_data_get(cb_dep_id);
1285 _editor_wdg_selected_set(wdg); 1280 dep_data_cb_set(dep_data, old_cb);
1286 cbview_item_selected_set(cb_dep_id);
1287 break;
1288 }
1289 case MEMENTO_CALLBACK_ADD_DEL:
1290 {
1291 Callback_Container *old_cc;
1292 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1293 1281
1294 Gui_Widget *wdg = wdg_get(wdg_id); 1282 propsview_view_switch(CALLBACK_TYPE);
1295 if (!wdg) 1283 _editor_wdg_selected_set(wdg);
1296 { 1284 cbview_item_selected_set(cb_dep_id);
1297 ERR("wdg not found"); 1285 break;
1298 return EINA_FALSE;
1299 } 1286 }
1300 old_cc = gui_memento_old_pointer_get(memento); 1287 case MEMENTO_CALLBACK_ADD_DEL:
1301 wdg_cb_container_unset(wdg); 1288 {
1302 wdg_cb_container_set(wdg, old_cc); 1289 Callback_Container *old_cc;
1290 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1303 1291
1304 propsview_view_switch(CALLBACK_TYPE); 1292 Gui_Widget *wdg = wdg_get(wdg_id);
1305 _editor_wdg_selected_set(wdg); 1293 if (!wdg)
1306 break; 1294 {
1307 } 1295 ERR("wdg not found");
1308 case MEMENTO_WIDGET: 1296 return EINA_FALSE;
1309 { 1297 }
1310 Dep_Id *wdg_id = gui_memento_wdg_get(memento); 1298 old_cc = gui_memento_old_pointer_get(memento);
1311 Eina_Bool old_state = (intptr_t) gui_memento_old_pointer_get(memento); 1299 wdg_cb_container_unset(wdg);
1312 _update_widget_on_undoredo(ctx, wdg_id, old_state); 1300 wdg_cb_container_set(wdg, old_cc);
1313 break; 1301 break;
1314 } 1302 }
1315 case MEMENTO_NONE: 1303 case MEMENTO_WIDGET:
1316 { 1304 {
1317 break; 1305 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1318 } 1306 Eina_Bool old_state = (intptr_t) gui_memento_old_pointer_get(memento);
1319 default: 1307 _update_widget_on_undoredo(ctx, wdg_id, old_state);
1320 ERR("case - default"); 1308 break;
1309 }
1310 case MEMENTO_NONE:
1311 {
1312 break;
1313 }
1314 default:
1315 ERR("case - default");
1316 }
1317 memento = gui_memento_next(memento);
1321 } 1318 }
1322 1319
1320 /* Update propview. */
1321 _editor_undo_redo_post(head_memento);
1322
1323 gui_context_memento_prev((Gui_Context *) ctx); 1323 gui_context_memento_prev((Gui_Context *) ctx);
1324 1324
1325 elm_object_item_disabled_set(g->main_win->toolbar_redo_it, gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE); 1325 elm_object_item_disabled_set(g->main_win->toolbar_redo_it, gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE);
@@ -1333,155 +1333,196 @@ static Eina_Bool
1333_editor_redo(const Gui_Context *ctx) 1333_editor_redo(const Gui_Context *ctx)
1334{ 1334{
1335 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE); 1335 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
1336 const Gui_Memento *memento; 1336 const Gui_Memento *memento, *head_memento;
1337 gui_context_memento_next((Gui_Context *) ctx); 1337 gui_context_memento_next((Gui_Context *) ctx);
1338 memento = gui_context_current_memento_get(ctx); 1338 /* Save head memento for post function. */
1339 head_memento = memento = gui_context_current_memento_get(ctx);
1339 1340
1340 Gui_Memento_Type type = gui_memento_type_get(memento); 1341 while (memento)
1341 switch (type)
1342 { 1342 {
1343 case MEMENTO_PROPERTY: 1343 Gui_Memento_Type type = gui_memento_type_get(memento);
1344 { 1344 switch (type)
1345 Dep_Id *wdg_id = gui_memento_wdg_get(memento); 1345 {
1346 const Op_Desc *op_desc = NULL; 1346 case MEMENTO_PROPERTY:
1347
1348 Gui_Widget *wdg = wdg_get(wdg_id);
1349 if (!wdg)
1350 { 1347 {
1351 ERR("wdg not found"); 1348 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1352 return EINA_FALSE; 1349 const Op_Desc *op_desc = NULL;
1353 }
1354 1350
1355 Gui_Widget_Property *new_prop, *old_prop; 1351 Gui_Widget *wdg = wdg_get(wdg_id);
1356 old_prop = gui_memento_old_pointer_get(memento); 1352 if (!wdg)
1357 new_prop = gui_memento_new_pointer_get(memento); 1353 {
1354 ERR("wdg not found");
1355 return EINA_FALSE;
1356 }
1358 1357
1359 if (old_prop) 1358 Gui_Widget_Property *new_prop, *old_prop;
1360 { 1359 old_prop = gui_memento_old_pointer_get(memento);
1361 wdg_prop_remove(wdg, old_prop); 1360 new_prop = gui_memento_new_pointer_get(memento);
1362 op_desc = prop_op_desc_get(old_prop);
1363 }
1364 1361
1365 propsview_view_switch(PROPERTY_TYPE); 1362 if (old_prop)
1366 if (new_prop) 1363 {
1367 { 1364 wdg_prop_remove(wdg, old_prop);
1368 op_desc = prop_op_desc_get(new_prop); 1365 op_desc = prop_op_desc_get(old_prop);
1369 wdg_prop_add(wdg, new_prop); 1366 }
1370 Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx); 1367
1371 manager_widget_property_add(session, wdg, new_prop, MODE_EDITOR, NULL); 1368 propsview_view_switch(PROPERTY_TYPE);
1372 if (_editor_wdg_selected_get() != wdg) 1369 if (new_prop)
1373 { 1370 {
1371 op_desc = prop_op_desc_get(new_prop);
1372 wdg_prop_add(wdg, new_prop);
1373 Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
1374 manager_widget_property_add(session, wdg, new_prop, MODE_EDITOR, NULL);
1375 if (_editor_wdg_selected_get() != wdg)
1376 {
1377 objtree_item_selected_set(wdg);
1378 }
1379 propview_item_update(new_prop);
1380 }
1381 else
1382 {
1383 _wdg_parent_win_reload(wdg);
1374 objtree_item_selected_set(wdg); 1384 objtree_item_selected_set(wdg);
1375 } 1385 }
1376 propview_item_update(new_prop); 1386 if (op_desc)
1387 propview_item_selected_set(op_desc);
1388 break;
1377 } 1389 }
1378 else 1390 case MEMENTO_CALLBACK:
1379 { 1391 {
1380 _wdg_parent_win_reload(wdg); 1392 Gui_Widget_Callback *new_cb;
1381 objtree_item_selected_set(wdg); 1393 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1382 }
1383 if (op_desc)
1384 propview_item_selected_set(op_desc);
1385 break;
1386 }
1387 case MEMENTO_CALLBACK:
1388 {
1389 Gui_Widget_Callback *new_cb;
1390 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1391 1394
1392 Gui_Widget *wdg = wdg_get(wdg_id); 1395 Gui_Widget *wdg = wdg_get(wdg_id);
1393 if (!wdg) 1396 if (!wdg)
1394 { 1397 {
1395 ERR("wdg not found"); 1398 ERR("wdg not found");
1396 return EINA_FALSE; 1399 return EINA_FALSE;
1397 } 1400 }
1398 1401
1399 new_cb = gui_memento_new_pointer_get(memento); 1402 new_cb = gui_memento_new_pointer_get(memento);
1400 Dep_Id *cb_dep_id = cb_dep_id_get(new_cb); 1403 Dep_Id *cb_dep_id = cb_dep_id_get(new_cb);
1401 1404
1402 Dep_Data *dep_data = gui_context_dep_data_get(cb_dep_id); 1405 Dep_Data *dep_data = gui_context_dep_data_get(cb_dep_id);
1403 dep_data_cb_set(dep_data, new_cb); 1406 dep_data_cb_set(dep_data, new_cb);
1404 1407
1405 propsview_view_switch(CALLBACK_TYPE); 1408 propsview_view_switch(CALLBACK_TYPE);
1406 _editor_wdg_selected_set(wdg); 1409 _editor_wdg_selected_set(wdg);
1407 cbview_item_selected_set(cb_dep_id); 1410 cbview_item_selected_set(cb_dep_id);
1408 break; 1411 break;
1409 } 1412 }
1410 case MEMENTO_CALLBACK_ADD_DEL: 1413 case MEMENTO_CALLBACK_ADD_DEL:
1411 { 1414 {
1412 Callback_Container *new_cc; 1415 Callback_Container *new_cc;
1413 Dep_Id *wdg_id = gui_memento_wdg_get(memento); 1416 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1417
1418 Gui_Widget *wdg = wdg_get(wdg_id);
1419 if (!wdg)
1420 {
1421 ERR("wdg not found");
1422 return EINA_FALSE;
1423 }
1424 new_cc = gui_memento_new_pointer_get(memento);
1425 wdg_cb_container_unset(wdg);
1426 wdg_cb_container_set(wdg, new_cc);
1414 1427
1415 Gui_Widget *wdg = wdg_get(wdg_id); 1428 propsview_view_switch(CALLBACK_TYPE);
1416 if (!wdg) 1429 _editor_wdg_selected_set(wdg);
1430 break;
1431 }
1432 case MEMENTO_OBJ_CONTAINER_ITEM:
1417 { 1433 {
1418 ERR("wdg not found"); 1434 Object_Container *new_container;
1419 return EINA_FALSE; 1435 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1436
1437 Gui_Widget *wdg = wdg_get(wdg_id);
1438 if (!wdg)
1439 {
1440 ERR("wdg not found");
1441 return EINA_FALSE;
1442 }
1443
1444 new_container = gui_memento_new_pointer_get(memento);
1445
1446 wdg_obj_container_unset(wdg);
1447 wdg_obj_container_set(wdg, new_container);
1448 break;
1420 } 1449 }
1421 new_cc = gui_memento_new_pointer_get(memento); 1450 case MEMENTO_ITEM_CONTAINER_ITEM:
1422 wdg_cb_container_unset(wdg); 1451 {
1423 wdg_cb_container_set(wdg, new_cc); 1452 Item_Container_Item *new_it;
1453 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1424 1454
1425 propsview_view_switch(CALLBACK_TYPE); 1455 Gui_Widget *wdg = wdg_get(wdg_id);
1426 _editor_wdg_selected_set(wdg); 1456 if (!wdg)
1427 break; 1457 {
1428 } 1458 ERR("wdg not found");
1429 case MEMENTO_OBJ_CONTAINER_ITEM: 1459 return EINA_FALSE;
1430 { 1460 }
1431 Object_Container *new_container; 1461
1432 Dep_Id *wdg_id = gui_memento_wdg_get(memento); 1462 new_it = gui_memento_new_pointer_get(memento);
1433 1463
1434 Gui_Widget *wdg = wdg_get(wdg_id); 1464 Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(new_it));
1435 if (!wdg) 1465 dep_data_item_set(dep_data, new_it);
1466 break;
1467 }
1468 case MEMENTO_WIDGET:
1469 {
1470 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1471 Eina_Bool new_state = (intptr_t) gui_memento_new_pointer_get(memento);
1472 _update_widget_on_undoredo(ctx, wdg_id, new_state);
1473 break;
1474 }
1475 case MEMENTO_NONE:
1436 { 1476 {
1437 ERR("wdg not found"); 1477 break;
1438 return EINA_FALSE;
1439 } 1478 }
1479 default:
1480 ERR("case - default");
1481 }
1482 memento = gui_memento_next(memento);
1483 }
1484 /* Update propview. */
1485 _editor_undo_redo_post(head_memento);
1440 1486
1441 new_container = gui_memento_new_pointer_get(memento); 1487 elm_object_item_disabled_set(g->main_win->toolbar_redo_it, gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE);
1488 elm_object_item_disabled_set(g->main_win->toolbar_undo_it, gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE);
1442 1489
1443 wdg_obj_container_unset(wdg); 1490 return EINA_TRUE;
1444 wdg_obj_container_set(wdg, new_container); 1491}
1445 1492
1446 /* Set content to container. */ 1493static void
1447 //Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx); 1494_editor_undo_redo_post(const Gui_Memento *memento)
1448 //manager_widget_content_unset_all(session, wdg, wdg_obj_container_class_name_get(wdg), MODE_EDITOR, NULL); 1495{
1449 //manager_widget_content_add(session, wdg, MODE_EDITOR, NULL); 1496 Gui_Memento_Type head_memento_type = gui_memento_type_get(memento);
1450 /* Update propview. */ 1497 Gui_Widget *head_memento_wdg = wdg_get(gui_memento_wdg_get(memento));
1451 propsview_view_switch(CONTENT_TYPE); 1498
1452 _wdg_parent_win_reload(wdg); 1499 switch (head_memento_type)
1453 _editor_wdg_selected_set(wdg); 1500 {
1454 objtree_item_selected_set(wdg); 1501 case MEMENTO_PROPERTY:
1502 {
1455 break; 1503 break;
1456 } 1504 }
1505 case MEMENTO_OBJ_CONTAINER_ITEM:
1457 case MEMENTO_ITEM_CONTAINER_ITEM: 1506 case MEMENTO_ITEM_CONTAINER_ITEM:
1458 { 1507 {
1459 Item_Container_Item *new_it;
1460 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1461
1462 Gui_Widget *wdg = wdg_get(wdg_id);
1463 if (!wdg)
1464 {
1465 ERR("wdg not found");
1466 return EINA_FALSE;
1467 }
1468
1469 new_it = gui_memento_new_pointer_get(memento);
1470
1471 Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(new_it));
1472 dep_data_item_set(dep_data, new_it);
1473
1474 propsview_view_switch(CONTENT_TYPE); 1508 propsview_view_switch(CONTENT_TYPE);
1475 _wdg_parent_win_reload(wdg); 1509 _wdg_parent_win_reload(head_memento_wdg);
1476 _editor_wdg_selected_set(wdg); 1510 _editor_wdg_selected_set(head_memento_wdg);
1477 objtree_item_selected_set(wdg); 1511 objtree_item_selected_set(head_memento_wdg);
1512 break;
1513 }
1514 case MEMENTO_CALLBACK:
1515 {
1516 break;
1517 }
1518 case MEMENTO_CALLBACK_ADD_DEL:
1519 {
1520 propsview_view_switch(CALLBACK_TYPE);
1521 _editor_wdg_selected_set(head_memento_wdg);
1478 break; 1522 break;
1479 } 1523 }
1480 case MEMENTO_WIDGET: 1524 case MEMENTO_WIDGET:
1481 { 1525 {
1482 Dep_Id *wdg_id = gui_memento_wdg_get(memento);
1483 Eina_Bool new_state = (intptr_t) gui_memento_new_pointer_get(memento);
1484 _update_widget_on_undoredo(ctx, wdg_id, new_state);
1485 break; 1526 break;
1486 } 1527 }
1487 case MEMENTO_NONE: 1528 case MEMENTO_NONE:
@@ -1491,11 +1532,6 @@ _editor_redo(const Gui_Context *ctx)
1491 default: 1532 default:
1492 ERR("case - default"); 1533 ERR("case - default");
1493 } 1534 }
1494
1495 elm_object_item_disabled_set(g->main_win->toolbar_redo_it, gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE);
1496 elm_object_item_disabled_set(g->main_win->toolbar_undo_it, gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE);
1497
1498 return EINA_TRUE;
1499} 1535}
1500 1536
1501static Eina_Bool 1537static Eina_Bool
@@ -2421,6 +2457,7 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_De
2421 2457
2422 Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container); 2458 Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
2423 gui_context_memento_add(ctx, memento); 2459 gui_context_memento_add(ctx, memento);
2460 gui_memento_append(NULL, memento);
2424 2461
2425 wdg_obj_container_unset((Gui_Widget *) wdg); 2462 wdg_obj_container_unset((Gui_Widget *) wdg);
2426 wdg_obj_container_set((Gui_Widget *) wdg, _new_container); 2463 wdg_obj_container_set((Gui_Widget *) wdg, _new_container);
@@ -2531,22 +2568,34 @@ _content_change_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_De
2531 /* Check if new_widget was packed previously: take it's parent and check 2568 /* Check if new_widget was packed previously: take it's parent and check
2532 * if widget is packed into it's parent. 2569 * if widget is packed into it's parent.
2533 * If so, we need to unpack widget and delete from contents*/ 2570 * If so, we need to unpack widget and delete from contents*/
2534 Gui_Widget *old_container = (Gui_Widget *) wdg_parent_get(new_param_wdg); 2571 Gui_Widget *prev_wdg_container = (Gui_Widget *) wdg_parent_get(new_param_wdg);
2535 if (!wdg_obj_container_item_get(old_container, -1, new_value)) 2572 if (!wdg_obj_container_item_get(prev_wdg_container, -1, new_value))
2536 old_container = NULL; 2573 prev_wdg_container = NULL;
2537 2574
2538 Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx); 2575 Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
2539 if (old_container) 2576 if (prev_wdg_container)
2540 { 2577 {
2578 Object_Container *_old_prev_container, *_new_prev_container;
2579 _old_prev_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) prev_wdg_container);
2580 _new_prev_container = obj_container_copy(_old_prev_container);
2581
2582 Gui_Memento *memento_next = gui_memento_new(wdg_dep_id_get(prev_wdg_container),
2583 MEMENTO_OBJ_CONTAINER_ITEM,
2584 _old_prev_container, _new_prev_container);
2585 gui_memento_append(memento, memento_next);
2586 wdg_obj_container_unset((Gui_Widget *) prev_wdg_container);
2587 wdg_obj_container_set((Gui_Widget *) prev_wdg_container, _new_prev_container);
2588
2589
2541 /* Take old container's class name from content-property. */ 2590 /* Take old container's class name from content-property. */
2542 Object_Container_Item *_ci = wdg_obj_container_item_get(old_container, -1, new_value); 2591 Object_Container_Item *_ci = wdg_obj_container_item_get(prev_wdg_container, -1, new_value);
2543 Gui_Widget_Property *old_prop = obj_container_item_prop_get(_ci); 2592 Gui_Widget_Property *old_prop = obj_container_item_prop_get(_ci);
2544 2593
2545 const Op_Desc *old_op_desc = prop_op_desc_get(old_prop); 2594 const Op_Desc *old_op_desc = prop_op_desc_get(old_prop);
2546 const char *old_container_name = db_op_desc_class_name_get(old_op_desc); 2595 const char *old_container_name = db_op_desc_class_name_get(old_op_desc);
2547 2596
2548 manager_widget_content_unset(session, old_container, old_container_name, old_prop, MODE_EDITOR, NULL); 2597 manager_widget_content_unset(session, prev_wdg_container, old_container_name, old_prop, MODE_EDITOR, NULL);
2549 wdg_obj_container_item_remove(old_container, _ci); 2598 wdg_obj_container_item_remove(prev_wdg_container, _ci);
2550 } 2599 }
2551 2600
2552 Dep_Id *dep_id = wdg_dep_id_get(new_param_wdg); 2601 Dep_Id *dep_id = wdg_dep_id_get(new_param_wdg);
diff --git a/src/lib/undoredo.c b/src/lib/undoredo.c
index e14186e..071b30e 100644
--- a/src/lib/undoredo.c
+++ b/src/lib/undoredo.c
@@ -4,6 +4,8 @@
4 4
5struct _Gui_Memento 5struct _Gui_Memento
6{ 6{
7 /* Inlist to keep a list of depended mementos. */
8 EINA_INLIST;
7 Dep_Id *wdg_id; 9 Dep_Id *wdg_id;
8 Gui_Memento_Type type; 10 Gui_Memento_Type type;
9 union 11 union
@@ -122,63 +124,83 @@ gui_memento_new(Dep_Id *wdg_id, Gui_Memento_Type type, void *old_pointer, void *
122void 124void
123gui_memento_del(Gui_Memento *memento) 125gui_memento_del(Gui_Memento *memento)
124{ 126{
125 ERR("memento del");
126 EINA_SAFETY_ON_NULL_RETURN(memento); 127 EINA_SAFETY_ON_NULL_RETURN(memento);
127 switch (memento->type) 128 Eina_Inlist *inlist = EINA_INLIST_GET(memento);
129 EINA_INLIST_FREE(inlist, memento)
128 { 130 {
129 case MEMENTO_PROPERTY: 131 inlist = eina_inlist_remove(inlist, EINA_INLIST_GET(memento));
130 { 132 switch (memento->type)
131 /* old_pointer can be NULL only when property was never set. */ 133 {
132 if (memento->old_property) 134 case MEMENTO_PROPERTY:
133 prop_unref((Gui_Widget_Property *) memento->old_property); 135 {
134 if (memento->new_property) 136 /* old_pointer can be NULL only when property was never set. */
135 prop_unref((Gui_Widget_Property *) memento->new_property); 137 if (memento->old_property)
136 break; 138 prop_unref((Gui_Widget_Property *) memento->old_property);
137 } 139 if (memento->new_property)
138 case MEMENTO_CALLBACK: 140 prop_unref((Gui_Widget_Property *) memento->new_property);
139 { 141 break;
140 if (memento->old_callback) 142 }
141 cb_unref((Gui_Widget_Callback *) memento->old_callback); 143 case MEMENTO_CALLBACK:
142 if (memento->new_callback) 144 {
143 cb_unref((Gui_Widget_Callback *) memento->new_callback); 145 if (memento->old_callback)
144 break; 146 cb_unref((Gui_Widget_Callback *) memento->old_callback);
145 } 147 if (memento->new_callback)
146 case MEMENTO_CALLBACK_ADD_DEL: 148 cb_unref((Gui_Widget_Callback *) memento->new_callback);
147 { 149 break;
148 if (memento->old_cb_container) 150 }
149 cb_container_unref((Callback_Container *) memento->old_cb_container); 151 case MEMENTO_CALLBACK_ADD_DEL:
150 if (memento->new_cb_container) 152 {
151 cb_container_unref((Callback_Container *) memento->new_cb_container); 153 if (memento->old_cb_container)
152 break; 154 cb_container_unref((Callback_Container *) memento->old_cb_container);
153 } 155 if (memento->new_cb_container)
154 case MEMENTO_OBJ_CONTAINER_ITEM: 156 cb_container_unref((Callback_Container *) memento->new_cb_container);
155 { 157 break;
156 if (memento->old_obj_container) 158 }
157 obj_container_unref((Object_Container *) memento->old_obj_container); 159 case MEMENTO_OBJ_CONTAINER_ITEM:
158 if (memento->new_obj_container) 160 {
159 obj_container_unref((Object_Container *) memento->new_obj_container); 161 if (memento->old_obj_container)
160 break; 162 obj_container_unref((Object_Container *) memento->old_obj_container);
161 } 163 if (memento->new_obj_container)
162 case MEMENTO_ITEM_CONTAINER_ITEM: 164 obj_container_unref((Object_Container *) memento->new_obj_container);
163 { 165 break;
164 if (memento->old_item) 166 }
165 item_container_item_unref((Item_Container_Item *) memento->old_item); 167 case MEMENTO_ITEM_CONTAINER_ITEM:
166 if (memento->new_item) 168 {
167 item_container_item_unref((Item_Container_Item *) memento->new_item); 169 if (memento->old_item)
168 break; 170 item_container_item_unref((Item_Container_Item *) memento->old_item);
169 } 171 if (memento->new_item)
170 case MEMENTO_WIDGET: 172 item_container_item_unref((Item_Container_Item *) memento->new_item);
171 { 173 break;
172 break; 174 }
173 } 175 case MEMENTO_WIDGET:
174 case MEMENTO_NONE: 176 {
175 { 177 break;
176 break; 178 }
177 } 179 case MEMENTO_NONE:
178 default: 180 {
179 ERR("case - default"); 181 break;
182 }
183 default:
184 ERR("case - default");
185 }
186 free(memento);
180 } 187 }
181 free(memento); 188}
189
190/* Get next Memento */
191Gui_Memento*
192gui_memento_next(const Gui_Memento *memento)
193{
194 return EINA_INLIST_CONTAINER_GET(EINA_INLIST_GET(memento)->next, Gui_Memento);
195}
196
197/* Append memento to the list of mementos */
198void
199gui_memento_append(Gui_Memento *head, Gui_Memento *in)
200{
201 Eina_Inlist *inlist = NULL;
202 if (head) inlist = EINA_INLIST_GET(head);
203 inlist = eina_inlist_append(inlist, EINA_INLIST_GET(in));
182} 204}
183 205
184/* Get Memento type */ 206/* Get Memento type */
diff --git a/src/lib/undoredo.h b/src/lib/undoredo.h
index f21627e..1d8a423 100644
--- a/src/lib/undoredo.h
+++ b/src/lib/undoredo.h
@@ -35,6 +35,14 @@ gui_memento_del(Gui_Memento *memento);
35Gui_Memento_Type 35Gui_Memento_Type
36gui_memento_type_get(const Gui_Memento *memento); 36gui_memento_type_get(const Gui_Memento *memento);
37 37
38/* Append memento to the list of mementos */
39void
40gui_memento_append(Gui_Memento *head, Gui_Memento *in);
41
42/* Get next Memento */
43Gui_Memento*
44gui_memento_next(const Gui_Memento *memento);
45
38/* Functions to set/get state in Gui_Memento. */ 46/* Functions to set/get state in Gui_Memento. */
39 47
40/* Get widget. */ 48/* Get widget. */