// Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. import { IEditorMimeTypeService } from '@jupyterlab/codeeditor'; import { ABCWidgetFactory, DocumentRegistry } from '@jupyterlab/docregistry'; import { IRenderMime } from '@jupyterlab/rendermime'; import { ToolbarItems } from './default-toolbar'; import { INotebookModel } from './model'; import { NotebookPanel } from './panel'; /** * A widget factory for notebook panels. */ export class NotebookWidgetFactory extends ABCWidgetFactory { /** * Construct a new notebook widget factory. * * @param options - The options used to construct the factory. */ constructor(options: NotebookWidgetFactory.IOptions) { super(options); this.rendermime = options.rendermime; this.contentFactory = options.contentFactory; this.mimeTypeService = options.mimeTypeService; } /* * The rendermime instance. */ readonly rendermime: IRenderMime; /** * The content factory used by the widget factory. */ readonly contentFactory: NotebookPanel.IContentFactory; /** * The service used to look up mime types. */ readonly mimeTypeService: IEditorMimeTypeService; /** * Create a new widget. * * #### Notes * The factory will start the appropriate kernel and populate * the default toolbar items using `ToolbarItems.populateDefaults`. */ protected createNewWidget(context: DocumentRegistry.IContext): NotebookPanel { let rendermime = this.rendermime.clone(); let panel = new NotebookPanel({ rendermime, contentFactory: this.contentFactory, mimeTypeService: this.mimeTypeService }); panel.context = context; ToolbarItems.populateDefaults(panel); return panel; } } /** * The namespace for `NotebookWidgetFactory` statics. */ export namespace NotebookWidgetFactory { /** * The options used to construct a `NotebookWidgetFactory`. */ export interface IOptions extends DocumentRegistry.IWidgetFactoryOptions { /* * A rendermime instance. */ rendermime: IRenderMime; /** * A notebook panel content factory. */ contentFactory: NotebookPanel.IContentFactory; /** * The service used to look up mime types. */ mimeTypeService: IEditorMimeTypeService; } }