mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-14 06:46:36 +00:00
Fixed missing New Sketch
menu in electron.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
55923be7fd
commit
4949df7395
@ -1,31 +1,49 @@
|
|||||||
import * as electron from 'electron';
|
import * as electron from 'electron';
|
||||||
import { injectable, inject } from "inversify";
|
import { injectable, inject } from 'inversify';
|
||||||
import { ElectronMenuContribution } from "@theia/core/lib/electron-browser/menu/electron-menu-contribution";
|
import { isOSX } from '@theia/core/lib/common/os';
|
||||||
import { FrontendApplication } from "@theia/core/lib/browser";
|
import { Disposable } from '@theia/core/lib/common/disposable';
|
||||||
import { isOSX } from '@theia/core';
|
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
|
||||||
import { WorkspaceService } from '@theia/workspace/lib/browser';
|
import { ElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
|
||||||
|
import { FrontendApplicationStateService, FrontendApplicationState } from '@theia/core/lib/browser/frontend-application-state';
|
||||||
|
|
||||||
|
// Code was copied from https://github.com/eclipse-theia/theia/pull/5140/commits/be873411eff1f48822a65261305bbe3549ac903d
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ElectronArduinoMenuContribution extends ElectronMenuContribution {
|
export class ElectronArduinoMenuContribution extends ElectronMenuContribution {
|
||||||
|
|
||||||
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
|
@inject(FrontendApplicationStateService)
|
||||||
|
protected readonly stateService: FrontendApplicationStateService;
|
||||||
|
|
||||||
onStart(app: FrontendApplication): void {
|
onStart(app: FrontendApplication): void {
|
||||||
this.workspaceService.onWorkspaceChanged(() => {
|
this.setMenu();
|
||||||
const createdMenuBar = this.factory.createMenuBar();
|
if (isOSX) {
|
||||||
const currentWindow = electron.remote.getCurrentWindow();
|
// OSX: Recreate the menus when changing windows.
|
||||||
if (isOSX) {
|
// OSX only has one menu bar for all windows, so we need to swap
|
||||||
electron.remote.Menu.setApplicationMenu(createdMenuBar);
|
// between them as the user switches windows.
|
||||||
currentWindow.on('focus', () =>
|
electron.remote.getCurrentWindow().on('focus', () => this.setMenu());
|
||||||
// OSX: Recreate the menus when changing windows.
|
}
|
||||||
// OSX only has one menu bar for all windows, so we need to swap
|
// Make sure the application menu is complete, once the frontend application is ready.
|
||||||
// between them as the user switch windows.
|
// https://github.com/theia-ide/theia/issues/5100
|
||||||
electron.remote.Menu.setApplicationMenu(this.factory.createMenuBar())
|
let onStateChange: Disposable | undefined = undefined;
|
||||||
);
|
const stateServiceListener = (state: FrontendApplicationState) => {
|
||||||
} else {
|
if (state === 'ready') {
|
||||||
// Unix/Windows: Set the per-window menus
|
this.setMenu();
|
||||||
currentWindow.setMenu(createdMenuBar);
|
|
||||||
}
|
}
|
||||||
});
|
if (state === 'closing_window') {
|
||||||
|
if (!!onStateChange) {
|
||||||
|
onStateChange.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
onStateChange = this.stateService.onStateChanged(stateServiceListener);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private setMenu(menu: electron.Menu = this.factory.createMenuBar(), electronWindow: electron.BrowserWindow = electron.remote.getCurrentWindow()): void {
|
||||||
|
if (isOSX) {
|
||||||
|
electron.remote.Menu.setApplicationMenu(menu);
|
||||||
|
} else {
|
||||||
|
// Unix/Windows: Set the per-window menus
|
||||||
|
electronWindow.setMenu(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user