diff --git a/src/vs/editor/contrib/indentation/common/indentation.ts b/src/vs/editor/contrib/indentation/common/indentation.ts index a81f4b15682191432a7d45a75e4ee1610ad1f3da..2633d2878efd6316c34bd74ea318c6592440a4c5 100644 --- a/src/vs/editor/contrib/indentation/common/indentation.ts +++ b/src/vs/editor/contrib/indentation/common/indentation.ts @@ -10,6 +10,7 @@ import {EditorAction} from 'vs/editor/common/editorAction'; import {ICommonCodeEditor, IEditorActionDescriptorData} from 'vs/editor/common/editorCommon'; import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions'; import {IndentationToSpacesCommand, IndentationToTabsCommand} from 'vs/editor/contrib/indentation/common/indentationCommands'; +import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService'; export class IndentationToSpacesAction extends EditorAction { static ID = 'editor.action.indentationToSpaces'; @@ -22,7 +23,7 @@ export class IndentationToSpacesAction extends EditorAction { const command = new IndentationToSpacesCommand(this.editor.getSelection(), this.editor.getIndentationOptions().tabSize); this.editor.executeCommands(this.id, [command]); - + return TPromise.as(true); } } @@ -43,6 +44,43 @@ export class IndentationToTabsAction extends EditorAction { } } +abstract class Indent extends EditorAction { + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, private insertSpaces: boolean, private quickOpenService: IQuickOpenService) { + super(descriptor, editor); + } + + public run(): TPromise { + return TPromise.timeout(50 /* quick open is sensitive to being opened so soon after another */).then(() => + this.quickOpenService.pick(['1', '2', '3', '4', '5', '6', '7', '8'], { placeHolder: nls.localize('selectTabWidth', "Select Tab Width")}).then(pick => { + this.editor.setIndentationOptions({ + insertSpaces: this.insertSpaces, + tabSize: parseInt(pick) + }); + return true; + }) + ); + } +} + +export class IndentUsingSpaces extends Indent { + static ID = 'editor.action.indentUsingSpaces'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IQuickOpenService quickOpenService: IQuickOpenService) { + super(descriptor, editor, true, quickOpenService); + } +} + +export class IndentUsingTabs extends Indent { + static ID = 'editor.action.indentUsingTabs'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IQuickOpenService quickOpenService: IQuickOpenService) { + super(descriptor, editor, false, quickOpenService); + } +} + // register actions CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentationToSpacesAction, IndentationToSpacesAction.ID, nls.localize('indentationToSpaces', "Convert Indentation to Spaces"))); CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentationToTabsAction, IndentationToTabsAction.ID, nls.localize('indentationToTabs', "Convert Indentation to Tabs"))); +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentUsingSpaces, IndentUsingSpaces.ID, nls.localize('indentUsingSpaces', "Indent Using Spaces"))); +CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentUsingTabs, IndentUsingTabs.ID, nls.localize('indentUsingTabs', "Indent Using Tabs"))); diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index aa67aa361de4ed14680e18879fdedbde740f746e..b42f3831d534e0d29fec49403b4ef1ad8b99db18 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -22,7 +22,7 @@ import {IDisposable, combinedDispose} from 'vs/base/common/lifecycle'; import {ICommonCodeEditor} from 'vs/editor/common/editorCommon'; import {ICodeEditor, IDiffEditor} from 'vs/editor/browser/editorBrowser'; import {EndOfLineSequence, ITokenizedModel, EditorType, IEditorSelection, ITextModel, IDiffEditorModel, IEditor} from 'vs/editor/common/editorCommon'; -import {IndentationToSpacesAction, IndentationToTabsAction} from 'vs/editor/contrib/indentation/common/indentation'; +import {IndentUsingSpaces, IndentUsingTabs, IndentationToSpacesAction, IndentationToTabsAction} from 'vs/editor/contrib/indentation/common/indentation'; import {EventType, ResourceEvent, EditorEvent, TextEditorSelectionEvent} from 'vs/workbench/common/events'; import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor'; import {IEditor as IBaseEditor} from 'vs/platform/editor/common/editor'; @@ -685,9 +685,9 @@ export class ChangeIndentationAction extends Action { } const control = activeEditor.getControl(); - return this.quickOpenService.pick([control.getAction(IndentationToSpacesAction.ID), control.getAction(IndentationToTabsAction.ID)], { + return this.quickOpenService.pick([control.getAction(IndentUsingSpaces.ID), control.getAction(IndentUsingTabs.ID), control.getAction(IndentationToSpacesAction.ID), control.getAction(IndentationToTabsAction.ID)], { placeHolder: nls.localize('pickAction', "Select Action") - }).then(action => action.run()); + }).then(action => action && action.run()); } }