change relation.appendMember to use the undo system, and update various places as...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / DeleteNodeAction.as
index 3a08001131a3dcdc61456f5a6c978426bfad9738..b5bebfa4e956629c2bf2510da501e8fe0f8c7640 100644 (file)
@@ -20,17 +20,38 @@ package net.systemeD.halcyon.connection.actions {
             node.removeFromParents(effects.push);
             effects.doAction();
             setDeleted(true);
-            markDirty();
-            node.dispatchEvent(new EntityEvent(Connection.NODE_DELETED, node));
+            
+            // The Delete[entity]Action is unusual, since it can be called both to delete an entity, and is also used to undo its creation
+            // (hence preserving the negative id, if the creation is subsequently redone). Normally a deletion would mark the entity dirty, but
+            // if a newly created entity is being deleted, the entity is now clean. 
+            // When the creation is "redone", it's actually an undo on the deletion of the new entity (see below),
+            // and so the connection will need to be considered dirty again. Usually it's an existing object that's deleted and restored,
+            // which would make things clean.
+            // See also CreateEntityAction
+            
+            if (node.id < 0) {
+              markClean();
+            } else {
+              markDirty();
+            }
+            node.dispatchEvent(new EntityEvent(Connection.NODE_DELETED, node));        // delete NodeUI
             
             return SUCCESS;
         }
             
         public override function undoAction():uint {
+            var node:Node = entity as Node;
             setDeleted(false);
-            markClean();
-            entity.dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
-            effects.undoAction();
+            
+            // See note above
+            if (node.id < 0) {
+              markDirty();
+            } else {
+              markClean();
+            }
+            Connection.getConnection().dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
+            if ( effects != null )
+                effects.undoAction();
             return SUCCESS;
         }
     }