Explorar el Código

Merge pull request #625 from blink1073/open-running

Open notebooks and terminals from the Running tab
Afshin Darian hace 8 años
padre
commit
2646d9d98a

+ 8 - 0
src/filebrowser/plugin.ts

@@ -70,6 +70,7 @@ const cmdIds = {
   saveAs: 'file-operations:saveAs',
   close: 'file-operations:close',
   closeAll: 'file-operations:closeAll',
+  open: 'file-operations:open',
   showBrowser: 'file-browser:activate',
   hideBrowser: 'file-browser:hide',
   toggleBrowser: 'file-browser:toggle'
@@ -92,6 +93,7 @@ function activateFileBrowser(app: JupyterLab, manager: IServiceManager, registry
         app.shell.addToMainArea(widget);
         tracker.addWidget(widget);
       }
+      app.shell.activateMain(widget.id);
     }
   };
   let { commands, keymap } = app;
@@ -213,6 +215,12 @@ function addCommands(app: JupyterLab, tracker: WidgetTracker<Widget>, fbWidget:
       }
     }
   });
+  commands.addCommand(cmdIds.open, {
+    execute: args => {
+      let path = args['path'] as string;
+      fbWidget.openPath(path);
+    }
+  });
   commands.addCommand(cmdIds.close, {
     label: 'Close',
     execute: () => {

+ 3 - 0
src/notebook/notebook/default-toolbar.ts

@@ -430,6 +430,9 @@ class KernelIndicator extends Widget {
    * Handle a status on a kernel.
    */
   private _handleStatus(kernel: IKernel, status: IKernel.Status) {
+    if (this.isDisposed) {
+      return;
+    }
     this.toggleClass(TOOLBAR_BUSY, status !== 'idle');
     let title = 'Kernel ' + status[0].toUpperCase() + status.slice(1);
     this.node.title = title;

+ 2 - 3
src/running/plugin.ts

@@ -32,12 +32,11 @@ function activateRunningSessions(app: JupyterLab, services: IServiceManager): vo
   running.id = 'jp-running-sessions';
   running.title.label = 'Running';
 
-  // TODO: replace these with execute calls in new phosphor.
   running.sessionOpenRequested.connect((sender, model) => {
-    console.log('requested session', model.notebook.path);
+    app.commands.execute('file-operations:open', { path: model.notebook.path });
   });
   running.terminalOpenRequested.connect((sender, model) => {
-    console.log('requested terminal', model.name);
+    app.commands.execute('terminal:open', { name: model.name });
   });
   // Rank has been chosen somewhat arbitrarily to give priority to the running
   // sessions widget in the sidebar.

+ 21 - 2
src/terminal/plugin.ts

@@ -1,6 +1,10 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import {
+  find
+} from 'phosphor/lib/algorithm/searching';
+
 import {
   Menu
 } from 'phosphor/lib/ui/menu';
@@ -59,6 +63,7 @@ function activateTerminal(app: JupyterLab, services: IServiceManager, mainMenu:
   let increaseTerminalFontSize = 'terminal:increase-font';
   let decreaseTerminalFontSize = 'terminal:decrease-font';
   let toggleTerminalTheme = 'terminal:toggle-theme';
+  let openTerminalId = 'terminal:open';
 
   let tracker = new WidgetTracker<TerminalWidget>();
   let options = {
@@ -70,13 +75,14 @@ function activateTerminal(app: JupyterLab, services: IServiceManager, mainMenu:
   commands.addCommand(newTerminalId, {
     label: 'New Terminal',
     caption: 'Start a new terminal session',
-    execute: () => {
+    execute: args => {
+      let name = args ? args['name'] as string : '';
       let term = new TerminalWidget(options);
       term.title.closable = true;
       term.title.icon = `${LANDSCAPE_ICON_CLASS} ${TERMINAL_ICON_CLASS}`;
       app.shell.addToMainArea(term);
       tracker.addWidget(term);
-      services.terminals.create().then(session => {
+      services.terminals.create({ name }).then(session => {
         term.session = session;
         // Trigger an update of the running kernels.
         services.terminals.listRunning();
@@ -127,6 +133,19 @@ function activateTerminal(app: JupyterLab, services: IServiceManager, mainMenu:
       }
     }
   });
+  commands.addCommand(openTerminalId, {
+    execute: args => {
+      let name = args['name'] as string;
+      // Check for a running terminal with the given name.
+      let widget = find(tracker.widgets, value => value.session.name === name);
+      if (widget) {
+        app.shell.activateMain(widget.id);
+      } else {
+        // Otherwise, create a new terminal with a given name.
+        commands.execute(newTerminalId, { name });
+      }
+    }
+  });
 
   let category = 'Terminal';
   [