Unify selection ControllerStates so they can work on either background or editable...
[potlatch2.git] / net / systemeD / potlatch2 / controller / NoSelection.as
index aa12eabc735c3e4621e4d5019fa45bc70a7d54e9..5c5072d2242f0fee477dc45f6368d5a89f00e279 100644 (file)
@@ -3,9 +3,9 @@ package net.systemeD.potlatch2.controller {
        import flash.display.*;
        import net.systemeD.potlatch2.EditController;
        import net.systemeD.halcyon.connection.*;
+    import net.systemeD.halcyon.connection.actions.*;
        import net.systemeD.halcyon.Map;
        import net.systemeD.halcyon.MapPaint;
-       import net.systemeD.halcyon.Globals;
 
        public class NoSelection extends ControllerState {
 
@@ -17,21 +17,25 @@ package net.systemeD.potlatch2.controller {
                }
                
                override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
+                       var cs:ControllerState = sharedMouseEvents(event, entity);
+                       if (cs) return cs;
+
+                       var paint:MapPaint = getMapPaint(DisplayObject(event.target));
                        var focus:Entity = getTopLevelFocusEntity(entity);
 
-                       if (event.type==MouseEvent.MOUSE_UP && focus==null && map.dragstate!=map.DRAGGING) {
+                       if (event.type==MouseEvent.MOUSE_UP && (focus==null || (paint && paint.isBackground)) && map.dragstate!=map.DRAGGING) {
                                map.dragstate=map.NOT_DRAGGING;
-                               var undo:CompositeUndoableAction = new CompositeUndoableAction("Begin way");
-                               var startNode:Node = controller.connection.createNode(
+                               var undo:CompositeUndoableAction = new BeginWayAction();
+                               var conn:Connection = layer.connection;
+                               var startNode:Node = conn.createNode(
                                        {}, 
                                        controller.map.coord2lat(event.localY),
                                        controller.map.coord2lon(event.localX), undo.push);
-                               var way:Way = controller.connection.createWay({}, [startNode], undo.push);
+                               var way:Way = conn.createWay({}, [startNode], undo.push);
                                MainUndoStack.getGlobalStack().addAction(undo);
                                return new DrawWay(way, true, false);
                        }
-                       var cs:ControllerState = sharedMouseEvents(event, entity);
-                       return cs ? cs : this;
+                       return this;
                }
                
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
@@ -41,10 +45,8 @@ package net.systemeD.potlatch2.controller {
                
         override public function enterState():void {
                        controller.map.mouseUpHandler();
-                       Globals.vars.root.addDebug("**** -> "+this);
         }
         override public function exitState(newState:ControllerState):void {
-                       Globals.vars.root.addDebug("**** <- "+this);
         }
                override public function toString():String {
                        return "NoSelection";