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' ;
32import {
43 Disposable ,
54 DisposableCollection ,
65} 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' ;
1311import { 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' ;
1613import { 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' ;
1917
2018@injectable ( )
21- export class OpenRecentSketch extends SketchContribution {
19+ export class OpenRecentSketch extends CloudSketchContribution {
2220 @inject ( CommandRegistry )
23- protected readonly commandRegistry : CommandRegistry ;
24-
21+ private readonly commandRegistry : CommandRegistry ;
2522 @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 ;
3424 @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 ;
3630
37- protected toDispose = new DisposableCollection ( ) ;
31+ private readonly toDispose = new DisposableCollection ( ) ;
32+ private cloudImage : NativeImage | undefined ;
3833
3934 override onStart ( ) : void {
4035 this . notificationCenter . onRecentSketchesDidChange ( ( { sketches } ) =>
4136 this . refreshMenu ( sketches )
4237 ) ;
38+ this . imageCache
39+ . getImage ( 'cloud' )
40+ . then ( ( image ) => ( this . cloudImage = image ) ) ;
4341 }
4442
4543 override async onReady ( ) : Promise < void > {
4644 this . update ( ) ;
4745 }
4846
49- private update ( forceUpdate ?: boolean ) : void {
50- this . sketchesService
51- . recentlyOpenedSketches ( forceUpdate )
52- . then ( ( sketches ) => this . refreshMenu ( sketches ) ) ;
53- }
54-
5547 override registerMenus ( registry : MenuModelRegistry ) : void {
5648 registry . registerSubmenu (
5749 ArduinoMenus . FILE__OPEN_RECENT_SUBMENU ,
@@ -60,12 +52,18 @@ export class OpenRecentSketch extends SketchContribution {
6052 ) ;
6153 }
6254
55+ private update ( forceUpdate ?: boolean ) : void {
56+ this . sketchesService
57+ . recentlyOpenedSketches ( forceUpdate )
58+ . then ( ( sketches ) => this . refreshMenu ( sketches ) ) ;
59+ }
60+
6361 private refreshMenu ( sketches : Sketch [ ] ) : void {
6462 this . register ( sketches ) ;
65- this . mainMenuManager . update ( ) ;
63+ this . menuManager . update ( ) ;
6664 }
6765
68- protected register ( sketches : Sketch [ ] ) : void {
66+ private register ( sketches : Sketch [ ] ) : void {
6967 const order = 0 ;
7068 this . toDispose . dispose ( ) ;
7169 for ( const sketch of sketches ) {
@@ -88,13 +86,14 @@ export class OpenRecentSketch extends SketchContribution {
8886 } ,
8987 } ;
9088 this . commandRegistry . registerCommand ( command , handler ) ;
89+ const menuAction = this . assignImage ( sketch , {
90+ commandId : command . id ,
91+ label : sketch . name ,
92+ order : String ( order ) ,
93+ } ) ;
9194 this . menuRegistry . registerMenuAction (
9295 ArduinoMenus . FILE__OPEN_RECENT_SUBMENU ,
93- {
94- commandId : command . id ,
95- label : sketch . name ,
96- order : String ( order ) ,
97- }
96+ menuAction
9897 ) ;
9998 this . toDispose . pushAll ( [
10099 new DisposableCollection (
@@ -108,4 +107,15 @@ export class OpenRecentSketch extends SketchContribution {
108107 ] ) ;
109108 }
110109 }
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+ }
111121}
0 commit comments