Retain preferences even when .swf filename has changed
[potlatch2.git] / net / systemeD / potlatch2 / Toolbox.mxml
index 38a4fc8..1826e26 100644 (file)
@@ -14,7 +14,7 @@
                <!-- Top row -->
 
                <s:Button icon="@Embed('../../../embedded/delete.svg')"
-                       click='doDelete();' 
+                       click='doDelete(event.ctrlKey,event.shiftKey);' 
                        enabled="{canDo('delete')}" 
                        alpha="{getAlpha('delete')}" 
                        toolTip="{deleteToolTipText()}" 
                        alpha="{getAlpha('split')}" 
                        toolTip="Split way (X)" 
                        width="28" height="28" y="4" x="66" />
-               <s:Button icon="@Embed('../../../embedded/merge.svg')"
+               <s:Button 
                        id="mergeButton"
                        click='doMerge();'
-                       enabled="{canDo('merge')}" 
-                       alpha="{getAlpha('merge')}" 
                        toolTip="Merge ways" 
                        width="28" height="28" y="4" x="96" />
 
         public var deleteWay:String = "Delete Way (Shift+Delete)";
         public var deleteItem:String = "Delete Item"; // When nothing is selected
 
+       [Bindable] [Embed(source="../../../embedded/merge.svg"       )] private var mergeIcon:Class;
+       [Bindable] [Embed(source="../../../embedded/multipolygon.svg")] private var multipolygonIcon:Class;
+
                public function init(controller:EditController):void {
                        this.controller=controller;
                        /* check if the toolbox was explictly turned off in a previous session */
-                       if( SharedObject.getLocal("user_state").data['toolbox_visible'] == false) {
+                       if( SharedObject.getLocal("user_state","/").data['toolbox_visible'] == false) {
                          this.visible = false;
                        }
                }
                        dispatchEvent(new Event("updateSkin"));
                        dispatchEvent(new Event("updateAlpha"));
                        updateDirectionArrow();
+                       updateMergeIcon();
                }
 
                private function handleDown(e:Event):void {
                
                public function toggle():void {
                        this.visible=!this.visible;
-                       var obj:SharedObject = SharedObject.getLocal("user_state");
+                       var obj:SharedObject = SharedObject.getLocal("user_state","/");
                        obj.setProperty("toolbox_visible",this.visible);
                        obj.flush();
                }
                                case 'circularise':                     return controller.state.hasSelectedAreas();
                                case 'split':                           return (controller.state is SelectedWayNode);
                                case 'parallelise':                     return (controller.state is SelectedWay);
-                               case 'merge':                           return controller.state.hasAdjoiningWays();
                        }
                        return false;
                }
                     } else {
                         rotateButtonStack.selectedChild = arrowBoxWrapper;
                         arrow.iconDisplay.rotation=w.angle;
+                                               arrow.iconDisplay.smooth=true;
                     }
                 }
             }
         }
 
+               private function updateMergeIcon():void {
+                       var multi:Object=controller.state.multipolygonMembers();
+                       if (multi.outer) {
+                               mergeButton.setStyle("icon",multipolygonIcon);
+                               mergeButton.alpha=1;
+                               mergeButton.enabled=true;
+                       } else if (controller.state.hasAdjoiningWays()) {
+                               mergeButton.setStyle("icon",mergeIcon);
+                               mergeButton.alpha=1;
+                               mergeButton.enabled=true;
+                       } else {
+                               mergeButton.setStyle("icon",mergeIcon);
+                               mergeButton.alpha=0.5;
+                               mergeButton.enabled=false;
+                       }
+               }
+
         private function reverseClicked():void {
             if(canDo('reverseDirection')) {
                 doReverseDirection();
                // --------------------------------------------------------------------------------
                // Individual toolbox actions
 
-               public function doDelete():void {
+               public function doDelete(controlKey:Boolean,shiftKey:Boolean):void {
                        var undo:CompositeUndoableAction = new CompositeUndoableAction("Delete objects");
-                       for each (var entity:Entity in controller.state.selection) {
-                               if (entity is Node) { entity.connection.unregisterPOI(Node(entity)); }
-                               entity.remove(undo.push);
-                       }
-                       MainUndoStack.getGlobalStack().addAction(undo);
-
-                       if (controller.state is SelectedWayNode) {
-                               controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
-                       } else {
+                       if (controlKey) {
+                               // Temporary function to delete everything with non-accepting status
+                               var conn:Connection=controller.state.selection[0].connection;
+                               var o:Object=conn.getObjectsByBbox(controller.map.edge_l, controller.map.edge_r, controller.map.edge_t, controller.map.edge_b);
+                               for each (var way:Way in o.waysInside) {
+                                       if (way.status=='no' || (shiftKey && way.status=='partial')) { way.remove(undo.push); }
+                               }
+                               for each (var poi:Node in o.poisInside) {
+                                       if (poi.status=='no' || (shiftKey && way.status=='partial')) { poi.connection.unregisterPOI(poi); poi.remove(undo.push); }
+                               }
+                               MainUndoStack.getGlobalStack().addAction(undo);
                                controller.setState(new NoSelection());
+                               
+                       } else {
+                               // Standard delete function
+                               for each (var entity:Entity in controller.state.selection) {
+                                       if (entity is Node) { entity.connection.unregisterPOI(Node(entity)); }
+                                       entity.remove(undo.push);
+                               }
+                               MainUndoStack.getGlobalStack().addAction(undo);
+
+                               if (controller.state is SelectedWayNode) {
+                                       controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
+                               } else {
+                                       controller.setState(new NoSelection());
+                               }
                        }
                }
                
                public function doMerge():void {
-                       controller.setState(SelectedMultiple(controller.state).mergeWays());
+                       var multi:Object=controller.state.multipolygonMembers();
+                       if (multi.outer) {
+                               controller.setState(SelectedMultiple(controller.state).createMultipolygon());
+                       } else {
+                               controller.setState(SelectedMultiple(controller.state).mergeWays());
+                       }
                }
 
                public function doReverseDirection():void {