mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 09:35:38 -05:00
* #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:
@@ -21,10 +21,9 @@ import {
|
||||
SqlMainContext, MainThreadNotebookDocumentsAndEditorsShape, SqlExtHostContext, ExtHostNotebookDocumentsAndEditorsShape,
|
||||
INotebookDocumentsAndEditorsDelta, INotebookEditorAddData, INotebookShowOptions, INotebookModelAddedData, INotebookModelChangedData
|
||||
} from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||
import { NotebookInputModel, NotebookInput } from 'sql/parts/notebook/notebookInput';
|
||||
import { NotebookInput, NotebookEditorModel } from 'sql/parts/notebook/notebookInput';
|
||||
import { INotebookService, INotebookEditor, DEFAULT_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/common/notebookService';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { getProvidersForFileName, getStandardKernelsForProvider } from 'sql/parts/notebook/notebookUtils';
|
||||
import { ISingleNotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { disposed } from 'vs/base/common/errors';
|
||||
import { ICellModel, NotebookContentChange, INotebookModel } from 'sql/parts/notebook/models/modelInterfaces';
|
||||
@@ -361,26 +360,10 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
|
||||
pinned: !options.preview
|
||||
};
|
||||
let trusted = uri.scheme === Schemas.untitled;
|
||||
let model = new NotebookInputModel(uri, undefined, trusted, undefined, undefined, undefined, options.connectionId);
|
||||
let providerId = options.providerId;
|
||||
let providers: string[] = undefined;
|
||||
// Ensure there is always a sensible provider ID for this file type
|
||||
providers = getProvidersForFileName(uri.fsPath, this._notebookService);
|
||||
// Try to use a non-builtin provider first
|
||||
if (providers) {
|
||||
providerId = providers.find(p => p !== DEFAULT_NOTEBOOK_PROVIDER);
|
||||
if (!providerId) {
|
||||
providerId = model.providerId;
|
||||
}
|
||||
}
|
||||
model.providers = providers;
|
||||
model.providerId = providerId;
|
||||
model.defaultKernel = options && options.defaultKernel;
|
||||
model.providers.forEach(provider => {
|
||||
let standardKernels = getStandardKernelsForProvider(provider, this._notebookService);
|
||||
model.standardKernels = standardKernels;
|
||||
});
|
||||
let input = this._instantiationService.createInstance(NotebookInput, undefined, model);
|
||||
let input = this._instantiationService.createInstance(NotebookInput, uri.fsPath, uri);
|
||||
input.isTrusted = trusted;
|
||||
input.defaultKernel = options.defaultKernel;
|
||||
input.connectionProfileId = options.connectionId;
|
||||
|
||||
let editor = await this._editorService.openEditor(input, editorOptions, viewColumnToEditorGroup(this._editorGroupService, options.position));
|
||||
if (!editor) {
|
||||
|
||||
@@ -22,6 +22,29 @@ import { nbformat } from 'sql/parts/notebook/models/nbformat';
|
||||
type MimeBundle = { [key: string]: string | string[] | undefined };
|
||||
|
||||
export class LocalContentManager implements nb.ContentManager {
|
||||
|
||||
public async loadFromContentString(contentString: string): Promise<nb.INotebookContents> {
|
||||
let contents: JSONObject = json.parse(contentString);
|
||||
|
||||
if (contents) {
|
||||
if (contents.nbformat === 4) {
|
||||
return v4.readNotebook(<any>contents);
|
||||
} else if (contents.nbformat === 3) {
|
||||
return v3.readNotebook(<any>contents);
|
||||
}
|
||||
if (contents.nbformat) {
|
||||
throw new TypeError(localize('nbformatNotRecognized', 'nbformat v{0}.{1} not recognized', contents.nbformat as any, contents.nbformat_minor as any));
|
||||
}
|
||||
} else if (contentString === '' || contentString === undefined) {
|
||||
// Empty?
|
||||
return v4.createEmptyNotebook();
|
||||
}
|
||||
|
||||
// else, fallthrough condition
|
||||
throw new TypeError(localize('nbNotSupported', 'This file does not have a valid notebook format'));
|
||||
|
||||
}
|
||||
|
||||
public async getNotebookContents(notebookUri: URI): Promise<nb.INotebookContents> {
|
||||
if (!notebookUri) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user