提交 2992a0da 编写于 作者: I isidor

indentation: indentUsingTabs, indentUsingSpaces actions

上级 460783f3
...@@ -52,11 +52,10 @@ export class IndentationToTabsAction extends EditorAction { ...@@ -52,11 +52,10 @@ export class IndentationToTabsAction extends EditorAction {
export class ChangeIndentationSizeAction extends EditorAction { export class ChangeIndentationSizeAction extends EditorAction {
static ID = 'editor.action.changeIndentationSize';
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor,
@IQuickOpenService private quickOpenService: IQuickOpenService, private insertSpaces: boolean,
@IConfigurationService private configurationService: IConfigurationService private quickOpenService: IQuickOpenService,
private configurationService: IConfigurationService
) { ) {
super(descriptor, editor); super(descriptor, editor);
} }
...@@ -67,15 +66,16 @@ export class ChangeIndentationSizeAction extends EditorAction { ...@@ -67,15 +66,16 @@ export class ChangeIndentationSizeAction extends EditorAction {
const picks = [1, 2, 3, 4, 5, 6, 7, 8].map(n => ({ const picks = [1, 2, 3, 4, 5, 6, 7, 8].map(n => ({
id: n.toString(), id: n.toString(),
label: 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); 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(() => 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) { if (pick) {
this.editor.updateOptions({ this.editor.updateOptions({
tabSize: parseInt(pick.label) tabSize: parseInt(pick.label),
insertSpaces: this.insertSpaces
}); });
} }
...@@ -86,6 +86,30 @@ export class ChangeIndentationSizeAction extends EditorAction { ...@@ -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 { export class ToggleRenderWhitespaceAction extends EditorAction {
static ID = 'editor.action.toggleRenderWhitespace'; static ID = 'editor.action.toggleRenderWhitespace';
...@@ -105,5 +129,6 @@ export class ToggleRenderWhitespaceAction extends EditorAction { ...@@ -105,5 +129,6 @@ export class ToggleRenderWhitespaceAction extends EditorAction {
// register actions // register actions
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(IndentationToSpacesAction, IndentationToSpacesAction.ID, nls.localize('indentationToSpaces', "Convert Indentation to Spaces"))); 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(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"))); CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(ToggleRenderWhitespaceAction, ToggleRenderWhitespaceAction.ID, nls.localize('toggleRenderWhitespace', "Toggle Render Whitespace")));
...@@ -22,7 +22,7 @@ import {IDisposable, combinedDispose} from 'vs/base/common/lifecycle'; ...@@ -22,7 +22,7 @@ import {IDisposable, combinedDispose} from 'vs/base/common/lifecycle';
import {ICommonCodeEditor} from 'vs/editor/common/editorCommon'; import {ICommonCodeEditor} from 'vs/editor/common/editorCommon';
import {ICodeEditor, IDiffEditor} from 'vs/editor/browser/editorBrowser'; import {ICodeEditor, IDiffEditor} from 'vs/editor/browser/editorBrowser';
import {EndOfLineSequence, ITokenizedModel, EditorType, IEditorSelection, ITextModel, IDiffEditorModel, IEditor} from 'vs/editor/common/editorCommon'; 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 {EventType, ResourceEvent, EditorEvent, TextEditorSelectionEvent} from 'vs/workbench/common/events';
import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor'; import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
import {IEditor as IBaseEditor} from 'vs/platform/editor/common/editor'; import {IEditor as IBaseEditor} from 'vs/platform/editor/common/editor';
...@@ -737,7 +737,7 @@ class ChangeIndentationAction extends Action { ...@@ -737,7 +737,7 @@ class ChangeIndentationAction extends Action {
} }
const control = <ICommonCodeEditor>activeEditor.getControl(); const control = <ICommonCodeEditor>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") placeHolder: nls.localize('pickAction', "Select Action")
}).then(action => action && action.run()); }).then(action => action && action.run());
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册