Skip to content

Commit 69c7383

Browse files
committed
Update Electron main menu when a toggle button is switched
1 parent f6a8dce commit 69c7383

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
301301
});
302302

303303
registry.registerCommand(ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG, {
304-
execute: () => this.editorMode.toggleCompileForDebug(),
304+
execute: () => {
305+
this.editorMode.toggleCompileForDebug();
306+
this.editorMode.menuContentChanged.fire();
307+
},
305308
isToggled: () => this.editorMode.compileForDebug
306309
});
307310

@@ -416,7 +419,10 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
416419
});
417420

418421
registry.registerCommand(ArduinoCommands.TOGGLE_ADVANCED_MODE, {
419-
execute: () => this.editorMode.toggleProMode(),
422+
execute: () => {
423+
this.editorMode.toggleProMode();
424+
this.editorMode.menuContentChanged.fire();
425+
},
420426
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right',
421427
isToggled: () => this.editorMode.proMode
422428
});

arduino-ide-extension/src/browser/editor-mode.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { injectable } from 'inversify';
2+
import { Emitter } from '@theia/core/lib/common/event';
23
import { ApplicationShell, FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser';
34
import { ArduinoShellLayoutRestorer } from './shell/arduino-shell-layout-restorer';
45
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
@@ -7,6 +8,8 @@ import { EditorWidget } from '@theia/editor/lib/browser';
78
@injectable()
89
export class EditorMode implements FrontendApplicationContribution {
910

11+
readonly menuContentChanged = new Emitter<void>();
12+
1013
protected app: FrontendApplication;
1114

1215
onStart(app: FrontendApplication): void {

arduino-ide-extension/src/electron-browser/electron-arduino-menu-contribution.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
import { injectable } from 'inversify';
1+
import * as electron from 'electron';
2+
import { injectable, inject, postConstruct } from 'inversify';
3+
import { isOSX } from '@theia/core/lib/common/os';
24
import { ElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
5+
import { EditorMode } from '../browser/editor-mode';
36

47
@injectable()
58
export class ElectronArduinoMenuContribution extends ElectronMenuContribution {
69

10+
@inject(EditorMode)
11+
protected readonly editorMode: EditorMode;
12+
13+
@postConstruct()
14+
protected init(): void {
15+
this.editorMode.menuContentChanged.event(() => {
16+
const createdMenuBar = this.factory.createMenuBar();
17+
if (isOSX) {
18+
electron.remote.Menu.setApplicationMenu(createdMenuBar);
19+
} else {
20+
electron.remote.getCurrentWindow().setMenu(createdMenuBar);
21+
}
22+
});
23+
}
24+
725
protected hideTopPanel(): void {
826
// NOOP
927
// We reuse the `div` for the Arduino toolbar.

0 commit comments

Comments
 (0)