#3920: Notebooks file save/save all/cache - for existing files (#4286)

* #3920: Notebooks file save

* Missed in merge

* #4290: Untitled save and native dirty implementation

* Misc changes

* Content Manager, notebooks extension and commented failed unit tests

* Removing modelLoaded event
This commit is contained in:
Raj
2019-03-07 18:07:20 -08:00
committed by GitHub
parent 2a903e9f03
commit 036ffe595a
15 changed files with 486 additions and 400 deletions

View File

@@ -369,6 +369,11 @@ export interface INotebookModel {
*/
saveModel(): Promise<boolean>;
/**
* Serialize notebook cell content to JSON
*/
toJSON(): nb.INotebookContents;
/**
* Notifies the notebook of a change in the cell
*/
@@ -455,6 +460,12 @@ export interface IModelFactory {
createClientSession(options: IClientSessionOptions): IClientSession;
}
export interface IContentManager {
/**
* This is a specialized method intended to load for a default context - just the current Notebook's URI
*/
loadContent(): Promise<nb.INotebookContents>;
}
export interface INotebookModelOptions {
/**
@@ -467,6 +478,7 @@ export interface INotebookModelOptions {
*/
factory: IModelFactory;
contentManager: IContentManager;
notebookManagers: INotebookManager[];
providerId: string;
standardKernels: IStandardKernelWithProvider[];
@@ -498,4 +510,4 @@ export interface ICellMagicMapper {
export namespace notebookConstants {
export const SQL = 'SQL';
}
}

View File

@@ -8,19 +8,18 @@
import { nb, connection } from 'azdata';
import { localize } from 'vs/nls';
import { Event, Emitter, forEach } from 'vs/base/common/event';
import { Event, Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { CellModel } from './cell';
import { IClientSession, INotebookModel, IDefaultConnection, INotebookModelOptions, ICellModel, notebookConstants, NotebookContentChange } from './modelInterfaces';
import { NotebookChangeType, CellType, CellTypes } from 'sql/parts/notebook/models/contracts';
import { IClientSession, INotebookModel, IDefaultConnection, INotebookModelOptions, ICellModel, NotebookContentChange } from './modelInterfaces';
import { NotebookChangeType, CellType } from 'sql/parts/notebook/models/contracts';
import { nbversion } from '../notebookConstants';
import * as notebookUtils from '../notebookUtils';
import { INotebookManager, SQL_NOTEBOOK_PROVIDER, DEFAULT_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/common/notebookService';
import { NotebookContexts } from 'sql/parts/notebook/models/notebookContexts';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { INotification, Severity } from 'vs/platform/notification/common/notification';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { ISingleNotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
@@ -130,6 +129,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
return this._contentChangedEmitter.event;
}
public get isSessionReady(): boolean {
return !!this._activeClientSession;
}
@@ -253,10 +253,11 @@ export class NotebookModel extends Disposable implements INotebookModel {
try {
this._trustedMode = isTrusted;
let contents = null;
if (this._notebookOptions.notebookUri.scheme !== Schemas.untitled) {
// TODO: separate ContentManager from NotebookManager
contents = await this.notebookManagers[0].contentManager.getNotebookContents(this._notebookOptions.notebookUri);
if (this._notebookOptions && this._notebookOptions.contentManager) {
contents = await this._notebookOptions.contentManager.loadContent();
}
let factory = this._notebookOptions.factory;
// if cells already exist, create them with language info (if it is saved)
this._cells = [];