diff --git a/src/vs/editor/common/editorAction.ts b/src/vs/editor/common/editorAction.ts index 178965e37316f5f0259c046a44800b0fa5be523e..fc3e2132c69a98a44bf7986e8ce86012a94546a7 100644 --- a/src/vs/editor/common/editorAction.ts +++ b/src/vs/editor/common/editorAction.ts @@ -128,20 +128,6 @@ export class NewEditorAction extends EditorAction { } } -export class HandlerEditorAction extends EditorAction { - private _handlerId: string; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor, handlerId: string) { - super(descriptor, editor); - this._handlerId = handlerId; - } - - public run(): TPromise { - this.editor.trigger(this.getId(), this._handlerId, null); - return TPromise.as(true); - } -} - export class DynamicEditorAction extends EditorAction { private static _transformBehaviour(behaviour:IActionEnablement): Behaviour { diff --git a/src/vs/editor/common/editorCommonExtensions.ts b/src/vs/editor/common/editorCommonExtensions.ts index d5c44f80ffcdbd314aeaee5c1a90ddc536fa030f..89eefa074e97198d6c171bd068a00f4f784465c5 100644 --- a/src/vs/editor/common/editorCommonExtensions.ts +++ b/src/vs/editor/common/editorCommonExtensions.ts @@ -378,6 +378,19 @@ export abstract class EditorAction2 { public abstract run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void | TPromise; } +export abstract class HandlerEditorAction2 extends EditorAction2 { + private _handlerId: string; + + constructor(id:string, label:string, alias:string, needsWritableEditor:boolean, handlerId: string) { + super(id, label, alias, needsWritableEditor); + this._handlerId = handlerId; + } + + public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void { + editor.trigger(this.id, this._handlerId, null); + } +} + export let EditorKbExpr: { TextFocus: KbExpr; Focus: KbExpr; diff --git a/src/vs/editor/contrib/linesOperations/common/linesOperations.ts b/src/vs/editor/contrib/linesOperations/common/linesOperations.ts index b657ecd4d4eb086c49ee33a881a0e978bc22b00d..303af21ef328c4279d0e9a29dd1423c1f69fba67 100644 --- a/src/vs/editor/contrib/linesOperations/common/linesOperations.ts +++ b/src/vs/editor/contrib/linesOperations/common/linesOperations.ts @@ -6,154 +6,205 @@ import * as nls from 'vs/nls'; import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; -import {TPromise} from 'vs/base/common/winjs.base'; import {SortLinesCommand} from 'vs/editor/contrib/linesOperations/common/sortLinesCommand'; import {TrimTrailingWhitespaceCommand} from 'vs/editor/common/commands/trimTrailingWhitespaceCommand'; -import {EditorAction, HandlerEditorAction} from 'vs/editor/common/editorAction'; -import {Handler, ICommand, ICommonCodeEditor, IEditorActionDescriptorData} from 'vs/editor/common/editorCommon'; -import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {Handler, ICommand, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {ServicesAccessor, EditorKbExpr, EditorAction2, HandlerEditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions'; import {CopyLinesCommand} from './copyLinesCommand'; import {DeleteLinesCommand} from './deleteLinesCommand'; import {MoveLinesCommand} from './moveLinesCommand'; // copy lines -class CopyLinesAction extends EditorAction { +abstract class AbstractCopyLinesAction extends EditorAction2 { private down:boolean; - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor, down:boolean) { - super(descriptor, editor); + constructor(id:string, label:string, alias:string, down:boolean) { + super(id, label, alias, true); this.down = down; } - public run():TPromise { + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void { var commands:ICommand[] = []; - var selections = this.editor.getSelections(); + var selections = editor.getSelections(); for (var i = 0; i < selections.length; i++) { commands.push(new CopyLinesCommand(selections[i], this.down)); } - this.editor.executeCommands(this.id, commands); - - return TPromise.as(true); + editor.executeCommands(this.id, commands); } } -class CopyLinesUpAction extends CopyLinesAction { - static ID = 'editor.action.copyLinesUpAction'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, false); +class CopyLinesUpAction extends AbstractCopyLinesAction { + constructor() { + super( + 'editor.action.copyLinesUpAction', + nls.localize('lines.copyUp', "Copy Line Up"), + 'Copy Line Up', + false + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.Alt | KeyMod.Shift | KeyCode.UpArrow, + linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyMod.Shift | KeyCode.UpArrow } + }; } - } -class CopyLinesDownAction extends CopyLinesAction { - static ID = 'editor.action.copyLinesDownAction'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, true); +class CopyLinesDownAction extends AbstractCopyLinesAction { + constructor() { + super( + 'editor.action.copyLinesDownAction', + nls.localize('lines.copyDown', "Copy Line Down"), + 'Copy Line Down', + true + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.Alt | KeyMod.Shift | KeyCode.DownArrow, + linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyMod.Shift | KeyCode.DownArrow } + }; } } // move lines -class MoveLinesAction extends EditorAction { +abstract class AbstractMoveLinesAction extends EditorAction2 { private down:boolean; - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor, down:boolean) { - super(descriptor, editor); + constructor(id:string, label:string, alias:string, down:boolean) { + super(id, label, alias, true); this.down = down; } - public run():TPromise { + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void { var commands:ICommand[] = []; - var selections = this.editor.getSelections(); + var selections = editor.getSelections(); for (var i = 0; i < selections.length; i++) { commands.push(new MoveLinesCommand(selections[i], this.down)); } - this.editor.executeCommands(this.id, commands); - - return TPromise.as(true); + editor.executeCommands(this.id, commands); } } -class MoveLinesUpAction extends MoveLinesAction { - static ID = 'editor.action.moveLinesUpAction'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, false); +class MoveLinesUpAction extends AbstractMoveLinesAction { + constructor() { + super( + 'editor.action.moveLinesUpAction', + nls.localize('lines.moveUp', "Move Line Up"), + 'Move Line Up', + false + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.Alt | KeyCode.UpArrow, + linux: { primary: KeyMod.Alt | KeyCode.UpArrow } + }; } } -class MoveLinesDownAction extends MoveLinesAction { - static ID = 'editor.action.moveLinesDownAction'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, true); +class MoveLinesDownAction extends AbstractMoveLinesAction { + constructor() { + super( + 'editor.action.moveLinesDownAction', + nls.localize('lines.moveDown', "Move Line Down"), + 'Move Line Down', + true + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.Alt | KeyCode.DownArrow, + linux: { primary: KeyMod.Alt | KeyCode.DownArrow } + }; } } -class SortLinesAction extends EditorAction { +abstract class AbstractSortLinesAction extends EditorAction2 { private descending:boolean; - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor, descending:boolean) { - super(descriptor, editor); + constructor(id:string, label:string, alias:string, descending:boolean) { + super(id, label, alias, true); this.descending = descending; } - public run():TPromise { + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void { - if (!SortLinesCommand.canRun(this.editor.getModel(), this.editor.getSelection(), this.descending)) { - return TPromise.as(false); + if (!SortLinesCommand.canRun(editor.getModel(), editor.getSelection(), this.descending)) { + return; } - var command = new SortLinesCommand(this.editor.getSelection(), this.descending); + var command = new SortLinesCommand(editor.getSelection(), this.descending); - this.editor.executeCommands(this.id, [command]); - - return TPromise.as(true); + editor.executeCommands(this.id, [command]); } } -class SortLinesAscendingAction extends SortLinesAction { - static ID ='editor.action.sortLinesAscending'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, false); +class SortLinesAscendingAction extends AbstractSortLinesAction { + constructor() { + super( + 'editor.action.sortLinesAscending', + nls.localize('lines.sortAscending', "Sort Lines Ascending"), + 'Sort Lines Ascending', + false + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_2 + }; } } -class SortLinesDescendingAction extends SortLinesAction { - static ID ='editor.action.sortLinesDescending'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, true); +class SortLinesDescendingAction extends AbstractSortLinesAction { + constructor() { + super( + 'editor.action.sortLinesDescending', + nls.localize('lines.sortDescending', "Sort Lines Descending"), + 'Sort Lines Descending', + true + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_3 + }; } } -export class TrimTrailingWhitespaceAction extends EditorAction { +export class TrimTrailingWhitespaceAction extends EditorAction2 { static ID = 'editor.action.trimTrailingWhitespace'; - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor); + constructor() { + super( + TrimTrailingWhitespaceAction.ID, + nls.localize('lines.trimTrailingWhitespace', "Trim Trailing Whitespace"), + 'Trim Trailing Whitespace', + true + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_X) + }; } - public run():TPromise { - - var command = new TrimTrailingWhitespaceCommand(this.editor.getSelection()); + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void { - this.editor.executeCommands(this.id, [command]); + var command = new TrimTrailingWhitespaceCommand(editor.getSelection()); - return TPromise.as(true); + editor.executeCommands(this.id, [command]); } } @@ -165,15 +216,15 @@ interface IDeleteLinesOperation { positionColumn:number; } -class AbstractRemoveLinesAction extends EditorAction { +abstract class AbstractRemoveLinesAction extends EditorAction2 { - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor); + constructor(id:string, label:string, alias:string) { + super(id, label, alias, true); } - _getLinesToRemove(): IDeleteLinesOperation[] { + _getLinesToRemove(editor:ICommonCodeEditor): IDeleteLinesOperation[] { // Construct delete operations - var operations:IDeleteLinesOperation[] = this.editor.getSelections().map((s) => { + var operations:IDeleteLinesOperation[] = editor.getSelections().map((s) => { var endLineNumber = s.endLineNumber; if (s.startLineNumber < s.endLineNumber && s.endColumn === 1) { @@ -215,109 +266,110 @@ class AbstractRemoveLinesAction extends EditorAction { class DeleteLinesAction extends AbstractRemoveLinesAction { - static ID = 'editor.action.deleteLines'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor); + constructor() { + super( + 'editor.action.deleteLines', + nls.localize('lines.delete', "Delete Line"), + 'Delete Line' + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_K + }; } - public run():TPromise { + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void { - var ops = this._getLinesToRemove(); + var ops = this._getLinesToRemove(editor); // Finally, construct the delete lines commands var commands:ICommand[] = ops.map((op) => { return new DeleteLinesCommand(op.startLineNumber, op.endLineNumber, op.positionColumn); }); - this.editor.executeCommands(this.id, commands); - - return TPromise.as(true); + editor.executeCommands(this.id, commands); } } -class IndentLinesAction extends HandlerEditorAction { - static ID = 'editor.action.indentLines'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, Handler.Indent); +class IndentLinesAction extends HandlerEditorAction2 { + constructor() { + super( + 'editor.action.indentLines', + nls.localize('lines.indent', "Indent Line"), + 'Indent Line', + true, + Handler.Indent + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyCode.US_CLOSE_SQUARE_BRACKET + }; } } -class OutdentLinesAction extends HandlerEditorAction { - static ID = 'editor.action.outdentLines'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, Handler.Outdent); +class OutdentLinesAction extends HandlerEditorAction2 { + constructor() { + super( + 'editor.action.outdentLines', + nls.localize('lines.outdent', "Outdent Line"), + 'Outdent Line', + true, + Handler.Outdent + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyCode.US_OPEN_SQUARE_BRACKET + }; } } -class InsertLineBeforeAction extends HandlerEditorAction { - static ID = 'editor.action.insertLineBefore'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, Handler.LineInsertBefore); +class InsertLineBeforeAction extends HandlerEditorAction2 { + constructor() { + super( + 'editor.action.insertLineBefore', + nls.localize('lines.insertBefore', "Insert Line Above"), + 'Insert Line Above', + true, + Handler.LineInsertBefore + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Enter + }; } } -class InsertLineAfterAction extends HandlerEditorAction { - static ID = 'editor.action.insertLineAfter'; - - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, Handler.LineInsertAfter); +class InsertLineAfterAction extends HandlerEditorAction2 { + constructor() { + super( + 'editor.action.insertLineAfter', + nls.localize('lines.insertAfter', "Insert Line Below"), + 'Insert Line Below', + true, + Handler.LineInsertAfter + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyCode.Enter + }; } } // register actions -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(DeleteLinesAction, DeleteLinesAction.ID, nls.localize('lines.delete', "Delete Line"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_K -}, 'Delete Line')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(SortLinesAscendingAction, SortLinesAscendingAction.ID, nls.localize('lines.sortAscending', "Sort Lines Ascending"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_2 -}, 'Sort Lines Ascending')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(SortLinesDescendingAction, SortLinesDescendingAction.ID, nls.localize('lines.sortDescending', "Sort Lines Descending"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_3 -}, 'Sort Lines Descending')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(TrimTrailingWhitespaceAction, TrimTrailingWhitespaceAction.ID, nls.localize('lines.trimTrailingWhitespace', "Trim Trailing Whitespace"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_X) -}, 'Trim Trailing Whitespace')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(MoveLinesDownAction, MoveLinesDownAction.ID, nls.localize('lines.moveDown', "Move Line Down"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.Alt | KeyCode.DownArrow, - linux: { primary: KeyMod.Alt | KeyCode.DownArrow } -}, 'Move Line Down')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(MoveLinesUpAction, MoveLinesUpAction.ID, nls.localize('lines.moveUp', "Move Line Up"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.Alt | KeyCode.UpArrow, - linux: { primary: KeyMod.Alt | KeyCode.UpArrow } -}, 'Move Line Up')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(CopyLinesDownAction, CopyLinesDownAction.ID, nls.localize('lines.copyDown', "Copy Line Down"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.Alt | KeyMod.Shift | KeyCode.DownArrow, - linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyMod.Shift | KeyCode.DownArrow } -}, 'Copy Line Down')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(CopyLinesUpAction, CopyLinesUpAction.ID, nls.localize('lines.copyUp', "Copy Line Up"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.Alt | KeyMod.Shift | KeyCode.UpArrow, - linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyMod.Shift | KeyCode.UpArrow } -}, 'Copy Line Up')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentLinesAction, IndentLinesAction.ID, nls.localize('lines.indent', "Indent Line"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyCode.US_CLOSE_SQUARE_BRACKET -}, 'Indent Line')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(OutdentLinesAction, OutdentLinesAction.ID, nls.localize('lines.outdent', "Outdent Line"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyCode.US_OPEN_SQUARE_BRACKET -}, 'Outdent Line')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InsertLineBeforeAction, InsertLineBeforeAction.ID, nls.localize('lines.insertBefore', "Insert Line Above"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Enter -}, 'Insert Line Above')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InsertLineAfterAction, InsertLineAfterAction.ID, nls.localize('lines.insertAfter', "Insert Line Below"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyCode.Enter -}, 'Insert Line Below')); +CommonEditorRegistry.registerEditorAction2(new DeleteLinesAction()); +CommonEditorRegistry.registerEditorAction2(new SortLinesAscendingAction()); +CommonEditorRegistry.registerEditorAction2(new SortLinesDescendingAction()); +CommonEditorRegistry.registerEditorAction2(new TrimTrailingWhitespaceAction()); +CommonEditorRegistry.registerEditorAction2(new MoveLinesDownAction()); +CommonEditorRegistry.registerEditorAction2(new MoveLinesUpAction()); +CommonEditorRegistry.registerEditorAction2(new CopyLinesDownAction()); +CommonEditorRegistry.registerEditorAction2(new CopyLinesUpAction()); +CommonEditorRegistry.registerEditorAction2(new IndentLinesAction()); +CommonEditorRegistry.registerEditorAction2(new OutdentLinesAction()); +CommonEditorRegistry.registerEditorAction2(new InsertLineBeforeAction()); +CommonEditorRegistry.registerEditorAction2(new InsertLineAfterAction()); diff --git a/src/vs/editor/contrib/links/browser/links.ts b/src/vs/editor/contrib/links/browser/links.ts index 730811c4d9d9823599fa4e37e8ff86c7b9cda7ab..de4fe30e9f3ba920e3c673feff051d7b64753ab2 100644 --- a/src/vs/editor/contrib/links/browser/links.ts +++ b/src/vs/editor/contrib/links/browser/links.ts @@ -15,10 +15,8 @@ import {TPromise} from 'vs/base/common/winjs.base'; import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent'; import {IMessageService} from 'vs/platform/message/common/message'; import {IOpenerService} from 'vs/platform/opener/common/opener'; -import {EditorAction} from 'vs/editor/common/editorAction'; -import {Behaviour} from 'vs/editor/common/editorActionEnablement'; import * as editorCommon from 'vs/editor/common/editorCommon'; -import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {ServicesAccessor, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions'; import {LinkProviderRegistry} from 'vs/editor/common/modes'; import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService'; import {IEditorMouseEvent, ICodeEditor} from 'vs/editor/browser/editorBrowser'; @@ -317,37 +315,34 @@ class LinkDetector implements editorCommon.IEditorContribution { } } -class OpenLinkAction extends EditorAction { +class OpenLinkAction extends EditorAction2 { - static ID = 'editor.action.openLink'; - - constructor( - descriptor: editorCommon.IEditorActionDescriptorData, - editor: editorCommon.ICommonCodeEditor - ) { - super(descriptor, editor, Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange); - } - - public dispose(): void { - super.dispose(); + constructor() { + super( + 'editor.action.openLink', + nls.localize('label', "Open Link"), + 'Open Link', + false + ); } - public getEnablementState(): boolean { - if (LinkDetector.get(this.editor).isComputing()) { + public enabled(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean { + let linkDetector = LinkDetector.get(editor); + if (linkDetector.isComputing()) { // optimistic enablement while state is being computed return true; } - return !!LinkDetector.get(this.editor).getLinkOccurence(this.editor.getPosition()); + return !!linkDetector.getLinkOccurence(editor.getPosition()); } - public run(): TPromise { - var link = LinkDetector.get(this.editor).getLinkOccurence(this.editor.getPosition()); + public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void { + let linkDetector = LinkDetector.get(editor); + let link = linkDetector.getLinkOccurence(editor.getPosition()); if (link) { - LinkDetector.get(this.editor).openLinkOccurence(link, false); + linkDetector.openLinkOccurence(link, false); } - return TPromise.as(null); } } -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(OpenLinkAction, OpenLinkAction.ID, nls.localize('label', "Open Link"), void 0, 'Open Link')); +CommonEditorRegistry.registerEditorAction2(new OpenLinkAction()); EditorBrowserRegistry.registerEditorContribution(LinkDetector); diff --git a/src/vs/editor/contrib/multicursor/common/multicursor.ts b/src/vs/editor/contrib/multicursor/common/multicursor.ts index b1d86651c8be0115ca3993f570b819a28d316e0d..47dd209a1b8e513cb4b9a16eefa21d0fdba264c2 100644 --- a/src/vs/editor/contrib/multicursor/common/multicursor.ts +++ b/src/vs/editor/contrib/multicursor/common/multicursor.ts @@ -6,84 +6,101 @@ import * as nls from 'vs/nls'; import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; -import {TPromise} from 'vs/base/common/winjs.base'; -import {EditorAction, HandlerEditorAction} from 'vs/editor/common/editorAction'; -import {Handler, ICommonCodeEditor, IEditorActionDescriptorData, ISelection} from 'vs/editor/common/editorCommon'; -import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {Handler, ICommonCodeEditor, ISelection} from 'vs/editor/common/editorCommon'; +import {ServicesAccessor, EditorKbExpr, EditorAction2, HandlerEditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions'; -class InsertCursorAbove extends HandlerEditorAction { - static ID = 'editor.action.insertCursorAbove'; +class InsertCursorAbove extends HandlerEditorAction2 { + constructor() { + super( + 'editor.action.insertCursorAbove', + nls.localize('mutlicursor.insertAbove', "Add Cursor Above"), + 'Add Cursor Above', + false, + Handler.AddCursorUp + ); - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, Handler.AddCursorUp); + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.UpArrow, + linux: { + primary: KeyMod.Shift | KeyMod.Alt | KeyCode.UpArrow, + secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow] + } + }; } } -class InsertCursorBelow extends HandlerEditorAction { - static ID = 'editor.action.insertCursorBelow'; +class InsertCursorBelow extends HandlerEditorAction2 { + constructor() { + super( + 'editor.action.insertCursorBelow', + nls.localize('mutlicursor.insertBelow', "Add Cursor Below"), + 'Add Cursor Below', + false, + Handler.AddCursorDown + ); - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, Handler.AddCursorDown); + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.DownArrow, + linux: { + primary: KeyMod.Shift | KeyMod.Alt | KeyCode.DownArrow, + secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.DownArrow] + } + }; } } -class InsertCursorAtEndOfEachLineSelected extends EditorAction { - static ID = 'editor.action.insertCursorAtEndOfEachLineSelected'; +class InsertCursorAtEndOfEachLineSelected extends EditorAction2 { - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor); + constructor() { + super( + 'editor.action.insertCursorAtEndOfEachLineSelected', + nls.localize('mutlicursor.insertAtEndOfEachLineSelected', "Create Multiple Cursors from Selected Lines"), + 'Create Multiple Cursors from Selected Lines', + false + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_I + }; } - public run(): TPromise { - let selection = this.editor.getSelection(); - if(!selection.isEmpty()) { - let model = this.editor.getModel(); - let newSelections = new Array(); - let selectionStart = selection.getStartPosition(); - let selectionEnd = selection.getEndPosition(); - for (var i = selectionStart.lineNumber; i <= selectionEnd.lineNumber; i++) { - if(i !== selectionEnd.lineNumber) { - let currentLineMaxColumn = model.getLineMaxColumn(i); - newSelections.push({ - selectionStartLineNumber: i, - selectionStartColumn: currentLineMaxColumn, - positionLineNumber: i, - positionColumn: currentLineMaxColumn - }); - } else if( selectionEnd.column > 0 ) { - newSelections.push({ - selectionStartLineNumber: selectionEnd.lineNumber, - selectionStartColumn: selectionEnd.column, - positionLineNumber: selectionEnd.lineNumber, - positionColumn: selectionEnd.column - }); - } + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void { + let selection = editor.getSelection(); + if (selection.isEmpty()) { + return; + } + + let model = editor.getModel(); + let newSelections = new Array(); + let selectionStart = selection.getStartPosition(); + let selectionEnd = selection.getEndPosition(); + for (var i = selectionStart.lineNumber; i <= selectionEnd.lineNumber; i++) { + if(i !== selectionEnd.lineNumber) { + let currentLineMaxColumn = model.getLineMaxColumn(i); + newSelections.push({ + selectionStartLineNumber: i, + selectionStartColumn: currentLineMaxColumn, + positionLineNumber: i, + positionColumn: currentLineMaxColumn + }); + } else if( selectionEnd.column > 0 ) { + newSelections.push({ + selectionStartLineNumber: selectionEnd.lineNumber, + selectionStartColumn: selectionEnd.column, + positionLineNumber: selectionEnd.lineNumber, + positionColumn: selectionEnd.column + }); } - this.editor.setSelections(newSelections); } - return TPromise.as(true); + editor.setSelections(newSelections); } } // register actions -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InsertCursorAbove, InsertCursorAbove.ID, nls.localize('mutlicursor.insertAbove', "Add Cursor Above"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.UpArrow, - linux: { - primary: KeyMod.Shift | KeyMod.Alt | KeyCode.UpArrow, - secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow] - } -}, 'Add Cursor Above')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InsertCursorBelow, InsertCursorBelow.ID, nls.localize('mutlicursor.insertBelow', "Add Cursor Below"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.DownArrow, - linux: { - primary: KeyMod.Shift | KeyMod.Alt | KeyCode.DownArrow, - secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.DownArrow] - } -}, 'Add Cursor Below')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InsertCursorAtEndOfEachLineSelected, InsertCursorAtEndOfEachLineSelected.ID, nls.localize('mutlicursor.insertAtEndOfEachLineSelected', "Create Multiple Cursors from Selected Lines"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_I -}, 'Create Multiple Cursors from Selected Lines')); +CommonEditorRegistry.registerEditorAction2(new InsertCursorAbove()); +CommonEditorRegistry.registerEditorAction2(new InsertCursorBelow()); +CommonEditorRegistry.registerEditorAction2(new InsertCursorAtEndOfEachLineSelected()); diff --git a/src/vs/editor/contrib/parameterHints/browser/parameterHints.ts b/src/vs/editor/contrib/parameterHints/browser/parameterHints.ts index b92b5aadaae2613889953ae421f07f0e11ad83e6..c1454f9d24fe57ece1e3c825b1e7e800e84352ba 100644 --- a/src/vs/editor/contrib/parameterHints/browser/parameterHints.ts +++ b/src/vs/editor/contrib/parameterHints/browser/parameterHints.ts @@ -6,15 +6,13 @@ import * as nls from 'vs/nls'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; -import { TPromise } from 'vs/base/common/winjs.base'; import { dispose } from 'vs/base/common/lifecycle'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { EditorAction } from 'vs/editor/common/editorAction'; -import { ICommonCodeEditor, IEditorActionDescriptorData, IEditorContribution, KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS } from 'vs/editor/common/editorCommon'; +import { ICommonCodeEditor, IEditorContribution, KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS } from 'vs/editor/common/editorCommon'; import { KbExpr } from 'vs/platform/keybinding/common/keybinding'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { withCodeEditorFromCommandHandler } from 'vs/editor/common/config/config'; -import { CommonEditorRegistry, ContextKey, EditorActionDescriptor } from 'vs/editor/common/editorCommonExtensions'; +import { ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorBrowserRegistry } from 'vs/editor/browser/editorBrowserExtensions'; import { SignatureHelpProviderRegistry } from 'vs/editor/common/modes'; @@ -62,21 +60,31 @@ class ParameterHintsController implements IEditorContribution { } } -export class TriggerParameterHintsAction extends EditorAction { +export class TriggerParameterHintsAction extends EditorAction2 { - static ID = 'editor.action.triggerParameterHints'; + constructor() { + super( + 'editor.action.triggerParameterHints', + nls.localize('parameterHints.trigger.label', "Trigger Parameter Hints"), + 'Trigger Parameter Hints', + false + ); - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor); + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Space + }; } - isSupported(): boolean { - return SignatureHelpProviderRegistry.has(this.editor.getModel()) && super.isSupported(); + public supported(accessor:ServicesAccessor, editor:ICommonCodeEditor): boolean { + if (!super.supported(accessor, editor)) { + return false; + } + return SignatureHelpProviderRegistry.has(editor.getModel()); } - run():TPromise { - ParameterHintsController.get(this.editor).trigger(); - return TPromise.as(true); + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void { + ParameterHintsController.get(editor).trigger(); } } @@ -90,13 +98,7 @@ function handler(id: string, fn: (controller: ParameterHintsController) => void) EditorBrowserRegistry.registerEditorContribution(ParameterHintsController); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor( - TriggerParameterHintsAction, - TriggerParameterHintsAction.ID, - nls.localize('parameterHints.trigger.label', "Trigger Parameter Hints"), - { context: ContextKey.EditorTextFocus, primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Space }, - 'Trigger Parameter Hints' -)); +CommonEditorRegistry.registerEditorAction2(new TriggerParameterHintsAction()); KeybindingsRegistry.registerCommandDesc({ id: 'closeParameterHints', diff --git a/src/vs/editor/contrib/quickFix/browser/quickFix.ts b/src/vs/editor/contrib/quickFix/browser/quickFix.ts index cab1bb1c4ae3de21e6221cfb8bf797d131560c46..776c190ee069f47c4943ee89539dc8583e5e761c 100644 --- a/src/vs/editor/contrib/quickFix/browser/quickFix.ts +++ b/src/vs/editor/contrib/quickFix/browser/quickFix.ts @@ -7,16 +7,14 @@ import * as nls from 'vs/nls'; import {onUnexpectedError} from 'vs/base/common/errors'; import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; -import {TPromise} from 'vs/base/common/winjs.base'; import {IEditorService} from 'vs/platform/editor/common/editor'; import {ICommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {IMarkerService} from 'vs/platform/markers/common/markers'; import {IMessageService} from 'vs/platform/message/common/message'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; -import {EditorAction} from 'vs/editor/common/editorAction'; -import {ICommonCodeEditor, IEditorActionDescriptorData, IEditorContribution, IRange} from 'vs/editor/common/editorCommon'; -import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {ICommonCodeEditor, IEditorContribution, IRange} from 'vs/editor/common/editorCommon'; +import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions'; import {ICodeEditor} from 'vs/editor/browser/editorBrowser'; import {CodeActionProviderRegistry} from 'vs/editor/common/modes'; import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions'; @@ -69,10 +67,9 @@ export class QuickFixController implements IEditorContribution { } } - public run():TPromise { + public run(): void { this.model.triggerDialog(false, this.editor.getPosition()); this.editor.focus(); - return TPromise.as(false); } public dispose(): void { @@ -118,21 +115,31 @@ export class QuickFixController implements IEditorContribution { } } -export class QuickFixAction extends EditorAction { +export class QuickFixAction extends EditorAction2 { - static ID = 'editor.action.quickFix'; + constructor() { + super( + 'editor.action.quickFix', + nls.localize('quickfix.trigger.label', "Quick Fix"), + 'Quick Fix', + true + ); - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor); + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyCode.US_DOT + }; } - public isSupported(): boolean { - var model = this.editor.getModel(); - return CodeActionProviderRegistry.has(model) && !this.editor.getConfiguration().readOnly; + public supported(accessor:ServicesAccessor, editor:ICommonCodeEditor): boolean { + if (!super.supported(accessor, editor)) { + return false; + } + return CodeActionProviderRegistry.has(editor.getModel()); } - public run():TPromise { - return QuickFixController.getQuickFixController(this.editor).run(); + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void { + QuickFixController.getQuickFixController(editor).run(); } } @@ -141,10 +148,7 @@ var CONTEXT_QUICK_FIX_WIDGET_VISIBLE = 'quickFixWidgetVisible'; var weight = CommonEditorRegistry.commandWeight(80); // register action -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(QuickFixAction, QuickFixAction.ID, nls.localize('quickfix.trigger.label', "Quick Fix"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyCode.US_DOT -}, 'Quick Fix')); +CommonEditorRegistry.registerEditorAction2(new QuickFixAction()); CommonEditorRegistry.registerEditorCommand('acceptQuickFixSuggestion', weight, { primary: KeyCode.Enter, secondary: [KeyCode.Tab] }, false, CONTEXT_QUICK_FIX_WIDGET_VISIBLE,(ctx, editor, args) => { var controller = QuickFixController.getQuickFixController(editor); controller.acceptSelectedSuggestion(); diff --git a/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts b/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts index b0e7918ed5bdbb153caf3049e66b5b2519178a30..71a825fff9f643425d808141ea6d2cffaac1789b 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts @@ -15,17 +15,14 @@ import {IKeybindingService, KbExpr} from 'vs/platform/keybinding/common/keybindi import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry'; import {Position} from 'vs/editor/common/core/position'; import {Range} from 'vs/editor/common/core/range'; -import {EditorAction} from 'vs/editor/common/editorAction'; -import {Behaviour} from 'vs/editor/common/editorActionEnablement'; import * as editorCommon from 'vs/editor/common/editorCommon'; -import {CommonEditorRegistry, ContextKey} from 'vs/editor/common/editorCommonExtensions'; +import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions'; import {Location, ReferenceProviderRegistry} from 'vs/editor/common/modes'; import {IPeekViewService, getOuterEditor} from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget'; import {provideReferences} from '../common/referenceSearch'; import {ReferenceWidget} from './referencesWidget'; import {ReferencesController, RequestOptions, ctxReferenceSearchVisible} from './referencesController'; import {ReferencesModel} from './referencesModel'; -import {ServicesAccessor} from 'vs/platform/instantiation/common/instantiation'; const defaultReferenceSearchOptions: RequestOptions = { getMetaTitle(model) { @@ -33,48 +30,75 @@ const defaultReferenceSearchOptions: RequestOptions = { } }; -export class ReferenceAction extends EditorAction { +export class ReferenceController implements editorCommon.IEditorContribution { - public static ID = 'editor.action.referenceSearch.trigger'; - - private peekViewService: IPeekViewService; - - // state - changes with every invocation + static ID = 'editor.contrib.referenceController'; constructor( - descriptor: editorCommon.IEditorActionDescriptorData, - editor: editorCommon.ICommonCodeEditor, + editor:editorCommon.ICommonCodeEditor, @IKeybindingService keybindingService: IKeybindingService, @optional(IPeekViewService) peekViewService: IPeekViewService ) { - super(descriptor, editor, Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange); + if (peekViewService) { + keybindingService.createKey(peekViewService.contextKey, true); + } + } - this.label = nls.localize('references.action.label', "Find All References"); + public dispose(): void { + } - this.peekViewService = peekViewService; - if (this.peekViewService) { - keybindingService.createKey(this.peekViewService.contextKey, true); - } + public getId(): string { + return ReferenceController.ID; } +} - public isSupported():boolean { - return ReferenceProviderRegistry.has(this.editor.getModel()) && super.isSupported(); +export class ReferenceAction extends EditorAction2 { + + constructor() { + super( + 'editor.action.referenceSearch.trigger', + nls.localize('references.action.label', "Find All References"), + 'Find All References', + false + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.Shift | KeyCode.F12 + }; + + this.menuOpts = { + kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasReferenceProvider), + group: 'navigation', + order: 1.3 + }; } - public getEnablementState():boolean { - if(this.peekViewService && this.peekViewService.isActive) { + public supported(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean { + if (!super.supported(accessor, editor)) { return false; } + return ReferenceProviderRegistry.has(editor.getModel()); + } - return ReferenceProviderRegistry.has(this.editor.getModel()); + public enabled(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean { + if (!super.enabled(accessor, editor)) { + return false; + } + const peekViewService = accessor.get(IPeekViewService, optional); + if (peekViewService && peekViewService.isActive) { + return false; + } + + return ReferenceProviderRegistry.has(editor.getModel()); } - public run():TPromise { - let range = this.editor.getSelection(); - let model = this.editor.getModel(); + public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void { + let range = editor.getSelection(); + let model = editor.getModel(); let references = provideReferences(model, range.getStartPosition()).then(references => new ReferencesModel(references)); - let controller = ReferencesController.getController(this.editor); - return TPromise.as(controller.toggleWidget(range, references, defaultReferenceSearchOptions)).then(() => true); + let controller = ReferencesController.getController(editor); + controller.toggleWidget(range, references, defaultReferenceSearchOptions); } } @@ -126,21 +150,8 @@ let showReferencesCommand: ICommandHandler = (accessor:ServicesAccessor, resourc // register action -CommonEditorRegistry.registerEditorAction({ - ctor: ReferenceAction, - id: ReferenceAction.ID, - label: nls.localize('references.action.name', "Find All References"), - alias: 'Find All References', - kbOpts: { - context: ContextKey.EditorTextFocus, - primary: KeyMod.Shift | KeyCode.F12 - }, - menuOpts: { - kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasReferenceProvider), - group: 'navigation', - order: 1.3 - } -}); +CommonEditorRegistry.registerEditorContribution(ReferenceController); +CommonEditorRegistry.registerEditorAction2(new ReferenceAction()); KeybindingsRegistry.registerCommandDesc({ id: 'editor.action.findReferences', diff --git a/src/vs/editor/contrib/rename/browser/rename.ts b/src/vs/editor/contrib/rename/browser/rename.ts index 1db588074377ba4b9c992a571727cef5a3bd680a..6e65859939206452e648adaf68431d77baf81e52 100644 --- a/src/vs/editor/contrib/rename/browser/rename.ts +++ b/src/vs/editor/contrib/rename/browser/rename.ts @@ -15,11 +15,10 @@ import {IEventService} from 'vs/platform/event/common/event'; import {IKeybindingContextKey, IKeybindingService, KbExpr} from 'vs/platform/keybinding/common/keybinding'; import {IMessageService} from 'vs/platform/message/common/message'; import {IProgressService} from 'vs/platform/progress/common/progress'; -import {EditorAction} from 'vs/editor/common/editorAction'; -import {Behaviour} from 'vs/editor/common/editorActionEnablement'; -import {IEditorActionDescriptorData, IRange} from 'vs/editor/common/editorCommon'; -import {CommonEditorRegistry, ContextKey} from 'vs/editor/common/editorCommonExtensions'; -import {KEYBINDING_CONTEXT_EDITOR_READONLY, ModeContextKeys} from 'vs/editor/common/editorCommon'; +import {IRange, ICommonCodeEditor} from 'vs/editor/common/editorCommon'; +import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions'; +import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions'; +import {KEYBINDING_CONTEXT_EDITOR_READONLY, ModeContextKeys, IEditorContribution} from 'vs/editor/common/editorCommon'; import {BulkEdit, createBulkEdit} from 'vs/editor/common/services/bulkEdit'; import {RenameProviderRegistry} from 'vs/editor/common/modes'; import {ICodeEditor} from 'vs/editor/browser/editorBrowser'; @@ -30,37 +29,38 @@ import RenameInputField from './renameInputField'; const CONTEXT_RENAME_INPUT_VISIBLE = 'renameInputVisible'; -// ---- action implementation +class RenameController implements IEditorContribution { -export class RenameAction extends EditorAction { + private static ID = 'editor.contrib.renameController'; - public static ID: string = 'editor.action.rename'; + public static get(editor:ICommonCodeEditor): RenameController { + return editor.getContribution(RenameController.ID); + } private _renameInputField: RenameInputField; private _renameInputVisible: IKeybindingContextKey; - constructor(descriptor: IEditorActionDescriptorData, editor: ICodeEditor, + constructor( + private editor:ICodeEditor, @IMessageService private _messageService: IMessageService, @IEventService private _eventService: IEventService, @IEditorService private _editorService: IEditorService, @IProgressService private _progressService: IProgressService, @IKeybindingService keybindingService: IKeybindingService ) { - super(descriptor, editor, Behaviour.WidgetFocus | Behaviour.Writeable); - this._renameInputField = new RenameInputField(editor); this._renameInputVisible = keybindingService.createKey(CONTEXT_RENAME_INPUT_VISIBLE, false); } - public isSupported(): boolean { - return RenameProviderRegistry.has(this.editor.getModel()) && !this.editor.getModel().hasEditableRange() && super.isSupported(); + public dispose(): void { + this._renameInputField.dispose(); } - public getEnablementState(): boolean { - return RenameProviderRegistry.has(this.editor.getModel()); + public getId(): string { + return RenameController.ID; } - public run(event?: any): TPromise { + public run(): TPromise { const selection = this.editor.getSelection(), word = this.editor.getModel().getWordAtPosition(selection.getStartPosition()); @@ -145,30 +145,59 @@ export class RenameAction extends EditorAction { } } -const weight = CommonEditorRegistry.commandWeight(99); +// ---- action implementation + +export class RenameAction extends EditorAction2 { -CommonEditorRegistry.registerEditorAction({ - ctor: RenameAction, - id: RenameAction.ID, - label: nls.localize('rename.label', "Rename Symbol"), - alias: 'Rename Symbol', - kbOpts: { - context: ContextKey.EditorTextFocus, - primary: KeyCode.F2 - }, - menuOpts: { - group: '1_modification', - order: 1.1, - kbExpr: KbExpr.and(KbExpr.has(ModeContextKeys.hasRenameProvider), KbExpr.not(KEYBINDING_CONTEXT_EDITOR_READONLY)) + constructor() { + super( + 'editor.action.rename', + nls.localize('rename.label', "Rename Symbol"), + 'Rename Symbol', + true + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyCode.F2 + }; + + this.menuOpts = { + group: '1_modification', + order: 1.1, + kbExpr: KbExpr.and(KbExpr.has(ModeContextKeys.hasRenameProvider), KbExpr.not(KEYBINDING_CONTEXT_EDITOR_READONLY)) + }; } -}); + + public supported(accessor:ServicesAccessor, editor:ICommonCodeEditor): boolean { + if (!super.supported(accessor, editor)) { + return false; + } + return RenameProviderRegistry.has(editor.getModel()) && !editor.getModel().hasEditableRange(); + } + + public enabled(accessor:ServicesAccessor, editor:ICommonCodeEditor): boolean { + if (!super.enabled(accessor, editor)) { + return false; + } + return RenameProviderRegistry.has(editor.getModel()); + } + + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): TPromise { + return RenameController.get(editor).run(); + } +} + +EditorBrowserRegistry.registerEditorContribution(RenameController); + +const weight = CommonEditorRegistry.commandWeight(99); + +CommonEditorRegistry.registerEditorAction2(new RenameAction()); CommonEditorRegistry.registerEditorCommand('acceptRenameInput', weight, { primary: KeyCode.Enter }, false, CONTEXT_RENAME_INPUT_VISIBLE, (ctx, editor, args) => { - const action = editor.getAction(RenameAction.ID); - action.acceptRenameInput(); + RenameController.get(editor).acceptRenameInput(); }); CommonEditorRegistry.registerEditorCommand('cancelRenameInput', weight, { primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }, false, CONTEXT_RENAME_INPUT_VISIBLE, (ctx, editor, args) => { - const action = editor.getAction(RenameAction.ID); - action.cancelRenameInput(); + RenameController.get(editor).cancelRenameInput(); }); diff --git a/src/vs/editor/contrib/smartSelect/common/jumpToBracket.ts b/src/vs/editor/contrib/smartSelect/common/jumpToBracket.ts index 43d81bd2a23f92b8110c1a8afa69804315211d50..668acf8f8bef399c3f4bfd3e8ef61ea6a1d5db56 100644 --- a/src/vs/editor/contrib/smartSelect/common/jumpToBracket.ts +++ b/src/vs/editor/contrib/smartSelect/common/jumpToBracket.ts @@ -6,31 +6,28 @@ import * as nls from 'vs/nls'; import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; -import {TPromise} from 'vs/base/common/winjs.base'; -import {EditorAction} from 'vs/editor/common/editorAction'; -import {Behaviour} from 'vs/editor/common/editorActionEnablement'; -import {Handler, ICommonCodeEditor, IEditorActionDescriptorData} from 'vs/editor/common/editorCommon'; -import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {Handler} from 'vs/editor/common/editorCommon'; +import {EditorKbExpr, HandlerEditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions'; -class SelectBracketAction extends EditorAction { +class SelectBracketAction extends HandlerEditorAction2 { static ID = 'editor.action.jumpToBracket'; - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) { - super(descriptor, editor, Behaviour.TextFocus); + constructor() { + super( + 'editor.action.jumpToBracket', + nls.localize('smartSelect.jumpBracket', "Go to Bracket"), + 'Go to Bracket', + false, + Handler.JumpToBracket + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_BACKSLASH + }; } - - public run():TPromise { - - this.editor.trigger(this.id, Handler.JumpToBracket, {}); - - return TPromise.as(true); - } - } // register actions -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(SelectBracketAction, SelectBracketAction.ID, nls.localize('smartSelect.jumpBracket', "Go to Bracket"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_BACKSLASH -}, 'Go to Bracket')); +CommonEditorRegistry.registerEditorAction2(new SelectBracketAction()); diff --git a/src/vs/editor/contrib/smartSelect/common/smartSelect.ts b/src/vs/editor/contrib/smartSelect/common/smartSelect.ts index c822f7bc02470e9facf6d6c62baeefc6a64856e5..722241f498f8a47dcad1214a8b55b50d0e278ff0 100644 --- a/src/vs/editor/contrib/smartSelect/common/smartSelect.ts +++ b/src/vs/editor/contrib/smartSelect/common/smartSelect.ts @@ -10,10 +10,8 @@ import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; import {TPromise} from 'vs/base/common/winjs.base'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; import {Range} from 'vs/editor/common/core/range'; -import {EditorAction} from 'vs/editor/common/editorAction'; -import {Behaviour} from 'vs/editor/common/editorActionEnablement'; -import {ICommonCodeEditor, ICursorPositionChangedEvent, IEditorActionDescriptorData} from 'vs/editor/common/editorCommon'; -import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; +import {ICommonCodeEditor, ICursorPositionChangedEvent, IEditorContribution} from 'vs/editor/common/editorCommon'; +import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions'; import {TokenSelectionSupport, ILogicalSelectionEntry} from './tokenSelectionSupport'; // --- selection state machine @@ -39,18 +37,31 @@ var ignoreSelection = false; // -- action implementation -class SmartSelect extends EditorAction { +class SmartSelectController implements IEditorContribution { + + private static ID = 'editor.contrib.smartSelectController'; + + public static get(editor:ICommonCodeEditor): SmartSelectController { + return editor.getContribution(SmartSelectController.ID); + } - private _forward: boolean; private _tokenSelectionSupport: TokenSelectionSupport; - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor, forward: boolean, instantiationService: IInstantiationService) { - super(descriptor, editor, Behaviour.TextFocus | Behaviour.UpdateOnModelChange); + constructor( + private editor: ICommonCodeEditor, + @IInstantiationService instantiationService: IInstantiationService + ) { this._tokenSelectionSupport = instantiationService.createInstance(TokenSelectionSupport); - this._forward = forward; } - public run(): TPromise { + public dispose(): void { + } + + public getId(): string { + return SmartSelectController.ID; + } + + public run(forward:boolean): TPromise { var selection = this.editor.getSelection(); var model = this.editor.getModel(); @@ -114,7 +125,7 @@ class SmartSelect extends EditorAction { return; } - state = this._forward ? state.next : state.previous; + state = forward ? state.next : state.previous; if (!state) { return; } @@ -126,37 +137,60 @@ class SmartSelect extends EditorAction { ignoreSelection = false; } - return true; + return; }); } } -class GrowSelectionAction extends SmartSelect { +abstract class AbstractSmartSelect extends EditorAction2 { - public static ID = 'editor.action.smartSelect.grow'; + private _forward: boolean; - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor, @IInstantiationService instantiationService: IInstantiationService) { - super(descriptor, editor, true, instantiationService); + constructor(id:string, label:string, alias:string, forward: boolean) { + super(id, label, alias, false); + this._forward = forward; } -} -class ShrinkSelectionAction extends SmartSelect { + public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): TPromise { + return SmartSelectController.get(editor).run(this._forward); + } +} - public static ID = 'editor.action.smartSelect.shrink'; +class GrowSelectionAction extends AbstractSmartSelect { + constructor() { + super( + 'editor.action.smartSelect.grow', + nls.localize('smartSelect.grow', "Expand Select"), + 'Expand Select', + true + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.Shift | KeyMod.Alt | KeyCode.RightArrow, + mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyMod.Shift | KeyCode.RightArrow } + }; + } +} - constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor, @IInstantiationService instantiationService: IInstantiationService) { - super(descriptor, editor, false, instantiationService); +class ShrinkSelectionAction extends AbstractSmartSelect { + constructor() { + super( + 'editor.action.smartSelect.shrink', + nls.localize('smartSelect.shrink', "Shrink Select"), + 'Shrink Select', + false + ); + + this.kbOpts = { + kbExpr: EditorKbExpr.TextFocus, + primary: KeyMod.Shift | KeyMod.Alt | KeyCode.LeftArrow, + mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyMod.Shift | KeyCode.LeftArrow } + }; } } // register actions -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(GrowSelectionAction, GrowSelectionAction.ID, nls.localize('smartSelect.grow', "Expand Select"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.Shift | KeyMod.Alt | KeyCode.RightArrow, - mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyMod.Shift | KeyCode.RightArrow } -}, 'Expand Select')); -CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ShrinkSelectionAction, ShrinkSelectionAction.ID, nls.localize('smartSelect.shrink', "Shrink Select"), { - context: ContextKey.EditorTextFocus, - primary: KeyMod.Shift | KeyMod.Alt | KeyCode.LeftArrow, - mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyMod.Shift | KeyCode.LeftArrow } -}, 'Shrink Select')); +CommonEditorRegistry.registerEditorContribution(SmartSelectController); +CommonEditorRegistry.registerEditorAction2(new GrowSelectionAction()); +CommonEditorRegistry.registerEditorAction2(new ShrinkSelectionAction());