本文整理汇总了TypeScript中vs/platform/commands/common/commands.CommandsRegistry.registerCommand方法的典型用法代码示例。如果您正苦于以下问题:TypeScript CommandsRegistry.registerCommand方法的具体用法?TypeScript CommandsRegistry.registerCommand怎么用?TypeScript CommandsRegistry.registerCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/platform/commands/common/commands.CommandsRegistry
的用法示例。
在下文中一共展示了CommandsRegistry.registerCommand方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('register/register/dispose', function () {
const command1 = function () { };
const command2 = function () { };
// dispose overriding command
let reg1 = CommandsRegistry.registerCommand('foo', command1);
assert.ok(CommandsRegistry.getCommand('foo').handler === command1);
let reg2 = CommandsRegistry.registerCommand('foo', command2);
assert.ok(CommandsRegistry.getCommand('foo').handler === command2);
reg2.dispose();
assert.ok(CommandsRegistry.getCommand('foo').handler === command1);
reg1.dispose();
assert.ok(CommandsRegistry.getCommand('foo') === void 0);
// dispose override command first
reg1 = CommandsRegistry.registerCommand('foo', command1);
reg2 = CommandsRegistry.registerCommand('foo', command2);
assert.ok(CommandsRegistry.getCommand('foo').handler === command2);
reg1.dispose();
assert.ok(CommandsRegistry.getCommand('foo').handler === command2);
reg2.dispose();
assert.ok(CommandsRegistry.getCommand('foo') === void 0);
});
示例2: test
test('CommandsRegistry with precondition', function () {
let r1 = CommandsRegistry.registerCommand('foo', () => { });
const precondition = new RawContextKey<boolean>('ddd', false);
let r2 = CommandsRegistry.registerCommand({
id: 'bar',
handler: () => { },
precondition
});
assert.ok(CommandsRegistry.getCommand('bar').precondition === precondition);
assert.equal(CommandsRegistry.getCommand('foo').precondition, undefined);
r1.dispose();
r2.dispose();
});
示例3: setTimeout
setTimeout(() => {
let reg = CommandsRegistry.registerCommand(event.substr('onCommand:'.length), () => {
callCounter += 1;
});
dispoables.push(reg);
resolve();
}, 0);
示例4: test
test('honor command-precondition', function () {
let contextKeyService = new ContextKeyService(new SimpleConfigurationService());
let commandService = new CommandService(
new InstantiationService(),
new SimpleExtensionService(),
contextKeyService
);
let counter = 0;
let reg = CommandsRegistry.registerCommand({
id: 'bar',
handler: () => { counter += 1; },
precondition: ContextKeyExpr.has('foocontext')
});
return commandService.executeCommand('bar').then(() => {
assert.throws(() => { });
}, () => {
contextKeyService.setContext('foocontext', true);
return commandService.executeCommand('bar');
}).then(() => {
assert.equal(counter, 1);
reg.dispose();
});
});
示例5: test
test('delegate to commandsService, command:someid', function () {
const openerService = new OpenerService(editorService, commandService);
// unknown command
openerService.open(URI.parse('command:foobar'));
assert.equal(lastCommand, undefined);
assert.equal(lastInput.resource.toString(), 'command:foobar');
assert.equal(lastInput.options.selection, undefined);
const id = `aCommand${Math.random()}`;
CommandsRegistry.registerCommand(id, function () { });
openerService.open(URI.parse('command:' + id));
assert.equal(lastCommand.id, id);
assert.equal(lastCommand.args.length, 0);
openerService.open(URI.parse('command:' + id).with({ query: '123' }));
assert.equal(lastCommand.id, id);
assert.equal(lastCommand.args.length, 1);
assert.equal(lastCommand.args[0], '123');
openerService.open(URI.parse('command:' + id).with({ query: JSON.stringify([12, true]) }));
assert.equal(lastCommand.id, id);
assert.equal(lastCommand.args.length, 2);
assert.equal(lastCommand.args[0], 12);
assert.equal(lastCommand.args[1], true);
});
示例6:
].forEach(command => {
CommandsRegistry.registerCommand(command.id, command.handler);
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command,
when: HasMacNativeTabsContext
});
});
示例7: setup
setup(() => {
instantiationService = new TestInstantiationService();
instantiationService.stub(IKeybindingService, {});
instantiationService.stub(IExtensionService, {}, 'onReady', () => TPromise.as(null));
testObject = instantiationService.createInstance(KeybindingsEditorModel, OS);
CommandsRegistry.registerCommand('command_without_keybinding', () => { });
});
示例8: test
test('convert without title and binding to entry', async () => {
CommandsRegistry.registerCommand('command_without_keybinding', () => { });
prepareKeybindingService();
await testObject.resolve({});
const actual = testObject.fetch('').filter(element => element.keybindingItem.command === 'command_without_keybinding')[0];
assert.equal(actual.keybindingItem.command, 'command_without_keybinding');
assert.equal(actual.keybindingItem.commandLabel, '');
assert.equal(actual.keybindingItem.commandDefaultLabel, null);
assert.equal(actual.keybindingItem.keybinding, null);
assert.equal(actual.keybindingItem.when, '');
});