@@ -66,9 +66,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
66
66
@inject ( BoardsNotificationService )
67
67
protected readonly boardsNotificationService : BoardsNotificationService ;
68
68
69
- @inject ( WorkspaceService )
70
- protected readonly workspaceService : WorkspaceService ;
71
-
72
69
@inject ( SelectionService )
73
70
protected readonly selectionService : SelectionService ;
74
71
@@ -108,6 +105,15 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
108
105
protected boardsToolbarItem : BoardsToolBarItem | null ;
109
106
protected attachedBoards : Board [ ] ;
110
107
protected selectedBoard : Board ;
108
+ protected wsSketchCount : number = 0 ;
109
+
110
+ constructor ( @inject ( WorkspaceService ) protected readonly workspaceService : WorkspaceService ) {
111
+ this . workspaceService . onWorkspaceChanged ( ( ) => {
112
+ if ( this . workspaceService . workspace ) {
113
+ this . registerSketchesInMenu ( this . menuRegistry ) ;
114
+ }
115
+ } )
116
+ }
111
117
112
118
@postConstruct ( )
113
119
protected async init ( ) : Promise < void > {
@@ -233,12 +239,16 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
233
239
isVisible : widget => this . isArduinoToolbar ( widget ) ,
234
240
isEnabled : widget => this . isArduinoToolbar ( widget ) ,
235
241
execute : async ( widget : Widget , target : EventTarget ) => {
236
- const el = ( target as HTMLElement ) . parentElement ;
237
- if ( el ) {
238
- this . contextMenuRenderer . render ( ArduinoToolbarContextMenu . OPEN_SKETCH_PATH , {
239
- x : el . getBoundingClientRect ( ) . left ,
240
- y : el . getBoundingClientRect ( ) . top + el . offsetHeight
241
- } ) ;
242
+ if ( this . wsSketchCount ) {
243
+ const el = ( target as HTMLElement ) . parentElement ;
244
+ if ( el ) {
245
+ this . contextMenuRenderer . render ( ArduinoToolbarContextMenu . OPEN_SKETCH_PATH , {
246
+ x : el . getBoundingClientRect ( ) . left ,
247
+ y : el . getBoundingClientRect ( ) . top + el . offsetHeight
248
+ } ) ;
249
+ }
250
+ } else {
251
+ this . commands . executeCommand ( ArduinoCommands . OPEN_FILE_NAVIGATOR . id ) ;
242
252
}
243
253
}
244
254
} ) ;
@@ -332,6 +342,10 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
332
342
label : 'Upload' ,
333
343
order : '2'
334
344
} ) ;
345
+ registry . registerMenuAction ( ArduinoToolbarContextMenu . OPEN_GROUP , {
346
+ commandId : ArduinoCommands . OPEN_FILE_NAVIGATOR . id ,
347
+ label : 'Open...'
348
+ } ) ;
335
349
336
350
registry . registerSubmenu ( ArduinoMenus . TOOLS , 'Tools' ) ;
337
351
}
@@ -342,6 +356,30 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
342
356
return menuId ;
343
357
}
344
358
359
+ protected registerSketchesInMenu ( registry : MenuModelRegistry ) {
360
+ this . getWorkspaceSketches ( ) . then ( sketches => {
361
+ this . wsSketchCount = sketches . length ;
362
+ sketches . forEach ( sketch => {
363
+ const command : Command = {
364
+ id : 'openSketch' + sketch . name
365
+ }
366
+ this . commands . registerCommand ( command , {
367
+ execute : ( ) => this . commands . executeCommand ( ArduinoCommands . OPEN_SKETCH . id , sketch )
368
+ } ) ;
369
+
370
+ registry . registerMenuAction ( ArduinoToolbarContextMenu . WS_SKETCHES_GROUP , {
371
+ commandId : command . id ,
372
+ label : sketch . name
373
+ } ) ;
374
+ } )
375
+ } )
376
+ }
377
+
378
+ protected async getWorkspaceSketches ( ) : Promise < Sketch [ ] > {
379
+ const sketches = this . sketches . getSketches ( this . workspaceService . workspace ) ;
380
+ return sketches ;
381
+ }
382
+
345
383
protected async openSketchFilesInNewWindow ( uri : string ) {
346
384
const location = new URL ( window . location . href ) ;
347
385
location . searchParams . set ( 'sketch' , uri ) ;
0 commit comments