mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-15 05:09:29 +00:00
Make tab width 2 spaces (#445)
This commit is contained in:
@@ -3,118 +3,116 @@ import { remote } from 'electron';
|
||||
import { isOSX } from '@theia/core/lib/common/os';
|
||||
import { Keybinding } from '@theia/core/lib/common/keybinding';
|
||||
import {
|
||||
CompositeMenuNode,
|
||||
MAIN_MENU_BAR,
|
||||
MenuPath,
|
||||
CompositeMenuNode,
|
||||
MAIN_MENU_BAR,
|
||||
MenuPath,
|
||||
} from '@theia/core/lib/common/menu';
|
||||
import {
|
||||
ElectronMainMenuFactory as TheiaElectronMainMenuFactory,
|
||||
ElectronMenuOptions,
|
||||
ElectronMainMenuFactory as TheiaElectronMainMenuFactory,
|
||||
ElectronMenuOptions,
|
||||
} from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory';
|
||||
import {
|
||||
ArduinoMenus,
|
||||
PlaceholderMenuNode,
|
||||
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
|
||||
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)
|
||||
createMenuBar(): Electron.Menu {
|
||||
this._toggledCommands.clear(); // https://github.com/eclipse-theia/theia/issues/8977
|
||||
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[]
|
||||
);
|
||||
this._menu = menu;
|
||||
return menu;
|
||||
}
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
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');
|
||||
}
|
||||
|
||||
// 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 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 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 [];
|
||||
protected handleDefault(
|
||||
menuNode: CompositeMenuNode,
|
||||
args: any[] = [],
|
||||
options?: ElectronMenuOptions
|
||||
): Electron.MenuItemConstructorOptions[] {
|
||||
if (menuNode instanceof PlaceholderMenuNode) {
|
||||
return [
|
||||
{
|
||||
label: menuNode.label,
|
||||
enabled: false,
|
||||
visible: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,39 +3,39 @@ import { CommandRegistry } from '@theia/core/lib/common/command';
|
||||
import { MenuModelRegistry } from '@theia/core/lib/common/menu';
|
||||
import { KeybindingRegistry } from '@theia/core/lib/browser/keybinding';
|
||||
import {
|
||||
ElectronMenuContribution as TheiaElectronMenuContribution,
|
||||
ElectronCommands,
|
||||
ElectronMenuContribution as TheiaElectronMenuContribution,
|
||||
ElectronCommands,
|
||||
} from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
|
||||
import { MainMenuManager } from '../../../common/main-menu-manager';
|
||||
|
||||
@injectable()
|
||||
export class ElectronMenuContribution
|
||||
extends TheiaElectronMenuContribution
|
||||
implements MainMenuManager
|
||||
extends TheiaElectronMenuContribution
|
||||
implements MainMenuManager
|
||||
{
|
||||
protected hideTopPanel(): void {
|
||||
// NOOP
|
||||
// We reuse the `div` for the Arduino toolbar.
|
||||
}
|
||||
protected hideTopPanel(): void {
|
||||
// NOOP
|
||||
// We reuse the `div` for the Arduino toolbar.
|
||||
}
|
||||
|
||||
update(): void {
|
||||
(this as any).setMenu();
|
||||
}
|
||||
update(): void {
|
||||
(this as any).setMenu();
|
||||
}
|
||||
|
||||
registerCommands(registry: CommandRegistry): void {
|
||||
super.registerCommands(registry);
|
||||
registry.unregisterCommand(ElectronCommands.CLOSE_WINDOW);
|
||||
}
|
||||
registerCommands(registry: CommandRegistry): void {
|
||||
super.registerCommands(registry);
|
||||
registry.unregisterCommand(ElectronCommands.CLOSE_WINDOW);
|
||||
}
|
||||
|
||||
registerMenus(registry: MenuModelRegistry): void {
|
||||
super.registerMenus(registry);
|
||||
registry.unregisterMenuAction(ElectronCommands.CLOSE_WINDOW);
|
||||
}
|
||||
registerMenus(registry: MenuModelRegistry): void {
|
||||
super.registerMenus(registry);
|
||||
registry.unregisterMenuAction(ElectronCommands.CLOSE_WINDOW);
|
||||
}
|
||||
|
||||
registerKeybindings(registry: KeybindingRegistry): void {
|
||||
super.registerKeybindings(registry);
|
||||
registry.unregisterKeybinding(ElectronCommands.CLOSE_WINDOW.id);
|
||||
registry.unregisterKeybinding(ElectronCommands.ZOOM_IN.id);
|
||||
registry.unregisterKeybinding(ElectronCommands.ZOOM_OUT.id);
|
||||
}
|
||||
registerKeybindings(registry: KeybindingRegistry): void {
|
||||
super.registerKeybindings(registry);
|
||||
registry.unregisterKeybinding(ElectronCommands.CLOSE_WINDOW.id);
|
||||
registry.unregisterKeybinding(ElectronCommands.ZOOM_IN.id);
|
||||
registry.unregisterKeybinding(ElectronCommands.ZOOM_OUT.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import { ElectronMainMenuFactory as TheiaElectronMainMenuFactory } from '@theia/
|
||||
import { ElectronMenuContribution as TheiaElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
|
||||
import { ElectronIpcConnectionProvider } from '@theia/core/lib/electron-browser/messaging/electron-ipc-connection-provider';
|
||||
import {
|
||||
SplashService,
|
||||
splashServicePath,
|
||||
SplashService,
|
||||
splashServicePath,
|
||||
} from '../../../electron-common/splash-service';
|
||||
import { MainMenuManager } from '../../../common/main-menu-manager';
|
||||
import { ElectronWindowService } from '../../electron-window-service';
|
||||
@@ -13,19 +13,19 @@ import { ElectronMainMenuFactory } from './electron-main-menu-factory';
|
||||
import { ElectronMenuContribution } from './electron-menu-contribution';
|
||||
|
||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
bind(ElectronMenuContribution).toSelf().inSingletonScope();
|
||||
bind(MainMenuManager).toService(ElectronMenuContribution);
|
||||
rebind(TheiaElectronMenuContribution).to(ElectronMenuContribution);
|
||||
bind(ElectronMainMenuFactory).toSelf().inRequestScope();
|
||||
rebind(TheiaElectronMainMenuFactory).toService(ElectronMainMenuFactory);
|
||||
bind(ElectronWindowService).toSelf().inSingletonScope();
|
||||
rebind(WindowService).toService(ElectronWindowService);
|
||||
bind(SplashService)
|
||||
.toDynamicValue((context) =>
|
||||
ElectronIpcConnectionProvider.createProxy(
|
||||
context.container,
|
||||
splashServicePath
|
||||
)
|
||||
)
|
||||
.inSingletonScope();
|
||||
bind(ElectronMenuContribution).toSelf().inSingletonScope();
|
||||
bind(MainMenuManager).toService(ElectronMenuContribution);
|
||||
rebind(TheiaElectronMenuContribution).to(ElectronMenuContribution);
|
||||
bind(ElectronMainMenuFactory).toSelf().inRequestScope();
|
||||
rebind(TheiaElectronMainMenuFactory).toService(ElectronMainMenuFactory);
|
||||
bind(ElectronWindowService).toSelf().inSingletonScope();
|
||||
rebind(WindowService).toService(ElectronWindowService);
|
||||
bind(SplashService)
|
||||
.toDynamicValue((context) =>
|
||||
ElectronIpcConnectionProvider.createProxy(
|
||||
context.container,
|
||||
splashServicePath
|
||||
)
|
||||
)
|
||||
.inSingletonScope();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user