mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-26 10:16:01 +01:00
editorStatus: show encoding
This commit is contained in:
@@ -11,7 +11,7 @@ import {ICommonCodeEditor, IEditorActionDescriptorData} from 'vs/editor/common/e
|
||||
import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
|
||||
import {IndentationToSpacesCommand, IndentationToTabsCommand} from 'vs/editor/contrib/indentation/common/indentationCommands';
|
||||
|
||||
class IndentationToSpacesAction extends EditorAction {
|
||||
export class IndentationToSpacesAction extends EditorAction {
|
||||
static ID = 'editor.action.indentationToSpaces';
|
||||
|
||||
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @INullService ns) {
|
||||
@@ -22,12 +22,12 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
class IndentationToTabsAction extends EditorAction {
|
||||
export class IndentationToTabsAction extends EditorAction {
|
||||
static ID = 'editor.action.indentationToTabs';
|
||||
|
||||
constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @INullService ns) {
|
||||
|
||||
@@ -79,6 +79,7 @@ interface IEditorSelectionStatus {
|
||||
}
|
||||
|
||||
interface IStateChange {
|
||||
indentation: boolean;
|
||||
selectionStatus: boolean;
|
||||
mode: boolean;
|
||||
encoding: boolean;
|
||||
@@ -91,6 +92,7 @@ interface StateDelta {
|
||||
mode?: string;
|
||||
encoding?: string;
|
||||
EOL?: string;
|
||||
indentation?: string;
|
||||
tabFocusMode?: boolean;
|
||||
}
|
||||
|
||||
@@ -107,6 +109,9 @@ class State {
|
||||
private _EOL: string;
|
||||
public get EOL(): string { return this._EOL; }
|
||||
|
||||
private _indentation: string;
|
||||
public get indentation(): string { return this._indentation; }
|
||||
|
||||
private _tabFocusMode: boolean;
|
||||
public get tabFocusMode(): boolean { return this._tabFocusMode; }
|
||||
|
||||
@@ -124,7 +129,8 @@ class State {
|
||||
mode: false,
|
||||
encoding: false,
|
||||
EOL: false,
|
||||
tabFocusMode: false
|
||||
tabFocusMode: false,
|
||||
indentation: false
|
||||
};
|
||||
let somethingChanged = false;
|
||||
|
||||
@@ -135,6 +141,13 @@ class State {
|
||||
e.selectionStatus = true;
|
||||
}
|
||||
}
|
||||
if (typeof update.indentation !== 'undefined') {
|
||||
if (this._indentation !== update.indentation) {
|
||||
this._indentation = update.indentation;
|
||||
somethingChanged = true;
|
||||
e.indentation = true;
|
||||
}
|
||||
}
|
||||
if (typeof update.mode !== 'undefined') {
|
||||
if (this._mode !== update.mode) {
|
||||
this._mode = update.mode;
|
||||
@@ -191,6 +204,7 @@ export class EditorStatus implements IStatusbarItem {
|
||||
private state: State;
|
||||
private element: HTMLElement;
|
||||
private tabFocusModeElement: HTMLElement;
|
||||
private indentationElement: HTMLElement;
|
||||
private selectionElement: HTMLElement;
|
||||
private encodingElement: HTMLElement;
|
||||
private eolElement: HTMLElement;
|
||||
@@ -217,6 +231,11 @@ export class EditorStatus implements IStatusbarItem {
|
||||
this.tabFocusModeElement.textContent = nlsTabFocusMode;
|
||||
hide(this.tabFocusModeElement);
|
||||
|
||||
this.indentationElement = append(this.element, $('a.editor-status-indentation'));
|
||||
this.indentationElement.title = nls.localize('indentation', "Indentation");
|
||||
this.indentationElement.onclick = () => this.onIndentationClick();
|
||||
hide(this.indentationElement);
|
||||
|
||||
this.selectionElement = append(this.element, $('a.editor-status-selection'));
|
||||
this.selectionElement.title = nls.localize('gotoLine', "Go to Line");
|
||||
this.selectionElement.onclick = () => this.onSelectionClick();
|
||||
@@ -243,7 +262,8 @@ export class EditorStatus implements IStatusbarItem {
|
||||
this.eventService.addListener2(EventType.TEXT_EDITOR_SELECTION_CHANGED, (e: TextEditorSelectionEvent) => this.onSelectionChange(e.editor)),
|
||||
this.eventService.addListener2(EventType.TEXT_EDITOR_MODE_CHANGED, (e: EditorEvent) => this.onModeChange(e.editor)),
|
||||
this.eventService.addListener2(EventType.TEXT_EDITOR_CONTENT_CHANGED, (e: EditorEvent) => this.onEOLChange(e.editor)),
|
||||
this.eventService.addListener2(EventType.TEXT_EDITOR_CONFIGURATION_CHANGED, (e: EditorEvent) => this.onTabFocusModeChange(e.editor))
|
||||
this.eventService.addListener2(EventType.TEXT_EDITOR_CONFIGURATION_CHANGED, (e: EditorEvent) => this.onTabFocusModeChange(e.editor)),
|
||||
this.eventService.addListener2(EventType.TEXT_EDITOR_CONFIGURATION_CHANGED, (e: EditorEvent) => this.onIndentationChange(e.editor))
|
||||
);
|
||||
|
||||
return combinedDispose(...this.toDispose);
|
||||
@@ -264,6 +284,15 @@ export class EditorStatus implements IStatusbarItem {
|
||||
}
|
||||
}
|
||||
|
||||
if (changed.indentation) {
|
||||
if (this.state.indentation) {
|
||||
this.indentationElement.textContent = this.state.indentation;
|
||||
show(this.indentationElement);
|
||||
} else {
|
||||
hide(this.indentationElement);
|
||||
}
|
||||
}
|
||||
|
||||
if (changed.selectionStatus) {
|
||||
if (this.state.selectionStatus) {
|
||||
this.selectionElement.textContent = this.state.selectionStatus;
|
||||
@@ -328,6 +357,12 @@ export class EditorStatus implements IStatusbarItem {
|
||||
action.dispose();
|
||||
}
|
||||
|
||||
private onIndentationClick(): void {
|
||||
const action = this.instantiationService.createInstance(ChangeIndentationAction, ChangeIndentationAction.ID, ChangeIndentationAction.LABEL);
|
||||
action.run().done(null, errors.onUnexpectedError);
|
||||
action.dispose();
|
||||
}
|
||||
|
||||
private onSelectionClick(): void {
|
||||
this.quickOpenService.show(':'); // "Go to line"
|
||||
}
|
||||
@@ -359,6 +394,7 @@ export class EditorStatus implements IStatusbarItem {
|
||||
this.onEOLChange(e);
|
||||
this.onEncodingChange(e);
|
||||
this.onTabFocusModeChange(e);
|
||||
this.onIndentationChange(e);
|
||||
}
|
||||
|
||||
private onModeChange(e: IBaseEditor): void {
|
||||
@@ -386,6 +422,16 @@ export class EditorStatus implements IStatusbarItem {
|
||||
this.updateState(info);
|
||||
}
|
||||
|
||||
private onIndentationChange(e: IBaseEditor): void {
|
||||
let update: StateDelta = { indentation: null };
|
||||
if (e instanceof BaseTextEditor) {
|
||||
const options = (<ICommonCodeEditor>e.getControl()).getIndentationOptions();
|
||||
update.indentation = options.insertSpaces ? nls.localize('spacesSize', "Spaces: {0}", options.tabSize) :
|
||||
nls.localize('tabSize', "Tab Size: {0}", options.tabSize);
|
||||
}
|
||||
this.updateState(update);
|
||||
}
|
||||
|
||||
private onSelectionChange(e: IBaseEditor): void {
|
||||
if (e && !this.isActiveEditor(e)) {
|
||||
return;
|
||||
@@ -603,6 +649,33 @@ export interface IChangeEOLEntry extends IPickOpenEntry {
|
||||
eol: EndOfLineSequence;
|
||||
}
|
||||
|
||||
export class ChangeIndentationAction extends Action {
|
||||
|
||||
public static ID = 'workbench.action.editor.changeIndentation';
|
||||
public static LABEL = nls.localize('changeIndentation', "Change Indentation");
|
||||
|
||||
constructor(
|
||||
actionId: string,
|
||||
actionLabel: string,
|
||||
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
|
||||
@IQuickOpenService private quickOpenService: IQuickOpenService
|
||||
) {
|
||||
super(actionId, actionLabel);
|
||||
}
|
||||
|
||||
public run(): TPromise<any> {
|
||||
const activeEditor = this.editorService.getActiveEditor();
|
||||
if (!(activeEditor instanceof BaseTextEditor)) {
|
||||
return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
|
||||
}
|
||||
if (!isWritableCodeEditor(<BaseTextEditor>activeEditor)) {
|
||||
return this.quickOpenService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
|
||||
}
|
||||
|
||||
return this.quickOpenService.show('>indentation');
|
||||
}
|
||||
}
|
||||
|
||||
export class ChangeEOLAction extends Action {
|
||||
|
||||
public static ID = 'workbench.action.editor.changeEOL';
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
.monaco-workbench .editor-statusbar-item > .editor-status-mode,
|
||||
.monaco-workbench .editor-statusbar-item > .editor-status-encoding,
|
||||
.monaco-workbench .editor-statusbar-item > .editor-status-eol,
|
||||
.monaco-workbench .editor-statusbar-item > .editor-status-selection {
|
||||
.monaco-workbench .editor-statusbar-item > .editor-status-selection,
|
||||
.monaco-workbench .editor-statusbar-item > .editor-status-indentation {
|
||||
padding: 0 5px 0 5px;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user