Merge pull request #79 from smsm1/improve_presets
authorRichard Fairhurst <richard@systemeD.net>
Fri, 5 Oct 2012 17:05:02 +0000 (10:05 -0700)
committerRichard Fairhurst <richard@systemeD.net>
Fri, 5 Oct 2012 17:05:02 +0000 (10:05 -0700)
Improve presets

net/systemeD/potlatch2/RelationSelectPanel.mxml
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/utils/KmlImporter.as

index 00b0bd1..6aeede8 100644 (file)
           //relationSelector.dataProvider = relationList;
           for each (var id:Number in relationList) {
             var relation:Relation = conn.getRelation(id);
-            titles.push({label:id + ": " + relation.getDescription(), relId:id});
+            titles.push({label:relation.getDescription(), relId:id});
           }
+          titles.sortOn('label');
+          titles.forEach(function(item:Object, index:int, arr:Array):void { arr[index].label=item.relId+": "+item.label; });
           relationSelector.dataProvider = titles;
         }
         
index 9ba9b14..31510af 100644 (file)
             itemDoubleClick="editRelation(relationsGrid.selectedItem.id)"
             doubleClick="if (event.target.parent==relationsGrid) { addToRelation(); }">
             <mx:columns>
-                <mx:DataGridColumn editable="false" dataField="description" headerText="Relation"/>
+                <mx:DataGridColumn editable="false" dataField="description" headerText="Relation" minWidth="100">
+                    <mx:itemRenderer>
+                        <fx:Component>
+                            <mx:Text x="4" y="0" width="100%" selectable="false" htmlText="{outerDocument.adaptHTMLDescription(data.description)}" height="20"/>
+                        </fx:Component>
+                    </mx:itemRenderer>
+                </mx:DataGridColumn>
                 <mx:DataGridColumn editable="false" dataField="id_idx" headerText="ID"/>
                 <mx:DataGridColumn editable="true" dataField="role" headerText="Role">
                     <mx:itemEditor><fx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></fx:Component></mx:itemEditor>
                 </mx:DataGridColumn>
-                               <mx:DataGridColumn width="20" editable="false">
+                               <mx:DataGridColumn width="40" minWidth="40" editable="false">
                                        <mx:itemRenderer>
                                                <fx:Component>
-                                   <mx:HBox horizontalAlign="center" verticalAlign="middle">
+                                                       <mx:HBox horizontalAlign="center" verticalAlign="middle" paddingLeft="4">
                                                                <mx:PopUpButton arrowButtonWidth="12" paddingLeft="0" paddingRight="0" width="12" height="12" 
                                                                                open="{outerDocument.updateRelationMenu(event);}" 
                                                                                creationComplete="{outerDocument.createRelationMenu(PopUpButton(event.target));}"/>
+                                                               <mx:Image source="@Embed('../../../embedded/delete_small.svg')"
+                                                                         click='event.stopPropagation();outerDocument.removeFromRelation(data.id, data.index);'
+                                                                         buttonMode="true" useHandCursor="true" width="12" height="12" />
                                                        </mx:HBox>
                                                </fx:Component>
                                        </mx:itemRenderer>
         itemDoubleClick="editRelation(multiRelationsGrid.selectedItem.id)"
         doubleClick="if (event.target.parent==multiRelationsGrid) { addToRelation(); }">
         <mx:columns>
-            <mx:DataGridColumn editable="false" dataField="description" headerText="Relation"/>
+            <mx:DataGridColumn editable="false" dataField="description" headerText="Relation">
+                <mx:itemRenderer>
+                    <fx:Component>
+                        <mx:Text x="4" y="0" width="100%" selectable="false" htmlText="{outerDocument.adaptHTMLDescription(data.description)}" height="20"/>
+                    </fx:Component>
+                </mx:itemRenderer>
+            </mx:DataGridColumn>
             <mx:DataGridColumn editable="false" dataField="id_idx" headerText="ID"/>
             <mx:DataGridColumn editable="true" dataField="role" headerText="Role">
                 <mx:itemEditor><fx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></fx:Component></mx:itemEditor>
             </mx:DataGridColumn>
-                       <mx:DataGridColumn width="20" editable="false">
+                       <mx:DataGridColumn width="40" minWidth="40" editable="false">
                                <mx:itemRenderer>
                                        <fx:Component>
                            <mx:HBox horizontalAlign="center" verticalAlign="middle">
                                                        <mx:PopUpButton arrowButtonWidth="12" paddingLeft="0" paddingRight="0" width="12" height="12" 
                                                                        open="{outerDocument.updateRelationMenu(event);}" 
                                                                        creationComplete="{outerDocument.createRelationMenu(PopUpButton(event.target));}"/>
+                                                       <mx:Image source="@Embed('../../../embedded/delete_small.svg')"
+                                                                 click='event.stopPropagation();outerDocument.removeFromRelation(data.id);'
+                                                                 buttonMode="true" useHandCursor="true" width="12" height="12" />
                                                </mx:HBox>
                                        </fx:Component>
                                </mx:itemRenderer>
               navigateToURL(new URLRequest(feature.helpURL), "potlatch_help");
       }
 
+      /** Slightly poshify the description by making it HTML. 
+          In theory we could have embedded images here, but htmlText is completely broken. **/
+      public function adaptHTMLDescription(text:String):String {
+          text=text.replace(/^route (\w+) /,"<b>$1</b> ");
+          text=text.replace(/ncn (\d+)/,"<font color='#FF0000'>$1</font>");
+          text=text.replace(/rcn (\d+)/,"<font color='#00CCCC'>$1</font>");
+          text=text.replace(/lcn (\d+)/,"<font color='#0000FF'>$1</font>");
+          return text;
+      }
+
       public function addToRelation():void {
           new RelationSelectPanel().init(selectedEntity,new Object());
       }
 
-      private function removeFromRelation(id:Number, index:int=-1):void {
+      public function removeFromRelation(id:Number, index:int=-1):void {
                var rel:Relation=connection.getRelation(id);
                if (index>-1) {
                        rel.removeMemberByIndex(index, MainUndoStack.getGlobalStack().addAction);
index 1460ff0..a40070e 100644 (file)
@@ -49,7 +49,7 @@ package net.systemeD.potlatch2.controller {
                        var paint:MapPaint = getMapPaint(DisplayObject(event.target));
             var focus:Entity = getTopLevelFocusEntity(entity);
 
-            if ( event.type == MouseEvent.MOUSE_DOWN && entity is Node && focus==firstSelected && event.shiftKey && !layer.isBackground ) {
+            if ( event.type == MouseEvent.MOUSE_DOWN && entity is Node && entity.hasParent(firstSelected) && event.shiftKey && !layer.isBackground ) {
                                // start new way
                                var way:Way = entity.connection.createWay({}, [entity], MainUndoStack.getGlobalStack().addAction);
                                return new DrawWay(way, true, false);
index ea846d1..6353068 100644 (file)
@@ -90,12 +90,13 @@ package net.systemeD.potlatch2.utils {
         private function importWay(coordinates:String, tags:Object, polygon:Boolean, push:Function): Way {
             var way:Way;
             var nodestring:Array = [];
+            var nodemap:Object = [];
 
-            if (polygon) {
-                coordinates = coordinates.slice(0, coordinates.lastIndexOf(" "));
-            }
+            var tuples:Array=coordinates.split(" ");
+            if (tuples[0]==tuples[tuples.length-1]) { polygon=true; }
+            if (polygon) { tuples.splice(-1,1); }
 
-            for each (var tuple:String in coordinates.split(" ")) {
+            for each (var tuple:String in tuples) {
                 var coords:Array = tuple.split(",");
                 var lon:Number = coords[0];
                 var lat:Number = coords[1];