提交 0ee66e5d 编写于 作者: B Benjamin Pasero

debt - clean up view state for resources/untitled when input gets disposed

上级 961c14ae
...@@ -14,16 +14,15 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn ...@@ -14,16 +14,15 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn
import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'; import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor'; import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
import URI from 'vs/base/common/uri';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService } from 'vs/platform/storage/common/storage'; import { IStorageService } from 'vs/platform/storage/common/storage';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IThemeService } from 'vs/platform/theme/common/themeService'; import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { once } from "vs/base/common/event";
/** /**
* An editor implementation that is capable of showing the contents of resource inputs. Uses * An editor implementation that is capable of showing the contents of resource inputs. Uses
...@@ -39,20 +38,11 @@ export class TextResourceEditor extends BaseTextEditor { ...@@ -39,20 +38,11 @@ export class TextResourceEditor extends BaseTextEditor {
@IStorageService storageService: IStorageService, @IStorageService storageService: IStorageService,
@IConfigurationService configurationService: IConfigurationService, @IConfigurationService configurationService: IConfigurationService,
@IThemeService themeService: IThemeService, @IThemeService themeService: IThemeService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IEditorGroupService editorGroupService: IEditorGroupService, @IEditorGroupService editorGroupService: IEditorGroupService,
@IModeService modeService: IModeService, @IModeService modeService: IModeService,
@ITextFileService textFileService: ITextFileService @ITextFileService textFileService: ITextFileService
) { ) {
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, modeService, textFileService, editorGroupService); super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, modeService, textFileService, editorGroupService);
this.toUnbind.push(this.untitledEditorService.onDidChangeDirty(e => this.onUntitledDirtyChange(e)));
}
private onUntitledDirtyChange(resource: URI): void {
if (!this.untitledEditorService.isDirty(resource)) {
this.clearTextEditorViewState([resource.toString()]); // untitled file got reverted, so remove view state
}
} }
public getTitle(): string { public getTitle(): string {
...@@ -83,7 +73,7 @@ export class TextResourceEditor extends BaseTextEditor { ...@@ -83,7 +73,7 @@ export class TextResourceEditor extends BaseTextEditor {
} }
// Remember view settings if input changes // Remember view settings if input changes
this.saveTextEditorViewState(oldInput); this.saveTextEditorViewStateForInput(oldInput);
// Different Input (Reload) // Different Input (Reload)
return input.resolve(true).then((resolvedModel: EditorModel) => { return input.resolve(true).then((resolvedModel: EditorModel) => {
...@@ -166,7 +156,7 @@ export class TextResourceEditor extends BaseTextEditor { ...@@ -166,7 +156,7 @@ export class TextResourceEditor extends BaseTextEditor {
public clearInput(): void { public clearInput(): void {
// Keep editor view state in settings to restore when coming back // Keep editor view state in settings to restore when coming back
this.saveTextEditorViewState(this.input); this.saveTextEditorViewStateForInput(this.input);
// Clear Model // Clear Model
this.getControl().setModel(null); this.getControl().setModel(null);
...@@ -176,22 +166,35 @@ export class TextResourceEditor extends BaseTextEditor { ...@@ -176,22 +166,35 @@ export class TextResourceEditor extends BaseTextEditor {
public shutdown(): void { public shutdown(): void {
// Save View State // Save View State (only for untitled)
this.saveTextEditorViewState(this.input); if (this.input instanceof UntitledEditorInput) {
this.saveTextEditorViewStateForInput(this.input);
}
// Call Super // Call Super
super.shutdown(); super.shutdown();
} }
protected saveTextEditorViewState(input: EditorInput): void; protected saveTextEditorViewStateForInput(input: EditorInput): void {
protected saveTextEditorViewState(key: string): void; if (!(input instanceof UntitledEditorInput) && !(input instanceof ResourceEditorInput)) {
protected saveTextEditorViewState(arg1: EditorInput | string): void { return; // only enabled for untitled and resource inputs
if (typeof arg1 === 'string') {
return super.saveTextEditorViewState(arg1);
} }
if ((arg1 instanceof UntitledEditorInput || arg1 instanceof ResourceEditorInput) && !arg1.isDisposed()) { const key = input.getResource().toString();
return super.saveTextEditorViewState(arg1.getResource().toString());
// Clear view state if input is disposed
if (input.isDisposed()) {
super.clearTextEditorViewState([key]);
}
// Otherwise save it
else {
super.saveTextEditorViewState(key);
// Make sure to clean up when the input gets disposed
once(input.onDispose)(() => {
super.clearTextEditorViewState([key]);
});
} }
} }
} }
\ No newline at end of file
...@@ -22,7 +22,6 @@ import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResour ...@@ -22,7 +22,6 @@ import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResour
import { OutputEditors, OUTPUT_PANEL_ID, IOutputService, CONTEXT_IN_OUTPUT } from 'vs/workbench/parts/output/common/output'; import { OutputEditors, OUTPUT_PANEL_ID, IOutputService, CONTEXT_IN_OUTPUT } from 'vs/workbench/parts/output/common/output';
import { SwitchOutputAction, SwitchOutputActionItem, ClearOutputAction, ToggleOutputScrollLockAction } from 'vs/workbench/parts/output/browser/outputActions'; import { SwitchOutputAction, SwitchOutputActionItem, ClearOutputAction, ToggleOutputScrollLockAction } from 'vs/workbench/parts/output/browser/outputActions';
import { IThemeService } from 'vs/platform/theme/common/themeService'; import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
...@@ -39,13 +38,12 @@ export class OutputPanel extends TextResourceEditor { ...@@ -39,13 +38,12 @@ export class OutputPanel extends TextResourceEditor {
@IConfigurationService configurationService: IConfigurationService, @IConfigurationService configurationService: IConfigurationService,
@IThemeService themeService: IThemeService, @IThemeService themeService: IThemeService,
@IOutputService private outputService: IOutputService, @IOutputService private outputService: IOutputService,
@IUntitledEditorService untitledEditorService: IUntitledEditorService,
@IContextKeyService private contextKeyService: IContextKeyService, @IContextKeyService private contextKeyService: IContextKeyService,
@IEditorGroupService editorGroupService: IEditorGroupService, @IEditorGroupService editorGroupService: IEditorGroupService,
@IModeService modeService: IModeService, @IModeService modeService: IModeService,
@ITextFileService textFileService: ITextFileService @ITextFileService textFileService: ITextFileService
) { ) {
super(telemetryService, instantiationService, storageService, configurationService, themeService, untitledEditorService, editorGroupService, modeService, textFileService); super(telemetryService, instantiationService, storageService, configurationService, themeService, editorGroupService, modeService, textFileService);
this.scopedInstantiationService = instantiationService; this.scopedInstantiationService = instantiationService;
this.toDispose = []; this.toDispose = [];
......
...@@ -16,7 +16,6 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn ...@@ -16,7 +16,6 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService'; import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { TestTextFileService, workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices'; import { TestTextFileService, workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices';
import { TPromise } from "vs/base/common/winjs.base"; import { TPromise } from "vs/base/common/winjs.base";
import { IModel } from 'vs/editor/common/editorCommon'; import { IModel } from 'vs/editor/common/editorCommon';
...@@ -30,8 +29,7 @@ class ServiceAccessor { ...@@ -30,8 +29,7 @@ class ServiceAccessor {
@ITextModelResolverService public textModelResolverService: ITextModelResolverService, @ITextModelResolverService public textModelResolverService: ITextModelResolverService,
@IModelService public modelService: IModelService, @IModelService public modelService: IModelService,
@IModeService public modeService: IModeService, @IModeService public modeService: IModeService,
@ITextFileService public textFileService: TestTextFileService, @ITextFileService public textFileService: TestTextFileService
@IUntitledEditorService public untitledEditorService: IUntitledEditorService
) { ) {
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册