diff --git a/src/vs/editor/contrib/indentation/common/indentation.ts b/src/vs/editor/contrib/indentation/common/indentation.ts index 975b171ba437e8d53cd635b62c1c8760cd7cf18c..b44d9949bd567ec7a420110e26d0864b505a6e85 100644 --- a/src/vs/editor/contrib/indentation/common/indentation.ts +++ b/src/vs/editor/contrib/indentation/common/indentation.ts @@ -52,11 +52,10 @@ export class IndentationToTabsAction extends EditorAction { export class ChangeIndentationSizeAction extends EditorAction { - static ID = 'editor.action.changeIndentationSize'; - constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, - @IQuickOpenService private quickOpenService: IQuickOpenService, - @IConfigurationService private configurationService: IConfigurationService + private insertSpaces: boolean, + private quickOpenService: IQuickOpenService, + private configurationService: IConfigurationService ) { super(descriptor, editor); } @@ -67,15 +66,16 @@ export class ChangeIndentationSizeAction extends EditorAction { const picks = [1, 2, 3, 4, 5, 6, 7, 8].map(n => ({ id: n.toString(), label: n.toString(), - description: n === config.tabSize ? nls.localize('configuredTabSize', "Configured Tab Size") : null + description: n === config.tabSize ? nls.localize('configuredIndentationSize', "Configured Indentation Size") : null })); const autoFocusIndex = Math.min(this.editor.getIndentationOptions().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('selectTabWidth', "Select Tab Size for Current File"), autoFocus: { autoFocusIndex } }).then(pick => { + this.quickOpenService.pick(picks, { placeHolder: nls.localize('selectIndentationSize', "Select Indentation Size for Current File"), autoFocus: { autoFocusIndex } }).then(pick => { if (pick) { this.editor.updateOptions({ - tabSize: parseInt(pick.label) + tabSize: parseInt(pick.label), + insertSpaces: this.insertSpaces }); } @@ -86,6 +86,30 @@ export class ChangeIndentationSizeAction extends EditorAction { } } +export class IndentUsingTabs extends ChangeIndentationSizeAction { + + static ID = 'editor.action.indentUsingTabs'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, + @IQuickOpenService quickOpenService: IQuickOpenService, + @IConfigurationService configurationService: IConfigurationService + ) { + super(descriptor, editor, false, quickOpenService, configurationService); + } +} + +export class IndentUsingSpaces extends ChangeIndentationSizeAction { + + static ID = 'editor.action.indentUsingSpaces'; + + constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, + @IQuickOpenService quickOpenService: IQuickOpenService, + @IConfigurationService configurationService: IConfigurationService + ) { + super(descriptor, editor, true, quickOpenService, configurationService); + } +} + export class ToggleRenderWhitespaceAction extends EditorAction { static ID = 'editor.action.toggleRenderWhitespace'; @@ -105,5 +129,6 @@ export class ToggleRenderWhitespaceAction extends EditorAction { // 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(ChangeIndentationSizeAction, ChangeIndentationSizeAction.ID, nls.localize('changeIndentationSize', "Change Tab Size for Current File"))); +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"))); CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ToggleRenderWhitespaceAction, ToggleRenderWhitespaceAction.ID, nls.localize('toggleRenderWhitespace', "Toggle Render Whitespace"))); diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 03050e74f7bff2c7ff917331cf3c4d1cafff7fb3..daab52963daa58634ac99dfe81d0e8425b188de7 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 {ChangeIndentationSizeAction, 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'; @@ -737,7 +737,7 @@ class ChangeIndentationAction extends Action { } const control = activeEditor.getControl(); - return this.quickOpenService.pick([control.getAction(ChangeIndentationSizeAction.ID), 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 && action.run()); }