fix bug undoing create
[potlatch2.git] / net / systemeD / halcyon / connection / actions / DeleteNodeAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class DeleteNodeAction extends UndoableEntityAction {
6         private var setDeleted:Function;
7         private var effects:CompositeUndoableAction;
8         
9         public function DeleteNodeAction(node:Node, setDeleted:Function) {
10             super(node, "Delete");
11             this.setDeleted = setDeleted;
12         }
13             
14         public override function doAction():uint {
15             var node:Node = entity as Node;
16             if ( node.isDeleted() )
17                 return NO_CHANGE;
18
19             effects = new CompositeUndoableAction("Delete refs");            
20             node.removeFromParents(effects.push);
21             effects.doAction();
22             setDeleted(true);
23             markDirty();
24             node.dispatchEvent(new EntityEvent(Connection.NODE_DELETED, node));
25             
26             return SUCCESS;
27         }
28             
29         public override function undoAction():uint {
30             setDeleted(false);
31             markClean();
32             entity.dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
33             if ( effects != null )
34                 effects.undoAction();
35             return SUCCESS;
36         }
37     }
38 }
39