本文整理汇总了TypeScript中vs/platform/commands/common/commands.CommandsRegistry类的典型用法代码示例。如果您正苦于以下问题:TypeScript CommandsRegistry类的具体用法?TypeScript CommandsRegistry怎么用?TypeScript CommandsRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandsRegistry类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('convert without title and binding to entry', () => {
CommandsRegistry.registerCommand('command_without_keybinding', () => { });
prepareKeybindingService();
return testObject.resolve({}).then(() => {
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, '');
});
});
示例2: appendSaveConflictEditorTitleAction
function appendSaveConflictEditorTitleAction(id: string, title: string, iconPath: { dark: string; light?: string; }, order: number, command: ICommandHandler): void {
// Command
CommandsRegistry.registerCommand(id, command);
// Action
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: { id, title, iconPath },
when: ContextKeyExpr.equals(CONFLICT_RESOLUTION_CONTEXT, true),
group: 'navigation',
order
});
}
示例3: setTimeout
setTimeout(() => {
// Register the command after some time
actualOrder.push('registering command');
let reg = CommandsRegistry.registerCommand(event.substr('onCommand:'.length), () => {
actualOrder.push('executing command');
});
disposables.push(reg);
setTimeout(() => {
// Resolve the activation event after some more time
actualOrder.push('resolving activation event');
resolve();
}, 10);
}, 10);
示例4: _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);
}
示例5: test
test('!onReady, but executeCommand', function () {
let callCounter = 0;
let reg = CommandsRegistry.registerCommand('bar', () => callCounter += 1);
let service = new CommandService(new InstantiationService(), new class extends NullExtensionService {
whenInstalledExtensionsRegistered() {
return new Promise<boolean>(_resolve => { /*ignore*/ });
}
}, new NullLogService());
service.executeCommand('bar');
assert.equal(callCounter, 1);
reg.dispose();
});
示例6: 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;
}
示例7: test
test('!onReady, but executeCommand', function () {
let callCounter = 0;
let reg = CommandsRegistry.registerCommand('bar', () => callCounter += 1);
let resolve: Function;
let service = new CommandService(new InstantiationService(), new class extends SimpleExtensionService {
onReady() {
return new TPromise<boolean>(_resolve => { resolve = _resolve; });
}
});
return service.executeCommand('bar').then(() => {
reg.dispose();
assert.equal(callCounter, 1);
});
});
示例8: test
test('dispose calls unregister', function () {
let lastUnregister: string;
const shape = new class extends mock<MainThreadCommandsShape>() {
$registerCommand(id: string): void {
//
}
$unregisterCommand(id: string): void {
lastUnregister = id;
}
};
const commands = new ExtHostCommands(SingleProxyRPCProtocol(shape), undefined, new NullLogService());
commands.registerCommand(true, 'foo', (): any => { }).dispose();
assert.equal(lastUnregister, 'foo');
assert.equal(CommandsRegistry.getCommand('foo'), undefined);
});
示例9: test
test('dispose calls unregister', function () {
let lastUnregister: string;
const shape = new class extends mock<MainThreadCommandsShape>() {
$registerCommand(id: string): TPromise<any> {
return undefined;
}
$unregisterCommand(id: string): TPromise<any> {
lastUnregister = id;
return undefined;
}
};
const commands = new ExtHostCommands(OneGetThreadService(shape), undefined, new NoopLogService());
commands.registerCommand('foo', (): any => { }).dispose();
assert.equal(lastUnregister, 'foo');
assert.equal(CommandsRegistry.getCommand('foo'), undefined);
});
示例10: registerWorkspaceActions
(function registerWorkspaceActions(): void {
const workspacesCategory = nls.localize('workspaces', "Workspaces");
registry.registerWorkbenchAction(new SyncActionDescriptor(AddRootFolderAction, AddRootFolderAction.ID, AddRootFolderAction.LABEL), 'Workspaces: Add Folder to Workspace...', workspacesCategory, SupportsWorkspacesContext);
registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalRemoveRootFolderAction, GlobalRemoveRootFolderAction.ID, GlobalRemoveRootFolderAction.LABEL), 'Workspaces: Remove Folder from Workspace...', workspacesCategory);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenWorkspaceAction, OpenWorkspaceAction.ID, OpenWorkspaceAction.LABEL), 'Workspaces: Open Workspace...', workspacesCategory, SupportsWorkspacesContext);
registry.registerWorkbenchAction(new SyncActionDescriptor(SaveWorkspaceAsAction, SaveWorkspaceAsAction.ID, SaveWorkspaceAsAction.LABEL), 'Workspaces: Save Workspace As...', workspacesCategory, SupportsWorkspacesContext);
registry.registerWorkbenchAction(new SyncActionDescriptor(DuplicateWorkspaceInNewWindowAction, DuplicateWorkspaceInNewWindowAction.ID, DuplicateWorkspaceInNewWindowAction.LABEL), 'Workspaces: Duplicate Workspace in New Window', workspacesCategory);
CommandsRegistry.registerCommand(OpenWorkspaceConfigFileAction.ID, serviceAccessor => {
serviceAccessor.get(IInstantiationService).createInstance(OpenWorkspaceConfigFileAction, OpenWorkspaceConfigFileAction.ID, OpenWorkspaceConfigFileAction.LABEL).run();
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: OpenWorkspaceConfigFileAction.ID,
title: { value: `${workspacesCategory}: ${OpenWorkspaceConfigFileAction.LABEL}`, original: 'Workspaces: Open Workspace Configuration File' },
},
when: WorkbenchStateContext.isEqualTo('workspace')
});
})();