Browse Source

Clean up opener and terminal plugins

Steven Silvester 9 years ago
parent
commit
8283031f23
2 changed files with 22 additions and 12 deletions
  1. 8 10
      src/fileopener/plugin.ts
  2. 14 2
      src/terminal/plugin.ts

+ 8 - 10
src/fileopener/plugin.ts

@@ -45,7 +45,7 @@ function resolve(container: Container): Promise<void> {
     create: (appShell: IAppShell, opener: IFileOpener, browser: IFileBrowserWidget, palette: ICommandPalette, registry: ICommandRegistry): void => {
       registry.add('jupyter-plugins:new:text-file', () => {
         browser.newUntitled('file', '.txt').then(
-          contents => this._opener.open(contents.path)
+          contents => opener.open(contents.path)
         );
       });
 
@@ -170,15 +170,13 @@ class FileOpener implements IFileOpener {
     if (!widget.isAttached) {
       this._appShell.addToMainArea(widget);
     }
-    let parent = widget.parent;
-    while (parent) {
-      if (parent instanceof TabPanel) {
-        if ((parent as TabPanel).childIndex(widget) !== -1) {
-          (parent as TabPanel).currentWidget = widget;
-          return widget;
-        }
-      }
-      parent = parent.parent;
+    let stack = widget.parent;
+    if (!stack) {
+      return;
+    }
+    let tabs = stack.parent;
+    if (tabs instanceof TabPanel) {
+      tabs.currentWidget = widget;
     }
     return widget;
   }

+ 14 - 2
src/terminal/plugin.ts

@@ -6,13 +6,17 @@ import {
   TerminalWidget, ITerminalOptions
 } from 'jupyter-js-terminal';
 
+import {
+  IAppShell, ICommandPalette, ICommandRegistry
+} from 'phosphide';
+
 import {
   Container, Token
 } from 'phosphor-di';
 
 import {
-  IAppShell, ICommandPalette, ICommandRegistry
-} from 'phosphide';
+  TabPanel
+} from 'phosphor-tabs';
 
 import './plugin.css';
 
@@ -28,6 +32,14 @@ function resolve(container: Container): Promise<void> {
         term.background = 'white';
         term.title.closable = true;
         shell.addToMainArea(term);
+        let stack = term.parent;
+        if (!stack) {
+          return;
+        }
+        let tabs = stack.parent;
+        if (tabs instanceof TabPanel) {
+          tabs.currentWidget = term;
+        }
       });
       let paletteItem = {
         id: 'jupyter-plugins:new:terminal',