11import { injectable } from 'inversify'
22import { remote } from 'electron' ;
3+ import { isOSX } from '@theia/core/lib/common/os' ;
34import { Keybinding } from '@theia/core/lib/common/keybinding' ;
4- import { CompositeMenuNode } from '@theia/core/lib/common/menu' ;
5+ import { CompositeMenuNode , MAIN_MENU_BAR , MenuPath } from '@theia/core/lib/common/menu' ;
56import { ElectronMainMenuFactory as TheiaElectronMainMenuFactory , ElectronMenuOptions } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory' ;
67import { ArduinoMenus , PlaceholderMenuNode } from '../../../browser/menu/arduino-menus' ;
78
@@ -10,7 +11,33 @@ export class ElectronMainMenuFactory extends TheiaElectronMainMenuFactory {
1011
1112 createMenuBar ( ) : Electron . Menu {
1213 this . _toggledCommands . clear ( ) ; // https://github.com/eclipse-theia/theia/issues/8977
13- return super . createMenuBar ( ) ;
14+ const menuModel = this . menuProvider . getMenu ( MAIN_MENU_BAR ) ;
15+ const template = this . fillMenuTemplate ( [ ] , menuModel ) ;
16+ if ( isOSX ) {
17+ template . unshift ( this . createOSXMenu ( ) ) ;
18+ }
19+ const menu = remote . Menu . buildFromTemplate ( this . escapeAmpersand ( template ) ) ;
20+ this . _menu = menu ;
21+ return menu ;
22+ }
23+
24+ createContextMenu ( menuPath : MenuPath , args ?: any [ ] ) : Electron . Menu {
25+ const menuModel = this . menuProvider . getMenu ( menuPath ) ;
26+ const template = this . fillMenuTemplate ( [ ] , menuModel , args , { showDisabled : false } ) ;
27+ return remote . Menu . buildFromTemplate ( this . escapeAmpersand ( template ) ) ;
28+ }
29+
30+ // TODO: remove after https://github.com/eclipse-theia/theia/pull/9231
31+ private escapeAmpersand ( template : Electron . MenuItemConstructorOptions [ ] ) : Electron . MenuItemConstructorOptions [ ] {
32+ for ( const option of template ) {
33+ if ( option . label ) {
34+ option . label = option . label . replace ( / \& + / g, '&$&' ) ;
35+ }
36+ if ( option . submenu ) {
37+ this . escapeAmpersand ( option . submenu as Electron . MenuItemConstructorOptions [ ] ) ;
38+ }
39+ }
40+ return template ;
1441 }
1542
1643 protected acceleratorFor ( keybinding : Keybinding ) : string {
0 commit comments