@@ -3,7 +3,7 @@ import { CommandRegistry } from '@theia/core/lib/common/command';
33import { MenuModelRegistry , MenuNode } from '@theia/core/lib/common/menu' ;
44import { Disposable , DisposableCollection } from '@theia/core/lib/common/disposable' ;
55import { BoardsServiceClientImpl } from './boards-service-client-impl' ;
6- import { Board , ConfigOption } from '../../common/protocol' ;
6+ import { Board , ConfigOption , Programmer } from '../../common/protocol' ;
77import { FrontendApplicationContribution } from '@theia/core/lib/browser' ;
88import { BoardsDataStore } from './boards-data-store' ;
99import { MainMenuManager } from '../../common/main-menu-manager' ;
@@ -41,7 +41,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
4141 this . mainMenuManager . update ( ) ;
4242 const { fqbn } = selectedBoard ;
4343 if ( fqbn ) {
44- const { configOptions, programmers } = await this . boardsDataStore . getData ( fqbn ) ;
44+ const { configOptions, programmers, selectedProgrammer } = await this . boardsDataStore . getData ( fqbn ) ;
4545 const boardsConfigMenuPath = [ ...ArduinoMenus . TOOLS , 'z01_boardsConfig' ] ; // `z_` is for ordering.
4646 for ( const { label, option, values } of configOptions . sort ( ConfigOption . LABEL_COMPARATOR ) ) {
4747 const menuPath = [ ...boardsConfigMenuPath , `${ option } ` ] ;
@@ -60,24 +60,31 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
6060 this . toDisposeOnBoardChange . pushAll ( [
6161 ...commands . values ( ) ,
6262 Disposable . create ( ( ) => this . unregisterSubmenu ( menuPath ) ) , // We cannot dispose submenu entries: https://github.com/eclipse-theia/theia/issues/7299
63- ...Array . from ( commands . keys ( ) ) . map ( ( commandId , index ) => {
63+ ...Array . from ( commands . keys ( ) ) . map ( ( commandId , i ) => {
6464 const { label } = commands . get ( commandId ) ! ;
65- this . menuRegistry . registerMenuAction ( menuPath , { commandId, order : String ( index ) , label } ) ;
65+ this . menuRegistry . registerMenuAction ( menuPath , { commandId, order : ` ${ i } ` , label } ) ;
6666 return Disposable . create ( ( ) => this . menuRegistry . unregisterMenuAction ( commandId ) ) ;
6767 } )
6868 ] ) ;
6969 }
70- const programmersMenuPath = [ ...ArduinoMenus . TOOLS , 'z02_programmers' ] ;
71- for ( const programmer of programmers ) {
72- const { id, name } = programmer ;
73- const menuPath = [ ...programmersMenuPath , `${ name } ` ] ;
74- const command = { id : `${ fqbn } -programmer--${ id } ` } ;
75- const handler = { execute : ( ) => this . boardsDataStore . selectProgrammer ( { fqbn, programmer } ) } ;
76- this . menuRegistry . registerMenuAction ( menuPath , { commandId : command . id , label : name } ) ;
77- this . toDisposeOnBoardChange . pushAll ( [
78- this . commandRegistry . registerCommand ( command , handler ) ,
79- Disposable . create ( ( ) => this . menuRegistry . unregisterMenuAction ( command , menuPath ) )
80- ] ) ;
70+ if ( programmers . length ) {
71+ const programmersMenuPath = [ ...ArduinoMenus . TOOLS , 'z02_programmers' ] ;
72+ const label = selectedProgrammer ? `Programmer: ${ selectedProgrammer . name } ` : 'Programmer'
73+ this . menuRegistry . registerSubmenu ( programmersMenuPath , label ) ;
74+ for ( const programmer of programmers ) {
75+ const { id, name } = programmer ;
76+ const command = { id : `${ fqbn } -programmer--${ id } ` } ;
77+ const handler = {
78+ execute : ( ) => this . boardsDataStore . selectProgrammer ( { fqbn, selectedProgrammer : programmer } ) ,
79+ isToggled : ( ) => Programmer . equals ( programmer , selectedProgrammer )
80+ } ;
81+ this . menuRegistry . registerMenuAction ( programmersMenuPath , { commandId : command . id , label : name } ) ;
82+ this . toDisposeOnBoardChange . pushAll ( [
83+ this . commandRegistry . registerCommand ( command , handler ) ,
84+ Disposable . create ( ( ) => this . unregisterSubmenu ( programmersMenuPath ) ) ,
85+ Disposable . create ( ( ) => this . menuRegistry . unregisterMenuAction ( command , programmersMenuPath ) )
86+ ] ) ;
87+ }
8188 }
8289 this . mainMenuManager . update ( ) ;
8390 }
0 commit comments