forked from jupyterlab/jupyterlab
/
manager.ts
85 lines (73 loc) · 2.04 KB
/
manager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
IInspector, InspectorPanel
} from '@jupyterlab/inspector';
import {
IDisposable
} from '@phosphor/disposable';
/**
* 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);
}
}
/**
* Create an inspector child item and return a disposable to remove it.
*
* @param item - The inspector child item being added to the inspector.
*
* @returns A disposable that removes the child item from the inspector.
*/
add(item: IInspector.IInspectorItem): IDisposable {
if (!this._inspector) {
throw new Error('Cannot add child item before creating an inspector.');
}
return this._inspector.add(item);
}
/**
* Handle the source disposed signal.
*/
private _onSourceDisposed() {
this._source = null;
}
private _inspector: InspectorPanel = null;
private _source: IInspector.IInspectable = null;
}