Reverse the markDirty and markClean for entity deletions, if the entity has a negativ...
authorAndy Allan <gravitystorm@gmail.com>
Fri, 20 Aug 2010 13:32:18 +0000 (13:32 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Fri, 20 Aug 2010 13:32:18 +0000 (13:32 +0000)
net/systemeD/halcyon/connection/actions/CreateEntityAction.as
net/systemeD/halcyon/connection/actions/DeleteNodeAction.as
net/systemeD/halcyon/connection/actions/DeleteRelationAction.as
net/systemeD/halcyon/connection/actions/DeleteWayAction.as

index 426a827..140bf12 100644 (file)
@@ -6,22 +6,32 @@ package net.systemeD.halcyon.connection.actions {
         private var setCreate:Function;
         private var deleteAction:UndoableAction;
         
+        // This is a bit unusual, since we need to handle undo and specifically redo slightly differently
+        // When undo is called, instead of simply removing the entity, we work through
+        // to make a Delete[Entity]Action, call that, and store it for later
+        // Then, when this action is called again (i.e. a redo), instead of creating yet another entity, we call the deleteAction.undoAction
+
         public function CreateEntityAction(entity:Entity, setCreate:Function) {
             super(entity, "Create");
             this.setCreate = setCreate;
         }
             
         public override function doAction():uint {
+            // check to see if this is the first pass - i.e. not a redo action.
+            // if it's redo (i.e. we've stored a deleteAction), undo the deletion
+            // if it's the first time, register the new entity with the connection
             if ( deleteAction != null ) {
                 deleteAction.undoAction();
             } else {
                 setCreate(entity, false);
             }
-            markDirty();
+            markDirty(); // if this is the first action taken, undoing it will then be able to clean the connection
             return SUCCESS;
         }
             
         public override function undoAction():uint {
+            // if the undo is called for the first time, call for a deletion, and (via setAction) store the
+            // deletion action for later. We'll undo the deletion if we get asked to redo this action
             if ( deleteAction == null ) {
                 entity.remove(setAction);
             }
index bb74207..323ba07 100644 (file)
@@ -20,15 +20,35 @@ package net.systemeD.halcyon.connection.actions {
             node.removeFromParents(effects.push);
             effects.doAction();
             setDeleted(true);
-            markDirty();
+            
+            // 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));
             
             return SUCCESS;
         }
             
         public override function undoAction():uint {
+            var node:Node = entity as Node;
             setDeleted(false);
-            markClean();
+            
+            // See note above
+            if (node.id < 0) {
+              markDirty();
+            } else {
+              markClean();
+            }
             entity.dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
             if ( effects != null )
                 effects.undoAction();
index 3043ecb..4ca186f 100644 (file)
@@ -28,7 +28,13 @@ package net.systemeD.halcyon.connection.actions {
                        memberList.splice(0, memberList.length);
                        effects.doAction();
                        setDeleted(true);
-                       markDirty();
+            
+            // see note in DeleteNodeAction
+            if (relation.id < 0) {
+              markClean();
+            } else {
+              markDirty();
+            }
             relation.dispatchEvent(new EntityEvent(Connection.RELATION_DELETED, relation));
 
             return SUCCESS;
@@ -37,7 +43,11 @@ package net.systemeD.halcyon.connection.actions {
         public override function undoAction():uint {
             var relation:Relation = entity as Relation;
             setDeleted(false);
-            markClean();
+            if (relation.id < 0) {
+              markDirty();
+            } else {
+              markClean();
+            }
             relation.dispatchEvent(new EntityEvent(Connection.NEW_RELATION, relation));
             effects.undoAction();
             for each(var member:RelationMember in oldMemberList) {
index 00725ff..da51595 100644 (file)
@@ -32,7 +32,13 @@ package net.systemeD.halcyon.connection.actions {
                        }
                        effects.doAction();
                        setDeleted(true);
-                       markDirty();
+            
+            // see note in DeleteNodeAction
+            if (way.id < 0) {
+              markClean();
+            } else {
+              markDirty();
+            }
             way.dispatchEvent(new EntityEvent(Connection.WAY_DELETED, way));
                        way.resume();
 
@@ -43,7 +49,11 @@ package net.systemeD.halcyon.connection.actions {
             var way:Way = entity as Way;
                        way.suspend();
             setDeleted(false);
-            markClean();
+            if (way.id < 0) {
+              markDirty();
+            } else {
+              markClean();
+            }
             way.dispatchEvent(new EntityEvent(Connection.NEW_WAY, way));
             effects.undoAction();
             for each(var node:Node in oldNodeList) {