1 |
|
2 |
|
3 | import { Token } from '@lumino/coreutils';
|
4 | import { DisposableDelegate } from '@lumino/disposable';
|
5 | import { Signal } from '@lumino/signaling';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export const ILabStatus = new Token('@jupyterlab/application:ILabStatus');
|
11 |
|
12 |
|
13 |
|
14 | export class LabStatus {
|
15 | |
16 |
|
17 |
|
18 | constructor(app) {
|
19 | this._busyCount = 0;
|
20 | this._dirtyCount = 0;
|
21 | this._busySignal = new Signal(app);
|
22 | this._dirtySignal = new Signal(app);
|
23 | }
|
24 | |
25 |
|
26 |
|
27 | get busySignal() {
|
28 | return this._busySignal;
|
29 | }
|
30 | |
31 |
|
32 |
|
33 | get dirtySignal() {
|
34 | return this._dirtySignal;
|
35 | }
|
36 | |
37 |
|
38 |
|
39 | get isBusy() {
|
40 | return this._busyCount > 0;
|
41 | }
|
42 | |
43 |
|
44 |
|
45 | get isDirty() {
|
46 | return this._dirtyCount > 0;
|
47 | }
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | setDirty() {
|
54 | const oldDirty = this.isDirty;
|
55 | this._dirtyCount++;
|
56 | if (this.isDirty !== oldDirty) {
|
57 | this._dirtySignal.emit(this.isDirty);
|
58 | }
|
59 | return new DisposableDelegate(() => {
|
60 | const oldDirty = this.isDirty;
|
61 | this._dirtyCount = Math.max(0, this._dirtyCount - 1);
|
62 | if (this.isDirty !== oldDirty) {
|
63 | this._dirtySignal.emit(this.isDirty);
|
64 | }
|
65 | });
|
66 | }
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 | setBusy() {
|
73 | const oldBusy = this.isBusy;
|
74 | this._busyCount++;
|
75 | if (this.isBusy !== oldBusy) {
|
76 | this._busySignal.emit(this.isBusy);
|
77 | }
|
78 | return new DisposableDelegate(() => {
|
79 | const oldBusy = this.isBusy;
|
80 | this._busyCount--;
|
81 | if (this.isBusy !== oldBusy) {
|
82 | this._busySignal.emit(this.isBusy);
|
83 | }
|
84 | });
|
85 | }
|
86 | }
|
87 |
|
\ | No newline at end of file |