当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript CommandsRegistry.registerCommand方法代码示例

本文整理汇总了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);
	});
开发者ID:GYGit,项目名称:vscode,代码行数:27,代码来源:commands.test.ts

示例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();
	});
开发者ID:SeanKilleen,项目名称:vscode,代码行数:16,代码来源:commands.test.ts

示例3: setTimeout

						setTimeout(() => {
							let reg = CommandsRegistry.registerCommand(event.substr('onCommand:'.length), () => {
								callCounter += 1;
							});
							dispoables.push(reg);
							resolve();
						}, 0);
开发者ID:joelday,项目名称:vscode,代码行数:7,代码来源:commandService.test.ts

示例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();
		});

	});
开发者ID:SeanKilleen,项目名称:vscode,代码行数:26,代码来源:commandService.test.ts

示例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);
	});
开发者ID:StateFarmIns,项目名称:vscode,代码行数:28,代码来源:openerService.test.ts

示例6:

			].forEach(command => {
				CommandsRegistry.registerCommand(command.id, command.handler);

				MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
					command,
					when: HasMacNativeTabsContext
				});
			});
开发者ID:joelday,项目名称:vscode,代码行数:8,代码来源:main.contribution.ts

示例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', () => { });
	});
开发者ID:elibarzilay,项目名称:vscode,代码行数:10,代码来源:keybindingsEditorModel.test.ts

示例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, '');
	});
开发者ID:PKRoma,项目名称:vscode,代码行数:12,代码来源:keybindingsEditorModel.test.ts


注:本文中的vs/platform/commands/common/commands.CommandsRegistry.registerCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。