Allow a custom dispatcher to be provided because the default (dispatching on

the stage) only routes commands to the global controller, bypassing the
controller for the current place view.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@190 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2007-04-08 02:42:16 +00:00
parent deec0b10b8
commit 47d8ed1d63
+30 -21
View File
@@ -23,6 +23,7 @@ package com.threerings.flex {
import flash.display.DisplayObject; import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer; import flash.display.DisplayObjectContainer;
import flash.events.IEventDispatcher;
import flash.geom.Rectangle; import flash.geom.Rectangle;
@@ -41,11 +42,10 @@ import com.threerings.util.CommandEvent;
use namespace mx_internal; use namespace mx_internal;
/** /**
* A pretty standard menu that can submit CommandEvents if menu items * A pretty standard menu that can submit CommandEvents if menu items have "command" and possibly
* have "command" and possibly "arg" properties. Commands are submitted to * "arg" properties. Commands are submitted to controllers for processing. Alternatively, you may
* controllers for processing. Alternatively, you may specify * specify "callback" properties that specify a function closure to call, with the "arg" property
* "callback" properties that specify a function closure to call, with the * containing either a single arg or an array of args.
* "arg" property containing either a single arg or an array of args.
* *
* Example dataProvider array: * Example dataProvider array:
* [ { label: "Go home", icon: homeIconClass, * [ { label: "Go home", icon: homeIconClass,
@@ -55,19 +55,10 @@ use namespace mx_internal;
* { label: "Other places", children: subMenuArray } * { label: "Other places", children: subMenuArray }
* ]; * ];
* *
* See "Defining menu structure and data" in the Flex manual for the * See "Defining menu structure and data" in the Flex manual for the full list.
* full list.
*/ */
public class CommandMenu extends ScrollableArrowMenu public class CommandMenu extends ScrollableArrowMenu
{ {
public function CommandMenu ()
{
super();
verticalScrollPolicy = ScrollPolicy.OFF;
addEventListener(MenuEvent.ITEM_CLICK, itemClicked);
}
/** /**
* Factory method to create a command menu. * Factory method to create a command menu.
* *
@@ -83,6 +74,22 @@ public class CommandMenu extends ScrollableArrowMenu
return menu; return menu;
} }
public function CommandMenu ()
{
super();
verticalScrollPolicy = ScrollPolicy.OFF;
addEventListener(MenuEvent.ITEM_CLICK, itemClicked);
}
/**
* Configures the event dispatcher to be used when dispatching this menu's events. By default
* they will be dispatched on the stage.
*/
public function setDispatcher (dispatcher :IEventDispatcher) :void
{
_dispatcher = dispatcher;
}
/** /**
* Actually pop up the menu. This can be used instead of show(). * Actually pop up the menu. This can be used instead of show().
*/ */
@@ -103,9 +110,8 @@ public class CommandMenu extends ScrollableArrowMenu
} }
/** /**
* Just like our superclass's show(), except that when invoked * Just like our superclass's show(), except that when invoked with no args, causes the menu to
* with no args, causes the menu to show at the current mouse location * show at the current mouse location instead of the top-left corner of the application.
* instead of the top-left corner of the application.
*/ */
override public function show (xShow :Object = null, yShow :Object = null) :void override public function show (xShow :Object = null, yShow :Object = null) :void
{ {
@@ -130,14 +136,15 @@ public class CommandMenu extends ScrollableArrowMenu
} }
if (cmdOrFn != null) { if (cmdOrFn != null) {
event.stopImmediatePropagation(); event.stopImmediatePropagation();
CommandEvent.dispatch(mx_internal::parentDisplayObject, cmdOrFn, arg) CommandEvent.dispatch(_dispatcher == null ? mx_internal::parentDisplayObject :
_dispatcher, cmdOrFn, arg);
} }
// else: no warning. There may be non-command menu items mixed in. // else: no warning. There may be non-command menu items mixed in.
} }
/** /**
* Get the specified property for the specified item, if any. * Get the specified property for the specified item, if any. Somewhat similar to bits in the
* Somewhat similar to bits in the DefaultDataDescriptor. * DefaultDataDescriptor.
*/ */
protected function getItemProp (item :Object, prop :String) :Object protected function getItemProp (item :Object, prop :String) :Object
{ {
@@ -154,5 +161,7 @@ public class CommandMenu extends ScrollableArrowMenu
} }
return null; return null;
} }
protected var _dispatcher :IEventDispatcher;
} }
} }