1
1
import { injectable } from 'inversify'
2
2
import { remote } from 'electron' ;
3
+ import { isOSX } from '@theia/core/lib/common/os' ;
3
4
import { 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' ;
5
6
import { ElectronMainMenuFactory as TheiaElectronMainMenuFactory , ElectronMenuOptions } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory' ;
6
7
import { ArduinoMenus , PlaceholderMenuNode } from '../../../browser/menu/arduino-menus' ;
7
8
@@ -10,7 +11,33 @@ export class ElectronMainMenuFactory extends TheiaElectronMainMenuFactory {
10
11
11
12
createMenuBar ( ) : Electron . Menu {
12
13
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 ;
14
41
}
15
42
16
43
protected acceleratorFor ( keybinding : Keybinding ) : string {
0 commit comments