Browse Source

wip add more options when opening

Steven Silvester 7 years ago
parent
commit
5fd2147ead

+ 5 - 16
packages/application/src/shell.ts

@@ -22,6 +22,10 @@ import {
   Panel, SplitPanel, StackedPanel, TabBar, Title, Widget
 } from '@phosphor/widgets';
 
+import {
+  DocumentRegistry
+} from '@jupyterlab/docregistry';
+
 
 /**
  * The class name added to AppShell instances.
@@ -757,22 +761,7 @@ namespace ApplicationShell {
    * The options for adding a widget to a side area of the shell.
    */
   export
-  interface IMainAreaOptions {
-    /**
-     * The reference widget id for the insert location.
-     *
-     * The default is `null`.
-     */
-    ref?: string | null;
-
-    /**
-     * The supported insertion modes.
-     *
-     * An insert mode is used to specify how a widget should be added
-     * to the main area relative to a reference widget.
-     */
-    mode?: DockLayout.InsertMode;
-  }
+  interface IMainAreaOptions extends DocumentRegistry.IOpenOptions {}
 }
 
 

+ 4 - 4
packages/docmanager-extension/src/index.ts

@@ -83,7 +83,7 @@ const plugin: JupyterLabPlugin<IDocumentManager> = {
     const manager = app.serviceManager;
     const contexts = new WeakSet<DocumentRegistry.Context>();
     const opener: DocumentManager.IWidgetOpener = {
-      open: widget => {
+      open: (widget, options) => {
         if (!widget.id) {
           widget.id = `document-manager-${++Private.id}`;
         }
@@ -92,13 +92,13 @@ const plugin: JupyterLabPlugin<IDocumentManager> = {
           ...widget.title.dataset
         };
         if (!widget.isAttached) {
-          app.shell.addToMainArea(widget);
+          app.shell.addToMainArea(widget, options || {});
 
           // Add a loading spinner, and remove it when the widget is ready.
-          if (widget.ready !== undefined) {
+          if ((widget as any).ready !== undefined) {
             let spinner = new Spinner();
             widget.node.appendChild(spinner.node);
-            widget.ready.then(() => { widget.node.removeChild(spinner.node); });
+            (widget as any).ready.then(() => { widget.node.removeChild(spinner.node); });
           }
         }
         app.shell.activateById(widget.id);

+ 4 - 3
packages/docmanager/src/manager.ts

@@ -377,9 +377,10 @@ class DocumentManager implements IDisposable {
    * Create a context from a path and a model factory.
    */
   private _createContext(path: string, factory: DocumentRegistry.ModelFactory, kernelPreference: IClientSession.IKernelPreference): Private.IContext {
-    let adopter = (widget: DocumentRegistry.IReadyWidget) => {
+    // Allow options to be passed when adding a sibling.
+    let adopter = (widget: Widget, options?: DocumentRegistry.IOpenOptions) => {
       this._widgetManager.adoptWidget(context, widget);
-      this._opener.open(widget);
+      this._opener.open(widget, options);
     };
     let modelDBFactory = this.services.contents.getModelDBFactory(path) || undefined;
     let context = new Context({
@@ -518,7 +519,7 @@ namespace DocumentManager {
     /**
      * Open the given widget.
      */
-    open(widget: DocumentRegistry.IReadyWidget): void;
+    open(widget: Widget, options?: DocumentRegistry.IOpenOptions): void;
   }
 }
 

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

@@ -125,7 +125,7 @@ class DocumentWidgetManager implements IDisposable {
    *
    * @param widget - The widget to adopt.
    */
-  adoptWidget(context: DocumentRegistry.Context, widget: DocumentRegistry.IReadyWidget): void {
+  adoptWidget(context: DocumentRegistry.Context, widget: Widget): void {
     let widgets = Private.widgetsProperty.get(context);
     widgets.push(widget);
     MessageLoop.installMessageHook(widget, this);
@@ -157,7 +157,7 @@ class DocumentWidgetManager implements IDisposable {
         return false;
       }
       return factory.name === widgetName;
-    });
+    }) as DocumentRegistry.IReadyWidget;
   }
 
   /**
@@ -448,7 +448,7 @@ namespace Private {
    * A private attached property for the widgets associated with a context.
    */
   export
-  const widgetsProperty = new AttachedProperty<DocumentRegistry.Context, DocumentRegistry.IReadyWidget[]>({
+  const widgetsProperty = new AttachedProperty<DocumentRegistry.Context, Widget[]>({
     name: 'widgets',
     create: () => []
   });

+ 13 - 3
packages/docregistry/src/context.ts

@@ -383,11 +383,21 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
 
   /**
    * Add a sibling widget to the document manager.
+   *
+   * @param widget - The widget to add to the document manager.
+   *
+   * @param options - The desired options for adding the sibling.
+   *
+   * @returns A disposable used to remove the sibling if desired.
+   *
+   * #### Notes
+   * It is assumed that the widget has the same model and context
+   * as the original widget.
    */
-  addSibling(widget: Widget): IDisposable {
+  addSibling(widget: Widget, options: DocumentRegistry.IOpenOptions = {}): IDisposable {
     let opener = this._opener;
     if (opener) {
-      opener(widget);
+      opener(widget, options);
     }
     return new DisposableDelegate(() => {
       widget.close();
@@ -622,7 +632,7 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
   }
 
   private _manager: ServiceManager.IManager;
-  private _opener: (widget: Widget) => void;
+  private _opener: (widget: Widget, options?: DocumentRegistry.IOpenOptions) => void;
   private _model: T;
   private _modelDB: IModelDB;
   private _path = '';

+ 25 - 2
packages/docregistry/src/registry.ts

@@ -22,7 +22,7 @@ import {
 } from '@phosphor/signaling';
 
 import {
-  Widget
+  DockLayout, Widget
 } from '@phosphor/widgets';
 
 import {
@@ -775,13 +775,15 @@ namespace DocumentRegistry {
      *
      * @param widget - The widget to add to the document manager.
      *
+     * @param options - The desired options for adding the sibling.
+     *
      * @returns A disposable used to remove the sibling if desired.
      *
      * #### Notes
      * It is assumed that the widget has the same model and context
      * as the original widget.
      */
-    addSibling(widget: Widget): IDisposable;
+    addSibling(widget: Widget, options?: IOpenOptions): IDisposable;
   }
 
   /**
@@ -849,6 +851,27 @@ namespace DocumentRegistry {
     readonly ready: Promise<void>;
   }
 
+  /**
+   * The options used to open a widget.
+   */
+  export
+  interface IOpenOptions {
+    /**
+     * The reference widget id for the insert location.
+     *
+     * The default is `null`.
+     */
+    ref?: string | null;
+
+    /**
+     * The supported insertion modes.
+     *
+     * An insert mode is used to specify how a widget should be added
+     * to the main area relative to a reference widget.
+     */
+    mode?: DockLayout.InsertMode;
+  }
+
   /**
    * The interface for a widget factory.
    */

+ 5 - 4
packages/notebook-extension/src/index.ts

@@ -1161,11 +1161,12 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
       widget.addClass('jp-LinkedOutputView');
       layout.addWidget(toolbar);
       layout.addWidget(outputAreaView);
-      current.context.addSibling(widget);
-      // Remove the output view if the parent notebook is closed.
-      nb.disposed.connect(
-        () => { widget.dispose(); }
+      current.context.addSibling(
+        widget, { ref: current.id, mode: 'split-bottom' }
       );
+
+      // Remove the output view if the parent notebook is closed.
+      nb.disposed.connect(widget.dispose);
     },
     isEnabled
   });