소스 검색

Add open inspector command to JupyterLab UI where possible.

Afshin Darian 6 년 전
부모
커밋
c38b138f33
2개의 변경된 파일35개의 추가작업 그리고 13개의 파일을 삭제
  1. 26 12
      packages/inspector-extension/src/index.ts
  2. 9 1
      packages/mainmenu-extension/src/index.ts

+ 26 - 12
packages/inspector-extension/src/index.ts

@@ -22,6 +22,8 @@ import {
   KernelConnector
 } from '@jupyterlab/inspector';
 
+import { ILauncher } from '@jupyterlab/launcher';
+
 import { INotebookTracker } from '@jupyterlab/notebook';
 
 /**
@@ -36,13 +38,14 @@ namespace CommandIDs {
  */
 const inspector: JupyterLabPlugin<IInspector> = {
   id: '@jupyterlab/inspector-extension:inspector',
-  requires: [ICommandPalette, ILayoutRestorer],
+  optional: [ICommandPalette, ILauncher, ILayoutRestorer],
   provides: IInspector,
   autoStart: true,
   activate: (
     app: JupyterLab,
-    palette: ICommandPalette,
-    restorer: ILayoutRestorer
+    palette: ICommandPalette | null,
+    launcher: ILauncher | null,
+    restorer: ILayoutRestorer | null
   ): IInspector => {
     const { commands, shell } = app;
     const category = 'Inspector';
@@ -55,7 +58,7 @@ const inspector: JupyterLabPlugin<IInspector> = {
 
     let source: IInspector.IInspectable | null = null;
     let inspector: MainAreaWidget<InspectorPanel>;
-    function createInspector(): void {
+    function openInspector(): void {
       if (!inspector || inspector.isDisposed) {
         inspector = new MainAreaWidget({ content: new InspectorPanel() });
         inspector.id = 'jp-inspector';
@@ -70,21 +73,32 @@ const inspector: JupyterLabPlugin<IInspector> = {
       shell.activateById(inspector.id);
     }
 
-    // Add command to registry and palette.
+    // Add command to registry.
     commands.addCommand(command, {
+      isEnabled: () =>
+        !inspector || inspector.isDisposed || !inspector.isAttached,
       label,
       execute: () => {
-        createInspector();
+        openInspector();
       }
     });
-    palette.addItem({ command, category });
+
+    // Add command to UI where possible.
+    if (palette) {
+      palette.addItem({ command, category });
+    }
+    if (launcher) {
+      launcher.add({ command });
+    }
 
     // Handle state restoration.
-    restorer.restore(tracker, {
-      command,
-      args: () => null,
-      name: () => 'inspector'
-    });
+    if (restorer) {
+      restorer.restore(tracker, {
+        command,
+        args: () => null,
+        name: () => 'inspector'
+      });
+    }
 
     // Create a proxy to pass the `source` to the current inspector.
     const proxy: IInspector = Object.defineProperty({}, 'source', {

+ 9 - 1
packages/mainmenu-extension/src/index.ts

@@ -13,6 +13,8 @@ import { ICommandPalette, showDialog, Dialog } from '@jupyterlab/apputils';
 
 import { PageConfig, URLExt } from '@jupyterlab/coreutils';
 
+import { IInspector } from '@jupyterlab/inspector';
+
 import {
   IMainMenu,
   IMenuExtender,
@@ -94,8 +96,13 @@ export namespace CommandIDs {
 const plugin: JupyterLabPlugin<IMainMenu> = {
   id: '@jupyterlab/mainmenu-extension:plugin',
   requires: [ICommandPalette],
+  optional: [IInspector],
   provides: IMainMenu,
-  activate: (app: JupyterLab, palette: ICommandPalette): IMainMenu => {
+  activate: (
+    app: JupyterLab,
+    palette: ICommandPalette,
+    inspector: IInspector | null
+  ): IMainMenu => {
     let menu = new MainMenu(app.commands);
     menu.id = 'jp-MainMenu';
 
@@ -334,6 +341,7 @@ export function createFileMenu(app: JupyterLab, menu: FileMenu): void {
   const newViewGroup = [
     { command: 'docmanager:clone' },
     { command: CommandIDs.createConsole },
+    { command: 'inspector:open' },
     { command: 'docmanager:open-direct' }
   ];