Skip to content

Commit 8a692d0

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
ATL-1068: Escape ampersand in the menu label.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 9867122 commit 8a692d0

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

Diff for: arduino-ide-extension/src/electron-browser/theia/core/electron-main-menu-factory.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { injectable } from 'inversify'
22
import { remote } from 'electron';
3+
import { isOSX } from '@theia/core/lib/common/os';
34
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';
56
import { ElectronMainMenuFactory as TheiaElectronMainMenuFactory, ElectronMenuOptions } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory';
67
import { 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

Comments
 (0)