-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathelectron-main-menu-factory.ts
59 lines (53 loc) · 2.45 KB
/
electron-main-menu-factory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { injectable } from 'inversify'
import { remote } from 'electron';
import { Keybinding } from '@theia/core/lib/common/keybinding';
import { CompositeMenuNode } 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';
@injectable()
export class ElectronMainMenuFactory extends TheiaElectronMainMenuFactory {
createMenuBar(): Electron.Menu {
this._toggledCommands.clear(); // https://github.com/eclipse-theia/theia/issues/8977
return super.createMenuBar();
}
protected acceleratorFor(keybinding: Keybinding): string {
// TODO: https://github.com/eclipse-theia/theia/issues/8207
return this.keybindingRegistry.resolveKeybinding(keybinding)
.map(binding => this.keybindingRegistry.acceleratorForKeyCode(binding, '+'))
.join('')
.replace('←', 'Left')
.replace('→', 'Right');
}
protected createOSXMenu(): Electron.MenuItemConstructorOptions {
const { submenu } = super.createOSXMenu();
const label = 'Arduino IDE';
if (!!submenu && !(submenu instanceof remote.Menu)) {
const [/* about */, /* preferences */, ...rest] = submenu;
const about = this.fillMenuTemplate([], this.menuProvider.getMenu(ArduinoMenus.HELP__ABOUT_GROUP));
const preferences = this.fillMenuTemplate([], this.menuProvider.getMenu(ArduinoMenus.FILE__PREFERENCES_GROUP));
const advanced = this.fillMenuTemplate([], this.menuProvider.getMenu(ArduinoMenus.FILE__ADVANCED_GROUP));
return {
label,
submenu: [
...about,
{ type: 'separator' },
...preferences,
...advanced,
{ type: 'separator' },
...rest
]
};
}
return { label, submenu };
}
protected handleDefault(menuNode: CompositeMenuNode, args: any[] = [], options?: ElectronMenuOptions): Electron.MenuItemConstructorOptions[] {
if (menuNode instanceof PlaceholderMenuNode) {
return [{
label: menuNode.label,
enabled: false,
visible: true
}];
}
return [];
}
}