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

Adopting EditorAction2

上级 04bed0f8
......@@ -63,7 +63,7 @@ class ExecCommandCutAction extends ClipboardWritingAction {
this.kbOpts = {
commandHandler: execCommandToHandler.bind(null, this.id, 'cut'),
kbExpr: KbExpr.and(EditorKbExpr.Focus, EditorKbExpr.Writable),
kbExpr: KbExpr.and(EditorKbExpr.TextFocus, EditorKbExpr.Writable),
primary: KeyMod.CtrlCmd | KeyCode.KEY_X,
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_X, secondary: [KeyMod.Shift | KeyCode.Delete] }
};
......@@ -101,7 +101,7 @@ class ExecCommandCopyAction extends ClipboardWritingAction {
this.kbOpts = {
commandHandler: execCommandToHandler.bind(null, this.id, 'copy'),
kbExpr: EditorKbExpr.Focus,
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_C, secondary: [KeyMod.CtrlCmd | KeyCode.Insert] }
};
......@@ -132,7 +132,7 @@ class ExecCommandPasteAction extends EditorAction2 {
this.kbOpts = {
commandHandler: execCommandToHandler.bind(null, this.id, 'paste'),
kbExpr: KbExpr.and(EditorKbExpr.Focus, EditorKbExpr.Writable),
kbExpr: KbExpr.and(EditorKbExpr.TextFocus, EditorKbExpr.Writable),
primary: KeyMod.CtrlCmd | KeyCode.KEY_V,
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_V, secondary: [KeyMod.Shift | KeyCode.Insert] }
};
......
......@@ -46,11 +46,11 @@ suite('FindController', () => {
// The cursor is at the very top, of the file, at the first ABC
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
let findState = findController.getState();
let startFindAction = new StartFindAction({id:'',label:''}, editor);
let nextMatchFindAction = new NextMatchFindAction({id:'',label:''}, editor);
let startFindAction = new StartFindAction();
let nextMatchFindAction = new NextMatchFindAction();
// I hit Ctrl+F to show the Find dialog
startFindAction.run();
startFindAction.run(null, editor);
// I type ABC.
findState.change({ searchString: 'A' }, true);
......@@ -84,14 +84,12 @@ suite('FindController', () => {
assert.deepEqual(fromRange(editor.getSelection()), [1, 4, 1, 4]);
// I hit F3 to "Find Next" to find the next occurrence of ABC, but instead it searches for XYZ.
nextMatchFindAction.run();
nextMatchFindAction.run(null, editor);
assert.equal(findState.searchString, 'ABC');
assert.equal(findController.hasFocus, false);
findController.dispose();
startFindAction.dispose();
nextMatchFindAction.dispose();
});
});
......@@ -101,21 +99,20 @@ suite('FindController', () => {
], {}, (editor, cursor) => {
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
let nextMatchFindAction = new NextMatchFindAction({id:'',label:''}, editor);
let nextMatchFindAction = new NextMatchFindAction();
editor.setPosition({
lineNumber: 1,
column: 9
});
nextMatchFindAction.run();
nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [1, 26, 1, 29]);
nextMatchFindAction.run();
nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [1, 8, 1, 11]);
findController.dispose();
nextMatchFindAction.dispose();
});
});
......@@ -127,23 +124,21 @@ suite('FindController', () => {
], {}, (editor, cursor) => {
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
let startFindAction = new StartFindAction({id:'',label:''}, editor);
let nextMatchFindAction = new NextMatchFindAction({id:'',label:''}, editor);
let startFindAction = new StartFindAction();
let nextMatchFindAction = new NextMatchFindAction();
editor.setSelection(new Selection(1, 9, 1, 13));
findController.toggleRegex();
startFindAction.run();
startFindAction.run(null, editor);
nextMatchFindAction.run();
nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [2, 9, 2, 13]);
nextMatchFindAction.run();
nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [1, 9, 1, 13]);
findController.dispose();
startFindAction.dispose();
nextMatchFindAction.dispose();
});
});
......@@ -155,11 +150,11 @@ suite('FindController', () => {
], {}, (editor, cursor) => {
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
let selectHighlightsAction = new SelectHighlightsAction({id:'',label:''}, editor);
let selectHighlightsAction = new SelectHighlightsAction();
editor.setSelection(new Selection(2, 9, 2, 16));
selectHighlightsAction.run();
selectHighlightsAction.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
[2, 9, 2, 16],
[1, 9, 1, 16],
......@@ -171,7 +166,6 @@ suite('FindController', () => {
assert.deepEqual(fromRange(editor.getSelection()), [2, 9, 2, 16]);
findController.dispose();
selectHighlightsAction.dispose();
});
});
......
......@@ -5,15 +5,12 @@
'use strict';
import * as nls from 'vs/nls';
import { onUnexpectedError } from 'vs/base/common/errors';
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 { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { KbExpr } from 'vs/platform/keybinding/common/keybinding';
import { EditorAction } from 'vs/editor/common/editorAction';
import { ICommonCodeEditor, IEditorActionDescriptorData, IEditorContribution, KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS } from 'vs/editor/common/editorCommon';
import { CommonEditorRegistry, ContextKey, EditorActionDescriptor } from 'vs/editor/common/editorCommonExtensions';
import { ICommonCodeEditor, IEditorContribution, KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS } from 'vs/editor/common/editorCommon';
import { ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
import { ISuggestSupport, SuggestRegistry } from 'vs/editor/common/modes';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorBrowserRegistry } from 'vs/editor/browser/editorBrowserExtensions';
......@@ -119,16 +116,14 @@ export class SuggestController implements IEditorContribution {
Object.keys(triggerCharacters).forEach(ch => {
this.triggerCharacterListeners.push(this.editor.addTypingListener(ch, () => {
this.triggerSuggest(ch, triggerCharacters[ch]).done(null, onUnexpectedError);
this.triggerSuggest(ch, triggerCharacters[ch]);
}));
});
}
triggerSuggest(triggerCharacter?: string, groups?: ISuggestSupport[][]): TPromise<boolean> {
triggerSuggest(triggerCharacter?: string, groups?: ISuggestSupport[][]): void {
this.model.trigger(false, triggerCharacter, false, groups);
this.editor.focus();
return TPromise.as(false);
}
acceptSelectedSuggestion(): void {
......@@ -174,34 +169,38 @@ export class SuggestController implements IEditorContribution {
}
}
export class TriggerSuggestAction extends EditorAction {
export class TriggerSuggestAction extends EditorAction2 {
static ID: string = 'editor.action.triggerSuggest';
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor) {
super(descriptor, editor);
constructor() {
super(
'editor.action.triggerSuggest',
nls.localize('suggest.trigger.label', "Trigger Suggest"),
'Trigger Suggest',
true
);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.CtrlCmd | KeyCode.Space,
mac: { primary: KeyMod.WinCtrl | KeyCode.Space }
};
}
isSupported(): boolean {
return SuggestRegistry.has(this.editor.getModel()) && !this.editor.getConfiguration().readOnly;
public supported(accessor:ServicesAccessor, editor:ICommonCodeEditor): boolean {
if (!super.supported(accessor, editor)) {
return false;
}
return SuggestRegistry.has(editor.getModel());
}
run(): TPromise<boolean> {
return SuggestController.getController(this.editor).triggerSuggest();
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
SuggestController.getController(editor).triggerSuggest();
}
}
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(
TriggerSuggestAction,
TriggerSuggestAction.ID,
nls.localize('suggest.trigger.label', "Trigger Suggest"),
{
context: ContextKey.EditorTextFocus,
primary: KeyMod.CtrlCmd | KeyCode.Space,
mac: { primary: KeyMod.WinCtrl | KeyCode.Space }
},
'Trigger Suggest'
));
CommonEditorRegistry.registerEditorAction2(new TriggerSuggestAction());
const weight = CommonEditorRegistry.commandWeight(90);
......
......@@ -7,12 +7,9 @@
import * as nls from 'vs/nls';
import {Registry} from 'vs/platform/platform';
import {TPromise} from 'vs/base/common/winjs.base';
import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
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 {getSnippetController, CodeSnippet} from 'vs/editor/contrib/snippet/common/snippet';
import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
import {IQuickOpenService, IPickOpenEntry} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {ISnippetsRegistry, Extensions, ISnippet} from 'vs/editor/common/modes/snippetsRegistry';
......@@ -20,22 +17,21 @@ interface ISnippetPick extends IPickOpenEntry {
snippet: ISnippet;
}
class ShowSnippetsActions extends EditorAction {
class ShowSnippetsActions extends EditorAction2 {
static ID: string = 'editor.action.showSnippets';
constructor(
descriptor: IEditorActionDescriptorData,
editor: ICommonCodeEditor,
@IQuickOpenService private _quickOpenService: IQuickOpenService,
@ICodeEditorService private _editorService: ICodeEditorService
) {
super(descriptor, editor, Behaviour.Writeable);
constructor() {
super(
'editor.action.showSnippets',
nls.localize('snippet.suggestions.label', "Insert Snippet"),
'Insert Snippet',
true
);
}
run(): TPromise<boolean> {
const editor = this._editorService.getFocusedCodeEditor();
if (!editor || !editor.getModel()) {
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): TPromise<void> {
const quickOpenService = accessor.get(IQuickOpenService);
if (!editor.getModel()) {
return;
}
......@@ -49,19 +45,12 @@ class ShowSnippetsActions extends EditorAction {
return true;
});
return this._quickOpenService.pick(picks).then(pick => {
return quickOpenService.pick(picks).then(pick => {
if (pick) {
getSnippetController(this.editor).run(new CodeSnippet(pick.snippet.codeSnippet), 0, 0);
return true;
getSnippetController(editor).run(new CodeSnippet(pick.snippet.codeSnippet), 0, 0);
}
});
}
}
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(
ShowSnippetsActions,
ShowSnippetsActions.ID,
nls.localize('snippet.suggestions.label', "Insert Snippet"),
undefined,
'Insert Snippet'
));
CommonEditorRegistry.registerEditorAction2(new ShowSnippetsActions());
......@@ -6,36 +6,32 @@
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 {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 {TabFocus} from 'vs/editor/common/config/commonEditorConfig';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
export class ToggleTabFocusModeAction extends EditorAction {
export class ToggleTabFocusModeAction extends EditorAction2 {
public static ID = 'editor.action.toggleTabFocusMode';
constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) {
super(descriptor, editor, Behaviour.TextFocus);
constructor() {
super(
ToggleTabFocusModeAction.ID,
nls.localize('toggle.tabfocusmode', "Toggle Use of Tab Key for Setting Focus"),
'Toggle Use of Tab Key for Setting Focus',
false
);
}
public run():TPromise<boolean> {
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
let oldValue = TabFocus.getTabFocusMode();
TabFocus.setTabFocusMode(!oldValue);
return TPromise.as(true);
}
}
// register actions
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ToggleTabFocusModeAction, ToggleTabFocusModeAction.ID, nls.localize('toggle.tabfocusmode', "Toggle Use of Tab Key for Setting Focus"), {
primary: null,
context: null
}, 'Toggle Use of Tab Key for Setting Focus'));
CommonEditorRegistry.registerEditorAction2(new ToggleTabFocusModeAction());
KeybindingsRegistry.registerCommandRule({
id: ToggleTabFocusModeAction.ID,
......
......@@ -6,23 +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 {ICommonCodeEditor, IEditorActionDescriptorData} from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
class ToggleWordWrapAction extends EditorAction {
static ID = 'editor.action.toggleWordWrap';
constructor(descriptor:IEditorActionDescriptorData, editor:ICommonCodeEditor) {
super(descriptor, editor, Behaviour.TextFocus);
import {ICommonCodeEditor} from 'vs/editor/common/editorCommon';
import {ServicesAccessor, EditorKbExpr, EditorAction2, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
class ToggleWordWrapAction extends EditorAction2 {
constructor() {
super(
'editor.action.toggleWordWrap',
nls.localize('toggle.wordwrap', "View: Toggle Word Wrap"),
'View: Toggle Word Wrap',
false
);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyMod.Alt | KeyCode.KEY_Z
};
}
public run():TPromise<boolean> {
public run(accessor:ServicesAccessor, editor:ICommonCodeEditor): void {
let wrappingInfo = this.editor.getConfiguration().wrappingInfo;
let wrappingInfo = editor.getConfiguration().wrappingInfo;
let newWrappingColumn: number;
if (!wrappingInfo.isViewportWrapping) {
......@@ -31,18 +36,11 @@ class ToggleWordWrapAction extends EditorAction {
newWrappingColumn = -1;
}
this.editor.updateOptions({
editor.updateOptions({
wrappingColumn: newWrappingColumn
});
return TPromise.as(true);
}
}
// register actions
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ToggleWordWrapAction, ToggleWordWrapAction.ID, nls.localize('toggle.wordwrap', "View: Toggle Word Wrap"), {
context: ContextKey.EditorTextFocus,
primary: KeyMod.Alt | KeyCode.KEY_Z,
mac: { primary: KeyMod.Alt | KeyCode.KEY_Z },
linux: { primary: KeyMod.Alt | KeyCode.KEY_Z }
}, 'View: Toggle Word Wrap'));
CommonEditorRegistry.registerEditorAction2(new ToggleWordWrapAction());
......@@ -10,9 +10,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {Range} from 'vs/editor/common/core/range';
import editorCommon = require('vs/editor/common/editorCommon');
import editorbrowser = require('vs/editor/browser/editorBrowser');
import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {KbExpr, IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {ICommandService} from 'vs/platform/commands/common/commands';
import debug = require('vs/workbench/parts/debug/common/debug');
import model = require('vs/workbench/parts/debug/common/debugModel');
......@@ -20,6 +18,8 @@ import {BreakpointWidget} from 'vs/workbench/parts/debug/browser/breakpointWidge
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {ServicesAccessor, EditorKbExpr, EditorAction2} from 'vs/editor/common/editorCommonExtensions';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import IDebugService = debug.IDebugService;
export class AbstractDebugAction extends actions.Action {
......@@ -516,45 +516,55 @@ export class EditConditionalBreakpointAction extends AbstractDebugAction {
}
}
export class ToggleBreakpointAction extends EditorAction {
static ID = 'editor.debug.action.toggleBreakpoint';
export class ToggleBreakpointAction extends EditorAction2 {
constructor() {
super(
'editor.debug.action.toggleBreakpoint',
nls.localize('toggleBreakpointAction', "Debug: Toggle Breakpoint"),
'Debug: Toggle Breakpoint',
false
);
constructor(descriptor: editorCommon.IEditorActionDescriptorData, editor: editorCommon.ICommonCodeEditor, @IDebugService private debugService: IDebugService) {
super(descriptor, editor, Behaviour.TextFocus);
this.kbOpts = {
kbExpr: EditorKbExpr.TextFocus,
primary: KeyCode.F9
};
}
public run(): TPromise<any> {
const lineNumber = this.editor.getPosition().lineNumber;
const modelUrl = this.editor.getModel().uri;
if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) {
const bp = this.debugService.getModel().getBreakpoints()
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): TPromise<void> {
const debugService = accessor.get(IDebugService);
const lineNumber = editor.getPosition().lineNumber;
const modelUrl = editor.getModel().uri;
if (debugService.getConfigurationManager().canSetBreakpointsIn(editor.getModel())) {
const bp = debugService.getModel().getBreakpoints()
.filter(bp => bp.lineNumber === lineNumber && bp.source.uri.toString() === modelUrl.toString()).pop();
return bp ? this.debugService.removeBreakpoints(bp.getId())
: this.debugService.addBreakpoints([{ uri: modelUrl, lineNumber: lineNumber }]);
return bp ? debugService.removeBreakpoints(bp.getId())
: debugService.addBreakpoints([{ uri: modelUrl, lineNumber: lineNumber }]);
}
}
}
export class EditorConditionalBreakpointAction extends EditorAction {
static ID = 'editor.debug.action.conditionalBreakpoint';
export class EditorConditionalBreakpointAction extends EditorAction2 {
constructor(
descriptor: editorCommon.IEditorActionDescriptorData,
editor: editorCommon.ICommonCodeEditor,
@IDebugService private debugService: IDebugService,
@IInstantiationService private instantiationService: IInstantiationService
) {
super(descriptor, editor, Behaviour.TextFocus);
constructor() {
super(
'editor.debug.action.conditionalBreakpoint',
nls.localize('conditionalBreakpointEditorAction', "Debug: Conditional Breakpoint"),
'Debug: Conditional Breakpoint',
false
);
}
public run(): TPromise<any> {
const lineNumber = this.editor.getPosition().lineNumber;
if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) {
BreakpointWidget.createInstance(<editorbrowser.ICodeEditor>this.editor, lineNumber, this.instantiationService);
}
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void {
const debugService = accessor.get(IDebugService);
const instantiationService = accessor.get(IInstantiationService);
return TPromise.as(null);
const lineNumber = editor.getPosition().lineNumber;
if (debugService.getConfigurationManager().canSetBreakpointsIn(editor.getModel())) {
BreakpointWidget.createInstance(<editorbrowser.ICodeEditor>editor, lineNumber, instantiationService);
}
}
}
......@@ -580,42 +590,55 @@ export class SetValueAction extends AbstractDebugAction {
}
}
export class RunToCursorAction extends EditorAction {
static ID = 'editor.debug.action.runToCursor';
export class RunToCursorAction extends EditorAction2 {
private debugService: IDebugService;
constructor() {
super(
'editor.debug.action.runToCursor',
nls.localize('runToCursor', "Debug: Run to Cursor"),
'Debug: Run to Cursor',
false
);
constructor(descriptor:editorCommon.IEditorActionDescriptorData, editor:editorCommon.ICommonCodeEditor, @IDebugService debugService: IDebugService) {
super(descriptor, editor, Behaviour.TextFocus);
this.debugService = debugService;
this.menuOpts = {
kbExpr: KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE),
group: 'debug'
};
}
public run(): TPromise<void> {
if (this.debugService.state !== debug.State.Stopped) {
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): TPromise<void> {
const debugService = accessor.get(IDebugService);
if (debugService.state !== debug.State.Stopped) {
return TPromise.as(null);
}
const lineNumber = this.editor.getPosition().lineNumber;
const uri = this.editor.getModel().uri;
const lineNumber = editor.getPosition().lineNumber;
const uri = editor.getModel().uri;
const oneTimeListener = this.debugService.getActiveSession().onDidEvent(event => {
const oneTimeListener = debugService.getActiveSession().onDidEvent(event => {
if (event.event === 'stopped' || event.event === 'exit') {
const toRemove = this.debugService.getModel().getBreakpoints()
const toRemove = debugService.getModel().getBreakpoints()
.filter(bp => bp.desiredLineNumber === lineNumber && bp.source.uri.toString() === uri.toString()).pop();
if (toRemove) {
this.debugService.removeBreakpoints(toRemove.getId());
debugService.removeBreakpoints(toRemove.getId());
}
oneTimeListener.dispose();
}
});
const bpExists = !!(this.debugService.getModel().getBreakpoints().filter(bp => bp.lineNumber === lineNumber && bp.source.uri.toString() === uri.toString()).pop());
return (bpExists ? TPromise.as(null) : this.debugService.addBreakpoints([{ uri, lineNumber }])).then(() => {
this.debugService.continue(this.debugService.getViewModel().getFocusedThreadId());
const bpExists = !!(debugService.getModel().getBreakpoints().filter(bp => bp.lineNumber === lineNumber && bp.source.uri.toString() === uri.toString()).pop());
return (bpExists ? TPromise.as(null) : debugService.addBreakpoints([{ uri, lineNumber }])).then(() => {
debugService.continue(debugService.getViewModel().getFocusedThreadId());
});
}
public isSupported(): boolean {
return super.isSupported() && this.debugService.state === debug.State.Stopped;
public supported(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean {
if (!super.supported(accessor, editor)) {
return false;
}
const debugService = accessor.get(IDebugService);
return debugService.state === debug.State.Stopped;
}
}
......@@ -637,46 +660,69 @@ export class AddWatchExpressionAction extends AbstractDebugAction {
}
}
export class SelectionToReplAction extends EditorAction {
static ID = 'editor.debug.action.selectionToRepl';
export class SelectionToReplAction extends EditorAction2 {
constructor(
descriptor: editorCommon.IEditorActionDescriptorData,
editor: editorCommon.ICommonCodeEditor,
@IDebugService private debugService: IDebugService,
@IPanelService private panelService: IPanelService
) {
super(descriptor, editor, Behaviour.UpdateOnCursorPositionChange);
constructor() {
super(
'editor.debug.action.selectionToRepl',
nls.localize('debugEvaluate', "Debug: Evaluate"),
'Debug: Evaluate',
false
);
this.menuOpts = {
kbExpr: KbExpr.and(KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION), KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE)),
group: 'debug'
};
}
public run(): TPromise<any> {
const text = this.editor.getModel().getValueInRange(this.editor.getSelection());
return this.debugService.addReplExpression(text)
.then(() => this.panelService.openPanel(debug.REPL_ID, true));
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): TPromise<void> {
const debugService = accessor.get(IDebugService);
const panelService = accessor.get(IPanelService);
const text = editor.getModel().getValueInRange(editor.getSelection());
return debugService.addReplExpression(text)
.then(() => panelService.openPanel(debug.REPL_ID, true))
.then(_ => void 0);
}
public isSupported(): boolean {
const selection = this.editor.getSelection();
return !!selection && !selection.isEmpty() && this.debugService.state !== debug.State.Disabled && this.debugService.state !== debug.State.Inactive;
public supported(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): boolean {
if (!super.supported(accessor, editor)) {
return false;
}
const debugService = accessor.get(IDebugService);
const selection = editor.getSelection();
return !!selection && !selection.isEmpty() && debugService.state !== debug.State.Disabled && debugService.state !== debug.State.Inactive;
}
}
export class ShowDebugHoverAction extends EditorAction {
static ID = 'editor.debug.action.showDebugHover';
export class ShowDebugHoverAction extends EditorAction2 {
constructor() {
super(
'editor.debug.action.showDebugHover',
nls.localize('showDebugHover', "Debug: Show Hover"),
'Debug: Show Hover',
false
);
constructor(descriptor: editorCommon.IEditorActionDescriptorData, editor: editorCommon.ICommonCodeEditor) {
super(descriptor, editor, Behaviour.TextFocus);
this.kbOpts = {
kbExpr: KbExpr.and(KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE), KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS)),
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_I)
};
}
public run(): TPromise<any> {
const position = this.editor.getPosition();
const word = this.editor.getModel().getWordAtPosition(position);
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): TPromise<void> {
const position = editor.getPosition();
const word = editor.getModel().getWordAtPosition(position);
if (!word) {
return TPromise.as(null);
}
const range = new Range(position.lineNumber, position.column, position.lineNumber, word.endColumn);
return (<debug.IDebugEditorContribution>this.editor.getContribution(debug.EDITOR_CONTRIBUTION_ID)).showHover(range, word.word, true);
return (<debug.IDebugEditorContribution>editor.getContribution(debug.EDITOR_CONTRIBUTION_ID)).showHover(range, word.word, true);
}
}
......
......@@ -8,8 +8,7 @@ import 'vs/css!../browser/media/debugHover';
import nls = require('vs/nls');
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import {TPromise} from 'vs/base/common/winjs.base';
import editorcommon = require('vs/editor/common/editorCommon');
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor, defaultEditorActionKeybindingOptions} from 'vs/editor/common/editorCommonExtensions';
import {CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import platform = require('vs/platform/platform');
......@@ -51,38 +50,11 @@ class OpenDebugViewletAction extends viewlet.ToggleViewletAction {
}
EditorBrowserRegistry.registerEditorContribution(DebugEditorContribution);
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ToggleBreakpointAction, ToggleBreakpointAction.ID, nls.localize('toggleBreakpointAction', "Debug: Toggle Breakpoint"), {
context: ContextKey.EditorTextFocus,
primary: KeyCode.F9
}, 'Debug: Toggle Breakpoint'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ShowDebugHoverAction, ShowDebugHoverAction.ID, nls.localize('showDebugHover', "Debug: Show Hover"), {
context: ContextKey.EditorTextFocus,
kbExpr: KbExpr.and(KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE), KbExpr.has(editorcommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS)),
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_I)
}, 'Debug: Show Hover'));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(EditorConditionalBreakpointAction, EditorConditionalBreakpointAction.ID, nls.localize('conditionalBreakpointEditorAction', "Debug: Conditional Breakpoint"), void 0, 'Debug: Conditional Breakpoint'));
CommonEditorRegistry.registerEditorAction({
ctor: SelectionToReplAction,
id: SelectionToReplAction.ID,
label: nls.localize('debugEvaluate', "Debug: Evaluate"),
alias: 'Debug: Evaluate',
kbOpts: defaultEditorActionKeybindingOptions,
menuOpts: {
kbExpr: KbExpr.and(KbExpr.has(editorcommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION), KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE)),
group: 'debug'
}
});
CommonEditorRegistry.registerEditorAction({
ctor: RunToCursorAction,
id: RunToCursorAction.ID,
label: nls.localize('runToCursor', "Debug: Run to Cursor"),
alias: 'Debug: Run to Cursor',
kbOpts: defaultEditorActionKeybindingOptions,
menuOpts: {
kbExpr: KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE),
group: 'debug'
}
});
CommonEditorRegistry.registerEditorAction2(new ToggleBreakpointAction());
CommonEditorRegistry.registerEditorAction2(new ShowDebugHoverAction());
CommonEditorRegistry.registerEditorAction2(new EditorConditionalBreakpointAction());
CommonEditorRegistry.registerEditorAction2(new SelectionToReplAction());
CommonEditorRegistry.registerEditorAction2(new RunToCursorAction());
// register viewlet
(<viewlet.ViewletRegistry>platform.Registry.as(viewlet.Extensions.Viewlets)).registerViewlet(new viewlet.ViewletDescriptor(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册