Remove previous bugfix for tab selection - no longer needed with Flex 4.5 as Adobe...
[potlatch2.git] / potlatch2.mxml
index 4754b11..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%"/>
@@ -85,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;
                        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>