@@ -311,14 +311,14 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
311
311
312
312
registry . registerCommand ( ArduinoCommands . OPEN_SKETCH , {
313
313
isEnabled : ( ) => true ,
314
- execute : async ( sketch : Sketch ) => {
314
+ execute : ( sketch : Sketch ) => {
315
315
this . workspaceService . open ( new URI ( sketch . uri ) ) ;
316
316
}
317
317
} ) ;
318
318
319
319
registry . registerCommand ( ArduinoCommands . SAVE_SKETCH , {
320
320
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
321
- execute : async ( sketch : Sketch ) => {
321
+ execute : ( sketch : Sketch ) => {
322
322
registry . executeCommand ( CommonCommands . SAVE_ALL . id ) ;
323
323
}
324
324
} ) ;
@@ -515,22 +515,21 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
515
515
}
516
516
517
517
protected async registerSketchesInMenu ( registry : MenuModelRegistry ) : Promise < void > {
518
- this . sketchService . getSketches ( ) . then ( sketches => {
519
- this . wsSketchCount = sketches . length ;
520
- sketches . forEach ( sketch => {
521
- const command : Command = {
522
- id : 'openSketch' + sketch . name
523
- }
524
- this . commandRegistry . registerCommand ( command , {
525
- execute : ( ) => this . commandRegistry . executeCommand ( ArduinoCommands . OPEN_SKETCH . id , sketch )
526
- } ) ;
527
-
528
- registry . registerMenuAction ( ArduinoToolbarContextMenu . WS_SKETCHES_GROUP , {
529
- commandId : command . id ,
530
- label : sketch . name
531
- } ) ;
532
- } )
533
- } )
518
+ const sketches = await this . sketchService . getSketches ( ) ;
519
+ this . wsSketchCount = sketches . length ;
520
+ sketches . forEach ( sketch => {
521
+ const command : Command = {
522
+ id : 'openSketch' + sketch . name
523
+ }
524
+ this . commandRegistry . registerCommand ( command , {
525
+ execute : ( ) => this . commandRegistry . executeCommand ( ArduinoCommands . OPEN_SKETCH . id , sketch )
526
+ } ) ;
527
+
528
+ registry . registerMenuAction ( ArduinoToolbarContextMenu . WS_SKETCHES_GROUP , {
529
+ commandId : command . id ,
530
+ label : sketch . name
531
+ } ) ;
532
+ } ) ;
534
533
}
535
534
536
535
async openSketchFiles ( uri : string ) : Promise < void > {
@@ -541,34 +540,39 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
541
540
}
542
541
543
542
/**
544
- * Opens a file after prompting the `Open File` dialog. Resolves to `undefined`, if
545
- * - the workspace root is not set ,
546
- * - the file to open does not exist , or
547
- * - it was not a file, but a directory .
543
+ * Opens a file after prompting the `Open File` dialog. Shows a warning message if
544
+ * - the file to open does not exist ,
545
+ * - it was not a file, but a directory , or
546
+ * - the file does not pass validation .
548
547
*
549
548
* Otherwise, resolves to the URI of the file.
550
549
*/
551
- protected async doOpenFile ( ) : Promise < URI | undefined > {
550
+ protected async doOpenFile ( ) : Promise < void > {
552
551
const props : OpenFileDialogProps = {
553
552
title : WorkspaceCommands . OPEN_FILE . dialogLabel ,
554
553
canSelectFolders : false ,
555
554
canSelectFiles : true
556
555
} ;
557
556
const [ rootStat ] = await this . workspaceService . roots ;
558
557
const destinationFileUri = await this . fileDialogService . showOpenDialog ( props , rootStat ) ;
559
- if ( destinationFileUri ) {
560
- const destinationFile = await this . fileSystem . getFileStat ( destinationFileUri . toString ( ) ) ;
561
- if ( destinationFile && ! destinationFile . isDirectory ) {
562
- const message = await this . validate ( destinationFile ) ;
563
- if ( ! message ) {
564
- this . workspaceService . open ( destinationFileUri ) ;
565
- return destinationFileUri ;
566
- } else {
567
- this . messageService . warn ( message ) ;
568
- }
569
- }
558
+ if ( ! destinationFileUri ) {
559
+ return ;
570
560
}
571
- return undefined ;
561
+ const destinationFile = await this . fileSystem . getFileStat ( destinationFileUri . toString ( ) ) ;
562
+ if ( ! destinationFile ) {
563
+ this . messageService . warn ( `File does not exist: ${ this . fileSystem . getFsPath ( destinationFileUri . toString ( ) ) } ` )
564
+ return ;
565
+ }
566
+ if ( destinationFile . isDirectory ) {
567
+ this . messageService . warn ( 'Please select a sketch file, not a directory.' )
568
+ return ;
569
+ }
570
+ const message = await this . validate ( destinationFile ) ;
571
+ if ( message ) {
572
+ this . messageService . warn ( message ) ;
573
+ return ;
574
+ }
575
+ this . workspaceService . open ( destinationFileUri . parent ) ;
572
576
}
573
577
574
578
protected getCurrentWidget ( ) : EditorWidget | undefined {
0 commit comments