Browse Source

Revert back to original widget creation workflow, but insist we get back a document widget.

Jason Grout 7 years ago
parent
commit
92d58d01a1

+ 0 - 35
packages/docmanager/src/documentwidget.ts

@@ -1,35 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-import {
-    Toolbar, MainAreaWidget
-} from '@jupyterlab/apputils';
-
-import {
-    IDocumentWidget, DocumentRegistry
-} from '@jupyterlab/docregistry';
-
-import {
-    Widget
-} from '@phosphor/widgets';
-
-/**
- * A document widget implementation.
- */
-export
-class DocumentWidget extends MainAreaWidget implements IDocumentWidget {
-  constructor(options: IDocumentWidget.IOptions) {
-    super(options);
-    this.context = options.context;
-  }
-
-  readonly context: DocumentRegistry.IContext<DocumentRegistry.IModel>;
-}
-
-export
-namespace DocumentWidget {
-    export
-    interface IOptions extends MainAreaWidget.IOptions {
-        context: DocumentRegistry.IContext<DocumentRegistry.IModel>;
-    }
-}

+ 0 - 3
packages/docmanager/src/widgetmanager.ts

@@ -97,9 +97,6 @@ class DocumentWidgetManager implements IDisposable {
    * @throws If the factory is not registered.
    */
   createWidget(factory: DocumentRegistry.WidgetFactory, context: DocumentRegistry.Context): DocumentRegistry.IReadyWidget {
-
-    let content = factory.create();
-
     let widget = factory.createNew(context);
     Private.factoryProperty.set(widget, factory);
 

+ 28 - 21
packages/docregistry/src/default.ts

@@ -22,7 +22,7 @@ import {
 } from '@phosphor/widgets';
 
 import {
-  Toolbar
+  Toolbar, MainAreaWidget
 } from '@jupyterlab/apputils';
 
 import {
@@ -288,7 +288,7 @@ class Base64ModelFactory extends TextModelFactory {
  * The default implementation of a widget factory.
  */
 export
-abstract class ABCWidgetFactory<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> implements DocumentRegistry.IWidgetFactory<T, U> {
+abstract class ABCWidgetFactory<T extends IDocumentWidget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> implements DocumentRegistry.IWidgetFactory<T, U> {
   /**
    * Construct a new `ABCWidgetFactory`.
    */
@@ -305,8 +305,8 @@ abstract class ABCWidgetFactory<T extends Widget = Widget, U extends DocumentReg
   /**
    * A signal emitted when a widget is created.
    */
-  get documentWidgetCreated(): ISignal<DocumentRegistry.IWidgetFactory<T, U>, T> {
-    return this._documentWidgetCreated;
+  get widgetCreated(): ISignal<DocumentRegistry.IWidgetFactory<T, U>, T> {
+    return this._widgetCreated;
   }
 
   /**
@@ -372,28 +372,13 @@ abstract class ABCWidgetFactory<T extends Widget = Widget, U extends DocumentReg
     return this._canStartKernel;
   }
 
-  /**
-   * Create a new empty content widget.
-   */
-  abstract createContent(): T;
-
-  /**
-   * Populate a content widget.
-   *
-   * @returns a promise that resolves when the content widget is ready to be
-   * shown.
-   */
-  abstract populate(context: DocumentRegistry.IContext<U>, toolbar: Toolbar<Widget>, content: T): Promise<void>;
-
-  abstract documentWidget(documentWidget: IDocumentWidget<T, U>): void;
-
   /**
    * Create a new widget given a document model and a context.
    *
    * #### Notes
    * It should emit the [widgetCreated] signal with the new widget.
    */
-  createContent(context: DocumentRegistry.IContext<U>): T {
+  createNew(context: DocumentRegistry.IContext<U>): T {
     let widget = this.createNewWidget(context);
     this._widgetCreated.emit(widget);
     return widget;
@@ -412,5 +397,27 @@ abstract class ABCWidgetFactory<T extends Widget = Widget, U extends DocumentReg
   private _modelName: string;
   private _fileTypes: string[];
   private _defaultFor: string[];
-  private _documentWidgetCreated = new Signal<DocumentRegistry.IWidgetFactory<T, U>, T>(this);
+  private _widgetCreated = new Signal<DocumentRegistry.IWidgetFactory<T, U>, T>(this);
+}
+
+
+/**
+ * A document widget implementation.
+ */
+export
+class DocumentWidget<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> extends MainAreaWidget<T> implements IDocumentWidget<T, U> {
+  constructor(options: DocumentWidget.IOptions<T, U>) {
+    super(options);
+    this.context = options.context;
+  }
+
+  readonly context: DocumentRegistry.IContext<U>;
+}
+
+export
+namespace DocumentWidget {
+  export
+  interface IOptions<T extends Widget, U extends DocumentRegistry.IModel> extends MainAreaWidget.IOptions<T> {
+      context: DocumentRegistry.IContext<U>;
+  }
 }

+ 7 - 28
packages/docregistry/src/registry.ts

@@ -870,36 +870,26 @@ namespace DocumentRegistry {
    * The interface for a widget factory.
    */
   export
-  interface IWidgetFactory<T extends Widget, U extends IModel> extends IDisposable, IWidgetFactoryOptions {
+  interface IWidgetFactory<T extends IDocumentWidget, U extends IModel> extends IDisposable, IWidgetFactoryOptions {
     /**
      * A signal emitted when a new widget is created.
      */
-    documentWidgetCreated: ISignal<IWidgetFactory<T, U>, IDocumentWidget<T, U>>;
+    widgetCreated: ISignal<IWidgetFactory<T, U>, IDocumentWidget<T, U>>;
 
     /**
-     * Create a new content widget which will be initialized later.
-     */
-    createContent(): T;
-
-    /**
-     * Initialize a content widget.
+     * Create a new widget given a context.
      *
-     * @returns a promise that resolves when the content widget is ready to be
-     * shown.
-     */
-    populate(context: IContext<U>, toolbar: Toolbar<Widget>, content: T): Promise<void>;
-
-    /**
-     * Called when a new document widget is created. Should emit the documentWidgetCreated signal.
+     * #### Notes
+     * It should emit the [widgetCreated] signal with the new widget.
      */
-    documentWidget(documentWidget: IDocumentWidget<T, U>): void;
+    createNew(context: IContext<U>): T;
   }
 
   /**
    * A type alias for a standard widget factory.
    */
   export
-  type WidgetFactory = IWidgetFactory<Widget, IModel>;
+  type WidgetFactory = IWidgetFactory<IDocumentWidget, IModel>;
 
   /**
    * An interface for a widget extension.
@@ -1203,17 +1193,6 @@ interface IDocumentWidget<T extends Widget = Widget, U extends DocumentRegistry.
   readonly toolbar: Toolbar<Widget>;
 }
 
-export
-namespace IDocumentWidget {
-  export
-  interface IOptions<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> extends Widget.IOptions {
-    readonly content: T;
-    readonly context: DocumentRegistry.IContext<U>;
-    readonly toolbar: Toolbar<Widget>;
-    readonly populated: Promise<void>;
-  }
-}
-
 /**
  * A private namespace for DocumentRegistry data.
  */