mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-05 12:55:10 +01:00
model - add a isDisposed method to generic editor models
This commit is contained in:
@@ -78,10 +78,17 @@ export class SimpleModel implements IResolvedTextEditorModel {
|
||||
return false;
|
||||
}
|
||||
|
||||
private disposed = false;
|
||||
public dispose(): void {
|
||||
this.disposed = true;
|
||||
|
||||
this._onDispose.fire();
|
||||
}
|
||||
|
||||
public isDisposed(): boolean {
|
||||
return this.disposed;
|
||||
}
|
||||
|
||||
public isResolved(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ export interface IEditorModel {
|
||||
*/
|
||||
load(): Promise<IEditorModel>;
|
||||
|
||||
/**
|
||||
* Find out if this model has been disposed.
|
||||
*/
|
||||
isDisposed(): boolean;
|
||||
|
||||
/**
|
||||
* Dispose associated resources
|
||||
*/
|
||||
|
||||
@@ -819,6 +819,8 @@ export class EditorModel extends Disposable implements IEditorModel {
|
||||
private readonly _onDispose = this._register(new Emitter<void>());
|
||||
readonly onDispose = this._onDispose.event;
|
||||
|
||||
private disposed = false;
|
||||
|
||||
/**
|
||||
* Causes this model to load returning a promise when loading is completed.
|
||||
*/
|
||||
@@ -833,10 +835,15 @@ export class EditorModel extends Disposable implements IEditorModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
isDisposed(): boolean {
|
||||
return this.disposed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should implement to free resources that have been claimed through loading.
|
||||
*/
|
||||
dispose(): void {
|
||||
this.disposed = true;
|
||||
this._onDispose.fire();
|
||||
|
||||
super.dispose();
|
||||
|
||||
@@ -86,7 +86,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
||||
private inConflictMode = false;
|
||||
private inOrphanMode = false;
|
||||
private inErrorMode = false;
|
||||
private disposed = false;
|
||||
|
||||
constructor(
|
||||
public readonly resource: URI,
|
||||
@@ -147,7 +146,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
||||
// file is really gone and not just a faulty file event.
|
||||
await timeout(100);
|
||||
|
||||
if (this.disposed) {
|
||||
if (this.isDisposed()) {
|
||||
newInOrphanModeValidated = true;
|
||||
} else {
|
||||
const exists = await this.fileService.exists(this.resource);
|
||||
@@ -155,7 +154,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
||||
}
|
||||
}
|
||||
|
||||
if (this.inOrphanMode !== newInOrphanModeValidated && !this.disposed) {
|
||||
if (this.inOrphanMode !== newInOrphanModeValidated && !this.isDisposed()) {
|
||||
this.setOrphaned(newInOrphanModeValidated);
|
||||
}
|
||||
}
|
||||
@@ -697,7 +696,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
||||
// one after the other without waiting for the save() to complete. If we are disposed(), we risk
|
||||
// saving contents to disk that are stale (see https://github.com/Microsoft/vscode/issues/50942).
|
||||
// To fix this issue, we will not store the contents to disk when we got disposed.
|
||||
if (this.disposed) {
|
||||
if (this.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -955,10 +954,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
||||
return this.fileService.hasCapability(this.resource, FileSystemProviderCapabilities.Readonly);
|
||||
}
|
||||
|
||||
isDisposed(): boolean {
|
||||
return this.disposed;
|
||||
}
|
||||
|
||||
getStat(): IFileStatWithMetadata | undefined {
|
||||
return this.lastResolvedFileStat;
|
||||
}
|
||||
@@ -966,7 +961,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
||||
dispose(): void {
|
||||
this.logService.trace('[text file model] dispose()', this.resource.toString(true));
|
||||
|
||||
this.disposed = true;
|
||||
this.inConflictMode = false;
|
||||
this.inOrphanMode = false;
|
||||
this.inErrorMode = false;
|
||||
|
||||
@@ -425,7 +425,6 @@ export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport
|
||||
getMode(): string | undefined;
|
||||
|
||||
isResolved(): this is IResolvedTextFileEditorModel;
|
||||
isDisposed(): boolean;
|
||||
}
|
||||
|
||||
export function isTextFileEditorModel(model: ITextEditorModel): model is ITextFileEditorModel {
|
||||
|
||||
Reference in New Issue
Block a user