Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
execute(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): Promise {
// Reject if the command is not registered.
let cmd = this._commands[id];
if (!cmd) {
return Promise.reject(new Error(`Command '${id}' not registered.`));
}
// Execute the command and reject if an exception is thrown.
let value: any;
try {
value = cmd.execute.call(undefined, args);
} catch (err) {
value = Promise.reject(err);
}
// Create the return promise which resolves the result.
let result = Promise.resolve(value);
private _evtClick(event: MouseEvent): void {
let target = event.target as HTMLElement;
while (target && target.parentElement) {
if (target.hasAttribute(`data-${COMMAND_ATTR}`)) {
event.preventDefault();
let command = target.getAttribute(`data-${COMMAND_ATTR}`);
if (!command) {
return;
}
let argsValue = target.getAttribute(`data-${ARGS_ATTR}`);
let args = JSONExt.emptyObject;
if (argsValue) {
args = JSON.parse(argsValue);
}
void this._commands.execute(command, args);
return;
}
target = target.parentElement;
}
}
function createKeyBinding(options: CommandRegistry.IKeyBindingOptions): CommandRegistry.IKeyBinding {
return {
keys: CommandRegistry.normalizeKeys(options),
selector: validateSelector(options),
command: options.command,
args: options.args || JSONExt.emptyObject
};
}
constructor(commands: CommandRegistry, options: Menu.IItemOptions) {
this._commands = commands;
this.type = options.type || 'command';
this.command = options.command || '';
this.args = options.args || JSONExt.emptyObject;
this.submenu = options.submenu || null;
}
constructor(commands: CommandRegistry, options: CommandPalette.IItemOptions) {
this._commands = commands;
this.category = normalizeCategory(options.category);
this.command = options.command;
this.args = options.args || JSONExt.emptyObject;
this.rank = options.rank !== undefined ? options.rank : Infinity;
}
mnemonic(id: string, args: ReadonlyPartialJSONObject = JSONExt.emptyObject): number {
let cmd = this._commands[id];
return cmd ? cmd.mnemonic.call(undefined, args) : -1;
}