@@ -3,7 +3,7 @@ import { CommandRegistry } from '@theia/core/lib/common/command';
3
3
import { MenuModelRegistry , MenuNode } from '@theia/core/lib/common/menu' ;
4
4
import { Disposable , DisposableCollection } from '@theia/core/lib/common/disposable' ;
5
5
import { BoardsServiceClientImpl } from './boards-service-client-impl' ;
6
- import { Board , ConfigOption } from '../../common/protocol' ;
6
+ import { Board , ConfigOption , Programmer } from '../../common/protocol' ;
7
7
import { FrontendApplicationContribution } from '@theia/core/lib/browser' ;
8
8
import { BoardsDataStore } from './boards-data-store' ;
9
9
import { MainMenuManager } from '../../common/main-menu-manager' ;
@@ -41,7 +41,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
41
41
this . mainMenuManager . update ( ) ;
42
42
const { fqbn } = selectedBoard ;
43
43
if ( fqbn ) {
44
- const { configOptions, programmers } = await this . boardsDataStore . getData ( fqbn ) ;
44
+ const { configOptions, programmers, selectedProgrammer } = await this . boardsDataStore . getData ( fqbn ) ;
45
45
const boardsConfigMenuPath = [ ...ArduinoMenus . TOOLS , 'z01_boardsConfig' ] ; // `z_` is for ordering.
46
46
for ( const { label, option, values } of configOptions . sort ( ConfigOption . LABEL_COMPARATOR ) ) {
47
47
const menuPath = [ ...boardsConfigMenuPath , `${ option } ` ] ;
@@ -60,24 +60,31 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
60
60
this . toDisposeOnBoardChange . pushAll ( [
61
61
...commands . values ( ) ,
62
62
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 ) => {
64
64
const { label } = commands . get ( commandId ) ! ;
65
- this . menuRegistry . registerMenuAction ( menuPath , { commandId, order : String ( index ) , label } ) ;
65
+ this . menuRegistry . registerMenuAction ( menuPath , { commandId, order : ` ${ i } ` , label } ) ;
66
66
return Disposable . create ( ( ) => this . menuRegistry . unregisterMenuAction ( commandId ) ) ;
67
67
} )
68
68
] ) ;
69
69
}
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
+ }
81
88
}
82
89
this . mainMenuManager . update ( ) ;
83
90
}
0 commit comments