-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathcloud-sketchbook-widget.ts
79 lines (66 loc) · 2.72 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { inject, injectable, postConstruct } from 'inversify';
import { CloudSketchbookCompositeWidget } from './cloud-sketchbook-composite-widget';
import { SketchbookWidget } from '../sketchbook/sketchbook-widget';
import { ArduinoPreferences } from '../../arduino-preferences';
import { Message } from '@theia/core/shared/@phosphor/messaging';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
import { SketchControl } from '../../contributions/sketch-control';
import { LocalCacheFsProvider } from '../../local-cache/local-cache-fs-provider';
import { REMOTE_SKETCHBOOK_FOLDER } from '../../utils/constants';
@injectable()
export class CloudSketchbookWidget extends SketchbookWidget {
@inject(CloudSketchbookCompositeWidget)
protected readonly widget: CloudSketchbookCompositeWidget;
@inject(ArduinoPreferences)
protected readonly arduinoPreferences: ArduinoPreferences;
@inject(SketchControl)
protected readonly sketchControl: SketchControl;
@inject(SketchesServiceClientImpl)
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
@inject(LocalCacheFsProvider)
protected readonly localCacheFsProvider: LocalCacheFsProvider;
@postConstruct()
protected init(): void {
super.init();
}
getTreeWidget(): any {
const widget: any = this.sketchbookTreesContainer.selectedWidgets().next();
if (widget && typeof widget.getTreeWidget !== 'undefined') {
return (widget as CloudSketchbookCompositeWidget).getTreeWidget();
}
return widget;
}
protected onAfterShow(msg: Message): void {
this.checkCloudEnabled();
super.onAfterShow(msg);
}
async checkCloudEnabled(): Promise<void> {
const currentSketch = await this.sketchesServiceClient.currentSketch();
const isCloudSketch =
currentSketch && currentSketch.uri.includes(REMOTE_SKETCHBOOK_FOLDER);
if (this.arduinoPreferences['arduino.cloud.enabled']) {
this.sketchbookTreesContainer.mode = 'multiple-document';
if (isCloudSketch) {
this.sketchbookTreesContainer.activateWidget(this.widget);
}
} else {
this.sketchbookTreesContainer.mode = 'single-document';
}
if (!isCloudSketch || !this.arduinoPreferences['arduino.cloud.enabled']) {
this.sketchbookTreesContainer.activateWidget(
this.localSketchbookTreeWidget
);
}
}
protected onAfterAttach(msg: any) {
this.sketchbookTreesContainer.addWidget(this.widget);
this.sketchbookTreesContainer.mode = 'single-document';
this.arduinoPreferences.onPreferenceChanged((event) => {
if (event.preferenceName === 'arduino.cloud.enabled') {
this.checkCloudEnabled();
}
});
this.checkCloudEnabled();
super.onAfterAttach(msg);
}
}