|
@@ -22,30 +22,78 @@ import {
|
|
export
|
|
export
|
|
const inspectorProvider: JupyterLabPlugin<IInspector> = {
|
|
const inspectorProvider: JupyterLabPlugin<IInspector> = {
|
|
id: 'jupyter.services.inspector',
|
|
id: 'jupyter.services.inspector',
|
|
- provides: IInspector,
|
|
|
|
requires: [ICommandPalette],
|
|
requires: [ICommandPalette],
|
|
|
|
+ provides: IInspector,
|
|
activate: activateInspector
|
|
activate: activateInspector
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * A class that manages inspector widget instances and offers persistent
|
|
|
|
+ * `IInspector` instance that other plugins can communicate with.
|
|
|
|
+ */
|
|
|
|
+class InspectorManager implements IInspector {
|
|
|
|
+ /**
|
|
|
|
+ * The current inspector widget.
|
|
|
|
+ */
|
|
|
|
+ get inspector(): Inspector {
|
|
|
|
+ return this._inspector;
|
|
|
|
+ }
|
|
|
|
+ set inspector(inspector: Inspector) {
|
|
|
|
+ if (this._inspector === inspector) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this._inspector = inspector;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * The source of events the inspector panel listens for.
|
|
|
|
+ */
|
|
|
|
+ get source(): Inspector.IInspectable {
|
|
|
|
+ if (this._inspector && !this._inspector.isDisposed) {
|
|
|
|
+ return this._inspector.source;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ set source(source: Inspector.IInspectable) {
|
|
|
|
+ if (this._inspector && !this._inspector.isDisposed) {
|
|
|
|
+ this._inspector.source = source;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private _inspector: Inspector = null;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Activate the console extension.
|
|
* Activate the console extension.
|
|
*/
|
|
*/
|
|
function activateInspector(app: JupyterLab, palette: ICommandPalette): IInspector {
|
|
function activateInspector(app: JupyterLab, palette: ICommandPalette): IInspector {
|
|
- let inspector = new Inspector({ items: Private.defaultInspectorItems });
|
|
|
|
|
|
+ let manager = new InspectorManager();
|
|
let openInspectorCommand = 'inspector:open';
|
|
let openInspectorCommand = 'inspector:open';
|
|
- let opened = false;
|
|
|
|
|
|
|
|
- inspector.id = 'jp-inspector';
|
|
|
|
- inspector.title.label = 'Inspector';
|
|
|
|
- inspector.title.closable = true;
|
|
|
|
|
|
+ function newInspector(): Inspector {
|
|
|
|
+ let inspector = new Inspector({ items: Private.defaultInspectorItems });
|
|
|
|
+ inspector.id = 'jp-inspector';
|
|
|
|
+ inspector.title.label = 'Inspector';
|
|
|
|
+ inspector.title.closable = true;
|
|
|
|
+ inspector.disposed.connect(() => {
|
|
|
|
+ if (manager.inspector === inspector) {
|
|
|
|
+ manager.inspector = null;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return inspector;
|
|
|
|
+ }
|
|
|
|
|
|
function openInspector(): void {
|
|
function openInspector(): void {
|
|
- if (!opened) {
|
|
|
|
- app.shell.addToMainArea(inspector);
|
|
|
|
- opened = true;
|
|
|
|
- } else {
|
|
|
|
- app.shell.activateMain(inspector.id);
|
|
|
|
|
|
+ if (!manager.inspector || manager.inspector.isDisposed) {
|
|
|
|
+ manager.inspector = newInspector();
|
|
|
|
+ app.shell.addToMainArea(manager.inspector);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (manager.inspector.isAttached) {
|
|
|
|
+ app.shell.activateMain(manager.inspector.id);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -59,7 +107,7 @@ function activateInspector(app: JupyterLab, palette: ICommandPalette): IInspecto
|
|
category: 'Inspector'
|
|
category: 'Inspector'
|
|
});
|
|
});
|
|
|
|
|
|
- return inspector;
|
|
|
|
|
|
+ return manager;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|