- Have Controller use the CommandEvent callback dispatch stuff once
the controller has located the appropriate function. - If the arg for a command or callback is an array, assume those are the parameters for the function. If you desire passing a single array argument, you've got to wrap it in another array, otherwise single args will be automatically wrapped for you. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4676 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -39,16 +39,34 @@ public class CommandEvent extends Event
|
|||||||
{
|
{
|
||||||
if (cmdOrFn is Function) {
|
if (cmdOrFn is Function) {
|
||||||
var fn :Function = (cmdOrFn as Function);
|
var fn :Function = (cmdOrFn as Function);
|
||||||
var args :Array = (arg as Array);
|
// build our args array
|
||||||
if (args == null && arg != null) {
|
var args :Array;
|
||||||
|
if (arg is Array) {
|
||||||
|
// if we were passed an array, treat it as the arg array.
|
||||||
|
// Note: if you want to pass a single array param, you've
|
||||||
|
// got to wrap it in another array, so sorry.
|
||||||
|
args = arg as Array;
|
||||||
|
|
||||||
|
} else {
|
||||||
args = [ arg ];
|
args = [ arg ];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
fn.apply(null, args);
|
fn.apply(null, args);
|
||||||
} catch (err :Error) {
|
} catch (err :Error) {
|
||||||
var log :Log = Log.getLog(CommandEvent);
|
if (arg == null) {
|
||||||
log.warning("Unable to call command callback, stack trace follows.");
|
try {
|
||||||
log.logStackTrace(err);
|
// try with no args
|
||||||
|
fn();
|
||||||
|
err = null; // on success, clear the error
|
||||||
|
} catch (err2 :Error) {
|
||||||
|
err = err2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (err != null) {
|
||||||
|
var log :Log = Log.getLog(CommandEvent);
|
||||||
|
log.warning("Unable to call command callback, stack trace follows.");
|
||||||
|
log.logStackTrace(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (cmdOrFn is String) {
|
} else if (cmdOrFn is String) {
|
||||||
|
|||||||
@@ -78,32 +78,14 @@ public class Controller
|
|||||||
// this + "]");
|
// this + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fn != null) {
|
if (fn == null) {
|
||||||
try {
|
// never found it?
|
||||||
try {
|
return false;
|
||||||
// try calling it with the arg
|
|
||||||
fn(arg);
|
|
||||||
} catch (ae :ArgumentError) {
|
|
||||||
if (arg == null) {
|
|
||||||
// try calling it without the arg
|
|
||||||
fn();
|
|
||||||
} else {
|
|
||||||
throw ae;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e :Error) {
|
|
||||||
var log :Log = Log.getLog(this);
|
|
||||||
log.warning("Error handling controller " +
|
|
||||||
"command [error=" + e + ", cmd=" + cmd +
|
|
||||||
", arg=" + arg + "].");
|
|
||||||
log.logStackTrace(e);
|
|
||||||
}
|
|
||||||
// we "handled" the event, even if it threw an error
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // not handled
|
// finally, dispatch it
|
||||||
|
CommandEvent.dispatch(_controlledPanel, fn, arg);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user