1
- import { inject , injectable } from '@theia/core/shared/inversify' ;
2
- import { WorkspaceServer } from '@theia/workspace/lib/common/workspace-protocol' ;
1
+ import { NativeImage } from '@theia/core/electron-shared/electron' ;
3
2
import {
4
3
Disposable ,
5
4
DisposableCollection ,
6
5
} from '@theia/core/lib/common/disposable' ;
7
- import {
8
- SketchContribution ,
9
- CommandRegistry ,
10
- MenuModelRegistry ,
11
- Sketch ,
12
- } from './contribution' ;
6
+ import { MenuAction } from '@theia/core/lib/common/menu' ;
7
+ import { nls } from '@theia/core/lib/common/nls' ;
8
+ import { inject , injectable } from '@theia/core/shared/inversify' ;
9
+ import { SketchesError } from '../../common/protocol' ;
10
+ import { ConfigServiceClient } from '../config/config-service-client' ;
13
11
import { ArduinoMenus } from '../menu/arduino-menus' ;
14
- import { MainMenuManager } from '../../common/main-menu-manager' ;
15
- import { OpenSketch } from './open-sketch' ;
12
+ import { NativeImageCache } from '../native-image-cache' ;
16
13
import { NotificationCenter } from '../notification-center' ;
17
- import { nls } from '@theia/core/lib/common' ;
18
- import { SketchesError } from '../../common/protocol' ;
14
+ import { CloudSketchContribution } from './cloud-contribution' ;
15
+ import { CommandRegistry , MenuModelRegistry , Sketch } from './contribution' ;
16
+ import { OpenSketch } from './open-sketch' ;
19
17
20
18
@injectable ( )
21
- export class OpenRecentSketch extends SketchContribution {
19
+ export class OpenRecentSketch extends CloudSketchContribution {
22
20
@inject ( CommandRegistry )
23
- protected readonly commandRegistry : CommandRegistry ;
24
-
21
+ private readonly commandRegistry : CommandRegistry ;
25
22
@inject ( MenuModelRegistry )
26
- protected readonly menuRegistry : MenuModelRegistry ;
27
-
28
- @inject ( MainMenuManager )
29
- protected readonly mainMenuManager : MainMenuManager ;
30
-
31
- @inject ( WorkspaceServer )
32
- protected readonly workspaceServer : WorkspaceServer ;
33
-
23
+ private readonly menuRegistry : MenuModelRegistry ;
34
24
@inject ( NotificationCenter )
35
- protected readonly notificationCenter : NotificationCenter ;
25
+ private readonly notificationCenter : NotificationCenter ;
26
+ @inject ( NativeImageCache )
27
+ private readonly imageCache : NativeImageCache ;
28
+ @inject ( ConfigServiceClient )
29
+ private readonly configServiceClient : ConfigServiceClient ;
36
30
37
- protected toDispose = new DisposableCollection ( ) ;
31
+ private readonly toDispose = new DisposableCollection ( ) ;
32
+ private cloudImage : NativeImage | undefined ;
38
33
39
34
override onStart ( ) : void {
40
35
this . notificationCenter . onRecentSketchesDidChange ( ( { sketches } ) =>
41
36
this . refreshMenu ( sketches )
42
37
) ;
38
+ this . imageCache
39
+ . getImage ( 'cloud' )
40
+ . then ( ( image ) => ( this . cloudImage = image ) ) ;
43
41
}
44
42
45
43
override async onReady ( ) : Promise < void > {
46
44
this . update ( ) ;
47
45
}
48
46
49
- private update ( forceUpdate ?: boolean ) : void {
50
- this . sketchesService
51
- . recentlyOpenedSketches ( forceUpdate )
52
- . then ( ( sketches ) => this . refreshMenu ( sketches ) ) ;
53
- }
54
-
55
47
override registerMenus ( registry : MenuModelRegistry ) : void {
56
48
registry . registerSubmenu (
57
49
ArduinoMenus . FILE__OPEN_RECENT_SUBMENU ,
@@ -60,12 +52,18 @@ export class OpenRecentSketch extends SketchContribution {
60
52
) ;
61
53
}
62
54
55
+ private update ( forceUpdate ?: boolean ) : void {
56
+ this . sketchesService
57
+ . recentlyOpenedSketches ( forceUpdate )
58
+ . then ( ( sketches ) => this . refreshMenu ( sketches ) ) ;
59
+ }
60
+
63
61
private refreshMenu ( sketches : Sketch [ ] ) : void {
64
62
this . register ( sketches ) ;
65
- this . mainMenuManager . update ( ) ;
63
+ this . menuManager . update ( ) ;
66
64
}
67
65
68
- protected register ( sketches : Sketch [ ] ) : void {
66
+ private register ( sketches : Sketch [ ] ) : void {
69
67
const order = 0 ;
70
68
this . toDispose . dispose ( ) ;
71
69
for ( const sketch of sketches ) {
@@ -88,13 +86,14 @@ export class OpenRecentSketch extends SketchContribution {
88
86
} ,
89
87
} ;
90
88
this . commandRegistry . registerCommand ( command , handler ) ;
89
+ const menuAction = this . assignImage ( sketch , {
90
+ commandId : command . id ,
91
+ label : sketch . name ,
92
+ order : String ( order ) ,
93
+ } ) ;
91
94
this . menuRegistry . registerMenuAction (
92
95
ArduinoMenus . FILE__OPEN_RECENT_SUBMENU ,
93
- {
94
- commandId : command . id ,
95
- label : sketch . name ,
96
- order : String ( order ) ,
97
- }
96
+ menuAction
98
97
) ;
99
98
this . toDispose . pushAll ( [
100
99
new DisposableCollection (
@@ -108,4 +107,15 @@ export class OpenRecentSketch extends SketchContribution {
108
107
] ) ;
109
108
}
110
109
}
110
+
111
+ private assignImage ( sketch : Sketch , menuAction : MenuAction ) : MenuAction {
112
+ if ( this . cloudImage ) {
113
+ const dataDirUri = this . configServiceClient . tryGetDataDirUri ( ) ;
114
+ const isCloud = this . createFeatures . isCloud ( sketch , dataDirUri ) ;
115
+ if ( isCloud ) {
116
+ Object . assign ( menuAction , { nativeImage : this . cloudImage } ) ;
117
+ }
118
+ }
119
+ return menuAction ;
120
+ }
111
121
}
0 commit comments