mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 09:35:38 -05:00
initial support for Notebook extensibility. Fixes #3148 , Fixes #3382. ## Design notes The extensibility patterns are modeled after the VSCode Document and Editor APIs but need to be different since core editor concepts are different - for example Notebooks have cells, and cells have contents rather than editors which have text lines. Most importantly, a lot of the code is based on the MainThreadDocumentsAndEditors class, with some related classes (the MainThreadDocuments, and MainThreadEditors) brought in too. Given our current limitations I felt moving to add 3 full sets of extension host API classes was overkill so am currently using one. Will see if we need to change this in the future based on what we add in the additional APIs ## Limitations The current implementation is limited to visible editors, rather than all documents in the workspace. We are not following the `openDocument` -> `showDocument` pattern, but instead just supporting `showDocument` directly. ## Changes in this PR - Renamed existing APIs to make clear that they were about notebook contents, not about notebook behavior - Added new APIs for querying notebook documents and editors - Added new API for opening a notebook - Moved `New Notebook` command to an extension, and added an `Open Notebook` command too - Moved notebook feature flag to the extension ## Not covered in this PR - Need to actually implement support for defining the provider and connection IDs for a notebook. this will be important to support New Notebook from a big data connection in Object Explorer - Need to add APIs for adding cells, to support - Need to implement the metadata for getting full notebook contents. I've only implemented to key APIs needed to make this all work.
103 lines
3.6 KiB
TypeScript
103 lines
3.6 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
import { TPromise } from 'vs/base/common/winjs.base';
|
|
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
|
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
|
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
|
|
import { EditorOptions } from 'vs/workbench/common/editor';
|
|
import * as DOM from 'vs/base/browser/dom';
|
|
import { $ } from 'vs/base/browser/builder';
|
|
import { bootstrapAngular } from 'sql/services/bootstrap/bootstrapService';
|
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
|
|
|
import { CancellationToken } from 'vs/base/common/cancellation';
|
|
import { NotebookInput } from 'sql/parts/notebook/notebookInput';
|
|
import { NotebookModule } from 'sql/parts/notebook/notebook.module';
|
|
import { NOTEBOOK_SELECTOR } from 'sql/parts/notebook/notebook.component';
|
|
import { INotebookParams, DEFAULT_NOTEBOOK_PROVIDER } from 'sql/services/notebook/notebookService';
|
|
|
|
export class NotebookEditor extends BaseEditor {
|
|
|
|
public static ID: string = 'workbench.editor.notebookEditor';
|
|
private _notebookContainer: HTMLElement;
|
|
protected _input: NotebookInput;
|
|
|
|
constructor(
|
|
@ITelemetryService telemetryService: ITelemetryService,
|
|
@IThemeService themeService: IThemeService,
|
|
@IInstantiationService private instantiationService: IInstantiationService,
|
|
) {
|
|
super(NotebookEditor.ID, telemetryService, themeService);
|
|
}
|
|
|
|
public get input(): NotebookInput {
|
|
return this._input;
|
|
}
|
|
|
|
/**
|
|
* Called to create the editor in the parent element.
|
|
*/
|
|
public createEditor(parent: HTMLElement): void {
|
|
}
|
|
|
|
/**
|
|
* Sets focus on this editor. Specifically, it sets the focus on the hosted text editor.
|
|
*/
|
|
public focus(): void {
|
|
}
|
|
|
|
/**
|
|
* Updates the internal variable keeping track of the editor's size, and re-calculates the sash position.
|
|
* To be called when the container of this editor changes size.
|
|
*/
|
|
public layout(dimension: DOM.Dimension): void {
|
|
}
|
|
|
|
public setInput(input: NotebookInput, options: EditorOptions): TPromise<void> {
|
|
if (this.input && this.input.matches(input)) {
|
|
return TPromise.as(undefined);
|
|
}
|
|
|
|
const parentElement = this.getContainer();
|
|
|
|
super.setInput(input, options, CancellationToken.None);
|
|
|
|
$(parentElement).clearChildren();
|
|
|
|
if (!input.hasBootstrapped) {
|
|
let container = DOM.$<HTMLElement>('.notebookEditor');
|
|
container.style.height = '100%';
|
|
this._notebookContainer = DOM.append(parentElement, container);
|
|
this.input.container = this._notebookContainer;
|
|
return TPromise.wrap<void>(this.bootstrapAngular(input));
|
|
} else {
|
|
this._notebookContainer = DOM.append(parentElement, this.input.container);
|
|
return TPromise.wrap<void>(null);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Load the angular components and record for this input that we have done so
|
|
*/
|
|
private bootstrapAngular(input: NotebookInput): void {
|
|
// Get the bootstrap params and perform the bootstrap
|
|
input.hasBootstrapped = true;
|
|
let params: INotebookParams = {
|
|
notebookUri: input.notebookUri,
|
|
input: input,
|
|
providerId: input.providerId ? input.providerId : DEFAULT_NOTEBOOK_PROVIDER,
|
|
isTrusted: input.isTrusted
|
|
};
|
|
bootstrapAngular(this.instantiationService,
|
|
NotebookModule,
|
|
this._notebookContainer,
|
|
NOTEBOOK_SELECTOR,
|
|
params,
|
|
input
|
|
);
|
|
}
|
|
}
|
|
|