- Moved common code to internal static methods in CommandButton.
- Fixed CommandButton to turn off buttonMode when disabled. - Created CommandCheckBox. All CommandButtons that are toggle buttons will use their 'selected' state as their arg if they have no regular arg. CommandCheckBoxes are of course always toggles. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@409 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -44,10 +44,7 @@ public class CommandButton extends Button
|
||||
*/
|
||||
public function CommandButton (label :String = null, cmdOrFn :* = null, arg :Object = null)
|
||||
{
|
||||
if (cmdOrFn != null && !(cmdOrFn is String) && !(cmdOrFn is Function)) {
|
||||
// runtime errors suck, but this is actionscript
|
||||
throw new Error("cmdOrFn must be a String or Function.");
|
||||
}
|
||||
validateCmd(cmdOrFn);
|
||||
this.label = label;
|
||||
_cmdOrFn = cmdOrFn;
|
||||
_arg = arg;
|
||||
@@ -72,21 +69,35 @@ public class CommandButton extends Button
|
||||
_arg = arg;
|
||||
}
|
||||
|
||||
override public function set enabled (val :Boolean) :void
|
||||
{
|
||||
super.enabled = val;
|
||||
buttonMode = val;
|
||||
}
|
||||
|
||||
override protected function clickHandler (event :MouseEvent) :void
|
||||
{
|
||||
super.clickHandler(event);
|
||||
processCommandClick(this, event, _cmdOrFn, _arg);
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
// stop the click event
|
||||
internal static function validateCmd (cmdOrFn :Object) :void
|
||||
{
|
||||
if (cmdOrFn != null && !(cmdOrFn is String) && !(cmdOrFn is Function)) {
|
||||
// runtime errors suck, but this is actionscript
|
||||
throw new Error("cmdOrFn must be a String or Function.");
|
||||
}
|
||||
}
|
||||
|
||||
internal static function processCommandClick (
|
||||
button :Button, event :MouseEvent, cmdOrFn :Object, arg :Object) :void
|
||||
{
|
||||
if (button.enabled) {
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
// dispatch the command event
|
||||
// if the arg is null and we're a toggle button, dispatch our state
|
||||
var arg :Object = _arg;
|
||||
if (arg == null && toggle) {
|
||||
arg = selected;
|
||||
if (arg == null && button.toggle) {
|
||||
arg = button.selected;
|
||||
}
|
||||
CommandEvent.dispatch(this, _cmdOrFn, arg);
|
||||
CommandEvent.dispatch(button, cmdOrFn, arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user