123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- // 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<NotebookPanel, INotebookModel> {
- /**
- * 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<INotebookModel>): 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;
- }
- }
|