浏览代码

Merge pull request #614 from blink1073/activate-widgets

Implement widget activation in the main shell area
Afshin Darian 8 年之前
父节点
当前提交
cbd0170fd4
共有 4 个文件被更改,包括 17 次插入44 次删除
  1. 2 12
      src/about/plugin.ts
  2. 11 7
      src/application/shell.ts
  3. 2 12
      src/faq/plugin.ts
  4. 2 13
      src/landing/plugin.ts

+ 2 - 12
src/about/plugin.ts

@@ -1,10 +1,6 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import {
-  TabPanel
-} from 'phosphor/lib/ui/tabpanel';
-
 import {
   Widget
 } from 'phosphor/lib/ui/widget';
@@ -48,14 +44,8 @@ function activateAbout(app: JupyterLab, palette: ICommandPalette): void {
     execute: () => {
       if (!widget.isAttached) {
         app.shell.addToMainArea(widget);
-      }
-      let stack = widget.parent;
-      if (!stack) {
-        return;
-      }
-      let tabs = stack.parent;
-      if (tabs instanceof TabPanel) {
-        tabs.currentWidget = widget;
+      } else {
+        app.shell.activateMain(widget.id);
       }
     }
   });

+ 11 - 7
src/application/shell.ts

@@ -9,7 +9,7 @@ import {
 } from 'phosphor/lib/collections/vector';
 
 import {
-  BoxLayout, BoxPanel
+  BoxPanel
 } from 'phosphor/lib/ui/boxpanel';
 
 import {
@@ -173,35 +173,39 @@ class ApplicationShell extends Panel {
   }
 
   /**
-   *
+   * Activate a widget in the left area.
    */
   activateLeft(id: string): void {
     this._leftHandler.activate(id);
   }
 
   /**
-   *
+   * Activate a widget in the right area.
    */
   activateRight(id: string): void {
     this._rightHandler.activate(id);
   }
 
   /**
-   *
+   * Activate a widget in the main area.
    */
   activateMain(id: string): void {
-    // TODO
+    let dock = this._dockPanel;
+    let widget = find(dock.widgets, value => value.id === id);
+    if (widget) {
+      dock.activateWidget(widget);
+    }
   }
 
   /**
-   *
+   * Collapse the left area.
    */
   collapseLeft(): void {
     this._leftHandler.collapse();
   }
 
   /**
-   *
+   * Collapse the right area.
    */
   collapseRight(): void {
     this._rightHandler.collapse();

+ 2 - 12
src/faq/plugin.ts

@@ -7,10 +7,6 @@ import {
   Message
 } from 'phosphor/lib/core/messaging';
 
-import {
-  TabPanel
-} from 'phosphor/lib/ui/tabpanel';
-
 import {
   Widget
 } from 'phosphor/lib/ui/widget';
@@ -336,14 +332,8 @@ function activateFAQ(app: JupyterLab, palette: ICommandPalette): void {
     execute: () => {
       if (!widget.isAttached) {
         app.shell.addToMainArea(widget);
-      }
-      let stack = widget.parent;
-      if (!stack) {
-        return;
-      }
-      let tabs = stack.parent;
-      if (tabs instanceof TabPanel) {
-        tabs.currentWidget = widget;
+      } else {
+        app.shell.activateMain(widget.id);
       }
     }
   });

+ 2 - 13
src/landing/plugin.ts

@@ -5,10 +5,6 @@ import {
   Widget
 } from 'phosphor/lib/ui/widget';
 
-import {
-  TabPanel
-} from 'phosphor/lib/ui/tabpanel';
-
 import {
   JupyterLab, JupyterLabPlugin
 } from '../application';
@@ -143,16 +139,9 @@ function activateLanding(app: JupyterLab, services: IServiceManager, pathTracker
     execute: () => {
       if (!widget.isAttached) {
         app.shell.addToMainArea(widget);
+      } else {
+        app.shell.activateMain(widget.id);
       }
-      let stack = widget.parent;
-      if (!stack) {
-        return;
-      }
-      let tabs = stack.parent;
-      if (tabs instanceof TabPanel) {
-        tabs.currentWidget = widget;
-      }
-      app.shell.activateMain(widget.id);
     }
   });