Remove previous bugfix for tab selection - no longer needed with Flex 4.5 as Adobe...
[potlatch2.git] / potlatch2.mxml
index d439af3..09c9861 100644 (file)
@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
-<mx:Application 
-       xmlns:mx="http://www.adobe.com/2006/mxml" 
+<mx:Application
+    xmlns:fx="http://ns.adobe.com/mxml/2009"
+       xmlns:mx="library://ns.adobe.com/flex/mx"
+    xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:halcyon="net.systemeD.halcyon.*"
        xmlns:potlatch2="net.systemeD.potlatch2.*"
        layout="vertical"
        addedToStage="startInit()"
        preloader="net.systemeD.potlatch2.Preloader">
 
-    <map:LocalizationMap xmlns:map="l10n.map.*" />
 
-       <mx:Style source="styles/Application.css"/>
 
-    <mx:Glow id="glowImage" duration="100" 
-        alphaFrom="0.3" alphaTo="1.0" 
-        blurXFrom="0.0" blurXTo="5.0" 
-        blurYFrom="0.0" blurYTo="5.0" 
-        color="0xFF8000"/>
-    <mx:Glow id="unglowImage" duration="100" 
-        alphaFrom="1.0" alphaTo="0.3" 
-        blurXFrom="5.0" blurXTo="0.0" 
-        blurYFrom="5.0" blurYTo="0.0" 
-        color="0xFF8000"/>
-    <mx:WipeLeft id="wipeOut" duration="250"/>
-    <mx:WipeRight id="wipeIn" duration="250"/>
+       <fx:Style source="styles/Application.css"/>
+
+    <fx:Declarations>
+        <map:LocalizationMap xmlns:map="l10n.map.*" />
+        <mx:Glow id="glowImage" duration="100"
+            alphaFrom="0.3" alphaTo="1.0"
+            blurXFrom="0.0" blurXTo="5.0"
+            blurYFrom="0.0" blurYTo="5.0"
+            color="0xFF8000"/>
+        <mx:Glow id="unglowImage" duration="100"
+            alphaFrom="1.0" alphaTo="0.3"
+            blurXFrom="5.0" blurXTo="0.0"
+            blurYFrom="5.0" blurYTo="0.0"
+            color="0xFF8000"/>
+        <mx:WipeLeft id="wipeOut" duration="250"/>
+        <mx:WipeRight id="wipeIn" duration="250"/>
+    </fx:Declarations>
 
     <mx:ApplicationControlBar dock="true">
         <mx:PopUpButton id="bgButton" label="Background" openAlways="true" styleName="appBarButton"
                                                     mx.controls.Menu(gpsButton.popUp).selectedIndex=0; /* Yes, we do need to call it twice */
                                                     theMap.removeLayerByName('GPS tracks'); }">
                        <mx:dataProvider>
-                               <mx:Array>
-                                       <mx:Object label="GPS data" id="gpsData" />
-                                       <mx:Object label="My tracks" id="myTracks" />
-                                       <mx:Object label="Clear" id="clearGps" />
-                               </mx:Array>
+                               <fx:Array>
+                                       <fx:Object label="GPS data" id="gpsData" />
+                                       <fx:Object label="My tracks" id="myTracks" />
+                                       <fx:Object label="Clear" id="clearGps" />
+                               </fx:Array>
                        </mx:dataProvider>
                </mx:PopUpMenuButton>
         <mx:Spacer width="100%"/>
@@ -51,7 +56,8 @@
             enabled="{MainUndoStack.getGlobalStack().canUndo()}"
             toolTip="{MainUndoStack.getGlobalStack().getUndoDescription() ? 'Undo '+MainUndoStack.getGlobalStack().getUndoDescription() : 'Undo last action'}" />
         <mx:Button id="redo" label="Redo" click="MainUndoStack.getGlobalStack().redo();" styleName="appBarButton"
-            enabled="{MainUndoStack.getGlobalStack().canRedo()}"/>
+            enabled="{MainUndoStack.getGlobalStack().canRedo()}"
+            toolTip="{MainUndoStack.getGlobalStack().getRedoDescription() ? 'Redo '+MainUndoStack.getGlobalStack().getRedoDescription() : 'Redo last action'}" />
         <mx:Spacer width="100%"/>
         <mx:Button id="helpButton" label="Help" click="new HelpDialog().init();" styleName="appBarButton" />
         <mx:Button id="optionsButton" label="Options" click="new OptionsDialog().init();" styleName="appBarButton" />
@@ -84,7 +90,7 @@
 
     </mx:HDividedBox>
 
-       <mx:Script><![CDATA[
+       <fx:Script><![CDATA[
                import net.systemeD.halcyon.*;
                import net.systemeD.halcyon.connection.*;
                import net.systemeD.potlatch2.*;
                import mx.managers.PopUpManager;
                import flash.system.Security;
                import flash.net.*;
+               import flash.utils.Timer;
+               import flash.events.TimerEvent;
                import flash.events.MouseEvent;
                import flash.display.Sprite;
                import mx.core.IChildList;
         import mx.containers.Canvas;
                import mx.core.Application;
+               import mx.core.FlexGlobals;
         import mx.events.DragEvent;
         import mx.events.CloseEvent;
         import mx.managers.DragManager;
 
                private var savecount:uint=0;
                private var loadcount:uint=0;
+               private var saveLabel:String='Save';
+               private var saveTimer:Timer;
 
         include "version.as";
 
                        Globals.vars.nocache = loaderInfo.parameters['nocache'] == 'true';
                        Globals.vars.flashvars = loaderInfo.parameters;
 
+                       // Remember localised Save text, because we change this dynamically
+                       saveLabel=saveButton.label;
+
                        // populate sharedObject with loaderInfo parameters if supplied
                        var obj:SharedObject = SharedObject.getLocal("user_state");
                        var objChanged:Boolean = false;
                        _root.addChild(yahoo);
                        _root.addChild(theMap);
 
-                       // Initialise 900913 background
-                       // >>>> REFACTOR: something odd about accessing map.tileparams here...
-                       theMap.tileset.blocks=[new RegExp("google","i")];       // hard-coded block on Google tiles
-                       theMap.tileset.init(theMap.tileparams, false, 
-                                           params['background_dim']    ==null ? true  : params['background_dim'],
-                                           params['background_sharpen']==null ? false : params['background_sharpen']);
+                       // Initialise stylesheets
+                       Stylesheets.instance().init();
+                       Stylesheets.instance().addEventListener(CollectionEvent.SELECT,
+                               function(e:CollectionEvent):void { theMap.editableLayer.setStyle(String(e.data)); }
+                       );
 
                        // Add core data layer
-                       // >>>> REFACTOR: shouldn't be hardcoded to XMLConnection
                        var conn:Connection = new XMLConnection("Main", params['api'], params['policy'], params);
             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
                        conn.addEventListener(MapEvent.ERROR, onMapError);
                        conn.addEventListener(AttentionEvent.ATTENTION, onAttention);
                        conn.addEventListener(AttentionEvent.ALERT, onAlert);
-                       // >>>> REFACTOR: shouldn't be trying to find out stylesheet from here
-                       theMap.addLayer(conn,params['styleurl'] ? params['styleurl'] : 'stylesheets/potlatch.css',false);
+                       theMap.addLayer(conn, Stylesheets.instance().selected, false, true);
 
             // Auto-load vector backgrounds from config
             theMap.addEventListener(MapEvent.INITIALISED, function(e:Event):void { VectorBackgrounds.instance().init(theMap); });
 
                        // Set start position of map
-                       // >>>> REFACTOR: what happens if lat/lon/zoom not supplied? (Hurleston GPX case)
+                       // ** FIXME: if lat/lon/zoom aren't supplied, we need to keep the map in a non-loading state 
+                       //           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
                        Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
                        Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
 
-                       // initialise imagery and stylesheets
+                       // initialise imagery
+                       theMap.tileset.blocks=[new RegExp("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, yahoo);
-                       Stylesheets.instance().init(theMap);
                        Imagery.instance().addEventListener(MapEvent.BUMP, bumpHandler);
+                       Imagery.instance().addEventListener(CollectionEvent.SELECT,
+                               function(e:CollectionEvent):void { theMap.tileset.init(e.data, e.data!=''); }
+                       );
 
                        // keyboard event attached to stage
                        stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
             t.visible = loaderInfo.parameters["show_debug"] == 'true';
                        Globals.vars.root=theMap;       // just for the addDebug function
 
+                       // create controller
             theController = new EditController(theMap, tagViewer, toolbox);
             theController.setActive();
+                       theController.addEventListener(AttentionEvent.ATTENTION, onAttention);
+                       theController.addEventListener(AttentionEvent.ALERT, onAlert);
             
             // set the access token from saved cookie
             var tokenObject:SharedObject = SharedObject.getLocal("access_token");
                        if (entity is Relation) {
                                // If it's a relation, just bring up the editor panel
                                var panel:RelationEditorPanel = RelationEditorPanel(
-                                       PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
+                                       PopUpManager.createPopUp(Application(FlexGlobals.topLevelApplication), RelationEditorPanel, true));
                                panel.setRelation(entity as Relation);
                                PopUpManager.centerPopUp(panel);
                                return;
             if (ExternalInterface.available) {
               ExternalInterface.call("markChanged", false);
             }
+                       if (!saveTimer || !saveTimer.running) {
+                               saveTimer=new Timer(60*1000,0);
+                               saveTimer.addEventListener(TimerEvent.TIMER,saveTimeUpdate);
+                               saveTimer.start();
+                       }
                }
                private function onDataClean(event:Event):void {
                        saveButton.enabled=false;
             if (ExternalInterface.available) {
               ExternalInterface.call("markChanged", true);
             }
+            if (saveTimer && saveTimer.running) {
+                               saveTimer.stop();
+                               saveTimer.removeEventListener(TimerEvent.TIMER,saveTimeUpdate);
+                               saveTimeWrite(0);
+                       }
+               }
+               private function saveTimeUpdate(event:TimerEvent):void {
+                       var timer:Timer=Timer(event.target);
+                       saveTimeWrite(uint(timer.delay*timer.currentCount/1000/60));
+               }
+               private function saveTimeWrite(minutes:uint):void {
+                       if (minutes<5) {
+                               saveButton.label=saveLabel;
+                       } else {
+                               saveButton.label=saveLabel+" ("+minutes+"m"+")"; 
+                               if (minutes>=20 && minutes/5==int(minutes/5)) {
+                                       theController.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, minutes+"m since last save - please save regularly"));
+                               }
+                       }
                }
-               
-
 
                private function scaleHandler(event:MapEvent):void {
                        dispatchEvent(new Event("rescale"));
             conn.fetchUserTraces();
         }
 
-       ]]></mx:Script>
+       ]]></fx:Script>
 
 </mx:Application>