@@ -99,7 +99,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
99
99
isVisible : widget => this . isArduinoToolbar ( widget ) ,
100
100
isEnabled : widget => this . isArduinoToolbar ( widget ) ,
101
101
execute : async ( ) => {
102
- const widget = this . editorManager . currentEditor ;
102
+ const widget = this . getCurrentWidget ( ) ;
103
103
if ( widget instanceof EditorWidget ) {
104
104
await widget . saveable . save ( ) ;
105
105
}
@@ -120,7 +120,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
120
120
isVisible : widget => this . isArduinoToolbar ( widget ) ,
121
121
isEnabled : widget => this . isArduinoToolbar ( widget ) ,
122
122
execute : async ( ) => {
123
- const widget = this . editorManager . currentEditor ;
123
+ const widget = this . getCurrentWidget ( ) ;
124
124
if ( widget instanceof EditorWidget ) {
125
125
await widget . saveable . save ( ) ;
126
126
}
@@ -148,7 +148,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
148
148
await this . sketchFactory . createNewSketch ( uri ) ;
149
149
} catch ( e ) {
150
150
await this . messageService . error ( e . toString ( ) ) ;
151
- }
151
+ }
152
152
}
153
153
} ) ) ;
154
154
registry . registerCommand ( ArduinoCommands . REFRESH_BOARDS , {
@@ -157,13 +157,24 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
157
157
} )
158
158
}
159
159
160
+ protected getCurrentWidget ( ) : EditorWidget | undefined {
161
+ let widget = this . editorManager . currentEditor ;
162
+ if ( ! widget ) {
163
+ const visibleWidgets = this . editorManager . all . filter ( w => w . isVisible ) ;
164
+ if ( visibleWidgets . length > 0 ) {
165
+ widget = visibleWidgets [ 0 ] ;
166
+ }
167
+ }
168
+ return widget ;
169
+ }
170
+
160
171
private async onNoBoardsInstalled ( ) {
161
172
const action = await this . messageService . info ( "You have no boards installed. Use the boards mangager to install one." , "Open Boards Manager" ) ;
162
173
if ( ! action ) {
163
174
return ;
164
175
}
165
176
166
- this . boardsListWidgetFrontendContribution . openView ( { reveal : true } ) ;
177
+ this . boardsListWidgetFrontendContribution . openView ( { reveal : true } ) ;
167
178
}
168
179
169
180
private async onUnknownBoard ( ) {
@@ -173,7 +184,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
173
184
return ;
174
185
}
175
186
176
- this . boardsListWidgetFrontendContribution . openView ( { reveal : true } ) ;
187
+ this . boardsListWidgetFrontendContribution . openView ( { reveal : true } ) ;
177
188
}
178
189
179
190
private isArduinoToolbar ( maybeToolbarWidget : any ) : boolean {
0 commit comments