Ah, I figured out how to fix up my one issue with controllers:

The default behavior of an event is determined by the entity that calls
into the event dispatcher, so the solution was to unify the dispatch of
these events. Created a utility method in CommandEvent to do that, and
did some singlton-like hackery on the constructor to prevent folks from
thinking they can just dispatch these themselves and have it work correctly.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4317 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-08-11 01:22:50 +00:00
parent 1d2c8ae7ac
commit ce5caaedfe
5 changed files with 65 additions and 10 deletions
+10 -4
View File
@@ -22,6 +22,15 @@ public class Controller
}
}
/**
* Post an action so that it can be handled by this controller or
* another controller above it in the display list.
*/
public final function postAction (cmd :String, arg :Object = null) :void
{
CommandEvent.dispatch(_panel, cmd, arg);
}
/**
* Handle an action that was generated by our panel or some child.
*
@@ -52,10 +61,6 @@ public class Controller
// suppress, and fall through
}
// TODO: This warning should really be inside the CommandEvent
// somewhere, and only generated if the event never gets cancelled
Log.getLog(this).warning("Unhandled controller command " +
"[cmd=" + cmd + ", arg=" + arg + "].");
return false; // not handled
}
@@ -68,6 +73,7 @@ public class Controller
if (handleAction(event.command, event.arg)) {
// if we handle the event, stop it from moving outward to another
// controller
event.preventDefault();
event.stopImmediatePropagation();
}
}
+1 -1
View File
@@ -21,7 +21,7 @@ public class MenuUtil
new ContextMenuItem(caption, separatorBefore, enabled, visible);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function (event :ContextMenuEvent) :void {
event.mouseTarget.dispatchEvent(new CommandEvent(cmd, arg));
CommandEvent.dispatch(event.mouseTarget, cmd, arg);
});
return item;
}