當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript MenuRegistry.addCommand方法代碼示例

本文整理匯總了TypeScript中vs/platform/actions/common/actions.MenuRegistry.addCommand方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript MenuRegistry.addCommand方法的具體用法?TypeScript MenuRegistry.addCommand怎麽用?TypeScript MenuRegistry.addCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vs/platform/actions/common/actions.MenuRegistry的用法示例。


在下文中一共展示了MenuRegistry.addCommand方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: handleCommand

	function handleCommand(userFriendlyCommand: schema.IUserFriendlyCommand , extension: IExtensionPointUser<any>) {

		if (!schema.isValidCommand(userFriendlyCommand, extension.collector)) {
			return;
		}

		let {icon, category, title, command} = userFriendlyCommand;
		let iconClass: string;
		if (icon) {
			iconClass = ids.nextId();
			if (typeof icon === 'string') {
				const path = join(extension.description.extensionFolderPath, icon);
				createCSSRule(`.icon.${iconClass}`, `background-image: url("${path}")`);
			} else {
				const light = join(extension.description.extensionFolderPath, icon.light);
				const dark = join(extension.description.extensionFolderPath, icon.dark);
				createCSSRule(`.icon.${iconClass}`, `background-image: url("${light}")`);
				createCSSRule(`.vs-dark .icon.${iconClass}, hc-black .icon.${iconClass}`, `background-image: url("${dark}")`);
			}
		}

		if (MenuRegistry.addCommand({ id: command, title, category, iconClass })) {
			extension.collector.info(localize('dup', "Command `{0}` appears multiple times in the `commands` section.", userFriendlyCommand.command));
		}
	}
開發者ID:baltth,項目名稱:vscode,代碼行數:25,代碼來源:menusExtensionPoint.ts

示例2: test

	test('special MenuId palette', function () {

		disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
			command: { id: 'a', title: 'Explicit' }
		}));

		MenuRegistry.addCommand({ id: 'b', title: 'Implicit' });

		let foundA = false;
		let foundB = false;
		for (const item of MenuRegistry.getMenuItems(MenuId.CommandPalette)) {
			if (isIMenuItem(item)) {
				if (item.command.id === 'a') {
					assert.equal(item.command.title, 'Explicit');
					foundA = true;
				}
				if (item.command.id === 'b') {
					assert.equal(item.command.title, 'Implicit');
					foundB = true;
				}
			}
		}
		assert.equal(foundA, true);
		assert.equal(foundB, true);
	});
開發者ID:developers23,項目名稱:vscode,代碼行數:25,代碼來源:menuService.test.ts

示例3: handleCommand

	function handleCommand(userFriendlyCommand: schema.IUserFriendlyCommand, extension: IExtensionPointUser<any>) {

		if (!schema.isValidCommand(userFriendlyCommand, extension.collector)) {
			return;
		}

		const { icon, category, title, command } = userFriendlyCommand;

		let absoluteIcon: { dark: string; light?: string; };
		if (icon) {
			//TODO@extensionLocation
			if (typeof icon === 'string') {
				absoluteIcon = { dark: join(extension.description.extensionLocation.fsPath, icon) };
			} else {
				absoluteIcon = {
					dark: join(extension.description.extensionLocation.fsPath, icon.dark),
					light: join(extension.description.extensionLocation.fsPath, icon.light)
				};
			}
		}

		if (MenuRegistry.addCommand({ id: command, title, category, iconPath: absoluteIcon })) {
			extension.collector.info(localize('dup', "Command `{0}` appears multiple times in the `commands` section.", userFriendlyCommand.command));
		}
	}
開發者ID:jinlongchen2018,項目名稱:vscode,代碼行數:25,代碼來源:menusExtensionPoint.ts

示例4: handleCommand

	function handleCommand(userFriendlyCommand: schema.IUserFriendlyCommand, extension: IExtensionPointUser<any>, disposables: IDisposable[]) {

		if (!schema.isValidCommand(userFriendlyCommand, extension.collector)) {
			return;
		}

		const { icon, enablement, category, title, command } = userFriendlyCommand;

		let absoluteIcon: { dark: URI; light?: URI; } | undefined;
		if (icon) {
			if (typeof icon === 'string') {
				absoluteIcon = { dark: resources.joinPath(extension.description.extensionLocation, icon) };
			} else {
				absoluteIcon = {
					dark: resources.joinPath(extension.description.extensionLocation, icon.dark),
					light: resources.joinPath(extension.description.extensionLocation, icon.light)
				};
			}
		}

		if (MenuRegistry.getCommand(command)) {
			extension.collector.info(localize('dup', "Command `{0}` appears multiple times in the `commands` section.", userFriendlyCommand.command));
		}
		const registration = MenuRegistry.addCommand({
			id: command,
			title,
			category,
			precondition: ContextKeyExpr.deserialize(enablement),
			iconLocation: absoluteIcon
		});
		disposables.push(registration);
	}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:32,代碼來源:menusExtensionPoint.ts

示例5: _registerWorkbenchCommandFromAction

	private _registerWorkbenchCommandFromAction(descriptor: SyncActionDescriptor, alias: string, category?: string): IDisposable {
		let registrations: IDisposable[] = [];

		// command
		registrations.push(CommandsRegistry.registerCommand(descriptor.id, this._createCommandHandler(descriptor)));

		// keybinding
		const when = descriptor.keybindingContext;
		const weight = (typeof descriptor.keybindingWeight === 'undefined' ? KeybindingsRegistry.WEIGHT.workbenchContrib() : descriptor.keybindingWeight);
		const keybindings = descriptor.keybindings;
		KeybindingsRegistry.registerKeybindingRule({
			id: descriptor.id,
			weight: weight,
			when: when,
			primary: keybindings && keybindings.primary,
			secondary: keybindings && keybindings.secondary,
			win: keybindings && keybindings.win,
			mac: keybindings && keybindings.mac,
			linux: keybindings && keybindings.linux
		});

		// menu item
		// TODO@Rob slightly weird if-check required because of
		// https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/parts/search/electron-browser/search.contribution.ts#L266
		if (descriptor.label) {

			let idx = alias.indexOf(': ');
			let categoryOriginal;
			if (idx > 0) {
				categoryOriginal = alias.substr(0, idx);
				alias = alias.substr(idx + 2);
			}

			const command = {
				id: descriptor.id,
				title: { value: descriptor.label, original: alias },
				category: category && { value: category, original: categoryOriginal }
			};

			MenuRegistry.addCommand(command);

			registrations.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command }));
		}

		// TODO@alex,joh
		// support removal of keybinding rule
		// support removal of command-ui
		return combinedDisposable(registrations);
	}
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:49,代碼來源:actions.ts

示例6: test

	test('special MenuId palette', function () {

		disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
			command: { id: 'a', title: 'Explicit' }
		}));

		MenuRegistry.addCommand({ id: 'b', title: 'Implicit' });

		const [first, second] = MenuRegistry.getMenuItems(MenuId.CommandPalette);
		assert.equal(first.command.id, 'a');
		assert.equal(first.command.title, 'Explicit');

		assert.equal(second.command.id, 'b');
		assert.equal(second.command.title, 'Implicit');
	});
開發者ID:yuit,項目名稱:vscode,代碼行數:15,代碼來源:menuService.test.ts

示例7: registerWorkbenchCommandFromAction

	private registerWorkbenchCommandFromAction(descriptor: SyncActionDescriptor, alias: string, category?: string, when?: ContextKeyExpr): IDisposable {
		const registrations = new DisposableStore();

		// command
		registrations.add(CommandsRegistry.registerCommand(descriptor.id, this.createCommandHandler(descriptor)));

		// keybinding
		const weight = (typeof descriptor.keybindingWeight === 'undefined' ? KeybindingWeight.WorkbenchContrib : descriptor.keybindingWeight);
		const keybindings = descriptor.keybindings;
		KeybindingsRegistry.registerKeybindingRule({
			id: descriptor.id,
			weight: weight,
			when: (descriptor.keybindingContext || when ? ContextKeyExpr.and(descriptor.keybindingContext, when) : null),
			primary: keybindings ? keybindings.primary : 0,
			secondary: keybindings && keybindings.secondary,
			win: keybindings && keybindings.win,
			mac: keybindings && keybindings.mac,
			linux: keybindings && keybindings.linux
		});

		// menu item
		// TODO@Rob slightly weird if-check required because of
		// https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/contrib/search/electron-browser/search.contribution.ts#L266
		if (descriptor.label) {

			let idx = alias.indexOf(': ');
			let categoryOriginal = '';
			if (idx > 0) {
				categoryOriginal = alias.substr(0, idx);
				alias = alias.substr(idx + 2);
			}

			const command: ICommandAction = {
				id: descriptor.id,
				title: { value: descriptor.label, original: alias },
				category: category ? { value: category, original: categoryOriginal } : undefined
			};

			MenuRegistry.addCommand(command);

			registrations.add(MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command, when }));
		}

		// TODO@alex,joh
		// support removal of keybinding rule
		// support removal of command-ui
		return registrations;
	}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:48,代碼來源:actions.ts

示例8: registerAction

function registerAction(desc: IActionDescriptor) {

	const { id, handler, title, category, iconClass, f1, menu, keybinding } = desc;

	// 1) register as command
	CommandsRegistry.registerCommand(id, handler);

	// 2) command palette
	let command = { id, title, iconClass, category };
	if (f1) {
		MenuRegistry.addCommand(command);
	}

	// 3) menus
	if (menu) {
		let { menuId, when, group } = menu;
		MenuRegistry.appendMenuItem(menuId, {
			command,
			when,
			group
		});
	}

	// 4) keybindings
	if (keybinding) {
		let { when, weight, keys } = keybinding;
		KeybindingsRegistry.registerKeybindingRule({
			id,
			when,
			weight,
			primary: keys.primary,
			secondary: keys.secondary,
			linux: keys.linux,
			mac: keys.mac,
			win: keys.win
		});
	}
}
開發者ID:armanio123,項目名稱:vscode,代碼行數:38,代碼來源:output.contribution.ts

示例9: deserialize

		}
		deserialize(instantiationService: IInstantiationService): PerfviewInput {
			return instantiationService.createInstance(PerfviewInput);
		}
	}
);

CommandsRegistry.registerCommand('perfview.show', accessor => {
	const editorService = accessor.get(IEditorService);
	const instaService = accessor.get(IInstantiationService);
	return editorService.openEditor(instaService.createInstance(PerfviewInput));
});

MenuRegistry.addCommand({
	id: 'perfview.show',
	category: localize('show.cat', "Developer"),
	title: localize('show.label', "Startup Performance")
});


// -- startup profiler

Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(
	StartupProfiler,
	LifecyclePhase.Restored
);

// -- startup timings

Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(
	StartupTimings,
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:31,代碼來源:performance.contribution.ts


注:本文中的vs/platform/actions/common/actions.MenuRegistry.addCommand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。