CommandManager.list Member
Gets a sorted Array of CommandRecord objects which match.
Syntax
object.list(partialName, flags);
Arguments
Argument | Summary |
---|---|
partialName | Optional. A String prefix to search for. |
flags | Optional. Flags to logically AND with commands. |
Returns
Remarks
After filtering by flags (if specified), if an exact match for partialName is found, only that is returned; otherwise, all commands starting with partialName are returned in alphabetical order by label.
See Also
Source Code
function cmgr_list (partialName, flags)
{
/* returns array of command objects which look like |partialName|, or
* all commands if |partialName| is not specified */
function compare (a, b)
{
a = a.labelstr.toLowerCase();
b = b.labelstr.toLowerCase();
if (a == b)
return 0;
if (a > b)
return 1;
return -1;
}
var ary = new Array();
var commandNames = keys(this.commands);
/* A command named "eval" wouldn't show up in the result of keys() because
* eval is not-enumerable, even if overwritten, in Mozilla 1.0. */
if (objectContains(this.commands, "eval") && !arrayContains(commandNames, "eval"))
commandNames.push("eval");
for (var i in commandNames)
{
var name = commandNames[i];
if (!flags || (this.commands[name].flags & flags))
{
if (!partialName ||
this.commands[name].name.indexOf(partialName) == 0)
{
if (partialName &&
partialName.length == this.commands[name].name.length)
{
/* exact match */
return [this.commands[name]];
}
else
{
ary.push (this.commands[name]);
}
}
}
}
ary.sort(compare);
return ary;
}