Переглянути джерело

Remove inspector manager class; it is superfluous.

Afshin Darian 6 роки тому
батько
коміт
a059b272c2

+ 8 - 30
packages/inspector-extension/src/index.ts

@@ -24,8 +24,6 @@ import {
 
 import { INotebookTracker } from '@jupyterlab/notebook';
 
-import { InspectorManager } from './manager';
-
 /**
  * The command IDs used by the inspector plugin.
  */
@@ -47,7 +45,6 @@ const inspector: JupyterLabPlugin<IInspector> = {
     restorer: ILayoutRestorer
   ): IInspector => {
     const { commands, shell } = app;
-    const manager = new InspectorManager();
     const category = 'Inspector';
     const command = CommandIDs.open;
     const label = 'Open Inspector';
@@ -55,27 +52,11 @@ const inspector: JupyterLabPlugin<IInspector> = {
     const tracker = new InstanceTracker<MainAreaWidget<InspectorPanel>>({
       namespace
     });
+    const widget = new MainAreaWidget({ content: new InspectorPanel() });
 
-    /**
-     * Create and track a new inspector.
-     */
-    function newInspectorPanel(): InspectorPanel {
-      const inspector = new InspectorPanel();
-
-      inspector.id = 'jp-inspector';
-      inspector.title.label = 'Inspector';
-      inspector.disposed.connect(() => {
-        if (manager.inspector === inspector) {
-          manager.inspector = null;
-        }
-      });
-
-      // Track the inspector.
-      let widget = new MainAreaWidget({ content: inspector });
-      tracker.add(widget);
-
-      return inspector;
-    }
+    widget.id = 'jp-inspector';
+    widget.title.label = 'Inspector';
+    tracker.add(widget);
 
     // Handle state restoration.
     restorer.restore(tracker, {
@@ -88,18 +69,15 @@ const inspector: JupyterLabPlugin<IInspector> = {
     commands.addCommand(command, {
       label,
       execute: () => {
-        if (!manager.inspector || manager.inspector.isDisposed) {
-          manager.inspector = newInspectorPanel();
-        }
-        if (!manager.inspector.isAttached) {
-          shell.addToMainArea(manager.inspector.parent, { activate: false });
+        if (!widget.isAttached) {
+          shell.addToMainArea(widget, { activate: false });
         }
-        shell.activateById(manager.inspector.parent.id);
+        shell.activateById(widget.id);
       }
     });
     palette.addItem({ command, category });
 
-    return manager;
+    return widget.content;
   }
 };
 

+ 0 - 66
packages/inspector-extension/src/manager.ts

@@ -1,66 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-import { IInspector, InspectorPanel } from '@jupyterlab/inspector';
-
-/**
- * A class that manages inspector widget instances and offers persistent
- * `IInspector` instance that other plugins can communicate with.
- */
-export class InspectorManager implements IInspector {
-  /**
-   * The current inspector widget.
-   */
-  get inspector(): InspectorPanel {
-    return this._inspector;
-  }
-  set inspector(inspector: InspectorPanel) {
-    if (this._inspector === inspector) {
-      return;
-    }
-    this._inspector = inspector;
-    // If an inspector was added and it has no source
-    if (inspector && !inspector.source) {
-      inspector.source = this._source;
-    }
-  }
-
-  /**
-   * The source of events the inspector panel listens for.
-   */
-  get source(): IInspector.IInspectable {
-    return this._source;
-  }
-  set source(source: IInspector.IInspectable) {
-    if (this._source === source) {
-      return;
-    }
-
-    if (this._source) {
-      this._source.disposed.disconnect(this._onSourceDisposed, this);
-    }
-
-    this._source = source;
-
-    if (this._inspector && !this._inspector.isDisposed) {
-      this._inspector.source = this._source;
-    }
-
-    if (this._source) {
-      this._source.disposed.connect(
-        this._onSourceDisposed,
-        this
-      );
-    }
-  }
-
-  /**
-   * Handle the source disposed signal.
-   */
-  private _onSourceDisposed() {
-    this._source = null;
-  }
-
-  private _inspector: InspectorPanel = null;
-  private _source: IInspector.IInspectable = null;
-}