Przeglądaj źródła

More LabShell refactoring, making more plugins options [WIP]

Afshin Darian 6 lat temu
rodzic
commit
0505fdeac9

+ 8 - 8
packages/application-extension/src/index.tsx

@@ -187,8 +187,8 @@ const main: JupyterLabPlugin<void> = {
  */
 const layout: JupyterLabPlugin<ILayoutRestorer> = {
   id: '@jupyterlab/application-extension:layout',
-  requires: [ILabShell, IStateDB],
-  activate: (app: JupyterClient, shell: ILabShell, state: IStateDB) => {
+  requires: [IStateDB, ILabShell],
+  activate: (app: JupyterClient, state: IStateDB, shell: ILabShell) => {
     const first = app.started;
     const registry = app.commands;
     const restorer = new LayoutRestorer({ first, registry, state });
@@ -546,10 +546,10 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void {
 const shell: JupyterLabPlugin<ILabShell> = {
   id: '@jupyterlab/application-extension:shell',
   activate: (app: JupyterClient) => {
-    if (app.shell instanceof LabShell) {
-      return app.shell;
+    if (!(app.shell instanceof LabShell)) {
+      throw new Error(`${shell.id} did not find an LabShell instance.`);
     }
-    throw new Error(`${shell.id} did not find an LabShell instance.`);
+    return app.shell;
   },
   autoStart: true,
   provides: ILabShell
@@ -561,10 +561,10 @@ const shell: JupyterLabPlugin<ILabShell> = {
 const status: JupyterLabPlugin<ILabStatus> = {
   id: '@jupyterlab/application-extension:status',
   activate: (app: JupyterClient) => {
-    if (app instanceof JupyterLab) {
-      return app;
+    if (!(app instanceof JupyterLab)) {
+      throw new Error(`${status.id} must be activated in JupyterLab.`);
     }
-    throw new Error(`${status.id} must be activated in JupyterLab.`);
+    return app;
   },
   autoStart: true,
   provides: ILabStatus

+ 4 - 11
packages/apputils-extension/src/palette.ts

@@ -10,11 +10,7 @@ import { DisposableDelegate, IDisposable } from '@phosphor/disposable';
 
 import { CommandPalette } from '@phosphor/widgets';
 
-import {
-  ILabShell,
-  ILayoutRestorer,
-  JupyterClient
-} from '@jupyterlab/application';
+import { ILayoutRestorer, JupyterClient } from '@jupyterlab/application';
 
 import { ICommandPalette, IPaletteItem } from '@jupyterlab/apputils';
 
@@ -77,11 +73,8 @@ class Palette implements ICommandPalette {
 /**
  * Activate the command palette.
  */
-export function activatePalette(
-  app: JupyterClient,
-  shell: ILabShell
-): ICommandPalette {
-  const { commands } = app;
+export function activatePalette(app: JupyterClient): ICommandPalette {
+  const { commands, shell } = app;
   const palette = Private.createPalette(app);
 
   // Show the current palette shortcut in its title.
@@ -111,7 +104,7 @@ export function activatePalette(
 
   palette.inputNode.placeholder = 'SEARCH';
 
-  shell.addToLeftArea(palette, { rank: 300 });
+  shell.add(palette, 'left', { rank: 300 });
 
   return new Palette(palette);
 }

+ 12 - 13
packages/console-extension/src/foreign.ts

@@ -1,11 +1,7 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import {
-  ILabShell,
-  JupyterClient,
-  JupyterLabPlugin
-} from '@jupyterlab/application';
+import { JupyterClient, JupyterLabPlugin } from '@jupyterlab/application';
 
 import { ICommandPalette } from '@jupyterlab/apputils';
 
@@ -25,7 +21,8 @@ import { ReadonlyJSONObject } from '@phosphor/coreutils';
  */
 export const foreign: JupyterLabPlugin<void> = {
   id: '@jupyterlab/console-extension:foreign',
-  requires: [IConsoleTracker, ICommandPalette, ILabShell],
+  requires: [IConsoleTracker],
+  optional: [ICommandPalette],
   activate: activateForeign,
   autoStart: true
 };
@@ -35,9 +32,9 @@ export default foreign;
 function activateForeign(
   app: JupyterClient,
   tracker: IConsoleTracker,
-  palette: ICommandPalette,
-  shell: ILabShell
+  palette: ICommandPalette | null
 ) {
+  const { shell } = app;
   tracker.widgetAdded.connect((sender, panel) => {
     const console = panel.console;
 
@@ -83,11 +80,13 @@ function activateForeign(
       tracker.currentWidget === shell.currentWidget
   });
 
-  palette.addItem({
-    command: toggleShowAllActivity,
-    category,
-    args: { isPalette: true }
-  });
+  if (palette) {
+    palette.addItem({
+      command: toggleShowAllActivity,
+      category,
+      args: { isPalette: true }
+    });
+  }
 
   app.contextMenu.addItem({
     command: toggleShowAllActivity,

+ 21 - 10
packages/tabmanager-extension/src/index.ts

@@ -22,10 +22,12 @@ const plugin: JupyterLabPlugin<void> = {
   activate: (
     app: JupyterClient,
     restorer: ILayoutRestorer,
-    shell: ILabShell
+    labShell: ILabShell | null
   ): void => {
+    const { shell } = app;
     const tabs = new TabBar<Widget>({ orientation: 'vertical' });
     const header = document.createElement('header');
+    let debouncer: number;
 
     restorer.add(tabs, 'tab-manager');
     tabs.id = 'tab-manager';
@@ -33,33 +35,42 @@ const plugin: JupyterLabPlugin<void> = {
     tabs.title.caption = 'Open Tabs';
     header.textContent = 'Open Tabs';
     tabs.node.insertBefore(header, tabs.contentNode);
-    shell.addToLeftArea(tabs, { rank: 600 });
+    shell.add(tabs, 'left', { rank: 600 });
 
     app.restored.then(() => {
       const populate = () => {
-        tabs.clearTabs();
-        each(shell.widgets('main'), widget => {
-          tabs.addTab(widget.title);
-        });
+        window.clearTimeout(debouncer);
+        debouncer = window.setTimeout(() => {
+          tabs.clearTabs();
+          each(shell.widgets('main'), widget => {
+            tabs.addTab(widget.title);
+          });
+        }, 0);
       };
 
       // Connect signal handlers.
-      shell.layoutModified.connect(() => {
-        populate();
-      });
       tabs.tabActivateRequested.connect((sender, tab) => {
         shell.activateById(tab.title.owner.id);
       });
       tabs.tabCloseRequested.connect((sender, tab) => {
         tab.title.owner.close();
+        populate();
       });
 
+      // If available, connect to the shell's layout modified signal.
+      if (labShell) {
+        labShell.layoutModified.connect(() => {
+          populate();
+        });
+      }
+
       // Populate the tab manager.
       populate();
     });
   },
   autoStart: true,
-  requires: [ILayoutRestorer, ILabShell]
+  requires: [ILayoutRestorer],
+  optional: [ILabShell]
 };
 
 /**