better Save button detection
authorRichard Fairhurst <richard@systemed.net>
Mon, 14 Jun 2010 16:28:56 +0000 (16:28 +0000)
committerRichard Fairhurst <richard@systemed.net>
Mon, 14 Jun 2010 16:28:56 +0000 (16:28 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/MainUndoStack.as
net/systemeD/halcyon/connection/UndoableEntityAction.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/halcyon/connection/actions/MoveNodeAction.as
potlatch2.mxml

index 09f18f9..13a9914 100755 (executable)
@@ -57,6 +57,8 @@ package net.systemeD.halcyon.connection {
         public static var LOAD_COMPLETED:String = "load_completed";
         public static var SAVE_STARTED:String = "save_started";
         public static var SAVE_COMPLETED:String = "save_completed";
+        public static var DATA_DIRTY:String = "data_dirty";
+        public static var DATA_CLEAN:String = "data_clean";
         public static var NEW_CHANGESET:String = "new_changeset";
         public static var NEW_CHANGESET_ERROR:String = "new_changeset_error";
         public static var NEW_NODE:String = "new_node";
@@ -89,6 +91,7 @@ package net.systemeD.halcyon.connection {
         private var relations:Object = {};
         private var pois:Array = [];
         private var changeset:Changeset = null;
+               private var modified:Boolean = false;
                public var nodecount:int=0;
                public var waycount:int=0;
                public var relationcount:int=0;
@@ -228,18 +231,21 @@ package net.systemeD.halcyon.connection {
         public function createNode(tags:Object, lat:Number, lon:Number, performCreate:Function):Node {
             var node:Node = new Node(nextNegative, 0, tags, true, lat, lon);
             performCreate(new CreateEntityAction(node, setNode));
+                       markDirty();
             return node;
         }
 
         public function createWay(tags:Object, nodes:Array, performCreate:Function):Way {
             var way:Way = new Way(nextNegative, 0, tags, true, nodes.concat());
             performCreate(new CreateEntityAction(way, setWay));
+                       markDirty();
             return way;
         }
 
         public function createRelation(tags:Object, members:Array, performCreate:Function):Relation {
             var relation:Relation = new Relation(nextNegative, 0, tags, true, members.concat());
             performCreate(new CreateEntityAction(relation, setRelation));
+                       markDirty();
             return relation;
         }
 
@@ -305,6 +311,18 @@ package net.systemeD.halcyon.connection {
                        // ** should purge POIs and relations too
                }
 
+               public function markDirty():void {
+            if (!modified) { dispatchEvent(new Event(DATA_DIRTY)); }
+                       modified=true;
+               }
+               public function markClean():void {
+            if (modified) { dispatchEvent(new Event(DATA_CLEAN)); }
+                       modified=false;
+               }
+               public function get isDirty():Boolean {
+                       return modified;
+               }
+
         // these are functions that the Connection implementation is expected to
         // provide. This class has some generic helpers for the implementation.
                public function loadBbox(left:Number, right:Number,
index 4e7fdb7..b302b21 100644 (file)
@@ -36,8 +36,11 @@ package net.systemeD.halcyon.connection {
                 if ( undoActions.length > 0 ) {
                     var previous:UndoableAction = undoActions[undoActions.length - 1];
                     var isMerged:Boolean = action.mergePrevious(previous);
-                    if ( isMerged )
+                    if ( isMerged ) {
+                                               UndoableEntityAction(action).wasDirty = UndoableEntityAction(previous).wasDirty;
+                                               UndoableEntityAction(action).connectionWasDirty = UndoableEntityAction(previous).connectionWasDirty;
                         undoActions.pop();
+                                       }
                 }
                 undoActions.push(action);
                 redoActions = [];
index 0dc9cfc..2f5d1f9 100644 (file)
@@ -1,7 +1,8 @@
 package net.systemeD.halcyon.connection {
 
     public class UndoableEntityAction extends UndoableAction {
-        private var wasDirty:Boolean;
+        public var wasDirty:Boolean;
+               public var connectionWasDirty:Boolean;
         protected var name:String;
         protected var entity:Entity;
             
@@ -11,14 +12,23 @@ package net.systemeD.halcyon.connection {
         }
             
         protected function markDirty():void {
+                       var conn:Connection = Connection.getConnectionInstance();
             wasDirty = entity.isDirty;
+                       connectionWasDirty = conn.isDirty;
+
             if ( !wasDirty )
                 entity.markDirty();
+
+            if ( !connectionWasDirty )
+                conn.markDirty();
         }
             
         protected function markClean():void {
             if ( !wasDirty )
                 entity.markClean(entity.id, entity.version);
+
+            if ( !connectionWasDirty )
+                Connection.getConnectionInstance().markClean();
         }
             
         public function toString():String {
index 0da9561..95fcb7d 100644 (file)
@@ -178,6 +178,7 @@ package net.systemeD.halcyon.connection {
             }
 
                dispatchEvent(new SaveCompleteEvent(SAVE_COMPLETED, true));
+               dispatchEvent(new Event(DATA_CLEAN, true));
         }
 
         private function diffUploadError(event:IOErrorEvent):void {
index 63768d1..f918d78 100644 (file)
@@ -36,7 +36,7 @@ package net.systemeD.halcyon.connection.actions {
             
         public override function undoAction():uint {
             setLatLon(oldLat, oldLon);
-            markDirty();
+            markClean();
             entity.dispatchEvent(new NodeMovedEvent(Connection.NODE_MOVED, Node(entity), newLat, newLon));
             return SUCCESS;
         }
index f878b7c..9aa18c6 100755 (executable)
@@ -35,8 +35,8 @@
         <mx:Spacer width="100%"/>
         <mx:Button label="Help" click="new HelpDialog().init();" />
         <mx:Button label="Options" click="new OptionsDialog().init();" /> 
-        <mx:Button label="Save" icon="@Embed('embedded/save.svg')" click="SaveManager.saveChanges();"
-                       enabled="{MainUndoStack.getGlobalStack().canUndo()}"/>
+        <mx:Button label="Save" icon="@Embed('embedded/save.svg')" click="SaveManager.saveChanges();" id="saveButton" 
+                       enabled="false"/>
     </mx:ApplicationControlBar>
     
     <mx:HDividedBox width="100%" height="100%">
             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
             conn.addEventListener(Connection.SAVE_STARTED, onDataStart);
             conn.addEventListener(Connection.SAVE_COMPLETED, onDataComplete);
+            conn.addEventListener(Connection.DATA_DIRTY, onDataDirty);
+            conn.addEventListener(Connection.DATA_CLEAN, onDataClean);
                }
                
         public function onResizeMap():void {
                        else                            { dataWorking.text=""; }
                        dataWorking.visible=(dataWorking.text!="");
                }
-        
+        private function onDataDirty(event:Event):void {
+                       saveButton.enabled=true;
+               }
+               private function onDataClean(event:Event):void {
+                       saveButton.enabled=false;
+               }
+               
         private function onImageryLoad(event:Event):void {
                        var xml:XML = new XML(URLLoader(event.target).data);
             theController.imagery=new Array(