提交 89a8ab2a 编写于 作者: B Benjamin Pasero

code cleanup

上级 194fa300
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import 'vs/css!./media/editorstatus'; import 'vs/css!./media/editorstatus';
import nls = require('vs/nls'); import nls = require('vs/nls');
import {TPromise} from 'vs/base/common/winjs.base'; import {TPromise} from 'vs/base/common/winjs.base';
import { $, append, runAtThisOrScheduleAtNextAnimationFrame } from 'vs/base/browser/dom'; import {$, append, runAtThisOrScheduleAtNextAnimationFrame} from 'vs/base/browser/dom';
import strings = require('vs/base/common/strings'); import strings = require('vs/base/common/strings');
import paths = require('vs/base/common/paths'); import paths = require('vs/base/common/paths');
import types = require('vs/base/common/types'); import types = require('vs/base/common/types');
...@@ -59,7 +59,7 @@ function getTextModel(editorWidget: IEditor): ITextModel { ...@@ -59,7 +59,7 @@ function getTextModel(editorWidget: IEditor): ITextModel {
let textModel: ITextModel; let textModel: ITextModel;
// Support for diff // Support for diff
let model = editorWidget.getModel(); const model = editorWidget.getModel();
if (model && !!(<IDiffEditorModel>model).modified) { if (model && !!(<IDiffEditorModel>model).modified) {
textModel = (<IDiffEditorModel>model).modified; textModel = (<IDiffEditorModel>model).modified;
} }
...@@ -151,7 +151,7 @@ class State { ...@@ -151,7 +151,7 @@ class State {
} }
public update(update: StateDelta): StateChange { public update(update: StateDelta): StateChange {
let e = new StateChange(); const e = new StateChange();
let somethingChanged = false; let somethingChanged = false;
if (typeof update.selectionStatus !== 'undefined') { if (typeof update.selectionStatus !== 'undefined') {
...@@ -303,7 +303,7 @@ export class EditorStatus implements IStatusbarItem { ...@@ -303,7 +303,7 @@ export class EditorStatus implements IStatusbarItem {
} }
private updateState(update: StateDelta): void { private updateState(update: StateDelta): void {
let changed = this.state.update(update); const changed = this.state.update(update);
if (!changed) { if (!changed) {
// Nothing really changed // Nothing really changed
return; return;
...@@ -313,7 +313,7 @@ export class EditorStatus implements IStatusbarItem { ...@@ -313,7 +313,7 @@ export class EditorStatus implements IStatusbarItem {
this.toRender = changed; this.toRender = changed;
this.delayedRender = runAtThisOrScheduleAtNextAnimationFrame(() => { this.delayedRender = runAtThisOrScheduleAtNextAnimationFrame(() => {
this.delayedRender = null; this.delayedRender = null;
let toRender = this.toRender; const toRender = this.toRender;
this.toRender = null; this.toRender = null;
this._renderNow(toRender); this._renderNow(toRender);
}); });
...@@ -391,14 +391,14 @@ export class EditorStatus implements IStatusbarItem { ...@@ -391,14 +391,14 @@ export class EditorStatus implements IStatusbarItem {
} else { } else {
if (info.charactersSelected) { if (info.charactersSelected) {
return strings.format(nlsMultiSelectionRange, info.selections.length, info.charactersSelected); return strings.format(nlsMultiSelectionRange, info.selections.length, info.charactersSelected);
} else { } else if (info.selections.length > 0) {
return strings.format(nlsMultiSelection, info.selections.length); return strings.format(nlsMultiSelection, info.selections.length);
} }
} }
} }
private onModeClick(): void { private onModeClick(): void {
let action = this.instantiationService.createInstance(ChangeModeAction, ChangeModeAction.ID, ChangeModeAction.LABEL); const action = this.instantiationService.createInstance(ChangeModeAction, ChangeModeAction.ID, ChangeModeAction.LABEL);
action.run().done(null, errors.onUnexpectedError); action.run().done(null, errors.onUnexpectedError);
action.dispose(); action.dispose();
...@@ -415,14 +415,14 @@ export class EditorStatus implements IStatusbarItem { ...@@ -415,14 +415,14 @@ export class EditorStatus implements IStatusbarItem {
} }
private onEOLClick(): void { private onEOLClick(): void {
let action = this.instantiationService.createInstance(ChangeEOLAction, ChangeEOLAction.ID, ChangeEOLAction.LABEL); const action = this.instantiationService.createInstance(ChangeEOLAction, ChangeEOLAction.ID, ChangeEOLAction.LABEL);
action.run().done(null, errors.onUnexpectedError); action.run().done(null, errors.onUnexpectedError);
action.dispose(); action.dispose();
} }
private onEncodingClick(): void { private onEncodingClick(): void {
let action = this.instantiationService.createInstance(ChangeEncodingAction, ChangeEncodingAction.ID, ChangeEncodingAction.LABEL); const action = this.instantiationService.createInstance(ChangeEncodingAction, ChangeEncodingAction.ID, ChangeEncodingAction.LABEL);
action.run().done(null, errors.onUnexpectedError); action.run().done(null, errors.onUnexpectedError);
action.dispose(); action.dispose();
...@@ -480,11 +480,11 @@ export class EditorStatus implements IStatusbarItem { ...@@ -480,11 +480,11 @@ export class EditorStatus implements IStatusbarItem {
// We only support text based editors // We only support text based editors
if (editorWidget) { if (editorWidget) {
let textModel = getTextModel(editorWidget); const textModel = getTextModel(editorWidget);
if (textModel) { if (textModel) {
// Compute mode // Compute mode
if (!!(<ITokenizedModel>textModel).getMode) { if (!!(<ITokenizedModel>textModel).getMode) {
let mode = (<ITokenizedModel>textModel).getMode(); const mode = (<ITokenizedModel>textModel).getMode();
if (mode) { if (mode) {
info = { mode: this.modeService.getLanguageName(mode.getId()) }; info = { mode: this.modeService.getLanguageName(mode.getId()) };
} }
...@@ -518,7 +518,7 @@ export class EditorStatus implements IStatusbarItem { ...@@ -518,7 +518,7 @@ export class EditorStatus implements IStatusbarItem {
} }
private onSelectionChange(editorWidget?: IEditor): void { private onSelectionChange(editorWidget?: IEditor): void {
let info: IEditorSelectionStatus = {}; const info: IEditorSelectionStatus = {};
// We only support text based editors // We only support text based editors
if (editorWidget) { if (editorWidget) {
...@@ -528,7 +528,7 @@ export class EditorStatus implements IStatusbarItem { ...@@ -528,7 +528,7 @@ export class EditorStatus implements IStatusbarItem {
// Compute selection length // Compute selection length
info.charactersSelected = 0; info.charactersSelected = 0;
let textModel = getTextModel(editorWidget); const textModel = getTextModel(editorWidget);
if (textModel) { if (textModel) {
info.selections.forEach((selection) => { info.selections.forEach((selection) => {
info.charactersSelected += textModel.getValueLengthInRange(selection); info.charactersSelected += textModel.getValueLengthInRange(selection);
...@@ -537,9 +537,9 @@ export class EditorStatus implements IStatusbarItem { ...@@ -537,9 +537,9 @@ export class EditorStatus implements IStatusbarItem {
// Compute the visible column for one selection. This will properly handle tabs and their configured widths // Compute the visible column for one selection. This will properly handle tabs and their configured widths
if (info.selections.length === 1) { if (info.selections.length === 1) {
let visibleColumn = editorWidget.getVisibleColumnFromPosition(editorWidget.getPosition()); const visibleColumn = editorWidget.getVisibleColumnFromPosition(editorWidget.getPosition());
let selectionClone = info.selections[0].clone(); // do not modify the original position we got from the editor const selectionClone = info.selections[0].clone(); // do not modify the original position we got from the editor
selectionClone.positionColumn = visibleColumn; selectionClone.positionColumn = visibleColumn;
info.selections[0] = selectionClone; info.selections[0] = selectionClone;
...@@ -550,11 +550,11 @@ export class EditorStatus implements IStatusbarItem { ...@@ -550,11 +550,11 @@ export class EditorStatus implements IStatusbarItem {
} }
private onEOLChange(editorWidget?: IEditor): void { private onEOLChange(editorWidget?: IEditor): void {
let info: StateDelta = { EOL: null }; const info: StateDelta = { EOL: null };
let codeEditor = getCodeEditor(editorWidget); const codeEditor = getCodeEditor(editorWidget);
if (codeEditor && !codeEditor.getConfiguration().readOnly) { if (codeEditor && !codeEditor.getConfiguration().readOnly) {
let codeEditorModel = codeEditor.getModel(); const codeEditorModel = codeEditor.getModel();
if (codeEditorModel) { if (codeEditorModel) {
info.EOL = codeEditorModel.getEOL(); info.EOL = codeEditorModel.getEOL();
} }
...@@ -568,14 +568,14 @@ export class EditorStatus implements IStatusbarItem { ...@@ -568,14 +568,14 @@ export class EditorStatus implements IStatusbarItem {
return; return;
} }
let info: StateDelta = { encoding: null }; const info: StateDelta = { encoding: null };
// We only support text based editors // We only support text based editors
if (e instanceof BaseTextEditor) { if (e instanceof BaseTextEditor) {
let encodingSupport: IEncodingSupport = <any>asFileOrUntitledEditorInput(e.input); const encodingSupport: IEncodingSupport = <any>asFileOrUntitledEditorInput(e.input);
if (encodingSupport && types.isFunction(encodingSupport.getEncoding)) { if (encodingSupport && types.isFunction(encodingSupport.getEncoding)) {
let rawEncoding = encodingSupport.getEncoding(); const rawEncoding = encodingSupport.getEncoding();
let encodingInfo = SUPPORTED_ENCODINGS[rawEncoding]; const encodingInfo = SUPPORTED_ENCODINGS[rawEncoding];
if (encodingInfo) { if (encodingInfo) {
info.encoding = encodingInfo.labelShort; // if we have a label, take it from there info.encoding = encodingInfo.labelShort; // if we have a label, take it from there
} else { } else {
...@@ -588,9 +588,9 @@ export class EditorStatus implements IStatusbarItem { ...@@ -588,9 +588,9 @@ export class EditorStatus implements IStatusbarItem {
} }
private onResourceEncodingChange(resource: uri): void { private onResourceEncodingChange(resource: uri): void {
let activeEditor = this.editorService.getActiveEditor(); const activeEditor = this.editorService.getActiveEditor();
if (activeEditor) { if (activeEditor) {
let activeResource = getUntitledOrFileResource(activeEditor.input, true); const activeResource = getUntitledOrFileResource(activeEditor.input, true);
if (activeResource && activeResource.toString() === resource.toString()) { if (activeResource && activeResource.toString() === resource.toString()) {
return this.onEncodingChange(<IBaseEditor>activeEditor); // only update if the encoding changed for the active resource return this.onEncodingChange(<IBaseEditor>activeEditor); // only update if the encoding changed for the active resource
} }
...@@ -598,13 +598,13 @@ export class EditorStatus implements IStatusbarItem { ...@@ -598,13 +598,13 @@ export class EditorStatus implements IStatusbarItem {
} }
private onTabFocusModeChange(): void { private onTabFocusModeChange(): void {
let info: StateDelta = { tabFocusMode: TabFocus.getTabFocusMode() }; const info: StateDelta = { tabFocusMode: TabFocus.getTabFocusMode() };
this.updateState(info); this.updateState(info);
} }
private isActiveEditor(e: IBaseEditor): boolean { private isActiveEditor(e: IBaseEditor): boolean {
let activeEditor = this.editorService.getActiveEditor(); const activeEditor = this.editorService.getActiveEditor();
return activeEditor && e && activeEditor === e; return activeEditor && e && activeEditor === e;
} }
...@@ -638,27 +638,27 @@ export class ChangeModeAction extends Action { ...@@ -638,27 +638,27 @@ export class ChangeModeAction extends Action {
} }
public run(): TPromise<any> { public run(): TPromise<any> {
let languages = this.modeService.getRegisteredLanguageNames(); const languages = this.modeService.getRegisteredLanguageNames();
let activeEditor = this.editorService.getActiveEditor(); let activeEditor = this.editorService.getActiveEditor();
if (!(activeEditor instanceof BaseTextEditor)) { if (!(activeEditor instanceof BaseTextEditor)) {
return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
} }
let editorWidget = (<BaseTextEditor>activeEditor).getControl(); const editorWidget = (<BaseTextEditor>activeEditor).getControl();
let textModel = getTextModel(editorWidget); const textModel = getTextModel(editorWidget);
let fileinput = asFileEditorInput(activeEditor.input, true); const fileinput = asFileEditorInput(activeEditor.input, true);
// Compute mode // Compute mode
let currentModeId: string; let currentModeId: string;
if (!!(<ITokenizedModel>textModel).getMode) { if (!!(<ITokenizedModel>textModel).getMode) {
let mode = (<ITokenizedModel>textModel).getMode(); const mode = (<ITokenizedModel>textModel).getMode();
if (mode) { if (mode) {
currentModeId = this.modeService.getLanguageName(mode.getId()); currentModeId = this.modeService.getLanguageName(mode.getId());
} }
} }
// All languages are valid picks // All languages are valid picks
let picks: IPickOpenEntry[] = languages.sort().map((lang, index) => { const picks: IPickOpenEntry[] = languages.sort().map((lang, index) => {
return { return {
label: lang, label: lang,
description: currentModeId === lang ? nls.localize('configuredLanguage', "Configured Language") : void 0 description: currentModeId === lang ? nls.localize('configuredLanguage', "Configured Language") : void 0
...@@ -676,13 +676,13 @@ export class ChangeModeAction extends Action { ...@@ -676,13 +676,13 @@ export class ChangeModeAction extends Action {
} }
} }
let configureModeAssociations: IPickOpenEntry = { const configureModeAssociations: IPickOpenEntry = {
label: configureLabel label: configureLabel
}; };
picks.unshift(configureModeAssociations); picks.unshift(configureModeAssociations);
// Offer to "Auto Detect" // Offer to "Auto Detect"
let autoDetectMode: IPickOpenEntry = { const autoDetectMode: IPickOpenEntry = {
label: nls.localize('autoDetect', "Auto Detect") label: nls.localize('autoDetect', "Auto Detect")
}; };
if (fileinput) { if (fileinput) {
...@@ -693,14 +693,14 @@ export class ChangeModeAction extends Action { ...@@ -693,14 +693,14 @@ export class ChangeModeAction extends Action {
if (language) { if (language) {
activeEditor = this.editorService.getActiveEditor(); activeEditor = this.editorService.getActiveEditor();
if (activeEditor instanceof BaseTextEditor) { if (activeEditor instanceof BaseTextEditor) {
let editorWidget = activeEditor.getControl(); const editorWidget = activeEditor.getControl();
let models: ITextModel[] = []; const models: ITextModel[] = [];
let textModel = getTextModel(editorWidget); const textModel = getTextModel(editorWidget);
models.push(textModel); models.push(textModel);
// Support for original side of diff // Support for original side of diff
let model = editorWidget.getModel(); const model = editorWidget.getModel();
if (model && !!(<IDiffEditorModel>model).original) { if (model && !!(<IDiffEditorModel>model).original) {
models.push((<IDiffEditorModel>model).original); models.push((<IDiffEditorModel>model).original);
} }
...@@ -799,7 +799,6 @@ export class ChangeEOLAction extends Action { ...@@ -799,7 +799,6 @@ export class ChangeEOLAction extends Action {
} }
public run(): TPromise<any> { public run(): TPromise<any> {
let activeEditor = this.editorService.getActiveEditor(); let activeEditor = this.editorService.getActiveEditor();
if (!(activeEditor instanceof BaseTextEditor)) { if (!(activeEditor instanceof BaseTextEditor)) {
return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
...@@ -809,22 +808,22 @@ export class ChangeEOLAction extends Action { ...@@ -809,22 +808,22 @@ export class ChangeEOLAction extends Action {
return this.quickOpenService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]); return this.quickOpenService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
} }
let editorWidget = (<BaseTextEditor>activeEditor).getControl(); const editorWidget = (<BaseTextEditor>activeEditor).getControl();
let textModel = getTextModel(editorWidget); const textModel = getTextModel(editorWidget);
let EOLOptions: IChangeEOLEntry[] = [ const EOLOptions: IChangeEOLEntry[] = [
{ label: nlsEOLLF, eol: EndOfLineSequence.LF }, { label: nlsEOLLF, eol: EndOfLineSequence.LF },
{ label: nlsEOLCRLF, eol: EndOfLineSequence.CRLF }, { label: nlsEOLCRLF, eol: EndOfLineSequence.CRLF },
]; ];
let selectedIndex = (textModel.getEOL() === '\n') ? 0 : 1; const selectedIndex = (textModel.getEOL() === '\n') ? 0 : 1;
return this.quickOpenService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), autoFocus: { autoFocusIndex: selectedIndex } }).then((eol) => { return this.quickOpenService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), autoFocus: { autoFocusIndex: selectedIndex } }).then((eol) => {
if (eol) { if (eol) {
activeEditor = this.editorService.getActiveEditor(); activeEditor = this.editorService.getActiveEditor();
if (activeEditor instanceof BaseTextEditor && isWritableCodeEditor(activeEditor)) { if (activeEditor instanceof BaseTextEditor && isWritableCodeEditor(activeEditor)) {
let editorWidget = activeEditor.getControl(); const editorWidget = activeEditor.getControl();
let textModel = getTextModel(editorWidget); const textModel = getTextModel(editorWidget);
textModel.setEOL(eol.eol); textModel.setEOL(eol.eol);
} }
} }
...@@ -886,13 +885,13 @@ export class ChangeEncodingAction extends Action { ...@@ -886,13 +885,13 @@ export class ChangeEncodingAction extends Action {
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(() => {
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>(); const configuration = this.configurationService.getConfiguration<IFilesConfiguration>();
let isReopenWithEncoding = (action === reopenWithEncodingPick); const isReopenWithEncoding = (action === reopenWithEncodingPick);
let configuredEncoding = configuration && configuration.files && configuration.files.encoding; const configuredEncoding = configuration && configuration.files && configuration.files.encoding;
let directMatchIndex: number; let directMatchIndex: number;
let aliasMatchIndex: number; let aliasMatchIndex: number;
// All encodings are valid picks // All encodings are valid picks
let picks: IPickOpenEntry[] = Object.keys(SUPPORTED_ENCODINGS) const picks: IPickOpenEntry[] = Object.keys(SUPPORTED_ENCODINGS)
.sort((k1, k2) => { .sort((k1, k2) => {
if (k1 === configuredEncoding) { if (k1 === configuredEncoding) {
return -1; return -1;
......
...@@ -122,10 +122,14 @@ export class TextFileEditor extends BaseTextEditor { ...@@ -122,10 +122,14 @@ export class TextFileEditor extends BaseTextEditor {
// Check Model state // Check Model state
const textFileModel = <TextFileEditorModel>resolvedModel; const textFileModel = <TextFileEditorModel>resolvedModel;
const hasInput = !!this.getInput();
const modelDisposed = textFileModel.isDisposed();
const inputChanged = (<FileEditorInput>this.getInput()).getResource().toString() !== textFileModel.getResource().toString();
if ( if (
!this.getInput() || // editor got hidden meanwhile !hasInput || // editor got hidden meanwhile
textFileModel.isDisposed() || // input got disposed meanwhile modelDisposed || // input got disposed meanwhile
(<FileEditorInput>this.getInput()).getResource().toString() !== textFileModel.getResource().toString() // a different input was set meanwhile inputChanged // a different input was set meanwhile
) { ) {
return null; return null;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册