Browse Source

Use focus tracker in console

Steven Silvester 8 years ago
parent
commit
9ca19b6612
2 changed files with 25 additions and 18 deletions
  1. 7 0
      src/console/panel.ts
  2. 18 18
      src/console/plugin.ts

+ 7 - 0
src/console/panel.ts

@@ -78,6 +78,13 @@ class ConsolePanel extends Panel {
     super.dispose();
   }
 
+  /**
+   * Handle `'activate-request'` messages.
+   */
+  protected onActivateRequest(msg: Message): void {
+    this.content.prompt.editor.focus();
+  }
+
   /**
    * Handle `'close-request'` messages.
    */

+ 18 - 18
src/console/plugin.ts

@@ -5,6 +5,10 @@ import {
   IKernel, ISession
 } from 'jupyter-js-services';
 
+import {
+  FocusTracker
+} from 'phosphor/lib/ui/focustracker';
+
 import {
   Menu
 } from 'phosphor/lib/ui/menu';
@@ -37,10 +41,6 @@ import {
   IServiceManager
 } from '../services';
 
-import {
-  WidgetTracker
-} from '../widgettracker';
-
 import {
   ConsolePanel, ConsoleWidget
 } from './';
@@ -80,7 +80,7 @@ const CONSOLE_ICON_CLASS = 'jp-ImageConsole';
  * Activate the console extension.
  */
 function activateConsole(app: JupyterLab, services: IServiceManager, rendermime: IRenderMime, mainMenu: IMainMenu, inspector: IInspector, palette: ICommandPalette, renderer: ConsoleWidget.IRenderer): void {
-  let tracker = new WidgetTracker<ConsolePanel>();
+  let tracker = new FocusTracker<ConsolePanel>();
   let manager = services.sessions;
   let { commands, keymap } = app;
   let category = 'Console';
@@ -92,8 +92,8 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
   let command: string;
 
   // Set the source of the code inspector to the current console.
-  tracker.activeWidgetChanged.connect((sender: any, panel: ConsolePanel) => {
-    inspector.source = panel.content.inspectionHandler;
+  tracker.currentChanged.connect((sender, args) => {
+    inspector.source = args.newValue.content.inspectionHandler;
   });
 
   // Set the main menu title.
@@ -136,7 +136,7 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
           panel.title.icon = `${LANDSCAPE_ICON_CLASS} ${CONSOLE_ICON_CLASS}`;
           panel.title.closable = true;
           app.shell.addToMainArea(panel);
-          tracker.addWidget(panel);
+          tracker.add(panel);
         });
       }
     });
@@ -148,8 +148,8 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
   commands.addCommand(command, {
     label: 'Clear Cells',
     execute: () => {
-      if (tracker.activeWidget) {
-        tracker.activeWidget.content.clear();
+      if (tracker.currentWidget) {
+        tracker.currentWidget.content.clear();
       }
     }
   });
@@ -160,8 +160,8 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
   command = 'console:dismiss-completion';
   commands.addCommand(command, {
     execute: () => {
-      if (tracker.activeWidget) {
-        tracker.activeWidget.content.dismissCompletion();
+      if (tracker.currentWidget) {
+        tracker.currentWidget.content.dismissCompletion();
       }
     }
   });
@@ -171,8 +171,8 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
   commands.addCommand(command, {
     label: 'Execute Cell',
     execute: () => {
-      if (tracker.activeWidget) {
-        tracker.activeWidget.content.execute();
+      if (tracker.currentWidget) {
+        tracker.currentWidget.content.execute();
       }
     }
   });
@@ -184,8 +184,8 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
   commands.addCommand(command, {
     label: 'Interrupt Kernel',
     execute: () => {
-      if (tracker.activeWidget) {
-        let kernel = tracker.activeWidget.content.session.kernel;
+      if (tracker.currentWidget) {
+        let kernel = tracker.currentWidget.content.session.kernel;
         if (kernel) {
           kernel.interrupt();
         }
@@ -200,10 +200,10 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
   commands.addCommand(command, {
     label: 'Switch Kernel',
     execute: () => {
-      if (!tracker.activeWidget) {
+      if (!tracker.currentWidget) {
         return;
       }
-      let widget = tracker.activeWidget.content;
+      let widget = tracker.currentWidget.content;
       let session = widget.session;
       let lang = '';
       if (session.kernel) {