mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-03 01:25:38 -05:00
* Fix 2 notebook issues - Do not create notebook model twice on start - Do not cause disposed warnings due to markdown cell deserialization * Fix notebook dirty on open issue Before model is resolved we weren't getting dirty events. Solution is to use backing text model until it's ready. Must hook to the dirty event & notify to get the dot to appear
This commit is contained in:
@@ -26,6 +26,7 @@ import { LocalContentManager } from 'sql/workbench/services/notebook/node/localC
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
|
||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
export type ModeViewSaveHandler = (handle: number) => Thenable<boolean>;
|
||||
|
||||
@@ -61,7 +62,7 @@ export class NotebookEditorModel extends EditorModel {
|
||||
return model.getValue();
|
||||
}
|
||||
|
||||
get isDirty(): boolean {
|
||||
isDirty(): boolean {
|
||||
return this.textEditorModel.isDirty();
|
||||
}
|
||||
|
||||
@@ -135,6 +136,7 @@ export class NotebookInput extends EditorInput {
|
||||
private _untitledEditorModel: UntitledEditorModel;
|
||||
private _contentManager: IContentManager;
|
||||
private _providersLoaded: Promise<void>;
|
||||
private _dirtyListener: IDisposable;
|
||||
|
||||
constructor(private _title: string,
|
||||
private resource: URI,
|
||||
@@ -148,6 +150,9 @@ export class NotebookInput extends EditorInput {
|
||||
this.resource = resource;
|
||||
this._standardKernels = [];
|
||||
this._providersLoaded = this.assignProviders();
|
||||
if (this._textInput) {
|
||||
this.hookDirtyListener(this._textInput.onDidChangeDirty, () => this._onDidChangeDirty.fire());
|
||||
}
|
||||
}
|
||||
|
||||
public get textInput(): UntitledEditorInput {
|
||||
@@ -256,7 +261,7 @@ export class NotebookInput extends EditorInput {
|
||||
}
|
||||
|
||||
async resolve(): Promise<NotebookEditorModel> {
|
||||
if (this._model && this._model.isModelCreated()) {
|
||||
if (this._model) {
|
||||
return Promise.resolve(this._model);
|
||||
} else {
|
||||
let textOrUntitledEditorModel: UntitledEditorModel | IEditorModel;
|
||||
@@ -268,11 +273,27 @@ export class NotebookInput extends EditorInput {
|
||||
textOrUntitledEditorModel = await textEditorModelReference.object.load();
|
||||
}
|
||||
this._model = this.instantiationService.createInstance(NotebookEditorModel, this.resource, textOrUntitledEditorModel);
|
||||
this._model.onDidChangeDirty(() => this._onDidChangeDirty.fire());
|
||||
this.hookDirtyListener(this._model.onDidChangeDirty, () => this._onDidChangeDirty.fire());
|
||||
return this._model;
|
||||
}
|
||||
}
|
||||
|
||||
private hookDirtyListener(dirtyEvent: Event<void>, listener: (e: any) => void): void {
|
||||
let disposable = dirtyEvent(listener);
|
||||
if (this._dirtyListener) {
|
||||
this._dirtyListener.dispose();
|
||||
} else {
|
||||
this._register({
|
||||
dispose: () => {
|
||||
if (this._dirtyListener) {
|
||||
this._dirtyListener.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
this._dirtyListener = disposable;
|
||||
}
|
||||
|
||||
private async assignProviders(): Promise<void> {
|
||||
await this.extensionService.whenInstalledExtensionsRegistered();
|
||||
let providerIds: string[] = getProvidersForFileName(this._title, this.notebookService);
|
||||
@@ -318,7 +339,9 @@ export class NotebookInput extends EditorInput {
|
||||
*/
|
||||
isDirty(): boolean {
|
||||
if (this._model) {
|
||||
return this._model.isDirty;
|
||||
return this._model.isDirty();
|
||||
} else if (this._textInput) {
|
||||
return this._textInput.isDirty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user