From 4d6271c16147618850ebe5e221efca02992b4eeb Mon Sep 17 00:00:00 2001 From: Raj <44002319+rajmusuku@users.noreply.github.com> Date: Fri, 8 Mar 2019 13:28:15 -0800 Subject: [PATCH] 'Confirm save' implementation while closing untitled/existing notebooks (#4349) * #4326: 'Confirm save' while closing both notebook * Adding comment --- src/sql/parts/notebook/notebookInput.ts | 34 +++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/sql/parts/notebook/notebookInput.ts b/src/sql/parts/notebook/notebookInput.ts index 6b07ed608e..adde8c09e6 100644 --- a/src/sql/parts/notebook/notebookInput.ts +++ b/src/sql/parts/notebook/notebookInput.ts @@ -8,7 +8,7 @@ import * as nls from 'vs/nls'; import { TPromise } from 'vs/base/common/winjs.base'; import { IEditorModel } from 'vs/platform/editor/common/editor'; -import { EditorInput, EditorModel } from 'vs/workbench/common/editor'; +import { EditorInput, EditorModel, ConfirmResult } from 'vs/workbench/common/editor'; import { Emitter, Event } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; import * as resources from 'vs/base/common/resources'; @@ -25,6 +25,7 @@ import { UntitledEditorModel } from 'vs/workbench/common/editor/untitledEditorMo import { Schemas } from 'vs/base/common/network'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { notebookModeId } from 'sql/common/constants'; +import { ITextFileService, ISaveOptions } from 'vs/workbench/services/textfile/common/textfiles'; import { LocalContentManager } from 'sql/workbench/services/notebook/node/localContentManager'; export type ModeViewSaveHandler = (handle: number) => Thenable; @@ -35,7 +36,8 @@ export class NotebookEditorModel extends EditorModel { private readonly _onDidChangeDirty: Emitter = this._register(new Emitter()); constructor(public readonly notebookUri: URI, private textEditorModel: TextFileEditorModel | UntitledEditorModel, - @INotebookService private notebookService: INotebookService + @INotebookService private notebookService: INotebookService, + @ITextFileService private textFileService: ITextFileService ) { super(); this._register(this.notebookService.onNotebookEditorAdd(notebook => { @@ -73,6 +75,24 @@ export class NotebookEditorModel extends EditorModel { this._onDidChangeDirty.fire(); } + public confirmSave(): TPromise { + return this.textFileService.confirmSave([this.notebookUri]); + } + + /** + * UntitledEditor uses TextFileService to save data from UntitledEditorInput + * Titled editor uses TextFileEditorModel to save existing notebook + */ + save(options: ISaveOptions): TPromise { + if (this.textEditorModel instanceof TextFileEditorModel) { + this.textEditorModel.save(options); + return TPromise.as(true); + } + else { + return this.textFileService.save(this.notebookUri, options); + } + } + public updateModel(): void { let notebookModel = this.getNotebookModel(); if (notebookModel && this.textEditorModel && this.textEditorModel.textEditorModel) { @@ -134,6 +154,10 @@ export class NotebookInput extends EditorInput { this.assignProviders(); } + public confirmSave(): TPromise { + return this._model.confirmSave(); + } + public get notebookUri(): URI { return this.resource; } @@ -188,6 +212,11 @@ export class NotebookInput extends EditorInput { this._providers = value; } + public save(): TPromise { + let options: ISaveOptions = { force: false }; + return this._model.save(options); + } + public set standardKernels(value: IStandardKernelWithProvider[]) { value.forEach(kernel => { this._standardKernels.push({ @@ -328,4 +357,5 @@ class NotebookEditorContentManager implements IContentManager { let contents = await contentManager.loadFromContentString(notebookEditorModel.contentString); return contents; } + }