浏览代码

Add getters to check if parts of the shell are empty. Only open the landing page if the main area is empty.

Afshin Darian 8 年之前
父节点
当前提交
3db26c822c
共有 2 个文件被更改,包括 36 次插入12 次删除
  1. 30 2
      src/application/shell.ts
  2. 6 10
      src/landing/plugin.ts

+ 30 - 2
src/application/shell.ts

@@ -177,6 +177,34 @@ class ApplicationShell extends Widget {
     return this._dockPanel.currentWidget;
   }
 
+  /**
+   * True if main area is empty.
+   */
+  get mainAreaIsEmpty(): boolean {
+    return this._dockPanel.isEmpty;
+  }
+
+  /**
+   * True if top area is empty.
+   */
+  get topAreaIsEmpty(): boolean {
+    return this._topPanel.widgets.length === 0;
+  }
+
+  /**
+   * True if left area is empty.
+   */
+  get leftAreaIsEmpty(): boolean {
+    return this._leftHandler.stackedPanel.widgets.length === 0;
+  }
+
+  /**
+   * True if right area is empty.
+   */
+  get rightAreaIsEmpty(): boolean {
+    return this._rightHandler.stackedPanel.widgets.length === 0;
+  }
+
   /**
    * Add a widget to the top content area.
    *
@@ -228,12 +256,12 @@ class ApplicationShell extends Widget {
    * #### Notes
    * Widgets must have a unique `id` property, which will be used as the DOM id.
    */
-  addToMainArea(widget: Widget, options: DockPanel.IAddOptions = { mode: 'tab-after' }): void {
+  addToMainArea(widget: Widget): void {
     if (!widget.id) {
       console.error('widgets added to app shell must have unique id property');
       return;
     }
-    this._dockPanel.addWidget(widget, options);
+    this._dockPanel.addWidget(widget, { mode: 'tab-after' });
   }
 
   /**

+ 6 - 10
src/landing/plugin.ts

@@ -83,15 +83,12 @@ function activateLanding(app: JupyterLab, pathTracker: IPathTracker, palette: IC
 
   app.commands.addCommand(command, {
     label: 'Show Landing',
-    execute: (args) => {
-      let inactive = args && args['inactive'] as boolean;
+    execute: () => {
       if (!widget || widget.isDisposed) {
         widget = newWidget();
-        app.shell.addToMainArea(widget, { mode: 'tab-before' });
-      }
-      if (!inactive) {
-        app.shell.activateMain(widget.id);
+        app.shell.addToMainArea(widget);
       }
+      app.shell.activateMain(widget.id);
     }
   });
 
@@ -105,11 +102,10 @@ function activateLanding(app: JupyterLab, pathTracker: IPathTracker, palette: IC
 
   palette.addItem({ category, command });
 
-  // If the layout has been restored and the landing widget was not re-opened,
-  // then open it in an inactive state.
+  // Only create a landing page if there are no other tabs open.
   layout.restored.then(() => {
-    if (!widget) {
-      app.commands.execute(command, { inactive: true });
+    if (app.shell.mainAreaIsEmpty) {
+      app.commands.execute(command, void 0);
     }
   });
 }