CommandManager.defineCommand Member

Adds a single command.

Syntax

object.defineCommand(name, func, flags, usage, bundle);

Arguments

ArgumentSummary
name The String name of the command to define.
func A Function to call to handle dispatch of the new command.
flags Optional. A Number indicating any special requirements for the command. The CommandManager only checks for CMD_NO_HELP; flags are stored unchanged.
usage Optional. A String specifying the arguments to the command. If not specified, the property string "cmd." + name + ".params" is read from bundle or defaultBundle.
bundle Optional. An nsIStringBundle to fetch parameters, labels, accelerator keys and help from. If not specified, the defaultBundle is used.

Returns

Remarks

See Also

Source Code

function cmdmgr_defcmd(name, func, flags, usage, bundle)
{
if (!bundle)
bundle = this.defaultBundle;
var helpDefault;
var labelDefault = name;
var aliasFor;
if (typeof flags != "number")
flags = this.defaultFlags;
if (flags & CMD_NO_HELP)
helpDefault = MSG_NO_HELP;
if (typeof usage != "string")
usage = getMsgFrom(bundle, "cmd." + name + ".params", null, "");
if (typeof func == "string")
{
var ary = func.match(/(\S+)/);
if (ary)
aliasFor = ary[1];
else
aliasFor = null;
helpDefault = getMsg (MSG_DEFAULT_ALIAS_HELP, func);
if (aliasFor)
labelDefault = getMsgFrom (bundle, "cmd." + aliasFor + ".label",
null, name);
}
var label = getMsgFrom(bundle, "cmd." + name + ".label", null,
labelDefault);
var accesskey = getMsgFrom(bundle, "cmd." + name + ".accesskey", null,
getAccessKey(label));
var help = getMsgFrom(bundle, "cmd." + name + ".help", null,
helpDefault);
var keystr = getMsgFrom (bundle, "cmd." + name + ".key", null, "");
var format = getMsgFrom (bundle, "cmd." + name + ".format", null, null);
var tip = getMsgFrom (bundle, "cmd." + name + ".tip", null, "");
var command = new CommandRecord(name, func, usage, help, label, accesskey,
flags, keystr, tip, format);
this.addCommand(command);
if (aliasFor)
command.aliasFor = aliasFor;
return command;
}