diff --git a/src/vs/workbench/api/browser/mainThreadNotebookDocuments.ts b/src/vs/workbench/api/browser/mainThreadNotebookDocuments.ts index 0c3f796a44c..216a865eb23 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookDocuments.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookDocuments.ts @@ -38,7 +38,7 @@ export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsS notebooksAndEditors.onDidRemoveNotebooks(this._handleNotebooksRemoved, this, this._disposables); // forward dirty and save events - this._disposables.add(this._notebookEditorModelResolverService.onDidChangeDirty(model => this._proxy.$acceptDirtyStateChanged(model.resource, model.isDirty))); + this._disposables.add(this._notebookEditorModelResolverService.onDidChangeDirty(model => this._proxy.$acceptDirtyStateChanged(model.resource, model.isDirty()))); this._disposables.add(this._notebookEditorModelResolverService.onDidSaveNotebook(e => this._proxy.$acceptModelSaved(e))); } diff --git a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts index 66b5fb6f59a..082d745e901 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -24,13 +24,13 @@ import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle import { Registry } from 'vs/platform/registry/common/platform'; import { EditorDescriptor, EditorsAssociations, editorsAssociationsSettingId, Extensions as EditorExtensions, IEditorRegistry } from 'vs/workbench/browser/editor'; import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; -import { EditorInput, Extensions as EditorInputExtensions, ICustomEditorInputFactory, IEditorInput, IEditorInputSerializer, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor'; +import { EditorInput, Extensions as EditorInputExtensions, ICustomEditorInputFactory, IEditorInput, IEditorInputSerializer, IEditorInputFactoryRegistry, IEditorInputWithOptions } from 'vs/workbench/common/editor'; import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor'; import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; import { NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl'; -import { CellKind, CellToolbarLocKey, CellUri, DisplayOrderKey, ExperimentalUseMarkdownRenderer, getCellUndoRedoComparisonKey, NotebookDocumentBackupData, NotebookEditorPriority, NotebookTextDiffEditorPreview, ShowCellStatusBarKey } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { CellKind, CellToolbarLocKey, CellUri, DisplayOrderKey, ExperimentalUseMarkdownRenderer, getCellUndoRedoComparisonKey, IResolvedNotebookEditorModel, NotebookDocumentBackupData, NotebookEditorPriority, NotebookTextDiffEditorPreview, ShowCellStatusBarKey } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -694,11 +694,12 @@ class NotebookFileTracker implements IWorkbenchContribution { private readonly _dirtyListener: IDisposable; constructor( + @IInstantiationService private readonly _instantiationService: IInstantiationService, @IEditorService private readonly _editorService: IEditorService, @INotebookEditorModelResolverService private readonly _notebookEditorModelService: INotebookEditorModelResolverService, ) { - type E = { resource: URI, isDirty: boolean }; + type E = IResolvedNotebookEditorModel; this._dirtyListener = Event.debounce( this._notebookEditorModelService.onDidChangeDirty, (last, current) => !last ? [current] : [...last, current], @@ -710,13 +711,13 @@ class NotebookFileTracker implements IWorkbenchContribution { this._dirtyListener.dispose(); } - private _openMissingDirtyNotebookEditors(inputs: { resource: URI, isDirty: boolean }[]): void { - const result: IResourceEditorInput[] = []; - for (let input of inputs) { - if (input.isDirty && !this._editorService.isOpen({ resource: input.resource })) { + private _openMissingDirtyNotebookEditors(models: IResolvedNotebookEditorModel[]): void { + const result: IEditorInputWithOptions[] = []; + for (let model of models) { + if (model.isDirty() && !this._editorService.isOpen({ resource: model.resource })) { result.push({ - resource: input.resource, - options: { inactive: true, preserveFocus: true, pinned: true } + editor: NotebookEditorInput.create(this._instantiationService, model.resource, model.viewType), + options: { inactive: true, preserveFocus: true, pinned: true, } }); } } diff --git a/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverService.ts b/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverService.ts index fe2fb23f0e1..ce712c5013d 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverService.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverService.ts @@ -15,7 +15,7 @@ export interface INotebookEditorModelResolverService { readonly _serviceBrand: undefined; readonly onDidSaveNotebook: Event; - readonly onDidChangeDirty: Event<{ resource: URI, isDirty: boolean }>; + readonly onDidChangeDirty: Event; isDirty(resource: URI): boolean; diff --git a/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.ts b/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.ts index bf9b8f9f7a1..0ca4d969c67 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.ts @@ -26,8 +26,8 @@ class NotebookModelReferenceCollection extends ReferenceCollection(); readonly onDidSaveNotebook: Event = this._onDidSaveNotebook.event; - private readonly _onDidChangeDirty = new Emitter<{ resource: URI, isDirty: boolean }>(); - readonly onDidChangeDirty: Event<{ resource: URI, isDirty: boolean }> = this._onDidChangeDirty.event; + private readonly _onDidChangeDirty = new Emitter(); + readonly onDidChangeDirty: Event = this._onDidChangeDirty.event; private readonly _dirtyStates = new ResourceMap(); @@ -78,7 +78,7 @@ class NotebookModelReferenceCollection extends ReferenceCollection { const isDirty = result.isDirty(); this._dirtyStates.set(result.resource, isDirty); - this._onDidChangeDirty.fire({ resource: result.resource, isDirty }); + this._onDidChangeDirty.fire(result); }), )); return result; @@ -102,7 +102,7 @@ export class NotebookModelResolverServiceImpl implements INotebookEditorModelRes private readonly _data: NotebookModelReferenceCollection; readonly onDidSaveNotebook: Event; - readonly onDidChangeDirty: Event<{ resource: URI, isDirty: boolean }>; + readonly onDidChangeDirty: Event; constructor( @IInstantiationService instantiationService: IInstantiationService,