Permalink
Browse files

Finished wiring Mac toolbar and icon menu

Added quit button to toolbar
Built ruler context menu and finished wiring
  • Loading branch information...
1 parent 4847bc1 commit 64f5f501923c12a19a27e449e2ecff62c6fad454 @destroytoday committed Jan 28, 2010
@@ -8,6 +8,8 @@ package com.destroytoday.dwarf.contexts {
import com.destroytoday.dwarf.mediators.ToolbarMediator;
import com.destroytoday.dwarf.models.ToolModel;
import com.destroytoday.dwarf.signals.AddRulerSignal;
+ import com.destroytoday.dwarf.signals.AddToolSignal;
+ import com.destroytoday.dwarf.signals.RemoveToolSignal;
import com.destroytoday.dwarf.views.ruler.RulerView;
import com.destroytoday.dwarf.views.toolbar.ToolbarView;
import com.destroytoday.util.ApplicationUtil;
@@ -35,15 +37,31 @@ package com.destroytoday.dwarf.contexts {
* @inheritDoc
*/
override public function startup():void {
+ // map controllers
injector.mapSingleton(ToolController);
+
+ // map models
injector.mapSingleton(ToolModel);
- injector.mapSingleton(MacToolbar);
+
+ // map instance classes
injector.mapSingleton(IconMenu);
injector.mapSingleton(RulerMenu);
+ // map signal commands
injector.mapValue(AddRulerSignal, signalCommandMap.mapSignalClass(AddRulerSignal, AddRulerCommand));
+ // map signals
+ injector.mapSingleton(AddToolSignal);
+ injector.mapSingleton(RemoveToolSignal);
+
+ // map view mediators
+ mediatorMap.mapView(ToolbarView, ToolbarMediator);
+ mediatorMap.mapView(RulerView, RulerMediator);
+
+ // continue mapping instances after signals
if (ApplicationUtil.mac) {
+ injector.mapSingleton(MacToolbar);
+
var toolbar:MacToolbar = new MacToolbar();
injector.injectInto(toolbar);
@@ -54,9 +72,6 @@ package com.destroytoday.dwarf.contexts {
var iconMenu:IconMenu = new IconMenu();
injector.injectInto(iconMenu);
iconMenu.setup();
-
- mediatorMap.mapView(ToolbarView, ToolbarMediator);
- mediatorMap.mapView(RulerView, RulerMediator);
}
}
}
@@ -3,7 +3,10 @@ package com.destroytoday.dwarf.controllers {
import com.destroytoday.dwarf.core.ITool;
import com.destroytoday.dwarf.models.ToolModel;
import com.destroytoday.dwarf.signals.AddRulerSignal;
+ import com.destroytoday.dwarf.signals.AddToolSignal;
+ import com.destroytoday.dwarf.signals.RemoveToolSignal;
import com.destroytoday.dwarf.views.ruler.RulerView;
+ import com.destroytoday.util.ApplicationUtil;
import com.destroytoday.util.WindowUtil;
import org.robotlegs.mvcs.Actor;
@@ -13,9 +16,27 @@ package com.destroytoday.dwarf.controllers {
* @author Jonnie Hallman
*/
public class ToolController extends Actor {
+ /**
+ * @private
+ */
[Inject]
public var model:ToolModel;
+ /**
+ * @private
+ */
+ [Inject]
+ public var addToolSignal:AddToolSignal;
+
+ /**
+ * @private
+ */
+ [Inject]
+ public var removeToolSignal:RemoveToolSignal;
+
+ /**
+ * @private
+ */
[Inject]
public var addRulerSignal:AddRulerSignal;
@@ -26,34 +47,40 @@ package com.destroytoday.dwarf.controllers {
}
/**
- * Adds a ruler.
+ * Adds a tool of the provided class.
+ * @param type the class type to add
*/
- public function addRuler():void {
- var ruler:RulerView = new RulerView();
+ public function addTool(type:Class):void {
+ var tool:ITool = new type();
- addRulerSignal.dispatch(ruler);
-
- ruler.open();
-
- model.addTool(ruler);
+ switch (type) {
+ case RulerView:
+ addRulerSignal.dispatch(tool);
+ break;
+ }
+
+ tool.open();
+ model.addTool(tool);
+ addToolSignal.dispatch(tool);
}
/**
- * Removes the provided ruler.
- * @param ruler
+ * Removes the provided tool.
+ * @param tool the tool to remove
*/
- public function removeRuler(ruler:RulerView):void {
- ruler.close();
- model.removeTool(ruler);
+ public function removeTool(tool:ITool):void {
+ tool.close();
+ model.removeTool(tool);
+ removeToolSignal.dispatch(tool);
}
/**
* Removes the current tool, as indicated by the ToolModel.
*/
public function removeCurrentTool():void {
- var tool:ITool = model.removeTool(model.currentTool);
-
- if (tool) tool.close();
+ if (model.currentTool) {
+ removeTool(model.currentTool);
+ }
}
}
}
@@ -2,7 +2,11 @@ package com.destroytoday.dwarf.desktop {
import com.destroytoday.desktop.NativeMenuPlus;
import com.destroytoday.dwarf.assets.Assets;
import com.destroytoday.dwarf.controllers.ToolController;
+ import com.destroytoday.dwarf.core.ITool;
import com.destroytoday.dwarf.models.ToolModel;
+ import com.destroytoday.dwarf.signals.AddToolSignal;
+ import com.destroytoday.dwarf.signals.RemoveToolSignal;
+ import com.destroytoday.dwarf.views.ruler.RulerView;
import com.destroytoday.util.ApplicationUtil;
import com.destroytoday.util.WindowUtil;
@@ -17,15 +21,36 @@ package com.destroytoday.dwarf.desktop {
import flash.ui.Keyboard;
public class IconMenu extends NativeMenuPlus {
+ /**
+ * @private
+ */
+ [Inject]
+ public var addToolSignal:AddToolSignal;
+
+ /**
+ * @private
+ */
+ [Inject]
+ public var removeToolSignal:RemoveToolSignal;
+
+ /**
+ * @private
+ */
[Inject]
public var toolController:ToolController;
+ /**
+ * @private
+ */
[Inject]
public var toolModel:ToolModel;
public function IconMenu() {
}
+ /**
+ * Builds the menu.
+ */
public function setup():void {
var modifier:uint;
@@ -36,8 +61,7 @@ package com.destroytoday.dwarf.desktop {
<menu>
<item name="newRuler" label="New Ruler" />
<separator />
- <item name="closeTool" label="Close Tool" />
- <item name="quit" label="Quit" />
+ <item name="closeTool" label="Close Tool" enabled="false" />
</menu>;
} else {
var icon:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
@@ -49,19 +73,39 @@ package com.destroytoday.dwarf.desktop {
<menu>
<item name="newRuler" label="New Ruler" />
<separator />
- <item name="closeTool" label="Close Tool" />
+ <item name="closeTool" label="Close Tool" enabled="false" />
<item name="quit" label="Quit" />
</menu>;
icon.addEventListener(ScreenMouseEvent.CLICK, iconClickHandler, false, 0, true);
}
//add listeners
+ addToolSignal.add(addToolHandler);
+ removeToolSignal.add(removeToolHandler);
itemSelectSignal.add(iconMenuItemSelectHandler);
}
/**
* @private
+ * @param tool
+ */
+ protected function addToolHandler(tool:ITool):void {
+ getItemByName("closeTool").enabled = true;
+ }
+
+ /**
+ * @private
+ * @param tool
+ */
+ protected function removeToolHandler(tool:ITool):void {
+ if (toolModel.tools.length == 0) {
+ getItemByName("closeTool").enabled = false;
+ }
+ }
+
+ /**
+ * @private
* @param menu
* @param item
*/
@@ -71,7 +115,7 @@ package com.destroytoday.dwarf.desktop {
navigateToURL(new URLRequest("http://github.com/destroytoday/Dwarf"));
break;
case "newRuler":
- toolController.addRuler();
+ toolController.addTool(RulerView);
break;
case "closeTool":
toolController.removeCurrentTool();
@@ -1,7 +1,11 @@
package com.destroytoday.dwarf.desktop {
import com.destroytoday.desktop.NativeMenuPlus;
import com.destroytoday.dwarf.controllers.ToolController;
+ import com.destroytoday.dwarf.core.ITool;
import com.destroytoday.dwarf.models.ToolModel;
+ import com.destroytoday.dwarf.signals.AddToolSignal;
+ import com.destroytoday.dwarf.signals.RemoveToolSignal;
+ import com.destroytoday.dwarf.views.ruler.RulerView;
import com.destroytoday.util.ApplicationUtil;
import com.destroytoday.util.WindowUtil;
@@ -18,9 +22,27 @@ package com.destroytoday.dwarf.desktop {
* @author Jonnie Hallman
*/
public class MacToolbar {
+ /**
+ * @private
+ */
+ [Inject]
+ public var addToolSignal:AddToolSignal;
+
+ /**
+ * @private
+ */
+ [Inject]
+ public var removeToolSignal:RemoveToolSignal;
+
+ /**
+ * @private
+ */
[Inject]
public var toolController:ToolController;
+ /**
+ * @private
+ */
[Inject]
public var toolModel:ToolModel;
@@ -91,7 +113,7 @@ package com.destroytoday.dwarf.desktop {
<menu>
<item name="newRuler" keyEquivalentModifiers="command" keyEquivalent="r" label="New Ruler" />
<separator />
- <item name="closeTool" keyEquivalentModifiers="command" keyEquivalent="w" label="Close Tool" />
+ <item name="closeTool" keyEquivalentModifiers="command" keyEquivalent="w" label="Close Tool" enabled="false" />
</menu>;
fileItem.submenu = fileMenu;
@@ -111,13 +133,37 @@ package com.destroytoday.dwarf.desktop {
windowItem.submenu = windowMenu;
//add listeners
+ addToolSignal.add(addToolHandler);
+ removeToolSignal.add(removeToolHandler);
applicationMenu.itemSelectSignal.add(applicationMenuItemSelectHandler);
fileMenu.itemSelectSignal.add(fileMenuItemSelectHandler);
windowMenu.itemSelectSignal.add(windowMenuItemSelectHandler);
}
/**
* @private
+ * @param tool
+ */
+ protected function addToolHandler(tool:ITool):void {
+ fileMenu.getItemByName("closeTool").enabled = true;
+ windowMenu.getItemByName("maximizeWindow").enabled = true;
+ windowMenu.getItemByName("minimizeWindow").enabled = true;
+ }
+
+ /**
+ * @private
+ * @param tool
+ */
+ protected function removeToolHandler(tool:ITool):void {
+ if (toolModel.tools.length == 0) {
+ fileMenu.getItemByName("closeTool").enabled = false;
+ windowMenu.getItemByName("maximizeWindow").enabled = false;
+ windowMenu.getItemByName("minimizeWindow").enabled = false;
+ }
+ }
+
+ /**
+ * @private
* @param menu
* @param item
*/
@@ -142,7 +188,7 @@ package com.destroytoday.dwarf.desktop {
protected function fileMenuItemSelectHandler(menu:NativeMenuPlus, item:NativeMenuItem):void {
switch (item.name) {
case "newRuler":
- toolController.addRuler();
+ toolController.addTool(RulerView);
break;
case "closeTool":
toolController.removeCurrentTool();
Oops, something went wrong.

0 comments on commit 64f5f50

Please sign in to comment.