Localisation updates from https://translatewiki.net.
[potlatch2.git] / potlatch2.mxml
index 9137c59..5c1fd75 100644 (file)
             enabled="{MainUndoStack.getGlobalStack().canRedo()}"
             toolTip="{MainUndoStack.getGlobalStack().getRedoDescription() ? 'Redo '+MainUndoStack.getGlobalStack().getRedoDescription() : 'Redo last action'}" />
         <mx:Spacer width="100%"/>
-        <mx:PopUpButton id="bgButton" label="Background" openAlways="true" styleName="appBarButton"
+        <mx:PopUpButton id="bgButton" label="Background" openAlways="true" styleName="appBarButton" open="disableMapMouse();" close="enableMapMouse();" 
             creationComplete="bgButton.popUp = new BackgroundSelector();"/>
-        <mx:PopUpButton id="styleButton" label="Map Style" openAlways="true" styleName="appBarButton"
+        <mx:PopUpButton id="styleButton" label="Map Style" openAlways="true" styleName="appBarButton" open="disableMapMouse();" close="enableMapMouse();" 
             creationComplete="styleButton.popUp = new StyleSelector();"/>
-               <mx:PopUpMenuButton id="gpsButton" label="GPS" styleName="appBarButton"
+               <mx:PopUpMenuButton id="gpsButton" label="GPS" styleName="appBarButton" open="disableMapMouse();" close="enableMapMouse();" 
                    itemClick="if (event.index==0) { trackLoader.load(); } 
                          else if (event.index==1) { new MyGpxDialog().init(); } 
                                              else { mx.controls.Menu(gpsButton.popUp).selectedIndex=0; 
@@ -62,6 +62,9 @@
                                </fx:Array>
                        </mx:dataProvider>
                </mx:PopUpMenuButton>
+        <mx:PopUpButton id="bookmarkButton" label="Bookmarks" openAlways="true" styleName="appBarButton" open="disableMapMouse();" close="enableMapMouse();" 
+            creationComplete="bookmarkButton.popUp = new BookmarkSelector().init();"/>
+        <mx:Button id="tasksButton" label="Tasks" click="new TasksDialog().init(theController);" styleName="appBarButton" toolTip="Load tasks file" />
         <mx:Button id="optionsButton" label="Options" click="new OptionsDialog().init();" styleName="appBarButton" />
     </mx:ApplicationControlBar>
     
          <!-- Tag viewer -->
          <potlatch2:TagViewer width="25%" height="100%" id="tagViewer"/>
 
-      <mx:Canvas width="75%" height="100%">
-        <mx:Canvas id="map_area" resize="onResizeMap()"
-            top="0" left="0" width="100%" height="100%" dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);">
+      <mx:VBox width="75%" height="100%" verticalGap="0" id="rhContent" >
+          <mx:Canvas width="100%" height="100%">
+            <mx:Canvas id="map_area" resize="onResizeMap()"
+                top="0" left="0" width="100%" height="100%" dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);">
+            </mx:Canvas>
+            <mx:Image source="@Embed('embedded/zoomIn.svg')" left="5" top="5" click="theMap.zoomIn(event.shiftKey ? 3 : 1);"
+                rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="{'Zoom in - currently z'+getScale()}" />
+            <mx:Image source="@Embed('embedded/zoomOut.svg')" left="5" top="22" click="theMap.zoomOut(event.shiftKey ? 3 : 1);"
+                rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="{'Zoom out - currently z'+getScale()}" />
+            <mx:Image source="@Embed('embedded/search.svg')" left="5" top="42" click="new FindDialog().init();"
+                rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="Find place" />
+            <mx:TextArea id="dataWorking" text="" right="5" top="5" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="18"
+                enabled="false" borderThickness="0"
+                showEffect="{wipeIn}" hideEffect="{wipeOut}"/>
+            <mx:TextArea id="coordsbox" left="25" top="5" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="33"
+                width="70" enabled="false" borderThickness="0" visible="false"/>
+
         </mx:Canvas>
-        <mx:Image source="@Embed('embedded/zoomIn.svg')" left="5" top="5" click="theMap.zoomIn();"
-            rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="{'Zoom in - currently z'+getScale()}" />
-        <mx:Image source="@Embed('embedded/zoomOut.svg')" left="5" top="22" click="theMap.zoomOut();"
-            rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="{'Zoom out - currently z'+getScale()}" />
-        <mx:Image source="@Embed('embedded/search.svg')" left="5" top="42" click="new FindDialog().init();"
-            rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="Find place" />
-        <mx:TextArea id="dataWorking" text="" right="5" top="5" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="18"
-            enabled="false" borderThickness="0"
-            showEffect="{wipeIn}" hideEffect="{wipeOut}"/>
-        <mx:TextArea id="coordsbox" left="25" top="5" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="33"
-            width="57" enabled="false" borderThickness="0" visible="false"/>
-
-    </mx:Canvas>
+        <potlatch2:ContextualHelp width="100%" height="30" id="contextHelp" />
+    </mx:VBox>
 
     </mx:HDividedBox>
 
         public var theController:EditController;
                public var trackLoader:TrackLoader;
                public var toolbox:Toolbox;
+               public var floatingMap:FloatingMap;
         public var bugLoader:BugLoader;
         public var bikeShopLoader:BikeShopLoader;
 
                private var spinner:Spinner;
                private var saveLabel:String='Save';
                private var saveTimer:Timer;
+               private var mouseTimer:Timer;
+               private var resizeTimer:Timer;
 
         include "version.as";
 
                        saveLabel=saveButton.label;
 
                        // populate sharedObject with loaderInfo parameters if supplied
-                       var obj:SharedObject = SharedObject.getLocal("user_state");
+                       var obj:SharedObject = SharedObject.getLocal("user_state","/");
                        var objChanged:Boolean = false;
                        if (loaderInfo.parameters['tileurl']) {
                                obj.setProperty('background_url',loaderInfo.parameters['tileurl']); 
                                obj.setProperty('stylesheet_name','Custom');
                                objChanged=true; 
                        }
-                       if (objChanged) { obj.flush(); }
+                       if (objChanged) { try { obj.flush(); } catch (e:Error) {} }
+
+                       // hide contextual help if user preference
+                       if (obj.data.hasOwnProperty('hide_context_help') && obj.data['hide_context_help']) {
+                               contextHelp.visible = false;
+                               contextHelp.height  = 0;
+                       }
 
                        // map backdrop object
             var w:uint = map_area.width;
                        // pass additional parameters to map
                        var params:Object={}; var k:String;
                        for (k in this.loaderInfo.parameters) params[k]=this.loaderInfo.parameters[k];
-                       for (k in SharedObject.getLocal('user_state').data) params[k]=SharedObject.getLocal('user_state').data[k];
+                       for (k in SharedObject.getLocal('user_state',"/").data) params[k]=SharedObject.getLocal('user_state',"/").data[k];
 
                        // Create map
-                       theMap=new Map();
+                       var overlay:Sprite=TileSet.overlaySprite();
+                       theMap=new Map(overlay);
                        theMap.backdrop=b;
             theMap.updateSize(w,h);
                        theMap.addEventListener(MapEvent.SCALE, scaleHandler);
                        _root.addChild(theMap);
+                       _root.addChild(overlay);
 
                        // Initialise stylesheets
                        Stylesheets.instance().init();
                        conn.addEventListener(MapEvent.ERROR, onMapError);
                        conn.addEventListener(AttentionEvent.ATTENTION, onAttention);
                        conn.addEventListener(AttentionEvent.ALERT, onAlert);
-                       if (params['licence_status']) conn.statusFetcher=new StatusFetcher("http://wtfe.gryph.de/api/0.6/problems",conn);
                        theMap.addLayer(conn, Stylesheets.instance().selected.url, false, true);
 
             // Auto-load vector backgrounds from config
                        //           until the user has decided where to start editing (e.g. when the first GPX loads)
                        theMap.init(params['lat'], params['lon'], params['zoom']);
 
-                       // add attribution/logo sprite
-                       var overlay:Sprite=new Sprite();
-                       var attribution:TextField=new TextField();
-                       attribution.width=220; attribution.height=300;
-                       attribution.multiline=true;
-                       attribution.wordWrap=true;
-                       attribution.selectable=false;
-                       attribution.defaultTextFormat=new TextFormat("_sans", 9, 0, false, false, false);
-                       overlay.addChild(attribution);
-                       var terms:TextField=new TextField();
-                       terms.width=200; terms.height=15;
-                       terms.selectable=false;
-                       terms.defaultTextFormat=new TextFormat("_sans", 9, 0, false, false, true);
-                       overlay.addChild(terms);
-                       _root.addChild(overlay);
-
                        // mouse-up handler attached to stage, so the user can release outside the map
                        stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
                        Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
                        theMap.tileset.blocks=[/google\./i];    // hard-coded block on Google tiles
                        theMap.tileset.setDimming(params['background_dim']    ==null ? true  : params['background_dim']);
                        theMap.tileset.setSharpen(params['background_sharpen']==null ? false : params['background_sharpen']);
-                       Imagery.instance().init(theMap, overlay);
-                       Imagery.instance().addEventListener(MapEvent.BUMP, bumpHandler);
-                       Imagery.instance().addEventListener(CollectionEvent.SELECT,
-                               function(e:CollectionEvent):void { theMap.tileset.init(e.data, e.data!=''); }
+                       var imagery:Imagery = Imagery.instance();
+                       imagery.init();
+                       theMap.tileset.init(imagery.selected, imagery.selected != '');
+                       imagery.addEventListener(MapEvent.BUMP, bumpHandler);
+                       imagery.addEventListener(CollectionEvent.SELECT,
+                               function(e:CollectionEvent):void { 
+                                       theMap.tileset.setBackgroundFromImagery(e.data,false);
+                               }
                        );
+                       imagery.addEventListener('imageryLoaded',function(e:Event):void {
+                               // Tell the function key manager that we'd like to receive function key calls
+                               FunctionKeyManager.instance().registerListener('Background imagery',
+                                       function(o:String):void { theMap.tileset.setBackgroundFromImagery(imagery.findBackgroundWithName(o),true); });
+                               dispatchEvent(new Event("collection_changed"));
+                       });
+                       imagery.addEventListener('refreshAttribution',function(e:Event):void {
+                               theMap.tileset.setLogo(); theMap.tileset.setAttribution(); theMap.tileset.setTerms(); 
+                       });
                        
                        // keyboard event attached to stage
                        stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
                        // position toolbox
                        toolbox=Toolbox(PopUpManager.createPopUp(this,Toolbox,false));
                        toolbox.init(theController);
-                       toolbox.x=stage.stageWidth-toolbox.width-5;
-                       toolbox.y=stage.stageHeight-toolbox.height-5;
-
-                       // add debug field
-                       var t:TextField=new TextField();
-                       t.width=500; t.height=150; t.border=true;
-                       t.multiline=true;
-                       _root.addChild(t);
-                       Globals.vars.debug=t;
-            t.visible = loaderInfo.parameters["show_debug"] == 'true';
-                       Globals.vars.root=theMap;       // just for the addDebug function
+                       toolbox.x=suggestToolboxX();
+                       toolbox.y=suggestToolboxY();
+                       Globals.vars.root=theMap;
 
                        // create controller
             theController = new EditController(theMap, tagViewer, toolbox);
             theController.setActive();
                        theController.addEventListener(AttentionEvent.ATTENTION, onAttention);
                        theController.addEventListener(AttentionEvent.ALERT, onAlert);
-            
+                       theController.addEventListener(EditController.CHANGED_STATE, onStateChanged);
+
+                       // add floating map
+                       floatingMap=FloatingMap(PopUpManager.createPopUp(this,FloatingMap,false));
+                       floatingMap.visible=false;
+                       floatingMap.init(theController);
+                       floatingMap.x=stage.stageWidth-410;
+                       floatingMap.y=36;
+
             // set the access token from saved cookie
-            var tokenObject:SharedObject = SharedObject.getLocal("access_token");
+            var tokenObject:SharedObject = SharedObject.getLocal("access_token","/");
             conn.setAccessToken(tokenObject.data["oauth_token"], tokenObject.data["oauth_token_secret"]);
 
             // Load any requested GPX track
 
                 var connection:Connection = new Connection(name, gpx_url, null, null);
                 var gpx:GpxImporter=new GpxImporter(connection, theMap,
-                                                function(success:Boolean,message:String=null):void {
+                                                function(connection:Connection,options:Object,success:Boolean,message:String=null):void {
                                                     if (!success) return;
                                                     var paint:MapPaint = theMap.addLayer(connection, "stylesheets/gpx.css");
                                                     paint.updateEntityUIs(false, false);
                        stage.addChild(alert);
                }
 
+               /** ControllerState has changed, so update contextual help */
+               
+               public function onStateChanged(event:Event):void {
+                       var helpId:String = theController.state.contextualHelpId();
+                       contextHelp.selectedChild = contextHelp.hasOwnProperty("context"+helpId) ? contextHelp["context"+helpId] : contextHelp["contextNotFound"];
+               }
+
         public function onResizeMap():void {
-            if ( theMap != null )
-                theMap.updateSize(map_area.width, map_area.height);
+                       if (!theMap) return;
+                       theMap.updateSize(map_area.width, map_area.height);
 
                        if (toolbox) {
-                               toolbox.x=Math.min(toolbox.x,stage.stageWidth-toolbox.width-5);
-                               toolbox.y=Math.min(toolbox.y,stage.stageHeight-toolbox.height-5);
+                               toolbox.x=Math.min(toolbox.x,suggestToolboxX());
+                               toolbox.y=Math.min(toolbox.y,suggestToolboxY());
                        }
+
+                       if (!resizeTimer) {
+                               resizeTimer=new Timer(300);
+                               resizeTimer.addEventListener(TimerEvent.TIMER, resizeMapEnd, false, 0, true);
+                       }
+                       resizeTimer.reset();
+                       resizeTimer.start();
         }
+               private function resizeMapEnd(e:Event):void {
+                       resizeTimer.stop();
+                       theMap.download();
+               }
                private function bumpHandler(e:MapEvent):void {
-                       if (toolbox) {
-                               toolbox.y=Math.min(toolbox.y,stage.stageHeight-toolbox.height-10-e.params.y);
+                       if (toolbox) { 
+                               toolbox.y=Math.min(toolbox.y,suggestToolboxY(e.params.y+5));
                        }
                }
+               private function suggestToolboxX():int {
+                       var rhCP:Point=rhContent.localToGlobal(new Point(0,0));
+                       return rhCP.x + theMap.scrollRect.width - toolbox.width - 5;
+               }
+               private function suggestToolboxY(yOffset:int=0):int {
+                       var rhCP:Point=rhContent.localToGlobal(new Point(0,0)); // stage co-ordinates of right-hand content area
+                       return rhCP.y + theMap.scrollRect.height - toolbox.height - 5 - yOffset;
+               }
+               public function suggestTasksPaletteX():int {
+                       var rhCP:Point=rhContent.localToGlobal(new Point(0,0));
+                       return rhCP.x + 5;
+               }
+               public function suggestTasksPaletteY():int {
+                       var rhCP:Point=rhContent.localToGlobal(new Point(0,0));
+                       return rhCP.y + theMap.scrollRect.height - 55;
+               }
+
+               private function disableMapMouse():void {
+                       map_area.mouseChildren=false;
+                       map_area.mouseEnabled=false;
+               }
+
+               private function enableMapMouse():void {
+                       mouseTimer=new Timer(300);
+                       mouseTimer.addEventListener(TimerEvent.TIMER, doEnable, false, 0, true);
+                       mouseTimer.start();
+               }
+               
+               private function doEnable(event:Event):void {
+                       map_area.mouseChildren=true;
+                       map_area.mouseEnabled=true;
+                       mouseTimer.removeEventListener(TimerEvent.TIMER, doEnable);
+                       mouseTimer=null;
+               }
 
         private function mouseoverHandler(e:MapEvent):void {
             if (coordsbox.visible) {