Memorise tag combinations
authorRichard Fairhurst <richard@systemeD.net>
Tue, 14 Oct 2014 09:32:57 +0000 (10:32 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Tue, 14 Oct 2014 09:32:57 +0000 (10:32 +0100)
(have been meaning to do this for ages...)

net/systemeD/halcyon/connection/TagList.as
net/systemeD/potlatch2/EditController.as
net/systemeD/potlatch2/FunctionKeyManager.as
net/systemeD/potlatch2/controller/ControllerState.as

index 1e5f34f..79b8b2e 100644 (file)
@@ -29,6 +29,13 @@ package net.systemeD.halcyon.connection {
                 arr.push(getTagKey(i) + "=" + getTagValue(i));
             return arr.join('; ');
         }
-    }
 
+               public static function fromString(str:String):Object {
+                       var kv:Object={};
+                       var arr:Array=str.split('; ');
+                       for (var i:uint = 0; i < arr.length; i++)
+                               kv[arr[i].split('=')[0]] = arr[i].split('=')[1];
+                       return kv;
+               }
+    }
 }
index fea0f1c..cc46dfa 100644 (file)
@@ -72,6 +72,9 @@ package net.systemeD.potlatch2 {
             map.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
             map.stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
 
+            FunctionKeyManager.instance().registerListener('Saved tags',
+                function(o:String):void { state.recallTags(o); });
+
             if (this.moveFunction) {
                 var lon:Number = ( map.edge_r + map.edge_l ) / 2;
                 var lat:Number = ( map.edge_b + map.edge_t ) / 2;
@@ -130,7 +133,7 @@ package net.systemeD.potlatch2 {
                        if (keys[event.keyCode] && new Date().getTime()-keys[event.keyCode]<300) return;
                        delete keys[event.keyCode];
 
-                       if (FunctionKeyManager.instance().handleKeypress(event.keyCode)) { return; }
+                       if (!event.shiftKey && FunctionKeyManager.instance().handleKeypress(event.keyCode)) { return; }
             
             if (event.keyCode == 77) { toggleSize(); } // 'M'
             var newState:ControllerState = state.processKeyboardEvent(event);
index 494ce61..511f5c6 100644 (file)
@@ -80,6 +80,5 @@ package net.systemeD.potlatch2 {
                        listeners[keys[fkey].code](keys[fkey].value);
                        return true;
                }
-               
        }
 }
index d6aa0c2..fa73da2 100644 (file)
@@ -7,6 +7,7 @@ package net.systemeD.potlatch2.controller {
     import net.systemeD.halcyon.AttentionEvent;
     import net.systemeD.potlatch2.collections.Imagery;
     import net.systemeD.potlatch2.EditController;
+    import net.systemeD.potlatch2.FunctionKeyManager;
     import net.systemeD.potlatch2.history.HistoryDialog;
        import net.systemeD.potlatch2.save.SaveManager;
        import net.systemeD.potlatch2.utils.SnapshotConnection;
@@ -77,6 +78,7 @@ package net.systemeD.potlatch2.controller {
                /** Default behaviour for the current state that should be called if state-specific action has been taken care of or ruled out. */
                protected function sharedKeyboardEvents(event:KeyboardEvent):ControllerState {
                        var editableLayer:MapPaint=controller.map.editableLayer;                                                                // shorthand for this method
+                       if (event.keyCode>=112 && event.keyCode<=126 && event.shiftKey) { memoriseTags(event.keyCode); return null; }
                        switch (event.keyCode) {
                                case 48:        removeTags(); break;                                                                                                    // 0 - remove all tags
                                case 66:        setSourceTag(); break;                                                                                                  // B - set source tag for current object
@@ -251,6 +253,29 @@ package net.systemeD.potlatch2.controller {
                        controller.updateSelectionUI();
                        for each (item in _selection) item.resume();
                }
+               
+               /** Memorise tags. 
+                       Should ideally do relations too. */
+               protected function memoriseTags(keycode:uint):void {
+                       if (selectCount!=1) return;
+                       var str:String=firstSelected.getTagList().toString();
+                       FunctionKeyManager.instance().setKey(keycode-111,'Saved tags',str);
+                       controller.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Tags memorised on F"+(keycode-111)));
+               }
+               
+               /** Recall memorised tags. */
+               public function recallTags(str:String):void {
+                       if (selectCount==0) return;
+                       var kv:Object=TagList.fromString(str);
+                   var undo:CompositeUndoableAction = new CompositeUndoableAction("Recall tags");
+                       for each (var item:Entity in _selection) {
+                               item.suspend();
+                               for (var k:String in kv) item.setTag(k, kv[k], undo.push)
+                       }
+                       MainUndoStack.getGlobalStack().addAction(undo);
+                       controller.updateSelectionUI();
+                       for each (item in _selection) item.resume();
+               }
 
         /** Show the history dialog, if only one object is selected. */
         protected function showHistory():void {