@@ -181,12 +181,12 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
181
181
registerToolbarItems ( registry : TabBarToolbarRegistry ) : void {
182
182
registry . registerItem ( {
183
183
id : ArduinoCommands . VERIFY . id ,
184
- command : ArduinoCommands . VERIFY . id ,
184
+ command : ArduinoCommands . VERIFY_TOOLBAR . id ,
185
185
tooltip : 'Verify'
186
186
} ) ;
187
187
registry . registerItem ( {
188
188
id : ArduinoCommands . UPLOAD . id ,
189
- command : ArduinoCommands . UPLOAD . id ,
189
+ command : ArduinoCommands . UPLOAD_TOOLBAR . id ,
190
190
tooltip : 'Upload'
191
191
} ) ;
192
192
registry . registerItem ( {
@@ -213,17 +213,15 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
213
213
} ) ;
214
214
registry . registerItem ( {
215
215
id : 'toggle-serial-monitor' ,
216
- command : MonitorViewContribution . OPEN_SERIAL_MONITOR ,
217
- tooltip : 'Toggle Serial Monitor' ,
218
- isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'right'
216
+ command : MonitorViewContribution . TOGGLE_SERIAL_MONITOR_TOOLBAR ,
217
+ tooltip : 'Toggle Serial Monitor'
219
218
} ) ;
220
219
221
220
registry . registerItem ( {
222
221
id : ArduinoCommands . TOGGLE_ADVANCED_MODE . id ,
223
- command : ArduinoCommands . TOGGLE_ADVANCED_MODE . id ,
222
+ command : ArduinoCommands . TOGGLE_ADVANCED_MODE_TOOLBAR . id ,
224
223
tooltip : 'Toggle Advanced Mode' ,
225
- text : ( this . editorMode . proMode ? '$(toggle-on)' : '$(toggle-off)' ) ,
226
- isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'right'
224
+ text : ( this . editorMode . proMode ? '$(toggle-on)' : '$(toggle-off)' )
227
225
} ) ;
228
226
}
229
227
@@ -266,38 +264,11 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
266
264
}
267
265
268
266
registry . registerCommand ( ArduinoCommands . VERIFY , {
267
+ execute : this . verify . bind ( this )
268
+ } ) ;
269
+ registry . registerCommand ( ArduinoCommands . VERIFY_TOOLBAR , {
269
270
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
270
- isEnabled : widget => true ,
271
- execute : async ( ) => {
272
- const widget = this . getCurrentWidget ( ) ;
273
- if ( widget instanceof EditorWidget ) {
274
- await widget . saveable . save ( ) ;
275
- }
276
-
277
- const uri = this . toUri ( widget ) ;
278
- if ( ! uri ) {
279
- return ;
280
- }
281
-
282
- try {
283
- const { boardsConfig } = this . boardsServiceClient ;
284
- if ( ! boardsConfig || ! boardsConfig . selectedBoard ) {
285
- throw new Error ( 'No boards selected. Please select a board.' ) ;
286
- }
287
- if ( ! boardsConfig . selectedBoard . fqbn ) {
288
- throw new Error ( `No core is installed for ${ boardsConfig . selectedBoard . name } . Please install the board.` ) ;
289
- }
290
- // Reveal the Output view asynchronously (don't await it)
291
- this . outputContribution . openView ( { reveal : true } ) ;
292
- await this . coreService . compile ( {
293
- uri : uri . toString ( ) ,
294
- board : boardsConfig . selectedBoard ,
295
- optimizeForDebug : this . editorMode . compileForDebug
296
- } ) ;
297
- } catch ( e ) {
298
- await this . messageService . error ( e . toString ( ) ) ;
299
- }
300
- }
271
+ execute : this . verify . bind ( this )
301
272
} ) ;
302
273
303
274
registry . registerCommand ( ArduinoCommands . TOGGLE_COMPILE_FOR_DEBUG , {
@@ -309,54 +280,15 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
309
280
} ) ;
310
281
311
282
registry . registerCommand ( ArduinoCommands . UPLOAD , {
283
+ execute : this . upload . bind ( this )
284
+ } ) ;
285
+ registry . registerCommand ( ArduinoCommands . UPLOAD_TOOLBAR , {
312
286
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
313
- isEnabled : widget => true ,
314
- execute : async ( ) => {
315
- const widget = this . getCurrentWidget ( ) ;
316
- if ( widget instanceof EditorWidget ) {
317
- await widget . saveable . save ( ) ;
318
- }
319
-
320
- const uri = this . toUri ( widget ) ;
321
- if ( ! uri ) {
322
- return ;
323
- }
324
-
325
- const monitorConfig = this . monitorConnection . monitorConfig ;
326
- if ( monitorConfig ) {
327
- await this . monitorConnection . disconnect ( ) ;
328
- }
329
-
330
- try {
331
- const { boardsConfig } = this . boardsServiceClient ;
332
- if ( ! boardsConfig || ! boardsConfig . selectedBoard ) {
333
- throw new Error ( 'No boards selected. Please select a board.' ) ;
334
- }
335
- const { selectedPort } = boardsConfig ;
336
- if ( ! selectedPort ) {
337
- throw new Error ( 'No ports selected. Please select a port.' ) ;
338
- }
339
- // Reveal the Output view asynchronously (don't await it)
340
- this . outputContribution . openView ( { reveal : true } ) ;
341
- await this . coreService . upload ( {
342
- uri : uri . toString ( ) ,
343
- board : boardsConfig . selectedBoard ,
344
- port : selectedPort . address ,
345
- optimizeForDebug : this . editorMode . compileForDebug
346
- } ) ;
347
- } catch ( e ) {
348
- await this . messageService . error ( e . toString ( ) ) ;
349
- } finally {
350
- if ( monitorConfig ) {
351
- await this . monitorConnection . connect ( monitorConfig ) ;
352
- }
353
- }
354
- }
287
+ execute : this . upload . bind ( this )
355
288
} ) ;
356
289
357
290
registry . registerCommand ( ArduinoCommands . SHOW_OPEN_CONTEXT_MENU , {
358
291
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
359
- isEnabled : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
360
292
execute : async ( widget : Widget , target : EventTarget ) => {
361
293
if ( this . wsSketchCount ) {
362
294
const el = ( target as HTMLElement ) . parentElement ;
@@ -385,7 +317,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
385
317
} ) ;
386
318
387
319
registry . registerCommand ( ArduinoCommands . SAVE_SKETCH , {
388
- isEnabled : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
389
320
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
390
321
execute : async ( sketch : Sketch ) => {
391
322
registry . executeCommand ( CommonCommands . SAVE_ALL . id ) ;
@@ -419,15 +350,89 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
419
350
} ) ;
420
351
421
352
registry . registerCommand ( ArduinoCommands . TOGGLE_ADVANCED_MODE , {
422
- execute : ( ) => {
423
- this . editorMode . toggleProMode ( ) ;
424
- this . editorMode . menuContentChanged . fire ( ) ;
425
- } ,
353
+ isToggled : ( ) => this . editorMode . proMode ,
354
+ execute : ( ) => this . editorMode . toggleProMode ( )
355
+ } ) ;
356
+ registry . registerCommand ( ArduinoCommands . TOGGLE_ADVANCED_MODE_TOOLBAR , {
426
357
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'right' ,
427
- isToggled : ( ) => this . editorMode . proMode
358
+ isToggled : ( ) => this . editorMode . proMode ,
359
+ execute : ( ) => this . editorMode . toggleProMode ( )
428
360
} ) ;
429
361
}
430
362
363
+ protected async verify ( ) {
364
+ const widget = this . getCurrentWidget ( ) ;
365
+ if ( widget instanceof EditorWidget ) {
366
+ await widget . saveable . save ( ) ;
367
+ }
368
+
369
+ const uri = this . toUri ( widget ) ;
370
+ if ( ! uri ) {
371
+ return ;
372
+ }
373
+
374
+ try {
375
+ const { boardsConfig } = this . boardsServiceClient ;
376
+ if ( ! boardsConfig || ! boardsConfig . selectedBoard ) {
377
+ throw new Error ( 'No boards selected. Please select a board.' ) ;
378
+ }
379
+ if ( ! boardsConfig . selectedBoard . fqbn ) {
380
+ throw new Error ( `No core is installed for ${ boardsConfig . selectedBoard . name } . Please install the board.` ) ;
381
+ }
382
+ // Reveal the Output view asynchronously (don't await it)
383
+ this . outputContribution . openView ( { reveal : true } ) ;
384
+ await this . coreService . compile ( {
385
+ uri : uri . toString ( ) ,
386
+ board : boardsConfig . selectedBoard ,
387
+ optimizeForDebug : this . editorMode . compileForDebug
388
+ } ) ;
389
+ } catch ( e ) {
390
+ await this . messageService . error ( e . toString ( ) ) ;
391
+ }
392
+ }
393
+
394
+ protected async upload ( ) {
395
+ const widget = this . getCurrentWidget ( ) ;
396
+ if ( widget instanceof EditorWidget ) {
397
+ await widget . saveable . save ( ) ;
398
+ }
399
+
400
+ const uri = this . toUri ( widget ) ;
401
+ if ( ! uri ) {
402
+ return ;
403
+ }
404
+
405
+ const monitorConfig = this . monitorConnection . monitorConfig ;
406
+ if ( monitorConfig ) {
407
+ await this . monitorConnection . disconnect ( ) ;
408
+ }
409
+
410
+ try {
411
+ const { boardsConfig } = this . boardsServiceClient ;
412
+ if ( ! boardsConfig || ! boardsConfig . selectedBoard ) {
413
+ throw new Error ( 'No boards selected. Please select a board.' ) ;
414
+ }
415
+ const { selectedPort } = boardsConfig ;
416
+ if ( ! selectedPort ) {
417
+ throw new Error ( 'No ports selected. Please select a port.' ) ;
418
+ }
419
+ // Reveal the Output view asynchronously (don't await it)
420
+ this . outputContribution . openView ( { reveal : true } ) ;
421
+ await this . coreService . upload ( {
422
+ uri : uri . toString ( ) ,
423
+ board : boardsConfig . selectedBoard ,
424
+ port : selectedPort . address ,
425
+ optimizeForDebug : this . editorMode . compileForDebug
426
+ } ) ;
427
+ } catch ( e ) {
428
+ await this . messageService . error ( e . toString ( ) ) ;
429
+ } finally {
430
+ if ( monitorConfig ) {
431
+ await this . monitorConnection . connect ( monitorConfig ) ;
432
+ }
433
+ }
434
+ }
435
+
431
436
registerMenus ( registry : MenuModelRegistry ) {
432
437
if ( ! this . editorMode . proMode ) {
433
438
// If are not in pro-mode, we have to disable the context menu for the tabs.
0 commit comments