@@ -2,6 +2,11 @@ import { inject, injectable, postConstruct } from 'inversify';
2
2
import { CloudSketchbookCompositeWidget } from './cloud-sketchbook-composite-widget' ;
3
3
import { SketchbookWidget } from '../sketchbook/sketchbook-widget' ;
4
4
import { ArduinoPreferences } from '../../arduino-preferences' ;
5
+ import { Message } from '@theia/core/shared/@phosphor/messaging' ;
6
+ import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl' ;
7
+ import { SketchControl } from '../../contributions/sketch-control' ;
8
+ import { LocalCacheFsProvider } from '../../local-cache/local-cache-fs-provider' ;
9
+ import { REMOTE_SKETCHBOOK_FOLDER } from '../../utils/constants' ;
5
10
6
11
@injectable ( )
7
12
export class CloudSketchbookWidget extends SketchbookWidget {
@@ -11,6 +16,15 @@ export class CloudSketchbookWidget extends SketchbookWidget {
11
16
@inject ( ArduinoPreferences )
12
17
protected readonly arduinoPreferences : ArduinoPreferences ;
13
18
19
+ @inject ( SketchControl )
20
+ protected readonly sketchControl : SketchControl ;
21
+
22
+ @inject ( SketchesServiceClientImpl )
23
+ protected readonly sketchesServiceClient : SketchesServiceClientImpl ;
24
+
25
+ @inject ( LocalCacheFsProvider )
26
+ protected readonly localCacheFsProvider : LocalCacheFsProvider ;
27
+
14
28
@postConstruct ( )
15
29
protected init ( ) : void {
16
30
super . init ( ) ;
@@ -25,33 +39,41 @@ export class CloudSketchbookWidget extends SketchbookWidget {
25
39
return widget ;
26
40
}
27
41
28
- checkCloudEnabled ( ) {
29
- if ( this . arduinoPreferences [ 'arduino.cloud.enabled' ] ) {
30
- this . sketchbookTreesContainer . activateWidget ( this . widget ) ;
31
- } else {
32
- this . sketchbookTreesContainer . activateWidget (
33
- this . localSketchbookTreeWidget
34
- ) ;
35
- }
36
- this . setDocumentMode ( ) ;
42
+ protected onAfterShow ( msg : Message ) : void {
43
+ this . checkCloudEnabled ( ) ;
44
+ super . onAfterShow ( msg ) ;
37
45
}
38
46
39
- setDocumentMode ( ) {
47
+ async checkCloudEnabled ( ) : Promise < void > {
48
+ const currentSketch = await this . sketchesServiceClient . currentSketch ( ) ;
49
+ const isCloudSketch =
50
+ currentSketch && currentSketch . uri . includes ( REMOTE_SKETCHBOOK_FOLDER ) ;
51
+
40
52
if ( this . arduinoPreferences [ 'arduino.cloud.enabled' ] ) {
41
53
this . sketchbookTreesContainer . mode = 'multiple-document' ;
54
+ if ( isCloudSketch ) {
55
+ this . sketchbookTreesContainer . activateWidget ( this . widget ) ;
56
+ }
42
57
} else {
43
58
this . sketchbookTreesContainer . mode = 'single-document' ;
44
59
}
60
+
61
+ if ( ! isCloudSketch || ! this . arduinoPreferences [ 'arduino.cloud.enabled' ] ) {
62
+ this . sketchbookTreesContainer . activateWidget (
63
+ this . localSketchbookTreeWidget
64
+ ) ;
65
+ }
45
66
}
46
67
47
68
protected onAfterAttach ( msg : any ) {
48
69
this . sketchbookTreesContainer . addWidget ( this . widget ) ;
49
- this . setDocumentMode ( ) ;
70
+ this . sketchbookTreesContainer . mode = 'single-document' ;
50
71
this . arduinoPreferences . onPreferenceChanged ( ( event ) => {
51
72
if ( event . preferenceName === 'arduino.cloud.enabled' ) {
52
73
this . checkCloudEnabled ( ) ;
53
74
}
54
75
} ) ;
76
+ this . checkCloudEnabled ( ) ;
55
77
super . onAfterAttach ( msg ) ;
56
78
}
57
79
}
0 commit comments