提交 820a8315 编写于 作者: J Johannes Rieken

remove getGroupId and shouldShowInContextMenu

上级 6df04efd
......@@ -40,13 +40,6 @@ export class EditorAction extends Action implements IEditorContribution {
super.dispose();
}
/**
* A helper to be able to group and sort actions when they are presented visually.
*/
public getGroupId(): string {
return this.id;
}
public getDescriptor(): IEditorActionDescriptorData {
return this._descriptor;
}
......@@ -118,11 +111,9 @@ export class HandlerEditorAction extends EditorAction {
export class DynamicEditorAction extends EditorAction {
private static _transformBehaviour(behaviour:IActionEnablement, contextMenuGroupId: string): Behaviour {
private static _transformBehaviour(behaviour:IActionEnablement): Behaviour {
var r = 0;
if (contextMenuGroupId) {
r |= Behaviour.ShowInContextMenu;
} else if (behaviour.textFocus) {
if (behaviour.textFocus) {
// Allowed to set text focus only if not appearing in the context menu
r |= Behaviour.TextFocus;
}
......@@ -142,7 +133,6 @@ export class DynamicEditorAction extends EditorAction {
return r;
}
private _contextMenuGroupId: string;
private _run: (editor:ICommonCodeEditor)=>void;
private _tokensAtPosition:string[];
private _wordAtPosition:boolean;
......@@ -152,19 +142,14 @@ export class DynamicEditorAction extends EditorAction {
super({
id: descriptor.id,
label: descriptor.label
}, editor, DynamicEditorAction._transformBehaviour(enablement, descriptor.contextMenuGroupId));
}, editor, DynamicEditorAction._transformBehaviour(enablement));
this._contextMenuGroupId = descriptor.contextMenuGroupId;
this._run = descriptor.run;
this._tokensAtPosition = enablement.tokensAtPosition;
this._wordAtPosition = enablement.wordAtPosition;
}
public getGroupId(): string {
return this._contextMenuGroupId;
}
public run(): TPromise<void> {
return TPromise.as(this._run(this.editor));
}
......
......@@ -3368,17 +3368,7 @@ export interface IActionDescriptor {
* A set of enablement conditions.
*/
enablement?: IActionEnablement;
/**
* Control if the action should show up in the context menu and where.
* Built-in groups:
* 1_goto/* => e.g. 1_goto/1_peekDefinition
* 2_change/* => e.g. 2_change/2_format
* 3_edit/* => e.g. 3_edit/1_copy
* 4_tools/* => e.g. 4_tools/1_commands
* You can also create your own group.
* Defaults to null (don't show in context menu).
*/
contextMenuGroupId?: string;
/**
* Method that will be executed when the action is triggered.
* @param editor The editor instance is passed in as a convinience
......
......@@ -66,10 +66,6 @@ class ExecCommandCutAction extends ClipboardWritingAction {
super(descriptor, editor, Behaviour.Writeable | Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange);
}
public getGroupId(): string {
return '3_edit/1_cut';
}
public getEnablementState(): boolean {
return super.getEnablementState() && editorCursorIsInEditableRange(this.editor);
}
......@@ -87,10 +83,6 @@ class ExecCommandCopyAction extends ClipboardWritingAction {
super(descriptor, editor, Behaviour.WidgetFocus);
}
public getGroupId(): string {
return '3_edit/2_copy';
}
public run(): TPromise<boolean> {
this.editor.focus();
document.execCommand('copy');
......@@ -104,10 +96,6 @@ class ExecCommandPasteAction extends EditorAction {
super(descriptor, editor, Behaviour.Writeable | Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange);
}
public getGroupId(): string {
return '3_edit/3_paste';
}
public getEnablementState(): boolean {
return editorCursorIsInEditableRange(this.editor);
}
......
......@@ -28,6 +28,19 @@ interface IPosition {
y: number;
}
interface OldContextMenuAction extends IAction {
getGroupId(): string;
shouldShowInContextMenu(): boolean;
isSupported(): boolean;
}
namespace OldContextMenuAction {
export function is(thing: any): thing is OldContextMenuAction {
return typeof (<OldContextMenuAction>thing).getGroupId === 'function'
&& typeof (<OldContextMenuAction>thing).shouldShowInContextMenu === 'function';
}
}
class ContextMenuController implements IEditorContribution {
public static ID = 'editor.contrib.contextmenu';
......@@ -130,8 +143,8 @@ class ContextMenuController implements IEditorContribution {
return [];
}
const contributedActions = <EditorAction[]>this._editor.getActions().filter(action => {
if (action instanceof EditorAction) {
const contributedActions = <OldContextMenuAction[]>this._editor.getActions().filter(action => {
if (OldContextMenuAction.is(action)) {
return action.shouldShowInContextMenu() && action.isSupported();
}
});
......@@ -141,7 +154,7 @@ class ContextMenuController implements IEditorContribution {
return actions;
}
private static _prepareActions(actions: EditorAction[]): IAction[] {
private static _prepareActions(actions: OldContextMenuAction[]): IAction[] {
const data = actions.map(action => {
const groupId = action.getGroupId();
......
......@@ -57,10 +57,6 @@ export class ReferenceAction extends EditorAction {
}
}
public getGroupId(): string {
return '1_goto/4_references';
}
public isSupported():boolean {
return ReferenceProviderRegistry.has(this.editor.getModel()) && super.isSupported();
}
......
......@@ -2795,17 +2795,6 @@ declare module monaco.editor {
* A set of enablement conditions.
*/
enablement?: IActionEnablement;
/**
* Control if the action should show up in the context menu and where.
* Built-in groups:
* 1_goto/* => e.g. 1_goto/1_peekDefinition
* 2_change/* => e.g. 2_change/2_format
* 3_edit/* => e.g. 3_edit/1_copy
* 4_tools/* => e.g. 4_tools/1_commands
* You can also create your own group.
* Defaults to null (don't show in context menu).
*/
contextMenuGroupId?: string;
/**
* Method that will be executed when the action is triggered.
* @param editor The editor instance is passed in as a convinience
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册