提交 5a3f6be1 编写于 作者: D Daniel Imms

Listen to TextFileEditorModel dispose from BackupModelService

Part of #14181
上级 160f0dfa
...@@ -34,8 +34,9 @@ export class BackupModelService implements IBackupModelService { ...@@ -34,8 +34,9 @@ export class BackupModelService implements IBackupModelService {
private registerListeners() { private registerListeners() {
this.toDispose.push(this.textFileService.models.onModelContentChanged((e) => this.onTextFileModelChanged(e))); this.toDispose.push(this.textFileService.models.onModelContentChanged((e) => this.onTextFileModelChanged(e)));
this.toDispose.push(this.textFileService.models.onModelSaved((e) => this.onTextFileModelClean(e))); this.toDispose.push(this.textFileService.models.onModelSaved((e) => this.onTextFileModelClean(e.resource)));
this.toDispose.push(this.textFileService.models.onModelReverted((e) => this.onTextFileModelClean(e))); this.toDispose.push(this.textFileService.models.onModelReverted((e) => this.onTextFileModelClean(e.resource)));
this.toDispose.push(this.textFileService.models.onModelDisposed((e) => this.onTextFileModelClean(e)));
this.toDispose.push(this.untitledEditorService.onDidChangeContent((e) => this.onUntitledModelChanged(e))); this.toDispose.push(this.untitledEditorService.onDidChangeContent((e) => this.onUntitledModelChanged(e)));
} }
...@@ -57,8 +58,8 @@ export class BackupModelService implements IBackupModelService { ...@@ -57,8 +58,8 @@ export class BackupModelService implements IBackupModelService {
} }
} }
private onTextFileModelClean(event: TextFileModelChangeEvent): void { private onTextFileModelClean(resource: Uri): void {
this.backupFileService.discardAndDeregisterResource(event.resource); this.backupFileService.discardAndDeregisterResource(resource);
} }
public dispose(): void { public dispose(): void {
......
...@@ -747,9 +747,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil ...@@ -747,9 +747,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
this.cancelAutoSavePromises(); this.cancelAutoSavePromises();
// TODO: Can this be moved to BackupModelService?
this.backupFileService.discardAndDeregisterResource(this.resource);
super.dispose(); super.dispose();
} }
} }
......
...@@ -24,6 +24,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager { ...@@ -24,6 +24,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
private toUnbind: IDisposable[]; private toUnbind: IDisposable[];
private _onModelDisposed: Emitter<URI>;
private _onModelContentChanged: Emitter<TextFileModelChangeEvent>; private _onModelContentChanged: Emitter<TextFileModelChangeEvent>;
private _onModelDirty: Emitter<TextFileModelChangeEvent>; private _onModelDirty: Emitter<TextFileModelChangeEvent>;
private _onModelSaveError: Emitter<TextFileModelChangeEvent>; private _onModelSaveError: Emitter<TextFileModelChangeEvent>;
...@@ -45,6 +46,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager { ...@@ -45,6 +46,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
) { ) {
this.toUnbind = []; this.toUnbind = [];
this._onModelDisposed = new Emitter<URI>();
this._onModelContentChanged = new Emitter<TextFileModelChangeEvent>(); this._onModelContentChanged = new Emitter<TextFileModelChangeEvent>();
this._onModelDirty = new Emitter<TextFileModelChangeEvent>(); this._onModelDirty = new Emitter<TextFileModelChangeEvent>();
this._onModelSaveError = new Emitter<TextFileModelChangeEvent>(); this._onModelSaveError = new Emitter<TextFileModelChangeEvent>();
...@@ -52,6 +54,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager { ...@@ -52,6 +54,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
this._onModelReverted = new Emitter<TextFileModelChangeEvent>(); this._onModelReverted = new Emitter<TextFileModelChangeEvent>();
this._onModelEncodingChanged = new Emitter<TextFileModelChangeEvent>(); this._onModelEncodingChanged = new Emitter<TextFileModelChangeEvent>();
this.toUnbind.push(this._onModelDisposed);
this.toUnbind.push(this._onModelContentChanged); this.toUnbind.push(this._onModelContentChanged);
this.toUnbind.push(this._onModelDirty); this.toUnbind.push(this._onModelDirty);
this.toUnbind.push(this._onModelSaveError); this.toUnbind.push(this._onModelSaveError);
...@@ -152,6 +155,10 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager { ...@@ -152,6 +155,10 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
return true; return true;
} }
public get onModelDisposed(): Event<URI> {
return this._onModelDisposed.event;
}
public get onModelContentChanged(): Event<TextFileModelChangeEvent> { public get onModelContentChanged(): Event<TextFileModelChangeEvent> {
return this._onModelContentChanged.event; return this._onModelContentChanged.event;
} }
...@@ -278,7 +285,10 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager { ...@@ -278,7 +285,10 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
// store in cache but remove when model gets disposed // store in cache but remove when model gets disposed
this.mapResourceToModel[resource.toString()] = model; this.mapResourceToModel[resource.toString()] = model;
this.mapResourceToDisposeListener[resource.toString()] = model.onDispose(() => this.remove(resource)); this.mapResourceToDisposeListener[resource.toString()] = model.onDispose(() => {
this.remove(resource);
this._onModelDisposed.fire(resource);
});
} }
public remove(resource: URI): void { public remove(resource: URI): void {
......
...@@ -183,6 +183,7 @@ export interface IRawTextContent extends IBaseStat { ...@@ -183,6 +183,7 @@ export interface IRawTextContent extends IBaseStat {
export interface ITextFileEditorModelManager { export interface ITextFileEditorModelManager {
onModelDisposed: Event<URI>;
onModelContentChanged: Event<TextFileModelChangeEvent>; onModelContentChanged: Event<TextFileModelChangeEvent>;
onModelDirty: Event<TextFileModelChangeEvent>; onModelDirty: Event<TextFileModelChangeEvent>;
onModelSaveError: Event<TextFileModelChangeEvent>; onModelSaveError: Event<TextFileModelChangeEvent>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册