Quellcode durchsuchen

Merge pull request #777 from afshin/inspector-focus

Connect console/notebook that has been activated to the inspector.
Steven Silvester vor 8 Jahren
Ursprung
Commit
9e904f69ca
4 geänderte Dateien mit 31 neuen und 19 gelöschten Zeilen
  1. 14 0
      src/console/panel.ts
  2. 6 10
      src/console/plugin.ts
  3. 7 0
      src/notebook/notebook/panel.ts
  4. 4 9
      src/notebook/plugin.ts

+ 14 - 0
src/console/panel.ts

@@ -9,6 +9,10 @@ import {
   Message
 } from 'phosphor/lib/core/messaging';
 
+import {
+  defineSignal, ISignal
+} from 'phosphor/lib/core/signaling';
+
 import {
   Panel
 } from 'phosphor/lib/ui/panel';
@@ -53,6 +57,11 @@ class ConsolePanel extends Panel {
     this.addWidget(this._console);
   }
 
+  /**
+   * A signal emitted when the console panel has been activated.
+   */
+  activated: ISignal<ConsolePanel, void>;
+
   /**
    * The console widget used by the panel.
    *
@@ -83,6 +92,7 @@ class ConsolePanel extends Panel {
    */
   protected onActivateRequest(msg: Message): void {
     this.content.activate();
+    this.activated.emit(void 0);
   }
 
   /**
@@ -113,6 +123,10 @@ class ConsolePanel extends Panel {
 }
 
 
+// Define the signals for the `ConsolePanel` class.
+defineSignal(ConsolePanel.prototype, 'activated');
+
+
 /**
  * A namespace for ConsolePanel statics.
  */

+ 6 - 10
src/console/plugin.ts

@@ -105,15 +105,6 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
   let submenu: Menu = null;
   let command: string;
 
-  // Set the source of the code inspector to the current console.
-  tracker.currentChanged.connect((sender, args) => {
-    if (args.newValue) {
-      inspector.source = args.newValue.content.inspectionHandler;
-    } else {
-      inspector.source = null;
-    }
-  });
-
   // Set the main menu title.
   menu.title.label = 'Console';
 
@@ -162,11 +153,16 @@ 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.add(panel);
+          // Update the caption of the tab with the last execution time.
           panel.content.executed.connect((sender, executed) => {
             captionOptions.executed = executed;
             panel.title.caption = Private.caption(captionOptions);
           });
+          // Set the source of the code inspector to the current console.
+          panel.activated.connect(() => {
+            inspector.source = panel.content.inspectionHandler;
+          });
+          tracker.add(panel);
         });
       }
     });

+ 7 - 0
src/notebook/notebook/panel.ts

@@ -111,6 +111,11 @@ class NotebookPanel extends Widget {
     });
   }
 
+  /**
+   * A signal emitted when the panel has been activated.
+   */
+  activated: ISignal<NotebookPanel, void>;
+
   /**
    * A signal emitted when the panel context changes.
    */
@@ -236,6 +241,7 @@ class NotebookPanel extends Widget {
    */
   protected onActivateRequest(msg: Message): void {
     this.content.activate();
+    this.activated.emit(void 0);
   }
 
   /**
@@ -397,6 +403,7 @@ class NotebookPanel extends Widget {
 
 
 // Define the signals for the `NotebookPanel` class.
+defineSignal(NotebookPanel.prototype, 'activated');
 defineSignal(NotebookPanel.prototype, 'contextChanged');
 defineSignal(NotebookPanel.prototype, 'kernelChanged');
 

+ 4 - 9
src/notebook/plugin.ts

@@ -173,18 +173,13 @@ function activateNotebookHandler(app: JupyterLab, registry: IDocumentRegistry, s
 
   widgetFactory.widgetCreated.connect((sender, widget) => {
     widget.title.icon = `${PORTRAIT_ICON_CLASS} ${NOTEBOOK_ICON_CLASS}`;
+    // Set the source of the code inspector to the current notebook.
+    widget.activated.connect(() => {
+      inspector.source = widget.content.inspectionHandler;
+    });
     tracker.add(widget);
   });
 
-  // Set the source of the code inspector to the current console.
-  tracker.currentChanged.connect((sender, args) => {
-    if (args.newValue) {
-      inspector.source = args.newValue.content.inspectionHandler;
-    } else {
-      inspector.source = null;
-    }
-  });
-
   // Add main menu notebook menu.
   mainMenu.addMenu(createMenu(app), { rank: 20 });