1 |
|
2 |
|
3 | import { WidgetTracker } from '@jupyterlab/apputils';
|
4 | import { Signal } from '@lumino/signaling';
|
5 | export class NotebookTracker extends WidgetTracker {
|
6 | constructor() {
|
7 | super(...arguments);
|
8 | this._activeCell = null;
|
9 | this._activeCellChanged = new Signal(this);
|
10 | this._selectionChanged = new Signal(this);
|
11 | }
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | get activeCell() {
|
20 | const widget = this.currentWidget;
|
21 | if (!widget) {
|
22 | return null;
|
23 | }
|
24 | return widget.content.activeCell || null;
|
25 | }
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | get activeCellChanged() {
|
33 | return this._activeCellChanged;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 | get selectionChanged() {
|
39 | return this._selectionChanged;
|
40 | }
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 | add(panel) {
|
47 | const promise = super.add(panel);
|
48 | panel.content.activeCellChanged.connect(this._onActiveCellChanged, this);
|
49 | panel.content.selectionChanged.connect(this._onSelectionChanged, this);
|
50 | return promise;
|
51 | }
|
52 | |
53 |
|
54 |
|
55 | dispose() {
|
56 | this._activeCell = null;
|
57 | super.dispose();
|
58 | }
|
59 | |
60 |
|
61 |
|
62 | onCurrentChanged(widget) {
|
63 |
|
64 | const activeCell = this.activeCell;
|
65 | if (activeCell && activeCell === this._activeCell) {
|
66 | return;
|
67 | }
|
68 | this._activeCell = activeCell;
|
69 | if (!widget) {
|
70 | return;
|
71 | }
|
72 |
|
73 | this._activeCellChanged.emit(widget.content.activeCell || null);
|
74 | }
|
75 | _onActiveCellChanged(sender, cell) {
|
76 |
|
77 | if (this.currentWidget && this.currentWidget.content === sender) {
|
78 | this._activeCell = cell || null;
|
79 | this._activeCellChanged.emit(this._activeCell);
|
80 | }
|
81 | }
|
82 | _onSelectionChanged(sender) {
|
83 |
|
84 | if (this.currentWidget && this.currentWidget.content === sender) {
|
85 | this._selectionChanged.emit(void 0);
|
86 | }
|
87 | }
|
88 | }
|
89 |
|
\ | No newline at end of file |