mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
'Confirm save' implementation while closing untitled/existing notebooks (#4349)
* #4326: 'Confirm save' while closing both notebook * Adding comment
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
import * as nls from 'vs/nls';
|
import * as nls from 'vs/nls';
|
||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
import { IEditorModel } from 'vs/platform/editor/common/editor';
|
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 { Emitter, Event } from 'vs/base/common/event';
|
||||||
import { URI } from 'vs/base/common/uri';
|
import { URI } from 'vs/base/common/uri';
|
||||||
import * as resources from 'vs/base/common/resources';
|
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 { Schemas } from 'vs/base/common/network';
|
||||||
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
|
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
|
||||||
import { notebookModeId } from 'sql/common/constants';
|
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';
|
import { LocalContentManager } from 'sql/workbench/services/notebook/node/localContentManager';
|
||||||
|
|
||||||
export type ModeViewSaveHandler = (handle: number) => Thenable<boolean>;
|
export type ModeViewSaveHandler = (handle: number) => Thenable<boolean>;
|
||||||
@@ -35,7 +36,8 @@ export class NotebookEditorModel extends EditorModel {
|
|||||||
private readonly _onDidChangeDirty: Emitter<void> = this._register(new Emitter<void>());
|
private readonly _onDidChangeDirty: Emitter<void> = this._register(new Emitter<void>());
|
||||||
constructor(public readonly notebookUri: URI,
|
constructor(public readonly notebookUri: URI,
|
||||||
private textEditorModel: TextFileEditorModel | UntitledEditorModel,
|
private textEditorModel: TextFileEditorModel | UntitledEditorModel,
|
||||||
@INotebookService private notebookService: INotebookService
|
@INotebookService private notebookService: INotebookService,
|
||||||
|
@ITextFileService private textFileService: ITextFileService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this._register(this.notebookService.onNotebookEditorAdd(notebook => {
|
this._register(this.notebookService.onNotebookEditorAdd(notebook => {
|
||||||
@@ -73,6 +75,24 @@ export class NotebookEditorModel extends EditorModel {
|
|||||||
this._onDidChangeDirty.fire();
|
this._onDidChangeDirty.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public confirmSave(): TPromise<ConfirmResult> {
|
||||||
|
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<boolean> {
|
||||||
|
if (this.textEditorModel instanceof TextFileEditorModel) {
|
||||||
|
this.textEditorModel.save(options);
|
||||||
|
return TPromise.as(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.textFileService.save(this.notebookUri, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public updateModel(): void {
|
public updateModel(): void {
|
||||||
let notebookModel = this.getNotebookModel();
|
let notebookModel = this.getNotebookModel();
|
||||||
if (notebookModel && this.textEditorModel && this.textEditorModel.textEditorModel) {
|
if (notebookModel && this.textEditorModel && this.textEditorModel.textEditorModel) {
|
||||||
@@ -134,6 +154,10 @@ export class NotebookInput extends EditorInput {
|
|||||||
this.assignProviders();
|
this.assignProviders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public confirmSave(): TPromise<ConfirmResult> {
|
||||||
|
return this._model.confirmSave();
|
||||||
|
}
|
||||||
|
|
||||||
public get notebookUri(): URI {
|
public get notebookUri(): URI {
|
||||||
return this.resource;
|
return this.resource;
|
||||||
}
|
}
|
||||||
@@ -188,6 +212,11 @@ export class NotebookInput extends EditorInput {
|
|||||||
this._providers = value;
|
this._providers = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public save(): TPromise<boolean> {
|
||||||
|
let options: ISaveOptions = { force: false };
|
||||||
|
return this._model.save(options);
|
||||||
|
}
|
||||||
|
|
||||||
public set standardKernels(value: IStandardKernelWithProvider[]) {
|
public set standardKernels(value: IStandardKernelWithProvider[]) {
|
||||||
value.forEach(kernel => {
|
value.forEach(kernel => {
|
||||||
this._standardKernels.push({
|
this._standardKernels.push({
|
||||||
@@ -328,4 +357,5 @@ class NotebookEditorContentManager implements IContentManager {
|
|||||||
let contents = await contentManager.loadFromContentString(notebookEditorModel.contentString);
|
let contents = await contentManager.loadFromContentString(notebookEditorModel.contentString);
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user