Jason Grout 7 سال پیش
والد
کامیت
2e93f837cb

+ 1 - 1
packages/apputils/src/mainareawidget.ts

@@ -256,7 +256,7 @@ namespace MainAreaWidget {
     toolbar?: Toolbar;
 
     /**
-     * An optional promise for when the content is fully populated.
+     * An optional promise for when the content is ready to be shown.
      */
     populated?: Promise<void>;
   }

+ 4 - 12
packages/docmanager/src/documentwidget.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-    Toolbar
+    Toolbar, MainAreaWidget
 } from '@jupyterlab/apputils';
 
 import {
@@ -17,19 +17,11 @@ import {
  * A document widget implementation.
  */
 export
-class DocumentWidget<T extends Widget, U extends DocumentRegistry.IModel> extends Widget implements IDocumentWidget<Widget, DocumentRegistry.IModel> {
-  constructor(options: IDocumentWidget.IOptions<Widget, DocumentRegistry.IModel>) {
-    super({node: options.node});
-    this.content = options.content;
-    this.contentReady = options.contentReady;
+class DocumentWidget extends MainAreaWidget implements IDocumentWidget {
+  constructor(options: IDocumentWidget.IOptions) {
+    super(options);
     this.context = options.context;
-    this.toolbar = options.toolbar;
-
-    // Set layout to boxpanel with appropriate sizing for toolbar
   }
 
-  readonly content: Widget;
-  readonly contentReady: Promise<void>;
   readonly context: DocumentRegistry.IContext<DocumentRegistry.IModel>;
-  readonly toolbar: Toolbar<Widget>;
 }

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

@@ -97,6 +97,9 @@ 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);
 

+ 29 - 6
packages/docregistry/src/default.ts

@@ -17,6 +17,14 @@ import {
   ISignal, Signal
 } from '@phosphor/signaling';
 
+import {
+  Widget
+} from '@phosphor/widgets';
+
+import {
+  Toolbar
+} from '@jupyterlab/apputils';
+
 import {
   CodeEditor
 } from '@jupyterlab/codeeditor';
@@ -30,7 +38,7 @@ import {
 } from '@jupyterlab/observables';
 
 import {
-  DocumentRegistry
+  DocumentRegistry, IDocumentWidget
 } from './index';
 
 
@@ -280,7 +288,7 @@ class Base64ModelFactory extends TextModelFactory {
  * The default implementation of a widget factory.
  */
 export
-abstract class ABCWidgetFactory<T extends DocumentRegistry.IReadyWidget, U extends DocumentRegistry.IModel> implements DocumentRegistry.IWidgetFactory<T, U> {
+abstract class ABCWidgetFactory<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> implements DocumentRegistry.IWidgetFactory<T, U> {
   /**
    * Construct a new `ABCWidgetFactory`.
    */
@@ -297,8 +305,8 @@ abstract class ABCWidgetFactory<T extends DocumentRegistry.IReadyWidget, U exten
   /**
    * A signal emitted when a widget is created.
    */
-  get widgetCreated(): ISignal<DocumentRegistry.IWidgetFactory<T, U>, T> {
-    return this._widgetCreated;
+  get documentWidgetCreated(): ISignal<DocumentRegistry.IWidgetFactory<T, U>, T> {
+    return this._documentWidgetCreated;
   }
 
   /**
@@ -364,13 +372,28 @@ abstract class ABCWidgetFactory<T extends DocumentRegistry.IReadyWidget, U exten
     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.
    */
-  createNew(context: DocumentRegistry.IContext<U>): T {
+  createContent(context: DocumentRegistry.IContext<U>): T {
     let widget = this.createNewWidget(context);
     this._widgetCreated.emit(widget);
     return widget;
@@ -389,5 +412,5 @@ abstract class ABCWidgetFactory<T extends DocumentRegistry.IReadyWidget, U exten
   private _modelName: string;
   private _fileTypes: string[];
   private _defaultFor: string[];
-  private _widgetCreated = new Signal<DocumentRegistry.IWidgetFactory<T, U>, T>(this);
+  private _documentWidgetCreated = new Signal<DocumentRegistry.IWidgetFactory<T, U>, T>(this);
 }

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

@@ -879,15 +879,15 @@ namespace DocumentRegistry {
     /**
      * Create a new content widget which will be initialized later.
      */
-    create(): T;
+    createContent(): T;
 
     /**
      * Initialize a content widget.
      *
      * @returns a promise that resolves when the content widget is ready to be
-     * visible.
+     * shown.
      */
-    initialize(context: IContext<U>, toolbar: Toolbar<Widget>, content: T): Promise<void>;
+    populate(context: IContext<U>, toolbar: Toolbar<Widget>, content: T): Promise<void>;
 
     /**
      * Called when a new document widget is created. Should emit the documentWidgetCreated signal.
@@ -1196,9 +1196,9 @@ namespace DocumentRegistry {
  * An interface for a document widget.
  */
 export
-interface IDocumentWidget<T extends Widget, U extends DocumentRegistry.IModel> extends Widget {
+interface IDocumentWidget<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> extends Widget {
   readonly content: T;
-  readonly contentReady: Promise<void>;
+  readonly populated: Promise<void>;
   readonly context: DocumentRegistry.IContext<U>;
   readonly toolbar: Toolbar<Widget>;
 }
@@ -1206,11 +1206,11 @@ interface IDocumentWidget<T extends Widget, U extends DocumentRegistry.IModel> e
 export
 namespace IDocumentWidget {
   export
-  interface IOptions<T extends Widget, U extends DocumentRegistry.IModel> extends Widget.IOptions {
+  interface IOptions<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> extends Widget.IOptions {
     readonly content: T;
-    readonly contentReady: Promise<void>;
     readonly context: DocumentRegistry.IContext<U>;
     readonly toolbar: Toolbar<Widget>;
+    readonly populated: Promise<void>;
   }
 }