-
-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathcloud-sketchbook-widget.ts
57 lines (49 loc) · 1.78 KB
/
cloud-sketchbook-widget.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
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { CloudSketchbookCompositeWidget } from './cloud-sketchbook-composite-widget';
import { SketchbookWidget } from '../sketchbook/sketchbook-widget';
import { ArduinoPreferences } from '../../arduino-preferences';
@injectable()
export class CloudSketchbookWidget extends SketchbookWidget {
@inject(CloudSketchbookCompositeWidget)
protected readonly widget: CloudSketchbookCompositeWidget;
@inject(ArduinoPreferences)
protected readonly arduinoPreferences: ArduinoPreferences;
@postConstruct()
protected override init(): void {
super.init();
}
override getTreeWidget(): any {
const widget: any = this.sketchbookTreesContainer.selectedWidgets().next();
if (widget && typeof widget.getTreeWidget !== 'undefined') {
return (widget as CloudSketchbookCompositeWidget).getTreeWidget();
}
return widget;
}
checkCloudEnabled() {
if (this.arduinoPreferences['arduino.cloud.enabled']) {
this.sketchbookTreesContainer.activateWidget(this.widget);
} else {
this.sketchbookTreesContainer.activateWidget(
this.localSketchbookTreeWidget
);
}
this.setDocumentMode();
}
setDocumentMode(): void {
if (this.arduinoPreferences['arduino.cloud.enabled']) {
this.sketchbookTreesContainer.mode = 'multiple-document';
} else {
this.sketchbookTreesContainer.mode = 'single-document';
}
}
protected override onAfterAttach(msg: any): void {
this.sketchbookTreesContainer.addWidget(this.widget);
this.setDocumentMode();
this.arduinoPreferences.onPreferenceChanged((event) => {
if (event.preferenceName === 'arduino.cloud.enabled') {
this.checkCloudEnabled();
}
});
super.onAfterAttach(msg);
}
}