mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
This commit is contained in:
@@ -11,7 +11,7 @@ import { isEqual, joinPath } from 'vs/base/common/resources';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
|
||||
import { IReference } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, IReference } from 'vs/base/common/lifecycle';
|
||||
import { IResolvedNotebookEditorModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
@@ -19,6 +19,7 @@ import { mark } from 'vs/workbench/contrib/notebook/common/notebookPerformance';
|
||||
import { FileSystemProviderCapabilities, IFileService } from 'vs/platform/files/common/files';
|
||||
import { AbstractResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
|
||||
import { IResourceEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
interface NotebookEditorInputOptions {
|
||||
startDirty?: boolean;
|
||||
@@ -33,6 +34,7 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
|
||||
static readonly ID: string = 'workbench.input.notebook';
|
||||
|
||||
private _editorModelReference: IReference<IResolvedNotebookEditorModel> | null = null;
|
||||
private _sideLoadedListener: IDisposable;
|
||||
private _defaultDirtyState: boolean = false;
|
||||
|
||||
constructor(
|
||||
@@ -48,9 +50,19 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
|
||||
) {
|
||||
super(resource, undefined, labelService, fileService);
|
||||
this._defaultDirtyState = !!options.startDirty;
|
||||
|
||||
// Automatically resolve this input when the "wanted" model comes to life via
|
||||
// some other way. This happens only once per input and resolve disposes
|
||||
// this listener
|
||||
this._sideLoadedListener = _notebookService.onDidAddNotebookDocument(e => {
|
||||
if (e.viewType === this.viewType && e.uri.toString() === this.resource.toString()) {
|
||||
this.resolve().catch(onUnexpectedError);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
override dispose() {
|
||||
this._sideLoadedListener.dispose();
|
||||
this._editorModelReference?.dispose();
|
||||
this._editorModelReference = null;
|
||||
super.dispose();
|
||||
@@ -188,6 +200,10 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
|
||||
|
||||
mark(this.resource, 'extensionActivated');
|
||||
|
||||
// we are now loading the notebook and don't need to listen to
|
||||
// "other" loading anymore
|
||||
this._sideLoadedListener.dispose();
|
||||
|
||||
if (!this._editorModelReference) {
|
||||
this._editorModelReference = await this._notebookModelResolverService.resolve(this.resource, this.viewType);
|
||||
if (this.isDisposed()) {
|
||||
|
||||
Reference in New Issue
Block a user