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

Listen to TextFileEditorModel dispose from BackupModelService

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