Parcourir la source

Allow opening a terminal from the running tab

Steven Silvester il y a 8 ans
Parent
commit
76f859aa41
2 fichiers modifiés avec 23 ajouts et 5 suppressions
  1. 2 3
      src/running/plugin.ts
  2. 21 2
      src/terminal/plugin.ts

+ 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';
   [