mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-09 05:36:33 +00:00
ATL-1068: Escape ampersand in the menu label.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
98671225ac
commit
8a692d0ce5
@ -1,7 +1,8 @@
|
||||
import { injectable } from 'inversify'
|
||||
import { remote } from 'electron';
|
||||
import { isOSX } from '@theia/core/lib/common/os';
|
||||
import { Keybinding } from '@theia/core/lib/common/keybinding';
|
||||
import { CompositeMenuNode } from '@theia/core/lib/common/menu';
|
||||
import { CompositeMenuNode, MAIN_MENU_BAR, MenuPath } from '@theia/core/lib/common/menu';
|
||||
import { ElectronMainMenuFactory as TheiaElectronMainMenuFactory, ElectronMenuOptions } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory';
|
||||
import { ArduinoMenus, PlaceholderMenuNode } from '../../../browser/menu/arduino-menus';
|
||||
|
||||
@ -10,7 +11,33 @@ export class ElectronMainMenuFactory extends TheiaElectronMainMenuFactory {
|
||||
|
||||
createMenuBar(): Electron.Menu {
|
||||
this._toggledCommands.clear(); // https://github.com/eclipse-theia/theia/issues/8977
|
||||
return super.createMenuBar();
|
||||
const menuModel = this.menuProvider.getMenu(MAIN_MENU_BAR);
|
||||
const template = this.fillMenuTemplate([], menuModel);
|
||||
if (isOSX) {
|
||||
template.unshift(this.createOSXMenu());
|
||||
}
|
||||
const menu = remote.Menu.buildFromTemplate(this.escapeAmpersand(template));
|
||||
this._menu = menu;
|
||||
return menu;
|
||||
}
|
||||
|
||||
createContextMenu(menuPath: MenuPath, args?: any[]): Electron.Menu {
|
||||
const menuModel = this.menuProvider.getMenu(menuPath);
|
||||
const template = this.fillMenuTemplate([], menuModel, args, { showDisabled: false });
|
||||
return remote.Menu.buildFromTemplate(this.escapeAmpersand(template));
|
||||
}
|
||||
|
||||
// TODO: remove after https://github.com/eclipse-theia/theia/pull/9231
|
||||
private escapeAmpersand(template: Electron.MenuItemConstructorOptions[]): Electron.MenuItemConstructorOptions[] {
|
||||
for (const option of template) {
|
||||
if (option.label) {
|
||||
option.label = option.label.replace(/\&+/g, '&$&');
|
||||
}
|
||||
if (option.submenu) {
|
||||
this.escapeAmpersand(option.submenu as Electron.MenuItemConstructorOptions[]);
|
||||
}
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
protected acceleratorFor(keybinding: Keybinding): string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user