New Bookmarks menu
authorRichard Fairhurst <richard@systemeD.net>
Sat, 4 Jul 2015 15:50:02 +0000 (16:50 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 4 Jul 2015 15:50:02 +0000 (16:50 +0100)
net/systemeD/controls/DeletableListItemRenderer.mxml [new file with mode: 0644]
net/systemeD/potlatch2/BookmarkSelector.mxml [new file with mode: 0644]
net/systemeD/potlatch2/dialogs/BookmarkNameDialog.mxml [new file with mode: 0644]
potlatch2.mxml
styles/Application.css

diff --git a/net/systemeD/controls/DeletableListItemRenderer.mxml b/net/systemeD/controls/DeletableListItemRenderer.mxml
new file mode 100644 (file)
index 0000000..3c013f8
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- http://blog.flexexamples.com/2010/04/09/adding-a-delete-button-in-the-hovered-state-of-a-spark-list-control-item-renderer-in-flex-4/ -->
+<s:ItemRenderer name="DeletableListItemRenderer"
+        xmlns:fx="http://ns.adobe.com/mxml/2009" 
+        xmlns:s="library://ns.adobe.com/flex/spark" 
+        xmlns:mx="library://ns.adobe.com/flex/mx" 
+        autoDrawBackground="true"
+        minHeight="24">
+    <s:states>
+        <s:State name="normal" />
+        <s:State name="hovered" />
+        <s:State name="selected" />
+    </s:states>
+    <fx:Script>
+        <![CDATA[
+            import mx.controls.Alert;
+            import mx.events.CloseEvent;
+            import spark.components.List;
+            protected function button1_clickHandler(evt:MouseEvent):void {
+                Alert.show(data.label,
+                        "Are you sure you want to delete this item?",
+                        Alert.YES|Alert.CANCEL,
+                        null,
+                        alrt_closeHandler);
+            }
+            protected function alrt_closeHandler(evt:CloseEvent):void {
+                switch (evt.detail) {
+                    case Alert.YES:
+                    case Alert.OK:
+                        Object(owner).dataProvider.removeItemAt(itemIndex);
+                        break;
+                    case Alert.CANCEL:
+                    case Alert.NO:
+                        Object(owner).selectedIndex = -1;
+                        break;
+                    default:
+                        break;
+                }
+            }
+        ]]>
+    </fx:Script>
+    <s:HGroup width="100%" height="100%"
+            verticalAlign="middle"
+            paddingLeft="2" paddingRight="2"
+            paddingTop="2" paddingBottom="2">
+        <s:Label id="lbl" text="{data.name}" width="100%" />
+        <s:Image id="btn" includeIn="hovered,selected" source="@Embed('../../../embedded/delete_small.svg')" click="button1_clickHandler(event)" />
+    </s:HGroup>
+</s:ItemRenderer>
diff --git a/net/systemeD/potlatch2/BookmarkSelector.mxml b/net/systemeD/potlatch2/BookmarkSelector.mxml
new file mode 100644 (file)
index 0000000..f90e712
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<s:BorderContainer
+    xmlns:controls="net.systemeD.controls.*"
+       xmlns:fx="http://ns.adobe.com/mxml/2009"
+    xmlns:s="library://ns.adobe.com/flex/spark" >
+
+    <s:layout>
+      <s:VerticalLayout
+          paddingLeft="5" paddingRight="5"
+          paddingTop="5" paddingBottom="5"/>
+    </s:layout>
+
+       <s:List width="100%" height="100%" id="bookmarkMenu"
+               labelField="name"
+            itemRenderer="net.systemeD.controls.DeletableListItemRenderer"
+               change="FlexGlobals.topLevelApplication.bookmarkButton.close(); goToBookmark(event);"
+            dataProvider="{bookmarks}">
+      <s:layout>
+        <s:VerticalLayout requestedRowCount="{bookmarks.length}" gap="0" rowHeight="20" variableRowHeight="false" horizontalAlign="contentJustify"/> 
+      </s:layout>
+    </s:List>
+
+       <s:Button id="addButton" label="Add..." click="FlexGlobals.topLevelApplication.bookmarkButton.close(); addBookmark();" />
+
+       <fx:Script><![CDATA[
+               import net.systemeD.halcyon.*;
+               import net.systemeD.halcyon.connection.*;
+               import net.systemeD.potlatch2.*;
+               import net.systemeD.potlatch2.collections.Stylesheets;
+               import net.systemeD.potlatch2.dialogs.*;
+               import net.systemeD.controls.DeletableListItemRenderer;
+               import mx.core.*;
+        import spark.events.IndexChangeEvent;
+               import mx.collections.ArrayCollection;
+        import mx.managers.PopUpManager;
+
+               [Bindable]
+        public var bookmarks:ArrayCollection = new ArrayCollection([]);
+               // of format { name: "Bookmark 1", lat: 53, lon: 0 }, { name: "Bookmark 2", lat: 54, lon: -1 }
+
+               private var userState:SharedObject=SharedObject.getLocal("user_state","/");
+
+               public function init():BookmarkSelector {
+                       if (userState.data['bookmarks']) {
+                               bookmarks = new ArrayCollection(userState.data['bookmarks']);
+                       }
+                       return this;
+               }
+
+               private function goToBookmark(event:IndexChangeEvent):void {
+                       FlexGlobals.topLevelApplication.theController.map.moveMapFromLatLon(event.currentTarget.selectedItem.lat, event.currentTarget.selectedItem.lon);
+               }
+               
+               private function addBookmark():void {
+                       var dialog:BookmarkNameDialog = BookmarkNameDialog(
+                           PopUpManager.createPopUp(Application(FlexGlobals.topLevelApplication), BookmarkNameDialog, true));
+                       PopUpManager.centerPopUp(dialog);
+                       // save to SharedObject
+               userState.setProperty("bookmarks",bookmarks.source);
+               try { userState.flush(); } catch (e:Error) {}
+               }
+    ]]></fx:Script>
+</s:BorderContainer>
+
diff --git a/net/systemeD/potlatch2/dialogs/BookmarkNameDialog.mxml b/net/systemeD/potlatch2/dialogs/BookmarkNameDialog.mxml
new file mode 100644 (file)
index 0000000..e64dd1d
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:TitleWindow
+       xmlns:fx="http://ns.adobe.com/mxml/2009"
+       xmlns:mx="library://ns.adobe.com/flex/mx"
+       xmlns:potlatch2="net.systemeD.potlatch2.*"
+       title="New Bookmark" width="350" height="160"
+       creationComplete="bookmarkName.setFocus()"
+       showCloseButton="true" close="PopUpManager.removePopUp(this);">
+       
+       <mx:HBox paddingLeft="3" paddingTop="4">
+               <mx:Label text="Bookmark name: " />
+               <mx:TextInput id="bookmarkName" enter="addBookmark();" />
+       </mx:HBox>
+    <mx:ControlBar>
+      <mx:Spacer width="100%"/>
+      <mx:Button label="Add" click="addBookmark();" styleName="titleWindowButton" />
+    </mx:ControlBar>
+       <fx:Script><![CDATA[
+               import net.systemeD.halcyon.*;
+               import net.systemeD.halcyon.connection.*;
+               import net.systemeD.potlatch2.*;
+               import mx.managers.PopUpManager;
+               import mx.core.FlexGlobals;
+
+               public function addBookmark():void {
+                       var controller:EditController = FlexGlobals.topLevelApplication.theController;
+                       FlexGlobals.topLevelApplication.bookmarkButton.popUp.bookmarks.addItem({ name: bookmarkName.text, lat: controller.map.centre_lat, lon: controller.map.centre_lon });
+               PopUpManager.removePopUp(this);
+               }
+
+    ]]></fx:Script>
+</mx:TitleWindow>
+
index d52e715..ad5f6c9 100644 (file)
@@ -62,6 +62,8 @@
                                </fx:Array>
                        </mx:dataProvider>
                </mx:PopUpMenuButton>
+        <mx:PopUpButton id="bookmarkButton" label="Bookmarks" openAlways="true" styleName="appBarButton" open="disableMapMouse();" close="enableMapMouse();" 
+            creationComplete="bookmarkButton.popUp = new BookmarkSelector().init();"/>
         <mx:Button id="tasksButton" label="Tasks" click="new TasksDialog().init(theController);" styleName="appBarButton" toolTip="Load tasks file" />
         <mx:Button id="optionsButton" label="Options" click="new OptionsDialog().init();" styleName="appBarButton" />
     </mx:ApplicationControlBar>
index b97ba8e..12a3e58 100644 (file)
@@ -45,7 +45,7 @@ mx|VScrollBar {
        thumbOffset: 1;
 }
 
-mx|CheckBox, mx|List, p2|StyleSelector, p2|BackgroundSelector { color: black; }
+mx|CheckBox, mx|List, p2|BookmarkSelector, p2|StyleSelector, p2|BackgroundSelector { color: black; textAlign: left; }
 
 mx|TabNavigator {
        horizontalGap: 3;