Prevent single-node ways from being created by undo.
[potlatch2.git] / net / systemeD / potlatch2 / controller / NoSelection.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.display.*;
4         import net.systemeD.potlatch2.EditController;
5         import net.systemeD.halcyon.connection.*;
6     import net.systemeD.halcyon.connection.actions.*;
7         import net.systemeD.halcyon.Map;
8         import net.systemeD.halcyon.MapPaint;
9
10         public class NoSelection extends ControllerState {
11
12                 public function NoSelection() {
13                 }
14
15                 override public function isSelectionState():Boolean {
16                         return false;
17                 }
18                 
19                 override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
20                         var cs:ControllerState = sharedMouseEvents(event, entity);
21                         if (cs) return cs;
22
23                         var paint:MapPaint = getMapPaint(DisplayObject(event.target));
24                         var focus:Entity = getTopLevelFocusEntity(entity);
25
26                         if (event.type==MouseEvent.MOUSE_UP && (focus==null || (paint && paint.isBackground)) && map.dragstate!=map.DRAGGING) {
27                                 map.dragstate=map.NOT_DRAGGING;
28                                 // ** FIXME: BeginWayAction ought to be a discrete class
29                                 var undo:CompositeUndoableAction = new BeginWayAction();
30                                 var conn:Connection = layer.connection;
31                                 var startNode:Node = conn.createNode(
32                                         {}, 
33                                         controller.map.coord2lat(event.localY),
34                                         controller.map.coord2lon(event.localX), undo.push);
35                                 var way:Way = conn.createWay({}, [startNode], undo.push);
36                                 MainUndoStack.getGlobalStack().addAction(undo);
37                                 return new DrawWay(way, true, false);
38                         }
39                         return this;
40                 }
41                 
42                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
43                         var cs:ControllerState = sharedKeyboardEvents(event);
44                         return cs ? cs : this;
45                 }
46                 
47         override public function enterState():void {
48                         controller.map.mouseUpHandler();
49         }
50         override public function exitState(newState:ControllerState):void {
51         }
52                 override public function toString():String {
53                         return "NoSelection";
54                 }
55
56         }
57 }