Assign relations to function keys
authorRichard Fairhurst <richard@systemeD.net>
Fri, 21 Jun 2019 09:01:44 +0000 (10:01 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Fri, 21 Jun 2019 09:01:44 +0000 (10:01 +0100)
net/systemeD/potlatch2/EditController.as
net/systemeD/potlatch2/FunctionKeyManager.as
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/controller/ControllerState.as

index 04b46fc..16540c9 100644 (file)
@@ -76,6 +76,8 @@ package net.systemeD.potlatch2 {
 
             FunctionKeyManager.instance().registerListener('Saved tags',
                 function(o:String):void { state.recallTags(o); });
+            FunctionKeyManager.instance().registerListener('Add to relation',
+                function(o:String):void { state.recallRelation(o); });
 
             if (this.moveFunction) {
                 var lon:Number = ( map.edge_r + map.edge_l ) / 2;
index 511f5c6..f3ab215 100644 (file)
@@ -44,7 +44,7 @@ package net.systemeD.potlatch2 {
                        keys[fkey]={ code:code, value:value };
                        var obj:SharedObject=SharedObject.getLocal("user_state","/");
                        obj.setProperty('F'+fkey,{ code:code, value:value });
-                       try { obj.flush(); } catch (e:Error) {}
+                       try { obj.flush(); } catch (e:Error) { trace("Error: "+e.toString()); }
                        dispatchEvent(new Event("key_changed"));
                }
 
index 928fc99..188aeed 100644 (file)
@@ -78,6 +78,7 @@
                                                </fx:Component>
                                        </mx:itemRenderer>
                                </mx:DataGridColumn>
+                               <mx:DataGridColumn minWidth="4" /><!-- Dummy column forces Flex to render previous one at proper width -->
             </mx:columns>
         </mx:DataGrid>
 
       }
 
       private function relationRoleChanged(event:DataGridEvent):void {
+               if (!selectedEntity) return;
                if (event.dataField != 'role') { return; }      // shouldn't really happen
 
                var relations:Array=event.currentTarget.dataProvider.toArray();
       }
 
       private function relationTagChanged(event:TagEvent):void {
+          if (!selectedEntity) return;
           resetRelationsGrid(selectedEntity);
           refreshFeatureIcon();
       }
 
       private function entityRelationMemberChanged(event:RelationMemberEvent):void {
+          if (!selectedEntity) return;
           resetRelationsGrid(selectedEntity);
       }
 
                var dp:Object = [ {label: "Select all members"}, 
                                                  {label: "Deselect all members"}, 
                                                  {label: "Add selection to this relation", enabled: false},
-                                                 {label: "Delete relation"} ]; 
+                                                 {label: "Delete relation"},
+                                                 {label: "Assign to F1"},
+                                                 {label: "Assign to F2"},
+                                                 {label: "Assign to F3"},
+                                                 {label: "Assign to F4"} ]; 
                menu.dataProvider = dp; 
                menu.addEventListener("itemClick", selectRelationMenu); 
                button.popUp = menu;
                                                rel.remove(MainUndoStack.getGlobalStack().addAction);
                                        } , null, Alert.CANCEL);
                                break;
+                               
+                       case 4: // Function key assignment
+                       case 5:
+                       case 6:
+                       case 7:
+                               FunctionKeyManager.instance().setKey(event.index-3, 'Add to relation',String(rel.id));
+                               break;
                }
        }
 
index f68869f..1cd8c63 100644 (file)
@@ -307,6 +307,25 @@ package net.systemeD.potlatch2.controller {
                        for each (item in _selection) item.resume();
                }
 
+               /** Recall memorised relation by ID. */
+               public function recallRelation(str:String):void {
+                       if (selectCount==0) return;
+                       var rel:Relation = controller.map.editableLayer.connection.getRelation(Number(str));
+                       if (!rel) {
+                               controller.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "That relation hasn't been loaded"));
+                               return;
+                       }
+                       var undo:CompositeUndoableAction = new CompositeUndoableAction("Recall relation");
+                       for each (var item:Entity in _selection) {
+                               item.suspend();
+                               rel.appendMember(new RelationMember(item, ''), undo.push);
+                       }
+                       MainUndoStack.getGlobalStack().addAction(undo);
+                       controller.updateSelectionUI();
+                       for each (item in _selection) item.resume();
+                       controller.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Added to relation"));
+               }
+
         /** Show the history dialog, if only one object is selected. */
         protected function showHistory():void {
             if (selectCount == 1 && firstSelected.id>0) {