mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-03 01:25:38 -05:00
Notebook Views Models (#13884)
* Add notebook editor Introduce notebook editor component to allow for separate notebook displays in order to accomodate notebook views * Localize notebook views configuration title * Refactor view mode and remove the views configuration while it is unused * Only fire view mode changed event when the value has been changed * Remove notebook views contribution * Add metadata capabilities * Notebook views definitions * Add notebook views models * Views test * Rename type arguments * Additional tests * Fix unused import * Update resize cell test
This commit is contained in:
@@ -128,6 +128,15 @@ export class CellModel extends Disposable implements ICellModel {
|
||||
return this._onCellModeChanged.event;
|
||||
}
|
||||
|
||||
public set metadata(data: any) {
|
||||
this._metadata = data;
|
||||
this.sendChangeToNotebook(NotebookChangeType.CellMetadataUpdated);
|
||||
}
|
||||
|
||||
public get metadata(): any {
|
||||
return this._metadata;
|
||||
}
|
||||
|
||||
public get isEditMode(): boolean {
|
||||
return this._isEditMode;
|
||||
}
|
||||
|
||||
@@ -345,6 +345,16 @@ export interface INotebookModel {
|
||||
*/
|
||||
viewMode: ViewMode;
|
||||
|
||||
/**
|
||||
* Add custom metadata values to the notebook
|
||||
*/
|
||||
setMetaValue(key: string, value: any);
|
||||
|
||||
/**
|
||||
* Get a custom metadata value from the notebook
|
||||
*/
|
||||
getMetaValue(key: string): any;
|
||||
|
||||
/**
|
||||
* Change the current kernel from the Kernel dropdown
|
||||
* @param displayName kernel name (as displayed in Kernel dropdown)
|
||||
@@ -476,6 +486,7 @@ export interface ICellModel {
|
||||
source: string | string[];
|
||||
cellType: CellType;
|
||||
trustedMode: boolean;
|
||||
metadata: any | undefined;
|
||||
active: boolean;
|
||||
hover: boolean;
|
||||
executionCount: number | undefined;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { INotebookModel, ICellModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||
import { NotebookChangeType } from 'sql/workbench/services/notebook/common/contracts';
|
||||
|
||||
export class NotebookExtension<TNotebookMeta, TCellMeta> {
|
||||
readonly version = 1;
|
||||
readonly extensionName = 'azuredatastudio';
|
||||
readonly extensionNamespace = 'extensions';
|
||||
|
||||
public getNotebookMetadata(notebook: INotebookModel): TNotebookMeta {
|
||||
const metadata = notebook.getMetaValue(this.extensionNamespace) || {};
|
||||
return metadata[this.extensionName] as TNotebookMeta;
|
||||
}
|
||||
|
||||
public setNotebookMetadata(notebook: INotebookModel, metadata: TNotebookMeta) {
|
||||
const meta = {};
|
||||
meta[this.extensionName] = metadata;
|
||||
notebook.setMetaValue(this.extensionNamespace, meta);
|
||||
notebook.serializationStateChanged(NotebookChangeType.MetadataChanged);
|
||||
}
|
||||
|
||||
public getCellMetadata(cell: ICellModel): TCellMeta {
|
||||
const namespaceMeta = cell.metadata[this.extensionNamespace] || {};
|
||||
return namespaceMeta[this.extensionName] as TCellMeta;
|
||||
}
|
||||
|
||||
public setCellMetadata(cell: ICellModel, metadata: TCellMeta) {
|
||||
const meta = {};
|
||||
meta[this.extensionName] = metadata;
|
||||
cell.metadata[this.extensionNamespace] = meta;
|
||||
cell.sendChangeToNotebook(NotebookChangeType.CellsModified);
|
||||
}
|
||||
}
|
||||
@@ -284,6 +284,26 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
return this._viewMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom metadata values to the notebook
|
||||
*/
|
||||
public setMetaValue(key: string, value: any) {
|
||||
this._existingMetadata[key] = value;
|
||||
let changeInfo: NotebookContentChange = {
|
||||
changeType: NotebookChangeType.MetadataChanged,
|
||||
isDirty: true,
|
||||
cells: [],
|
||||
};
|
||||
this._contentChangedEmitter.fire(changeInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a custom metadata value from the notebook
|
||||
*/
|
||||
public getMetaValue(key: string): any {
|
||||
return this._existingMetadata[key];
|
||||
}
|
||||
|
||||
public set viewMode(mode: ViewMode) {
|
||||
if (mode !== this._viewMode) {
|
||||
this._viewMode = mode;
|
||||
|
||||
Reference in New Issue
Block a user