提交 2b0800a5 编写于 作者: A Alex Dima

Simplify Command registration

上级 403a5869
......@@ -1620,7 +1620,7 @@ function findFocusedEditor(accessor: ServicesAccessor): ICodeEditor {
}
function registerCommand(command: Command) {
KeybindingsRegistry.registerCommandAndKeybindingRule(command.toCommandAndKeybindingRule(CORE_WEIGHT));
command.register(CORE_WEIGHT);
}
/**
......
......@@ -31,11 +31,18 @@ export interface ICommandKeybindingsOptions extends IKeybindings {
kbExpr?: ContextKeyExpr;
weight?: number;
}
// export interface ICommandMenubarOptions {
// group?: string;
// order?: number;
// when?: ContextKeyExpr;
// title?: string;
// }
export interface ICommandOptions {
id: string;
precondition: ContextKeyExpr;
kbOpts?: ICommandKeybindingsOptions;
description?: ICommandHandlerDescription;
// menubarOpts?: ICommandMenubarOptions;
}
export abstract class Command {
public readonly id: string;
......@@ -50,7 +57,7 @@ export abstract class Command {
this._description = opts.description;
}
public toCommandAndKeybindingRule(defaultWeight: number): ICommandAndKeybindingRule {
private _toCommandAndKeybindingRule(defaultWeight: number): ICommandAndKeybindingRule {
const kbOpts = this._kbOpts || { primary: 0 };
let kbWhen = kbOpts.kbExpr;
......@@ -78,6 +85,10 @@ export abstract class Command {
};
}
public register(defaultWeight: number): void {
KeybindingsRegistry.registerCommandAndKeybindingRule(this._toCommandAndKeybindingRule(defaultWeight));
}
public abstract runCommand(accessor: ServicesAccessor, args: any): void | TPromise<void>;
}
......@@ -166,7 +177,7 @@ export abstract class EditorAction extends EditorCommand {
this.menuOpts = opts.menuOpts;
}
public toMenuItem(): IMenuItem {
private _toMenuItem(): IMenuItem {
if (!this.menuOpts) {
return null;
}
......@@ -182,6 +193,16 @@ export abstract class EditorAction extends EditorCommand {
};
}
public register(defaultWeight: number): void {
let menuItem = this._toMenuItem();
if (menuItem) {
MenuRegistry.appendMenuItem(MenuId.EditorContext, menuItem);
}
super.register(defaultWeight);
}
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void> {
this.reportTelemetry(accessor, editor);
return this.run(accessor, editor, args || {});
......@@ -295,14 +316,7 @@ class EditorContributionRegistry {
}
public registerEditorAction(action: EditorAction) {
let menuItem = action.toMenuItem();
if (menuItem) {
MenuRegistry.appendMenuItem(MenuId.EditorContext, menuItem);
}
KeybindingsRegistry.registerCommandAndKeybindingRule(action.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
action.register(KeybindingsRegistry.WEIGHT.editorContrib());
this.editorActions.push(action);
}
......@@ -315,7 +329,7 @@ class EditorContributionRegistry {
}
public registerEditorCommand(editorCommand: EditorCommand) {
KeybindingsRegistry.registerCommandAndKeybindingRule(editorCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
editorCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
this.editorCommands[editorCommand.id] = editorCommand;
}
......
......@@ -1124,4 +1124,4 @@ const showCommand = new ShowExtensionEditorFindCommand({
primary: KeyMod.CtrlCmd | KeyCode.KEY_F
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(showCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
showCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
......@@ -353,7 +353,7 @@ const startSearchCommand = new StartSearchDefaultSettingsCommand({
precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR),
kbOpts: { primary: KeyMod.CtrlCmd | KeyCode.KEY_F }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(startSearchCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
startSearchCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
class FocusSearchFromSettingsCommand extends SettingsCommand {
......@@ -369,7 +369,7 @@ const focusSearchFromSettingsCommand = new FocusSearchFromSettingsCommand({
precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_FIRST_ROW_FOCUS),
kbOpts: { primary: KeyCode.UpArrow }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(focusSearchFromSettingsCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib()));
focusSearchFromSettingsCommand.register(KeybindingsRegistry.WEIGHT.workbenchContrib());
class ClearSearchResultsCommand extends SettingsCommand {
......@@ -386,7 +386,7 @@ const clearSearchResultsCommand = new ClearSearchResultsCommand({
precondition: CONTEXT_SETTINGS_SEARCH_FOCUS,
kbOpts: { primary: KeyCode.Escape }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(clearSearchResultsCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
clearSearchResultsCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
class FocusSettingsFileEditorCommand extends SettingsCommand {
......@@ -404,14 +404,14 @@ const focusSettingsFileEditorCommand = new FocusSettingsFileEditorCommand({
precondition: CONTEXT_SETTINGS_SEARCH_FOCUS,
kbOpts: { primary: KeyCode.DownArrow }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(focusSettingsFileEditorCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
focusSettingsFileEditorCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
const focusSettingsFromSearchCommand = new FocusSettingsFileEditorCommand({
id: SETTINGS_EDITOR_COMMAND_FOCUS_SETTINGS_FROM_SEARCH,
precondition: CONTEXT_SETTINGS_SEARCH_FOCUS,
kbOpts: { primary: KeyCode.DownArrow }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(focusSettingsFromSearchCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib()));
focusSettingsFromSearchCommand.register(KeybindingsRegistry.WEIGHT.workbenchContrib());
class FocusNextSearchResultCommand extends SettingsCommand {
......@@ -427,7 +427,7 @@ const focusNextSearchResultCommand = new FocusNextSearchResultCommand({
precondition: CONTEXT_SETTINGS_SEARCH_FOCUS,
kbOpts: { primary: KeyCode.Enter }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(focusNextSearchResultCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
focusNextSearchResultCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
class FocusPreviousSearchResultCommand extends SettingsCommand {
......@@ -443,7 +443,7 @@ const focusPreviousSearchResultCommand = new FocusPreviousSearchResultCommand({
precondition: CONTEXT_SETTINGS_SEARCH_FOCUS,
kbOpts: { primary: KeyMod.Shift | KeyCode.Enter }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(focusPreviousSearchResultCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
focusPreviousSearchResultCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
class EditFocusedSettingCommand extends SettingsCommand {
......@@ -459,7 +459,7 @@ const editFocusedSettingCommand = new EditFocusedSettingCommand({
precondition: CONTEXT_SETTINGS_SEARCH_FOCUS,
kbOpts: { primary: KeyMod.CtrlCmd | KeyCode.US_DOT }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(editFocusedSettingCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
editFocusedSettingCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
class EditFocusedSettingCommand2 extends SettingsCommand {
......@@ -476,7 +476,7 @@ const editFocusedSettingCommand2 = new EditFocusedSettingCommand2({
precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_ROW_FOCUS),
kbOpts: { primary: KeyCode.Enter }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(editFocusedSettingCommand2.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib()));
editFocusedSettingCommand2.register(KeybindingsRegistry.WEIGHT.workbenchContrib());
class FocusSettingsListCommand extends SettingsCommand {
......@@ -493,7 +493,7 @@ const focusSettingsListCommand = new FocusSettingsListCommand({
precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_TOC_ROW_FOCUS),
kbOpts: { primary: KeyCode.Enter }
});
KeybindingsRegistry.registerCommandAndKeybindingRule(focusSettingsListCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib()));
focusSettingsListCommand.register(KeybindingsRegistry.WEIGHT.workbenchContrib());
// Preferences menu
......
......@@ -45,7 +45,7 @@ const showNextFindWdigetCommand = new ShowWebViewEditorFindWidgetCommand({
primary: KeyMod.CtrlCmd | KeyCode.KEY_F
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(showNextFindWdigetCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
showNextFindWdigetCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
const hideCommand = new HideWebViewEditorFindCommand({
id: HideWebViewEditorFindCommand.ID,
......@@ -56,7 +56,7 @@ const hideCommand = new HideWebViewEditorFindCommand({
primary: KeyCode.Escape
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(hideCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
hideCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
const selectAllCommand = new SelectAllWebviewEditorCommand({
id: SelectAllWebviewEditorCommand.ID,
......@@ -65,7 +65,7 @@ const selectAllCommand = new SelectAllWebviewEditorCommand({
primary: KeyMod.CtrlCmd | KeyCode.KEY_A
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(selectAllCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
selectAllCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
actionRegistry.registerWorkbenchAction(
new SyncActionDescriptor(OpenWebviewDeveloperToolsAction, OpenWebviewDeveloperToolsAction.ID, OpenWebviewDeveloperToolsAction.LABEL),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册