Fix formatting, and restore Relation method
authorRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 18:40:01 +0000 (19:40 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 18:40:01 +0000 (19:40 +0100)
(a method for this already exists)

net/systemeD/halcyon/connection/Relation.as
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/SelectedPOINode.as

index aa94d7d..0842cac 100644 (file)
@@ -83,11 +83,10 @@ package net.systemeD.halcyon.connection {
                        return a;
                }
 
-               /** Is there an entity member in this specific role. (role=null for any role) */
-               public function hasMemberInRole(entity:Entity,role:String=null):Boolean {
+               /** Is there an entity member in this specific role? */
+               public function hasMemberInRole(entity:Entity,role:String):Boolean {
             for (var index:uint = 0; index < members.length; index++) {
-                               if (members[index].entity == entity &&
-                                   (members[index].role==role || role == null)) { return true; }
+                               if (members[index].entity == entity && members[index].role==role) { return true; }
                        }
                        return false;
                }
index d8e7d31..3aea911 100644 (file)
@@ -201,47 +201,42 @@ package net.systemeD.potlatch2.controller {
                                object.setTag(k, controller.clipboards[object.getType()][k], undo.push)
                        }
                        MainUndoStack.getGlobalStack().addAction(undo);
-            controller.updateSelectionUI();
+                       controller.updateSelectionUI();
                        object.resume();
                }
 
-        /** Create a "repeat relations" action on the current entity, if possible. */
-        protected function repeatRelations(object:Entity):void {
-            if (!controller.relationClipboards[object.getType()]) { return; }
-            object.suspend();
-
-            var undo:CompositeUndoableAction = new CompositeUndoableAction("Repeat relations");
-            var relationsadded: int;
-            for each (var rr:Object in controller.relationClipboards[object.getType()]) {
-                if (!rr.relation.hasMemberInRole(object, null)) {
-                       rr.relation.appendMember(new RelationMember(object, rr.role), undo.push);
-                       relationsadded ++;
-                       
-                }
-            }
-            MainUndoStack.getGlobalStack().addAction(undo);
-            controller.updateSelectionUI();
-            object.resume();
-            if (relationsadded > 0) {
-                   var msg:String=relationsadded.toString() + " relation(s) added to " + object.getType() + ".";
-                   controller.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg));
-               }
-        }
-        
-        /** Copy list of relations from current object, for future repeatRelation() call. */
-        protected function copyRelations(object: Entity):void {
-               // Leave existing relations alone if it doesn't have any
-               if (object.parentRelations.length == 0)
-                  return;
-               controller.relationClipboards[object.getType()]=[];
-               for each (var rm:Object in object.getRelationMemberships() ) {
-                       var rr:Object={
-                         relation: rm.relation,
-                         role: rm.role
-                       };
-                       controller.relationClipboards[object.getType()].push(rr);
-            }
-        }
+               /** Create a "repeat relations" action on the current entity, if possible. */
+               protected function repeatRelations(object:Entity):void {
+                       if (!controller.relationClipboards[object.getType()]) { return; }
+                       object.suspend();
+
+                       var undo:CompositeUndoableAction = new CompositeUndoableAction("Repeat relations");
+                       var relationsadded:uint;
+                       for each (var rr:Object in controller.relationClipboards[object.getType()]) {
+                               if (!rr.relation.findEntityMemberIndex(object)>-1) {
+                                       rr.relation.appendMember(new RelationMember(object, rr.role), undo.push);
+                                       relationsadded++;
+                               }
+                       }
+                       MainUndoStack.getGlobalStack().addAction(undo);
+                       controller.updateSelectionUI();
+                       object.resume();
+                       if (relationsadded > 0) {
+                               var msg:String=relationsadded.toString() + " relation(s) added to " + object.getType() + ".";
+                               controller.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg));
+                       }
+               }
+
+               /** Copy list of relations from current object, for future repeatRelation() call. */
+               protected function copyRelations(object: Entity):void {
+                       // Leave existing relations alone if it doesn't have any
+                       if (object.parentRelations.length == 0) return;
+                       controller.relationClipboards[object.getType()]=[];
+                       for each (var rm:Object in object.getRelationMemberships() ) {
+                               var rr:Object = { relation: rm.relation, role: rm.role };
+                               controller.relationClipboards[object.getType()].push(rr);
+                       }
+               }
                
                /** Remove all tags from current selection. */
                protected function removeTags():void {
index 51b1d94..07c1058 100644 (file)
@@ -178,9 +178,9 @@ package net.systemeD.potlatch2.controller {
                                case Keyboard.BACKSPACE:        
                                case 189: /* minus */       return backspaceNode(MainUndoStack.getGlobalStack().addAction);
                                case 79: /* O */                        return replaceNode();
-                case 82:  /* R */           { if (! event.shiftKey) repeatTags(firstSelected); 
-                                              else                  repeatRelations(firstSelected);
-                                              return this; }
+                               case 82: /* R */                        if (!event.shiftKey) { repeatTags(firstSelected); }
+                                                                                       else { repeatRelations(firstSelected); }
+                                                                                       return this;
                                case 70: /* F */            followWay(); return this;
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
index 46d0b75..d67dc8a 100644 (file)
@@ -52,9 +52,9 @@ package net.systemeD.potlatch2.controller {
                        switch (event.keyCode) {
                                case Keyboard.BACKSPACE:        return deletePOI();
                                case Keyboard.DELETE:           return deletePOI();
-                case 82:  /* R */           { if (! event.shiftKey) repeatTags(firstSelected); 
-                                              else                  repeatRelations(firstSelected);
-                                              return this; }
+                               case 82: /* R */                        if (!event.shiftKey) { repeatTags(firstSelected); }
+                                                                                       else { repeatRelations(firstSelected); }
+                                                                                       return this;
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
                        return cs ? cs : this;