add undo for creating stuff
[potlatch2.git] / net / systemeD / halcyon / connection / actions / AddNodeToWayAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class AddNodeToWayAction extends UndoableEntityAction {
6         private var node:Node;
7         private var nodeList:Array;
8         private var index:int;
9         
10         public function AddNodeToWayAction(way:Way, node:Node, nodeList:Array, index:int) {
11             super(way, "Add node "+node.id+" to");
12             this.node = node;
13             this.nodeList = nodeList;
14             this.index = index;
15         }
16             
17         public override function doAction():uint {
18             var way:Way = entity as Way;
19             if ( index == -1 )
20                 index = nodeList.length;
21             node.addParent(way);
22             nodeList.splice(index, 0, node);
23             markDirty();
24             way.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_ADDED, node, way, index));
25             
26             return SUCCESS;
27         }
28             
29         public override function undoAction():uint {
30             var way:Way = entity as Way;
31             var removed:Array=nodeList.splice(index, 1);
32                         if (nodeList.indexOf(removed[0])==-1) { removed[0].removeParent(way); }
33                         markClean();
34             way.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, removed[0], way, index));
35             
36             return SUCCESS;
37         }
38     }
39 }
40