提交 936b1364 编写于 作者: B Benjamin Pasero

grid - remove onWillCloseEditor() from editor service

上级 8cb8c024
......@@ -14,7 +14,7 @@ import { Action } from 'vs/base/common/actions';
import { VIEWLET_ID, IExplorerViewlet, TEXT_FILE_EDITOR_ID } from 'vs/workbench/parts/files/common/files';
import { ITextFileEditorModel, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
import { EditorOptions, TextEditorOptions, IEditorCloseEvent } from 'vs/workbench/common/editor';
import { EditorOptions, TextEditorOptions } from 'vs/workbench/common/editor';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
......@@ -30,7 +30,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorGroupsService, INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { CancellationToken } from 'vs/base/common/cancellation';
/**
......@@ -59,9 +59,6 @@ export class TextFileEditor extends BaseTextEditor {
// Clear view state for deleted files
this.toUnbind.push(this.fileService.onFileChanges(e => this.onFilesChanged(e)));
// React to editors closing to preserve view state
this.toUnbind.push(editorService.onWillCloseEditor(e => this.onWillCloseEditor(e)));
}
private onFilesChanged(e: FileChangesEvent): void {
......@@ -71,12 +68,6 @@ export class TextFileEditor extends BaseTextEditor {
}
}
private onWillCloseEditor(e: IEditorCloseEvent): void {
if (e.editor === this.input && this.group.id === e.groupId) {
this.doSaveTextEditorViewState(this.input);
}
}
public getTitle(): string {
return this.input ? this.input.getName() : nls.localize('textFileEditor', "Text File Editor");
}
......@@ -85,6 +76,19 @@ export class TextFileEditor extends BaseTextEditor {
return this._input as FileEditorInput;
}
setEditorVisible(visible: boolean, group: INextEditorGroup): void {
super.setEditorVisible(visible, group);
// React to editors closing to preserve view state. This needs to happen
// in the onWillCloseEditor because at that time the editor has not yet
// been disposed and we can safely persist the view state still.
this.toUnbind.push(group.onWillCloseEditor(e => {
if (e.editor === this.input) {
this.doSaveTextEditorViewState(this.input);
}
}));
}
public setOptions(options: EditorOptions): void {
const textOptions = <TextEditorOptions>options;
if (textOptions && types.isFunction(textOptions.apply)) {
......
......@@ -48,9 +48,6 @@ export class NextEditorService extends Disposable implements INextEditorService
private _onDidVisibleEditorsChange: Emitter<void> = this._register(new Emitter<void>());
get onDidVisibleEditorsChange(): Event<void> { return this._onDidVisibleEditorsChange.event; }
private _onWillCloseEditor: Emitter<IEditorCloseEvent> = this._register(new Emitter<IEditorCloseEvent>());
get onWillCloseEditor(): Event<IEditorCloseEvent> { return this._onWillCloseEditor.event; }
private _onDidCloseEditor: Emitter<IEditorCloseEvent> = this._register(new Emitter<IEditorCloseEvent>());
get onDidCloseEditor(): Event<IEditorCloseEvent> { return this._onDidCloseEditor.event; }
......@@ -112,10 +109,6 @@ export class NextEditorService extends Disposable implements INextEditorService
}
}));
groupDisposeables.push(group.onWillCloseEditor(event => {
this._onWillCloseEditor.fire(event);
}));
groupDisposeables.push(group.onDidCloseEditor(event => {
this._onDidCloseEditor.fire(event);
}));
......
......@@ -41,13 +41,6 @@ export interface INextEditorService {
*/
readonly onDidVisibleEditorsChange: Event<void>;
/**
* Emitted when an editor is about to get closed. Listeners can
* for example save view state now before the underlying widget
* gets disposed.
*/
readonly onWillCloseEditor: Event<IEditorCloseEvent>;
/**
* Emitted when an editor is closed.
*/
......
......@@ -99,11 +99,6 @@ suite('Editor service (editor2)', () => {
didCloseEditorListenerCounter++;
});
let willCloseEditorListenerCounter = 0;
const willCloseEditorListener = service.onWillCloseEditor(editor => {
willCloseEditorListenerCounter++;
});
// Open input
return service.openEditor(input, { pinned: true }).then(editor => {
assert.ok(editor instanceof TestEditorControl);
......@@ -121,7 +116,6 @@ suite('Editor service (editor2)', () => {
// Close input
editor.group.closeEditor(input);
assert.equal(willCloseEditorListenerCounter, 1);
assert.equal(didCloseEditorListenerCounter, 1);
assert.equal(activeEditorChangeEventCounter, 2);
assert.equal(visibleEditorChangeEventCounter, 2);
......@@ -139,7 +133,6 @@ suite('Editor service (editor2)', () => {
activeEditorChangeListener.dispose();
visibleEditorChangeListener.dispose();
willCloseEditorListener.dispose();
didCloseEditorListener.dispose();
willOpenEditorListener.dispose();
});
......
......@@ -859,7 +859,6 @@ export class TestNextEditorService implements INextEditorService {
onDidActiveEditorChange: Event<void> = Event.None;
onDidVisibleEditorsChange: Event<void> = Event.None;
onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
onWillOpenEditor: Event<IEditorOpeningEvent> = Event.None;
onDidOpenEditorFail: Event<IEditorIdentifier> = Event.None;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册