提交 1ae17c0e 编写于 作者: I isidor

indentation: IndentUsingTabs and IndentUsingSpaces actions

上级 f61fb802
......@@ -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<boolean> {
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")));
......@@ -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 = <ICommonCodeEditor>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());
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册