提交 ce86f17e 编写于 作者: A Alex Dima

Clean up `menuOpts`

上级 016c161e
......@@ -8,7 +8,7 @@ import {illegalArgument} from 'vs/base/common/errors';
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
import {ServicesAccessor, IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {KbExpr, IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {CommandsRegistry} from 'vs/platform/commands/common/commands';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {Registry} from 'vs/platform/platform';
......@@ -17,7 +17,7 @@ import {ICommandOptions, Command as ConfigBasicCommand, EditorCommand as ConfigE
import {Position} from 'vs/editor/common/core/position';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {IModelService} from 'vs/editor/common/services/modelService';
import {MenuId, MenuRegistry} from 'vs/platform/actions/common/actions';
import {MenuId, MenuRegistry, IMenuItem} from 'vs/platform/actions/common/actions';
export type ServicesAccessor = ServicesAccessor;
export const Command = ConfigBasicCommand;
......@@ -26,8 +26,6 @@ export type ICommandOptions = ICommandOptions;
// --- Keybinding extensions to make it more concise to express keybindings conditions
export interface IEditorCommandMenuOptions {
kbExpr: KbExpr;
menu?: MenuId;
group?: string;
order?: number;
}
......@@ -118,16 +116,9 @@ class EditorContributionRegistry {
public registerEditorAction(action:EditorAction) {
if (action.menuOpts) {
MenuRegistry.appendMenuItem(action.menuOpts.menu || MenuId.EditorContext, {
command: {
id: action.id,
title: action.label
},
when: action.menuOpts.kbExpr,
group: action.menuOpts.group,
order: action.menuOpts.order
});
let menuItem = action.toMenuItem();
if (menuItem) {
MenuRegistry.appendMenuItem(MenuId.EditorContext, menuItem);
}
KeybindingsRegistry.registerCommandAndKeybindingRule(action.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
......@@ -155,7 +146,7 @@ export abstract class EditorAction extends ConfigEditorCommand {
public label: string;
public alias: string;
public menuOpts: IEditorCommandMenuOptions;
private menuOpts: IEditorCommandMenuOptions;
constructor(opts:IActionOptions) {
super(opts);
......@@ -164,6 +155,22 @@ export abstract class EditorAction extends ConfigEditorCommand {
this.menuOpts = opts.menuOpts;
}
public toMenuItem(): IMenuItem {
if (!this.menuOpts) {
return null;
}
return {
command: {
id: this.id,
title: this.label
},
when: this.precondition,
group: this.menuOpts.group,
order: this.menuOpts.order
};
}
protected runEditorCommand(accessor:ServicesAccessor, editor: editorCommon.ICommonCodeEditor, args: any): void | TPromise<void> {
if (!this.enabled(accessor, editor)) {
return;
......
......@@ -13,7 +13,6 @@ import {ServicesAccessor} from 'vs/platform/instantiation/common/instantiation';
import {findFocusedEditor} from 'vs/editor/common/config/config';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {IActionOptions, EditorAction, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {MenuId} from 'vs/platform/actions/common/actions';
import EditorContextKeys = editorCommon.EditorContextKeys;
......@@ -59,8 +58,6 @@ class ExecCommandCutAction extends ExecCommandAction {
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_X, secondary: [KeyMod.Shift | KeyCode.Delete] }
},
menuOpts: {
kbExpr: EditorContextKeys.Writable,
menu: MenuId.EditorContext,
group: CLIPBOARD_CONTEXT_MENU_GROUP,
order: 1
}
......@@ -90,8 +87,6 @@ class ExecCommandCopyAction extends ExecCommandAction {
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_C, secondary: [KeyMod.CtrlCmd | KeyCode.Insert] }
},
menuOpts: {
kbExpr: null,
menu: MenuId.EditorContext,
group: CLIPBOARD_CONTEXT_MENU_GROUP,
order: 2
}
......@@ -121,8 +116,6 @@ class ExecCommandPasteAction extends ExecCommandAction {
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_V, secondary: [KeyMod.Shift | KeyCode.Insert] }
},
menuOpts: {
kbExpr: EditorContextKeys.Writable,
menu: MenuId.EditorContext,
group: CLIPBOARD_CONTEXT_MENU_GROUP,
order: 3
}
......
......@@ -665,15 +665,14 @@ export class CompatChangeAll extends AbstractSelectHighlightsAction {
id: 'editor.action.changeAll',
label: nls.localize('changeAll.label', "Change All Occurrences"),
alias: 'Change All Occurrences',
precondition: null,
precondition: EditorContextKeys.Writable,
kbOpts: {
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.CtrlCmd | KeyCode.F2
},
menuOpts: {
group: '1_modification',
order: 1.2,
kbExpr: EditorContextKeys.Writable
order: 1.2
}
});
}
......
......@@ -150,8 +150,7 @@ export class FormatAction extends EditorAction {
},
menuOpts: {
group: '1_modification',
order: 1.3,
kbExpr: ModeContextKeys.hasFormattingProvider
order: 1.3
}
});
}
......
......@@ -162,8 +162,7 @@ export class GoToDefinitionAction extends DefinitionAction {
},
menuOpts: {
group: 'navigation',
order: 1.1,
kbExpr: ModeContextKeys.hasDefinitionProvider
order: 1.1
}
});
}
......@@ -201,8 +200,7 @@ export class PeekDefinitionAction extends DefinitionAction {
},
menuOpts: {
group: 'navigation',
order: 1.2,
kbExpr: ModeContextKeys.hasDefinitionProvider
order: 1.2
}
});
}
......
......@@ -82,7 +82,6 @@ export class QuickCommandAction extends BaseEditorQuickOpenAction {
primary: (browser.isIE11orEarlier ? KeyMod.Alt | KeyCode.F1 : KeyCode.F1)
},
menuOpts: {
kbExpr: EditorContextKeys.Focus
}
});
}
......
......@@ -121,8 +121,7 @@ export class QuickOutlineAction extends BaseEditorQuickOpenAction {
},
menuOpts: {
group: 'navigation',
order: 3,
kbExpr: ModeContextKeys.hasDocumentSymbolProvider
order: 3
}
});
}
......
......@@ -67,7 +67,6 @@ export class ReferenceAction extends EditorAction {
primary: KeyMod.Shift | KeyCode.F12
},
menuOpts: {
kbExpr: ModeContextKeys.hasReferenceProvider,
group: 'navigation',
order: 1.3
}
......
......@@ -159,8 +159,7 @@ export class RenameAction extends EditorAction {
},
menuOpts: {
group: '1_modification',
order: 1.1,
kbExpr: KbExpr.and(ModeContextKeys.hasRenameProvider, EditorContextKeys.Writable)
order: 1.1
}
});
}
......
......@@ -600,7 +600,6 @@ export class RunToCursorAction extends EditorAction {
alias: 'Debug: Run to Cursor',
precondition: debug.CONTEXT_IN_DEBUG_MODE,
menuOpts: {
kbExpr: debug.CONTEXT_IN_DEBUG_MODE,
group: 'debug'
}
});
......@@ -658,9 +657,8 @@ export class SelectionToReplAction extends EditorAction {
id: 'editor.debug.action.selectionToRepl',
label: nls.localize('debugEvaluate', "Debug: Evaluate"),
alias: 'Debug: Evaluate',
precondition: debug.CONTEXT_IN_DEBUG_MODE,
precondition: KbExpr.and(EditorContextKeys.HasNonEmptySelection, debug.CONTEXT_IN_DEBUG_MODE),
menuOpts: {
kbExpr: KbExpr.and(EditorContextKeys.HasNonEmptySelection, debug.CONTEXT_IN_DEBUG_MODE),
group: 'debug'
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册