Shift-R: paste relations from previously selected object, as per #3596.
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectArea.as
index 73cb2fc578112d2018d14d79ceebe8fa355d9ffb..b00b944b3b6a8dbfd3017c25c255e9cfa9ca2229 100644 (file)
@@ -12,8 +12,11 @@ package net.systemeD.potlatch2.controller {
                private var endY:Number;
                private var box:Shape;
                private const TOLERANCE:uint=4;
+               private var originalSelection:Array;
 
-               public function SelectArea(x:Number,y:Number) {
+               public function SelectArea(x:Number,y:Number,sel:Array) {
+                       selection = sel.concat();
+                       originalSelection = sel.concat();
                        startX=endX=x;
                        startY=endY=y;
                }
@@ -29,12 +32,12 @@ package net.systemeD.potlatch2.controller {
                                var a:Number;
                                if (startX>endX) { a=startX; startX=endX; endX=a; }
                                if (startY>endY) { a=startY; startY=endY; endY=a; }
-                               if (endX-startX<TOLERANCE && endY-startY<TOLERANCE) { return new NoSelection(); }
+                               if (endX-startX<TOLERANCE && endY-startY<TOLERANCE) { return controller.findStateForSelection(originalSelection); }
                                var left:Number=controller.map.coord2lon(startX);
                                var right:Number=controller.map.coord2lon(endX);
                                var top:Number=controller.map.coord2lat(startY);
                                var bottom:Number=controller.map.coord2lat(endY);
-                               var entities:Object=editableLayer.connection.getObjectsByBbox(left,right,top,bottom);
+                               var entities:Object=layer.connection.getObjectsByBbox(left,right,top,bottom);
                                for each (var way:Way  in entities.waysInside) { if (way.intersects(left,right,top,bottom)) toggleSelection(way); }
                                for each (var poi:Node in entities.poisInside) { toggleSelection(poi); }
                                return controller.findStateForSelection(selection);
@@ -50,13 +53,19 @@ package net.systemeD.potlatch2.controller {
                }
                
                override public function enterState():void {
+                       for each (var entity:Entity in selection) {
+                               layer.setHighlight(entity, { selected: true });
+                       }
                        box=new Shape();
-                       var l:DisplayObject=editableLayer.getPaintSpriteAt(editableLayer.maxlayer);
+                       var l:DisplayObject=layer.getPaintSpriteAt(layer.maxlayer);
                        var o:DisplayObject=Sprite(l).getChildAt(3);
                        (o as Sprite).addChild(box);
                        controller.map.draggable=false;
                }
                override public function exitState(newState:ControllerState):void {
+                       for each (var entity:Entity in originalSelection) {
+                               layer.setHighlight(entity, { selected: false });
+                       }
                        box.parent.removeChild(box);
                        controller.map.draggable=true;
                        if (!newState.isSelectionState()) { controller.updateSelectionUI(); }