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