CreatePOIAction, so that redo has a chance to re-register POI and redraw it (not...
authorAndy Allan <gravitystorm@gmail.com>
Wed, 25 Aug 2010 13:35:45 +0000 (13:35 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Wed, 25 Aug 2010 13:35:45 +0000 (13:35 +0000)
net/systemeD/halcyon/connection/actions/CreatePOIAction.as [new file with mode: 0644]
net/systemeD/potlatch2/controller/DrawWay.as

diff --git a/net/systemeD/halcyon/connection/actions/CreatePOIAction.as b/net/systemeD/halcyon/connection/actions/CreatePOIAction.as
new file mode 100644 (file)
index 0000000..961a735
--- /dev/null
@@ -0,0 +1,43 @@
+package net.systemeD.halcyon.connection.actions {
+
+    import net.systemeD.halcyon.connection.*;
+    import net.systemeD.halcyon.Map;
+    import flash.events.*;
+    
+    public class CreatePOIAction extends CompositeUndoableAction {
+    
+        private var newNode:Node;
+        private var event:MouseEvent;
+        private var map:Map;
+        
+        public function CreatePOIAction(event:MouseEvent, map:Map) {
+          super("Create POI");
+          this.event = event;
+          this.map = map;
+        }
+        
+        public override function doAction():uint {
+          if (newNode == null) {
+            newNode = Connection.getConnection().createNode(
+                {},
+                map.coord2lat(event.localY),
+                map.coord2lon(event.localX), push);
+          }
+          super.doAction();
+          Connection.getConnection().registerPOI(newNode);
+          
+          return SUCCESS;
+        }
+        
+        public override function undoAction():uint {
+          super.undoAction();
+          Connection.getConnection().unregisterPOI(newNode);
+          
+          return SUCCESS;
+        }
+        
+        public function getNode():Node {
+          return newNode;
+        }
+    }
+}
\ No newline at end of file
index 224eb1e..3741626 100644 (file)
@@ -5,6 +5,7 @@ package net.systemeD.potlatch2.controller {
        import flash.ui.Keyboard;
        import net.systemeD.potlatch2.EditController;
        import net.systemeD.halcyon.connection.*;
+    import net.systemeD.halcyon.connection.actions.*;
        import net.systemeD.halcyon.Elastic;
        import net.systemeD.halcyon.Globals;
        import net.systemeD.halcyon.MapPaint;
@@ -48,14 +49,12 @@ package net.systemeD.potlatch2.controller {
                                        if (entity==lastClick && (new Date().getTime()-lastClickTime.getTime())<1000) {
                                                if (selectedWay.length==1 && selectedWay.getNode(0).parentWays.length==1) {
                                                        // double-click to create new POI
+                            stopDrawing();
                             MainUndoStack.getGlobalStack().undo(); // undo the BeginWayAction that (presumably?) just happened
-                            node = controller.connection.createNode(
-                              {},
-                              controller.map.coord2lat(event.localY),
-                              controller.map.coord2lon(event.localX), MainUndoStack.getGlobalStack().addAction);
-                                                       stopDrawing();
-                                                       controller.connection.registerPOI(node);
-                                                       return new SelectedPOINode(node);
+                            
+                            var newPoiAction:CreatePOIAction = new CreatePOIAction(event, controller.map);
+                            MainUndoStack.getGlobalStack().addAction(newPoiAction);
+                            return new SelectedPOINode(newPoiAction.getNode());
                                                } else {
                                                        // double-click at end of way
                                                        return stopDrawing();