Adopting EditorAction2

This commit is contained in:
Alex Dima 2016-08-04 10:51:53 +02:00
parent 093290327a
commit 1217e8d274
9 changed files with 507 additions and 443 deletions

View file

@ -15,10 +15,8 @@ import {ActionItem, Separator} from 'vs/base/browser/ui/actionbar/actionbar';
import {IContextMenuService, IContextViewService} from 'vs/platform/contextview/browser/contextView';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {IMenuService, IMenu, MenuId} from 'vs/platform/actions/common/actions';
import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
import {ICommonCodeEditor, IEditorActionDescriptorData, IEditorContribution, MouseTargetType} from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {ICommonCodeEditor, IEditorContribution, MouseTargetType} from 'vs/editor/common/editorCommon';
import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {ICodeEditor, IEditorMouseEvent} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
@ -220,28 +218,27 @@ class ContextMenuController implements IEditorContribution {
}
}
class ShowContextMenu extends EditorAction {
class ShowContextMenu extends EditorAction2 {
public static ID = 'editor.action.showContextMenu';
constructor() {
super(
'editor.action.showContextMenu',
nls.localize('action.showContextMenu.label', "Show Editor Context Menu"),
'Show Editor Context Menu',
false
);
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor) {
super(descriptor, editor, Behaviour.TextFocus);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.Shift | KeyCode.F10
};
}
public run(): TPromise<boolean> {
var contribution = <ContextMenuController>this.editor.getContribution(ContextMenuController.ID);
if (!contribution) {
return TPromise.as(null);
}
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
var contribution = <ContextMenuController>editor.getContribution(ContextMenuController.ID);
contribution.showContextMenu();
return TPromise.as(null);
}
}
EditorBrowserRegistry.registerEditorContribution(ContextMenuController);
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ShowContextMenu, ShowContextMenu.ID, nls.localize('action.showContextMenu.label', "Show Editor Context Menu"), {
context: ContextKey.EditorTextFocus,
primary: KeyMod.Shift | KeyCode.F10
}, 'Show Editor Context Menu'));
CommonEditorRegistry.registerEditorAction2(new ShowContextMenu());

View file

@ -11,7 +11,6 @@ import {RunOnceScheduler} from 'vs/base/common/async';
import {MarkedString} from 'vs/base/common/htmlContent';
import {CommonKeybindings, KeyCode, KeyMod, Keybinding} from 'vs/base/common/keyCodes';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {TPromise} from 'vs/base/common/winjs.base';
import * as dom from 'vs/base/browser/dom';
import {renderHtml} from 'vs/base/browser/htmlContentRenderer';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
@ -19,10 +18,8 @@ import {StyleMutator} from 'vs/base/browser/styleMutator';
import {IOSupport} from 'vs/platform/keybinding/common/keybindingResolver';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
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, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, OverlayWidgetPositionPreference} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import {CodeSnippet, getSnippetController} from 'vs/editor/contrib/snippet/common/snippet';
@ -30,7 +27,6 @@ import {SmartSnippetInserter} from 'vs/editor/contrib/defineKeybinding/common/sm
const NLS_LAUNCH_MESSAGE = nls.localize('defineKeybinding.start', "Define Keybinding");
const NLS_DEFINE_MESSAGE = nls.localize('defineKeybinding.initial', "Press desired key combination and ENTER");
const NLS_DEFINE_ACTION_LABEL = nls.localize('DefineKeybindingAction',"Define Keybinding");
const NLS_KB_LAYOUT_INFO_MESSAGE = nls.localize('defineKeybinding.kbLayoutInfoMessage', "For your current keyboard layout press ");
const NLS_KB_LAYOUT_ERROR_MESSAGE = nls.localize('defineKeybinding.kbLayoutErrorMessage', "You won't be able to produce this key combination under your current keyboard layout.");
@ -447,25 +443,34 @@ class DefineKeybindingWidget implements IOverlayWidget {
}
}
export class DefineKeybindingAction extends EditorAction {
export class DefineKeybindingAction extends EditorAction2 {
static ID = 'editor.action.defineKeybinding';
constructor(descriptor:editorCommon.IEditorActionDescriptorData, editor:editorCommon.ICommonCodeEditor) {
super(descriptor, editor, Behaviour.WidgetFocus | Behaviour.UpdateOnModelChange | Behaviour.Writeable);
constructor() {
super(
DefineKeybindingAction.ID,
nls.localize('DefineKeybindingAction',"Define Keybinding"),
'Define Keybinding',
true
);
this.kbOpts = {
kbExpr: EditorKbExpr.Focus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_K)
};
}
public isSupported(): boolean {
if (!super.isSupported()) {
public supported(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean {
if (!super.supported(accessor, editor)) {
return false;
}
return isInterestingEditorModel(this.editor);
return isInterestingEditorModel(editor);
}
public run(): TPromise<boolean> {
var controller = DefineKeybindingController.get(this.editor);
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void {
var controller = DefineKeybindingController.get(editor);
controller.launch();
return TPromise.as(true);
}
}
@ -483,7 +488,4 @@ function isInterestingEditorModel(editor:editorCommon.ICommonCodeEditor): boolea
}
EditorBrowserRegistry.registerEditorContribution(DefineKeybindingController);
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(DefineKeybindingAction, DefineKeybindingAction.ID, NLS_DEFINE_ACTION_LABEL, {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_K)
}, 'Define Keybinding'));
CommonEditorRegistry.registerEditorAction2(new DefineKeybindingAction());

View file

@ -11,11 +11,9 @@ import {RunOnceScheduler} from 'vs/base/common/async';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {TPromise} from 'vs/base/common/winjs.base';
import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {Range} from 'vs/editor/common/core/range';
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {ICodeEditor, IEditorMouseEvent} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import {IFoldingRange} from 'vs/editor/contrib/folding/common/foldingRange';
@ -648,130 +646,187 @@ export class FoldingController implements editorCommon.IEditorContribution {
}
}
abstract class FoldingAction extends EditorAction {
constructor(descriptor: editorCommon.IEditorActionDescriptorData, editor: editorCommon.ICommonCodeEditor) {
super(descriptor, editor, Behaviour.TextFocus);
abstract class FoldingAction2 extends EditorAction2 {
constructor(id:string, label:string, alias:string, keybinding:number) {
super(id, label, alias, false);
this.kbOpts = {
kbExpr: EditorKbExpr.Focus,
primary: keybinding
};
}
abstract invoke(foldingController: FoldingController): void;
abstract invoke(foldingController: FoldingController, editor:editorCommon.ICommonCodeEditor): void;
public run(): TPromise<boolean> {
let foldingController = FoldingController.getFoldingController(this.editor);
this.invoke(foldingController);
return TPromise.as(true);
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void {
let foldingController = FoldingController.getFoldingController(editor);
this.invoke(foldingController, editor);
}
}
class UnfoldAction extends FoldingAction {
public static ID = 'editor.unfold';
class UnfoldAction extends FoldingAction2 {
invoke(foldingController: FoldingController): void {
constructor() {
super(
'editor.unfold',
nls.localize('unfoldAction.label', "Unfold"),
'Unfold',
KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_CLOSE_SQUARE_BRACKET
);
}
invoke(foldingController: FoldingController, editor:editorCommon.ICommonCodeEditor): void {
foldingController.unfold();
}
}
class UnFoldRecursivelyAction extends FoldingAction {
public static ID = 'editor.unFoldRecursively';
class UnFoldRecursivelyAction extends FoldingAction2 {
invoke(foldingController: FoldingController): void {
constructor() {
super(
'editor.unFoldRecursively',
nls.localize('unFoldRecursivelyAction.label', "Unfold Recursively"),
'Unfold Recursively',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.US_CLOSE_SQUARE_BRACKET)
);
}
invoke(foldingController: FoldingController, editor:editorCommon.ICommonCodeEditor): void {
foldingController.foldUnfoldRecursively(false);
}
}
class FoldAction extends FoldingAction {
public static ID = 'editor.fold';
class FoldAction extends FoldingAction2 {
invoke(foldingController: FoldingController): void {
constructor() {
super(
'editor.fold',
nls.localize('foldAction.label', "Fold"),
'Fold',
KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_OPEN_SQUARE_BRACKET
);
}
invoke(foldingController: FoldingController, editor:editorCommon.ICommonCodeEditor): void {
foldingController.fold();
}
}
class FoldRecursivelyAction extends FoldingAction {
public static ID = 'editor.foldRecursively';
class FoldRecursivelyAction extends FoldingAction2 {
invoke(foldingController: FoldingController): void {
constructor() {
super(
'editor.foldRecursively',
nls.localize('foldRecursivelyAction.label', "Fold Recursively"),
'Fold Recursively',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.US_OPEN_SQUARE_BRACKET)
);
}
invoke(foldingController: FoldingController, editor:editorCommon.ICommonCodeEditor): void {
foldingController.foldUnfoldRecursively(true);
}
}
class FoldAllAction extends FoldingAction {
public static ID = 'editor.foldAll';
class FoldAllAction extends FoldingAction2 {
invoke(foldingController: FoldingController): void {
constructor() {
super(
'editor.foldAll',
nls.localize('foldAllAction.label', "Fold All"),
'Fold All',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_0)
);
}
invoke(foldingController: FoldingController, editor:editorCommon.ICommonCodeEditor): void {
foldingController.changeAll(true);
}
}
class UnfoldAllAction extends FoldingAction {
public static ID = 'editor.unfoldAll';
class UnfoldAllAction extends FoldingAction2 {
invoke(foldingController: FoldingController): void {
constructor() {
super(
'editor.unfoldAll',
nls.localize('unfoldAllAction.label', "Unfold All"),
'Unfold All',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_J)
);
}
invoke(foldingController: FoldingController, editor:editorCommon.ICommonCodeEditor): void {
foldingController.changeAll(false);
}
}
class FoldLevelAction extends FoldingAction {
class FoldLevelAction extends FoldingAction2 {
private static ID_PREFIX = 'editor.foldLevel';
public static ID = (level:number) => FoldLevelAction.ID_PREFIX + level;
constructor(id:string, label:string, alias:string, keybinding:number) {
super(id, label, alias, keybinding);
}
private getFoldingLevel() {
return parseInt(this.id.substr(FoldLevelAction.ID_PREFIX.length));
}
private getSelectedLines() {
return this.editor.getSelections().map(s => s.startLineNumber);
private getSelectedLines(editor:editorCommon.ICommonCodeEditor) {
return editor.getSelections().map(s => s.startLineNumber);
}
invoke(foldingController: FoldingController): void {
foldingController.foldLevel(this.getFoldingLevel(), this.getSelectedLines());
invoke(foldingController: FoldingController, editor:editorCommon.ICommonCodeEditor): void {
foldingController.foldLevel(this.getFoldingLevel(), this.getSelectedLines(editor));
}
}
EditorBrowserRegistry.registerEditorContribution(FoldingController);
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(UnfoldAction, UnfoldAction.ID, nls.localize('unfoldAction.label', "Unfold"), {
context: ContextKey.EditorFocus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_CLOSE_SQUARE_BRACKET
}, 'Unfold'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(UnFoldRecursivelyAction, UnFoldRecursivelyAction.ID, nls.localize('unFoldRecursivelyAction.label', "Unfold Recursively"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.US_CLOSE_SQUARE_BRACKET)
}, 'Unfold Recursively'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(FoldAction, FoldAction.ID, nls.localize('foldAction.label', "Fold"), {
context: ContextKey.EditorFocus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_OPEN_SQUARE_BRACKET
}, 'Fold'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(FoldRecursivelyAction, FoldRecursivelyAction.ID, nls.localize('foldRecursivelyAction.label', "Fold Recursively"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.US_OPEN_SQUARE_BRACKET)
}, 'Fold Recursively'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(FoldAllAction, FoldAllAction.ID, nls.localize('foldAllAction.label', "Fold All"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_0)
}, 'Fold All'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(UnfoldAllAction, UnfoldAllAction.ID, nls.localize('unfoldAllAction.label', "Unfold All"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_J)
}, 'Unfold All'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(FoldLevelAction, FoldLevelAction.ID(1), nls.localize('foldLevel1Action.label', "Fold Level 1"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_1)
}, 'Fold Level 1'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(FoldLevelAction, FoldLevelAction.ID(2), nls.localize('foldLevel2Action.label', "Fold Level 2"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_2)
}, 'Fold Level 2'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(FoldLevelAction, FoldLevelAction.ID(3), nls.localize('foldLevel3Action.label', "Fold Level 3"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_3)
}, 'Fold Level 3'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(FoldLevelAction, FoldLevelAction.ID(4), nls.localize('foldLevel4Action.label', "Fold Level 4"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_4)
}, 'Fold Level 4'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(FoldLevelAction, FoldLevelAction.ID(5), nls.localize('foldLevel5Action.label', "Fold Level 5"), {
context: ContextKey.EditorFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_5)
}, 'Fold Level 5'));
CommonEditorRegistry.registerEditorAction2(new UnfoldAction());
CommonEditorRegistry.registerEditorAction2(new UnFoldRecursivelyAction());
CommonEditorRegistry.registerEditorAction2(new FoldAction());
CommonEditorRegistry.registerEditorAction2(new FoldRecursivelyAction());
CommonEditorRegistry.registerEditorAction2(new FoldAllAction());
CommonEditorRegistry.registerEditorAction2(new UnfoldAllAction());
CommonEditorRegistry.registerEditorAction2(
new FoldLevelAction(
FoldLevelAction.ID(1),
nls.localize('foldLevel1Action.label', "Fold Level 1"),
'Fold Level 1',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_1)
)
);
CommonEditorRegistry.registerEditorAction2(
new FoldLevelAction(
FoldLevelAction.ID(2),
nls.localize('foldLevel2Action.label', "Fold Level 2"),
'Fold Level 2',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_2)
)
);
CommonEditorRegistry.registerEditorAction2(
new FoldLevelAction(
FoldLevelAction.ID(3),
nls.localize('foldLevel3Action.label', "Fold Level 3"),
'Fold Level 3',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_3)
)
);
CommonEditorRegistry.registerEditorAction2(
new FoldLevelAction(
FoldLevelAction.ID(4),
nls.localize('foldLevel4Action.label', "Fold Level 4"),
'Fold Level 4',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_4)
)
);
CommonEditorRegistry.registerEditorAction2(
new FoldLevelAction(
FoldLevelAction.ID(5),
nls.localize('foldLevel5Action.label', "Fold Level 5"),
'Fold Level 5',
KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_5)
)
);

View file

@ -9,11 +9,9 @@ import * as arrays from 'vs/base/common/arrays';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {TPromise} from 'vs/base/common/winjs.base';
import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {CommonEditorRegistry, ContextKey} from 'vs/editor/common/editorCommonExtensions';
import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {DocumentFormattingEditProviderRegistry, DocumentRangeFormattingEditProviderRegistry, OnTypeFormattingEditProviderRegistry} from 'vs/editor/common/modes';
import {getOnTypeFormattingEdits, getDocumentFormattingEdits, getDocumentRangeFormattingEdits} from '../common/format';
import {EditOperationsCommand} from './formatCommand';
@ -134,40 +132,45 @@ class FormatOnType implements editorCommon.IEditorContribution {
}
}
export class FormatAction extends EditorAction {
export class FormatAction extends EditorAction2 {
public static ID = 'editor.action.format';
constructor() {
super(
'editor.action.format',
nls.localize('formatAction.label', "Format Code"),
'Format Code',
true
);
private _disposables: IDisposable[];
this.kbOpts = {
kbExpr: KbExpr.and(EditorKbExpr.TextFocus, EditorKbExpr.Writable),
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_F,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I }
};
constructor(descriptor:editorCommon.IEditorActionDescriptorData, editor:editorCommon.ICommonCodeEditor) {
super(descriptor, editor, Behaviour.WidgetFocus | Behaviour.Writeable | Behaviour.UpdateOnModelChange);
this._disposables = [
DocumentFormattingEditProviderRegistry.onDidChange(() => this.resetEnablementState()),
DocumentRangeFormattingEditProviderRegistry.onDidChange(() => this.resetEnablementState())
];
this.menuOpts = {
group: '1_modification',
order: 1.3,
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasFormattingProvider)
};
}
public dispose() {
super.dispose();
this._disposables = dispose(this._disposables);
}
public isSupported(): boolean {
public supported(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean {
if (!super.supported(accessor, editor)) {
return false;
}
return (
(
DocumentFormattingEditProviderRegistry.has(this.editor.getModel())
|| DocumentRangeFormattingEditProviderRegistry.has(this.editor.getModel())
)
&& super.isSupported()
DocumentFormattingEditProviderRegistry.has(editor.getModel())
|| DocumentRangeFormattingEditProviderRegistry.has(editor.getModel())
);
}
public run(): TPromise<boolean> {
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): TPromise<void> {
const model = this.editor.getModel(),
editorSelection = this.editor.getSelection(),
modelOpts = model.getOptions(),
options = {
const model = editor.getModel();
const editorSelection = editor.getSelection();
const modelOpts = model.getOptions();
const options = {
tabSize: modelOpts.tabSize,
insertSpaces: modelOpts.insertSpaces,
};
@ -181,26 +184,26 @@ export class FormatAction extends EditorAction {
}
if (!formattingPromise) {
return TPromise.as(false);
return TPromise.as(void 0);
}
// Capture the state of the editor
var state = this.editor.captureState(editorCommon.CodeEditorStateFlag.Value, editorCommon.CodeEditorStateFlag.Position);
var state = editor.captureState(editorCommon.CodeEditorStateFlag.Value, editorCommon.CodeEditorStateFlag.Position);
// Receive formatted value from worker
return formattingPromise.then((result: editorCommon.ISingleEditOperation[]) => {
if (!state.validate(this.editor)) {
return false;
if (!state.validate(editor)) {
return;
}
if (!result || result.length === 0) {
return false;
return;
}
this.apply(this.editor, editorSelection, result);
this.editor.focus();
return true;
this.apply(editor, editorSelection, result);
editor.focus();
});
}
@ -220,20 +223,5 @@ export class FormatAction extends EditorAction {
}
// register action
CommonEditorRegistry.registerEditorAction({
ctor: FormatAction,
id: FormatAction.ID,
label: nls.localize('formatAction.label', "Format Code"),
alias: 'Format Code',
kbOpts: {
context: ContextKey.EditorTextFocus,
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_F,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I }
},
menuOpts: {
group: '1_modification',
order: 1.3,
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasFormattingProvider)
}
});
CommonEditorRegistry.registerEditorAction2(new FormatAction());
CommonEditorRegistry.registerEditorContribution(FormatOnType);

View file

@ -21,10 +21,8 @@ import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {IEditorService} from 'vs/platform/editor/common/editor';
import {IMessageService} from 'vs/platform/message/common/message';
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, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {Location, DefinitionProviderRegistry} from 'vs/editor/common/modes';
import {ICodeEditor, IEditorMouseEvent, IMouseTarget} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
@ -39,7 +37,6 @@ import {optional} from 'vs/platform/instantiation/common/instantiation';
export class DefinitionActionConfig {
constructor(
public condition = Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange,
public openToSide = false,
public openInPeek = false,
public filterCurrent = true
@ -48,34 +45,35 @@ export class DefinitionActionConfig {
}
}
export class DefinitionAction extends EditorAction {
export class DefinitionAction extends EditorAction2 {
constructor(
descriptor: editorCommon.IEditorActionDescriptorData,
editor: editorCommon.ICommonCodeEditor,
private _messageService: IMessageService,
private _editorService: IEditorService,
private _configuration: DefinitionActionConfig
) {
super(descriptor, editor, _configuration.condition);
private _configuration: DefinitionActionConfig;
constructor(id: string, label: string, alias: string, configuration: DefinitionActionConfig) {
super(id, label, alias, false);
this._configuration = configuration;
}
public isSupported(): boolean {
return DefinitionProviderRegistry.has(this.editor.getModel()) && super.isSupported();
}
public getEnablementState(): boolean {
if (!super.getEnablementState()) {
public supported(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean {
if (!super.supported(accessor, editor)) {
return false;
}
return DefinitionProviderRegistry.has(this.editor.getModel());
return DefinitionProviderRegistry.has(editor.getModel());
}
public run(): TPromise<any> {
public enabled(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean {
if (!super.enabled(accessor, editor)) {
return false;
}
return DefinitionProviderRegistry.has(editor.getModel());
}
let model = this.editor.getModel();
let pos = this.editor.getPosition();
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): TPromise<void> {
const messageService = accessor.get(IMessageService);
const editorService = accessor.get(IEditorService);
let model = editor.getModel();
let pos = editor.getPosition();
return getDeclarationsAtPosition(model, pos).then(references => {
@ -108,31 +106,31 @@ export class DefinitionAction extends EditorAction {
return;
}
return this._onResult(new ReferencesModel(result));
return this._onResult(editorService, editor, new ReferencesModel(result));
}, (err) => {
// report an error
this._messageService.show(Severity.Error, err);
messageService.show(Severity.Error, err);
return false;
});
}
private _onResult(model: ReferencesModel) {
private _onResult(editorService:IEditorService, editor:editorCommon.ICommonCodeEditor, model: ReferencesModel) {
if (this._configuration.openInPeek) {
this._openInPeek(this.editor, model);
this._openInPeek(editorService, editor, model);
} else {
let next = model.nearestReference(this.editor.getModel().uri, this.editor.getPosition());
this._openReference(next, this._configuration.openToSide).then(editor => {
let next = model.nearestReference(editor.getModel().uri, editor.getPosition());
this._openReference(editorService, next, this._configuration.openToSide).then(editor => {
if (model.references.length > 1) {
this._openInPeek(editor, model);
this._openInPeek(editorService, editor, model);
}
});
}
}
private _openReference(reference: Location, sideBySide: boolean): TPromise<editorCommon.ICommonCodeEditor>{
private _openReference(editorService:IEditorService, reference: Location, sideBySide: boolean): TPromise<editorCommon.ICommonCodeEditor>{
let {uri, range} = reference;
return this._editorService.openEditor({
return editorService.openEditor({
resource: uri,
options: {
selection: range,
@ -143,7 +141,7 @@ export class DefinitionAction extends EditorAction {
});
}
private _openInPeek(target: editorCommon.ICommonCodeEditor, model: ReferencesModel) {
private _openInPeek(editorService:IEditorService, target: editorCommon.ICommonCodeEditor, model: ReferencesModel) {
let controller = ReferencesController.getController(target);
controller.toggleWidget(target.getSelection(), TPromise.as(model), {
getMetaTitle: (model) => {
@ -151,58 +149,90 @@ export class DefinitionAction extends EditorAction {
},
onGoto: (reference) => {
controller.closeWidget();
return this._openReference(reference, false);
return this._openReference(editorService, reference, false);
}
});
}
}
const goToDeclarationKb = platform.isWeb
? KeyMod.CtrlCmd | KeyCode.F12
: KeyCode.F12;
export class GoToDefinitionAction extends DefinitionAction {
public static ID = 'editor.action.goToDeclaration';
constructor(
descriptor: editorCommon.IEditorActionDescriptorData,
editor: editorCommon.ICommonCodeEditor,
@IMessageService messageService: IMessageService,
@IEditorService editorService: IEditorService
) {
super(descriptor, editor, messageService, editorService, new DefinitionActionConfig());
}
constructor() {
super(
GoToDefinitionAction.ID,
nls.localize('actions.goToDecl.label', "Go to Definition"),
'Go to Definition',
new DefinitionActionConfig()
);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: goToDeclarationKb
};
this.menuOpts = {
group: 'navigation',
order: 1.1,
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasDefinitionProvider)
};
}
}
export class OpenDefinitionToSideAction extends DefinitionAction {
public static ID = 'editor.action.openDeclarationToTheSide';
constructor(
descriptor: editorCommon.IEditorActionDescriptorData,
editor: editorCommon.ICommonCodeEditor,
@IMessageService messageService: IMessageService,
@IEditorService editorService: IEditorService
) {
super(descriptor, editor, messageService, editorService, new DefinitionActionConfig(Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange, true));
constructor() {
super(
OpenDefinitionToSideAction.ID,
nls.localize('actions.goToDeclToSide.label', "Open Definition to the Side"),
'Open Definition to the Side',
new DefinitionActionConfig(true)
);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, goToDeclarationKb)
};
}
}
export class PeekDefinitionAction extends DefinitionAction {
public static ID = 'editor.action.previewDeclaration';
constructor() {
super(
'editor.action.previewDeclaration',
nls.localize('actions.previewDecl.label', "Peek Definition"),
'Peek Definition',
new DefinitionActionConfig(void 0, true, false)
);
constructor(
descriptor: editorCommon.IEditorActionDescriptorData,
editor: editorCommon.ICommonCodeEditor,
@IMessageService messageService: IMessageService,
@IEditorService editorService: IEditorService,
@optional(IPeekViewService) private _peekViewService: IPeekViewService
) {
super(descriptor, editor, messageService, editorService, new DefinitionActionConfig(void 0, void 0, true, false));
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.Alt | KeyCode.F12,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F10 }
};
this.menuOpts = {
group: 'navigation',
order: 1.2,
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasDefinitionProvider)
};
}
getEnablementState(): boolean {
return (!this._peekViewService || !this._peekViewService.isActive)
&& super.getEnablementState();
public enabled(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean {
if (!super.enabled(accessor, editor)) {
return false;
}
const peekViewService = accessor.get(IPeekViewService, optional);
return (!peekViewService || !peekViewService.isActive);
}
}
@ -487,46 +517,8 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
// register actions
CommonEditorRegistry.registerEditorAction({
id: PeekDefinitionAction.ID,
ctor: PeekDefinitionAction,
label: nls.localize('actions.previewDecl.label', "Peek Definition"),
alias: 'Peek Definition',
kbOpts: {
context: ContextKey.EditorTextFocus,
primary: KeyMod.Alt | KeyCode.F12,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F10 }
},
menuOpts: {
group: 'navigation',
order: 1.2,
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasDefinitionProvider)
}
});
const goToDeclarationKb = platform.isWeb
? KeyMod.CtrlCmd | KeyCode.F12
: KeyCode.F12;
CommonEditorRegistry.registerEditorAction({
ctor: GoToDefinitionAction,
id: GoToDefinitionAction.ID,
label: nls.localize('actions.goToDecl.label', "Go to Definition"),
alias: 'Go to Definition',
kbOpts: {
context: ContextKey.EditorTextFocus,
primary: goToDeclarationKb
},
menuOpts: {
group: 'navigation',
order: 1.1,
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasDefinitionProvider)
}
});
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(OpenDefinitionToSideAction, OpenDefinitionToSideAction.ID, nls.localize('actions.goToDeclToSide.label', "Open Definition to the Side"), {
context: ContextKey.EditorTextFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, goToDeclarationKb)
}, 'Open Definition to the Side'));
CommonEditorRegistry.registerEditorAction2(new PeekDefinitionAction());
CommonEditorRegistry.registerEditorAction2(new GoToDefinitionAction());
CommonEditorRegistry.registerEditorAction2(new OpenDefinitionToSideAction());
EditorBrowserRegistry.registerEditorContribution(GotoDefinitionWithMouseEditorContribution);

View file

@ -22,10 +22,8 @@ import {IMarker, IMarkerService} from 'vs/platform/markers/common/markers';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
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, 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 {ZoneWidget} from 'vs/editor/contrib/zoneWidget/browser/zoneWidget';
@ -408,21 +406,20 @@ class MarkerNavigationWidget extends ZoneWidget {
}
}
class MarkerNavigationAction extends EditorAction {
class MarkerNavigationAction extends EditorAction2 {
private _isNext: boolean;
private telemetryService: ITelemetryService;
constructor(descriptor: editorCommon.IEditorActionDescriptorData, editor: editorCommon.ICommonCodeEditor, next: boolean, @ITelemetryService telemetryService: ITelemetryService) {
super(descriptor, editor, Behaviour.WidgetFocus | Behaviour.Writeable | Behaviour.UpdateOnModelChange);
this.telemetryService = telemetryService;
constructor(id:string, label:string, alias:string, next: boolean) {
super(id, label, alias, true);
this._isNext = next;
}
public run(): TPromise<boolean> {
var model = MarkerController.getMarkerController(this.editor).getOrCreateModel();
this.telemetryService.publicLog('zoneWidgetShown', { mode: 'go to error' });
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void {
const telemetryService = accessor.get(ITelemetryService);
let model = MarkerController.getMarkerController(editor).getOrCreateModel();
telemetryService.publicLog('zoneWidgetShown', { mode: 'go to error' });
if (model) {
if (this._isNext) {
model.next();
@ -431,7 +428,6 @@ class MarkerNavigationAction extends EditorAction {
}
model.reveal();
}
return TPromise.as(true);
}
}
@ -515,32 +511,42 @@ class MarkerController implements editorCommon.IEditorContribution {
}
class NextMarkerAction extends MarkerNavigationAction {
public static ID = 'editor.action.marker.next';
constructor() {
super(
'editor.action.marker.next',
nls.localize('markerAction.next.label', "Go to Next Error or Warning"),
'Go to Next Error or Warning',
true
);
constructor(descriptor: editorCommon.IEditorActionDescriptorData, editor: editorCommon.ICommonCodeEditor, @ITelemetryService telemetryService: ITelemetryService) {
super(descriptor, editor, true, telemetryService);
this.kbOpts = {
kbExpr: EditorKbExpr.Focus,
primary: KeyCode.F8
};
}
}
class PrevMarkerAction extends MarkerNavigationAction {
public static ID = 'editor.action.marker.prev';
constructor() {
super(
'editor.action.marker.prev',
nls.localize('markerAction.previous.label', "Go to Previous Error or Warning"),
'Go to Previous Error or Warning',
false
);
constructor(descriptor: editorCommon.IEditorActionDescriptorData, editor: editorCommon.ICommonCodeEditor, @ITelemetryService telemetryService: ITelemetryService) {
super(descriptor, editor, false, telemetryService);
this.kbOpts = {
kbExpr: EditorKbExpr.Focus,
primary: KeyMod.Shift | KeyCode.F8
};
}
}
var CONTEXT_MARKERS_NAVIGATION_VISIBLE = 'markersNavigationVisible';
// register actions
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(NextMarkerAction, NextMarkerAction.ID, nls.localize('markerAction.next.label', "Go to Next Error or Warning"), {
context: ContextKey.EditorFocus,
primary: KeyCode.F8
}, 'Go to Next Error or Warning'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(PrevMarkerAction, PrevMarkerAction.ID, nls.localize('markerAction.previous.label', "Go to Previous Error or Warning"), {
context: ContextKey.EditorFocus,
primary: KeyMod.Shift | KeyCode.F8
}, 'Go to Previous Error or Warning'));
CommonEditorRegistry.registerEditorAction2(new NextMarkerAction());
CommonEditorRegistry.registerEditorAction2(new PrevMarkerAction());
CommonEditorRegistry.registerEditorCommand('closeMarkersNavigation', CommonEditorRegistry.commandWeight(50), { primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }, false, CONTEXT_MARKERS_NAVIGATION_VISIBLE, (ctx, editor, args) => {
var controller = MarkerController.getMarkerController(editor);
controller.closeMarkersNavigation();

View file

@ -9,16 +9,12 @@ import 'vs/css!./hover';
import * as nls from 'vs/nls';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform';
import {TPromise} from 'vs/base/common/winjs.base';
import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {IOpenerService} from 'vs/platform/opener/common/opener';
import {IModeService} from 'vs/editor/common/services/modeService';
import {KbExpr} from 'vs/platform/keybinding/common/keybinding';
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, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {ICodeEditor, IEditorMouseEvent} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import {ModesContentHoverWidget} from './modesContentHover';
@ -145,25 +141,28 @@ class ModesHoverController implements editorCommon.IEditorContribution {
}
}
class ShowHoverAction extends EditorAction {
static ID = 'editor.action.showHover';
class ShowHoverAction extends EditorAction2 {
constructor(descriptor: editorCommon.IEditorActionDescriptorData, editor: editorCommon.ICommonCodeEditor) {
super(descriptor, editor, Behaviour.TextFocus);
constructor() {
super(
'editor.action.showHover',
nls.localize('showHover', "Show Hover"),
'Show Hover',
false
);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_I)
};
}
public run(): TPromise<any> {
const position = this.editor.getPosition();
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void {
const position = editor.getPosition();
const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
(<ModesHoverController>this.editor.getContribution(ModesHoverController.ID)).showContentHover(range, true);
return TPromise.as(null);
(<ModesHoverController>editor.getContribution(ModesHoverController.ID)).showContentHover(range, true);
}
}
EditorBrowserRegistry.registerEditorContribution(ModesHoverController);
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ShowHoverAction, ShowHoverAction.ID, nls.localize('showHover', "Show Hover"), {
context: ContextKey.EditorTextFocus,
kbExpr: KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_I)
}, 'Show Hover'));
CommonEditorRegistry.registerEditorAction2(new ShowHoverAction());

View file

@ -8,20 +8,25 @@ import * as nls from 'vs/nls';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
import {TPromise} from 'vs/base/common/winjs.base';
import {Range} from 'vs/editor/common/core/range';
import {EditorAction} from 'vs/editor/common/editorAction';
import {CodeEditorStateFlag, ICommonCodeEditor, IEditorActionDescriptorData, IModelDecorationsChangeAccessor} from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorContribution, CodeEditorStateFlag, ICommonCodeEditor, IModelDecorationsChangeAccessor} from 'vs/editor/common/editorCommon';
import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {IInplaceReplaceSupportResult} from 'vs/editor/common/modes';
import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService';
import {InPlaceReplaceCommand} from './inPlaceReplaceCommand';
class InPlaceReplace extends EditorAction {
class InPlaceReplaceController implements IEditorContribution {
static ID = 'editor.contrib.inPlaceReplaceController';
static get(editor:ICommonCodeEditor): InPlaceReplaceController {
return <InPlaceReplaceController>editor.getContribution(InPlaceReplaceController.ID);
}
private static DECORATION = {
className: 'valueSetReplacement'
};
private up:boolean;
private editor:ICommonCodeEditor;
private requestIdPool:number;
private currentRequest:TPromise<IInplaceReplaceSupportResult>;
private decorationRemover:TPromise<void>;
@ -29,21 +34,25 @@ class InPlaceReplace extends EditorAction {
private editorWorkerService:IEditorWorkerService;
constructor(
descriptor:IEditorActionDescriptorData,
editor:ICommonCodeEditor,
up:boolean,
@IEditorWorkerService editorWorkerService:IEditorWorkerService
) {
super(descriptor, editor);
this.editor = editor;
this.editorWorkerService = editorWorkerService;
this.up = up;
this.requestIdPool = 0;
this.currentRequest = TPromise.as(<IInplaceReplaceSupportResult>null);
this.decorationRemover = TPromise.as(<void>null);
this.decorationIds = [];
}
public run():TPromise<boolean> {
public dispose(): void {
}
public getId(): string {
return InPlaceReplaceController.ID;
}
public run(source:string, up:boolean): TPromise<void> {
// cancel any pending request
this.currentRequest.cancel();
@ -60,14 +69,14 @@ class InPlaceReplace extends EditorAction {
var state = this.editor.captureState(CodeEditorStateFlag.Value, CodeEditorStateFlag.Position);
this.currentRequest = this.editorWorkerService.navigateValueSet(modelURI, selection, this.up);
this.currentRequest = this.editorWorkerService.navigateValueSet(modelURI, selection, up);
this.currentRequest = this.currentRequest.then((basicResult) => {
if (basicResult && basicResult.range && basicResult.value) {
return basicResult;
}
if (support) {
return support.navigateValueSet(modelURI, selection, this.up);
return support.navigateValueSet(modelURI, selection, up);
}
return null;
@ -96,12 +105,12 @@ class InPlaceReplace extends EditorAction {
// Insert new text
var command = new InPlaceReplaceCommand(editRange, selection, result.value);
this.editor.executeCommand(this.id, command);
this.editor.executeCommand(source, command);
// add decoration
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, [{
range: highlightRange,
options: InPlaceReplace.DECORATION
options: InPlaceReplaceController.DECORATION
}]);
// remove decoration after delay
@ -112,44 +121,52 @@ class InPlaceReplace extends EditorAction {
this.decorationIds = accessor.deltaDecorations(this.decorationIds, []);
});
});
return true;
});
}
}
class InPlaceReplaceUp extends InPlaceReplace {
class InPlaceReplaceUp extends EditorAction2 {
public static ID = 'editor.action.inPlaceReplace.up';
constructor() {
super(
'editor.action.inPlaceReplace.up',
nls.localize('InPlaceReplaceAction.previous.label', "Replace with Previous Value"),
'Replace with Previous Value',
true
);
constructor(
descriptor:IEditorActionDescriptorData,
editor:ICommonCodeEditor,
@IEditorWorkerService editorWorkerService:IEditorWorkerService
) {
super(descriptor, editor, true, editorWorkerService);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_COMMA
};
}
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): TPromise<void> {
return InPlaceReplaceController.get(editor).run(this.id, true);
}
}
class InPlaceReplaceDown extends InPlaceReplace {
class InPlaceReplaceDown extends EditorAction2 {
public static ID = 'editor.action.inPlaceReplace.down';
constructor() {
super(
'editor.action.inPlaceReplace.down',
nls.localize('InPlaceReplaceAction.next.label', "Replace with Next Value"),
'Replace with Next Value',
true
);
constructor(
descriptor:IEditorActionDescriptorData,
editor:ICommonCodeEditor,
@IEditorWorkerService editorWorkerService:IEditorWorkerService
) {
super(descriptor, editor, false, editorWorkerService);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_DOT
};
}
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): TPromise<void> {
return InPlaceReplaceController.get(editor).run(this.id, false);
}
}
// register actions
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InPlaceReplaceUp, InPlaceReplaceUp.ID, nls.localize('InPlaceReplaceAction.previous.label', "Replace with Previous Value"), {
context: ContextKey.EditorTextFocus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_COMMA
}, 'Replace with Previous Value'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InPlaceReplaceDown, InPlaceReplaceDown.ID, nls.localize('InPlaceReplaceAction.next.label', "Replace with Next Value"), {
context: ContextKey.EditorTextFocus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_DOT
}, 'Replace with Next Value'));
CommonEditorRegistry.registerEditorContribution(InPlaceReplaceController);
CommonEditorRegistry.registerEditorAction2(new InPlaceReplaceUp());
CommonEditorRegistry.registerEditorAction2(new InPlaceReplaceDown());

View file

@ -5,77 +5,80 @@
import * as nls from 'vs/nls';
import {TPromise} from 'vs/base/common/winjs.base';
import {EditorAction} from 'vs/editor/common/editorAction';
import {ICommonCodeEditor, IEditorActionDescriptorData} from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {ICommonCodeEditor} from 'vs/editor/common/editorCommon';
import {ServicesAccessor, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {IndentationToSpacesCommand, IndentationToTabsCommand} from 'vs/editor/contrib/indentation/common/indentationCommands';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IModelService} from 'vs/editor/common/services/modelService';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
export class IndentationToSpacesAction extends EditorAction {
export class IndentationToSpacesAction extends EditorAction2 {
static ID = 'editor.action.indentationToSpaces';
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor) {
super(descriptor, editor);
constructor() {
super(
IndentationToSpacesAction.ID,
nls.localize('indentationToSpaces', "Convert Indentation to Spaces"),
'Convert Indentation to Spaces',
true
);
}
public run(): TPromise<boolean> {
let model = this.editor.getModel();
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
let model = editor.getModel();
if (!model) {
return;
}
let modelOpts = model.getOptions();
const command = new IndentationToSpacesCommand(this.editor.getSelection(), modelOpts.tabSize);
this.editor.executeCommands(this.id, [command]);
const command = new IndentationToSpacesCommand(editor.getSelection(), modelOpts.tabSize);
editor.executeCommands(this.id, [command]);
model.updateOptions({
insertSpaces: true
});
return TPromise.as(true);
}
}
export class IndentationToTabsAction extends EditorAction {
export class IndentationToTabsAction extends EditorAction2 {
static ID = 'editor.action.indentationToTabs';
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor) {
super(descriptor, editor);
constructor() {
super(
IndentationToTabsAction.ID,
nls.localize('indentationToTabs', "Convert Indentation to Tabs"),
'Convert Indentation to Tabs',
true
);
}
public run(): TPromise<boolean> {
let model = this.editor.getModel();
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
let model = editor.getModel();
if (!model) {
return;
}
let modelOpts = model.getOptions();
const command = new IndentationToTabsCommand(this.editor.getSelection(), modelOpts.tabSize);
this.editor.executeCommands(this.id, [command]);
const command = new IndentationToTabsCommand(editor.getSelection(), modelOpts.tabSize);
editor.executeCommands(this.id, [command]);
model.updateOptions({
insertSpaces: false
});
return TPromise.as(true);
}
}
export class ChangeIndentationSizeAction extends EditorAction {
export class ChangeIndentationSizeAction extends EditorAction2 {
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor,
private insertSpaces: boolean,
private quickOpenService: IQuickOpenService,
private modelService:IModelService
) {
super(descriptor, editor, Behaviour.Writeable);
constructor(id: string, label: string, alias: string, private insertSpaces: boolean) {
super(id, label, alias, false);
}
public run(): TPromise<boolean> {
let model = this.editor.getModel();
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): TPromise<void> {
const quickOpenService = accessor.get(IQuickOpenService);
const modelService = accessor.get(IModelService);
let model = editor.getModel();
if (!model) {
return;
}
let creationOpts = this.modelService.getCreationOptions();
let creationOpts = modelService.getCreationOptions();
const picks = [1, 2, 3, 4, 5, 6, 7, 8].map(n => ({
id: n.toString(),
label: n.toString(),
@ -87,15 +90,13 @@ export class ChangeIndentationSizeAction extends EditorAction {
const autoFocusIndex = Math.min(model.getOptions().tabSize - 1, 7);
return TPromise.timeout(50 /* quick open is sensitive to being opened so soon after another */).then(() =>
this.quickOpenService.pick(picks, { placeHolder: nls.localize({key: 'selectTabWidth', comment: ['Tab corresponds to the tab key'] }, "Select Tab Size for Current File"), autoFocus: { autoFocusIndex } }).then(pick => {
quickOpenService.pick(picks, { placeHolder: nls.localize({key: 'selectTabWidth', comment: ['Tab corresponds to the tab key'] }, "Select Tab Size for Current File"), autoFocus: { autoFocusIndex } }).then(pick => {
if (pick) {
model.updateOptions({
tabSize: parseInt(pick.label, 10),
insertSpaces: this.insertSpaces
});
}
return true;
})
);
}
@ -105,13 +106,13 @@ export class IndentUsingTabs extends ChangeIndentationSizeAction {
static ID = 'editor.action.indentUsingTabs';
constructor(
descriptor: IEditorActionDescriptorData,
editor: ICommonCodeEditor,
@IQuickOpenService quickOpenService: IQuickOpenService,
@IModelService modelService:IModelService
) {
super(descriptor, editor, false, quickOpenService, modelService);
constructor() {
super(
IndentUsingTabs.ID,
nls.localize('indentUsingTabs', "Indent Using Tabs"),
'Indent Using Tabs',
false
);
}
}
@ -119,76 +120,83 @@ export class IndentUsingSpaces extends ChangeIndentationSizeAction {
static ID = 'editor.action.indentUsingSpaces';
constructor(
descriptor: IEditorActionDescriptorData,
editor: ICommonCodeEditor,
@IQuickOpenService quickOpenService: IQuickOpenService,
@IModelService modelService:IModelService
) {
super(descriptor, editor, true, quickOpenService, modelService);
constructor() {
super(
IndentUsingSpaces.ID,
nls.localize('indentUsingSpaces', "Indent Using Spaces"),
'Indent Using Spaces',
true
);
}
}
export class DetectIndentation extends EditorAction {
export class DetectIndentation extends EditorAction2 {
static ID = 'editor.action.detectIndentation';
constructor(
descriptor: IEditorActionDescriptorData,
editor: ICommonCodeEditor,
@IModelService private modelService:IModelService
) {
super(descriptor, editor);
constructor() {
super(
DetectIndentation.ID,
nls.localize('detectIndentation', "Detect Indentation from Content"),
'Detect Indentation from Content',
false
);
}
public run(): TPromise<boolean> {
let model = this.editor.getModel();
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
const modelService = accessor.get(IModelService);
let model = editor.getModel();
if (!model) {
return;
}
let creationOpts = this.modelService.getCreationOptions();
let creationOpts = modelService.getCreationOptions();
model.detectIndentation(creationOpts.insertSpaces, creationOpts.tabSize);
}
}
export class ToggleRenderWhitespaceAction extends EditorAction {
static ID = 'editor.action.toggleRenderWhitespace';
export class ToggleRenderWhitespaceAction extends EditorAction2 {
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor) {
super(descriptor, editor, Behaviour.TextFocus);
constructor() {
super(
'editor.action.toggleRenderWhitespace',
nls.localize('toggleRenderWhitespace', "Toggle Render Whitespace"),
'Toggle Render Whitespace',
false
);
}
public run(): TPromise<boolean> {
this.editor.updateOptions({
renderWhitespace: !this.editor.getConfiguration().viewInfo.renderWhitespace
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
editor.updateOptions({
renderWhitespace: !editor.getConfiguration().viewInfo.renderWhitespace
});
return TPromise.as(true);
}
}
export class ToggleRenderControlCharacterAction extends EditorAction {
static ID = 'editor.action.toggleRenderControlCharacter';
export class ToggleRenderControlCharacterAction extends EditorAction2 {
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor) {
super(descriptor, editor, Behaviour.TextFocus);
constructor() {
super(
'editor.action.toggleRenderControlCharacter',
nls.localize('toggleRenderControlCharacters', "Toggle Control Characters"),
'Toggle Render Control Characters',
false
);
}
public run(): TPromise<boolean> {
this.editor.updateOptions({
renderControlCharacters: !this.editor.getConfiguration().viewInfo.renderControlCharacters
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
editor.updateOptions({
renderControlCharacters: !editor.getConfiguration().viewInfo.renderControlCharacters
});
return TPromise.as(true);
}
}
// register actions
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentationToSpacesAction, IndentationToSpacesAction.ID, nls.localize('indentationToSpaces', "Convert Indentation to Spaces"), void 0, 'Convert Indentation to Spaces'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentationToTabsAction, IndentationToTabsAction.ID, nls.localize('indentationToTabs', "Convert Indentation to Tabs"), void 0, 'Convert Indentation to Tabs'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentUsingSpaces, IndentUsingSpaces.ID, nls.localize('indentUsingSpaces', "Indent Using Spaces"), void 0, 'Indent Using Spaces'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentUsingTabs, IndentUsingTabs.ID, nls.localize('indentUsingTabs', "Indent Using Tabs"), void 0, 'Indent Using Tabs'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(DetectIndentation, DetectIndentation.ID, nls.localize('detectIndentation', "Detect Indentation from Content"), void 0, 'Detect Indentation from Content'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ToggleRenderWhitespaceAction, ToggleRenderWhitespaceAction.ID, nls.localize('toggleRenderWhitespace', "Toggle Render Whitespace"), void 0, 'Toggle Render Whitespace'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ToggleRenderControlCharacterAction, ToggleRenderControlCharacterAction.ID, nls.localize('toggleRenderControlCharacters', "Toggle Control Characters"), void 0, 'Toggle Render Control Characters'));
CommonEditorRegistry.registerEditorAction2(new IndentationToSpacesAction());
CommonEditorRegistry.registerEditorAction2(new IndentationToTabsAction());
CommonEditorRegistry.registerEditorAction2(new IndentUsingSpaces());
CommonEditorRegistry.registerEditorAction2(new IndentUsingTabs());
CommonEditorRegistry.registerEditorAction2(new DetectIndentation());
CommonEditorRegistry.registerEditorAction2(new ToggleRenderWhitespaceAction());
CommonEditorRegistry.registerEditorAction2(new ToggleRenderControlCharacterAction());