Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
New Bookmarks menu
Browse files Browse the repository at this point in the history
  • Loading branch information
systemed committed Jul 4, 2015
1 parent 1cf6a54 commit c81f9b2
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 1 deletion.
55 changes: 55 additions & 0 deletions net/systemeD/controls/DeletableListItemRenderer.mxml
Original file line number Diff line number Diff line change
@@ -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>
64 changes: 64 additions & 0 deletions net/systemeD/potlatch2/BookmarkSelector.mxml
Original file line number Diff line number Diff line change
@@ -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>

33 changes: 33 additions & 0 deletions net/systemeD/potlatch2/dialogs/BookmarkNameDialog.mxml
Original file line number Diff line number Diff line change
@@ -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>

2 changes: 2 additions & 0 deletions potlatch2.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion styles/Application.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c81f9b2

Please sign in to comment.