Skip to content

Commit 2a0273c

Browse files
committed
Brought back the menu.
With a restricted set of items. Signed-off-by: jbicker <jan.bicker@typefox.io>
1 parent 35086ca commit 2a0273c

11 files changed

+162
-38
lines changed

arduino-ide-extension/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@theia/outline-view": "next",
1818
"@theia/workspace": "next",
1919
"@theia/navigator": "next",
20+
"@theia/terminal": "next",
2021
"p-queue": "^5.0.0"
2122
},
2223
"scripts": {

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

+55-8
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,30 @@ import { QuickPickService } from '@theia/core/lib/common/quick-pick-service';
1515
import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-frontend-contribution';
1616
import { BoardsNotificationService } from './boards-notification-service';
1717
import { WorkspaceRootUriAwareCommandHandler, WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';
18-
import { SelectionService, MenuModelRegistry } from '@theia/core';
18+
import { SelectionService, MenuContribution, MenuModelRegistry, MAIN_MENU_BAR } from '@theia/core';
1919
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
2020
import { SketchFactory } from './sketch-factory';
2121
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
22-
import { EditorManager } from '@theia/editor/lib/browser';
22+
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
2323
import { ContextMenuRenderer, OpenerService, Widget } from '@theia/core/lib/browser';
2424
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
2525
import { FileSystem } from '@theia/filesystem/lib/common';
2626
import { ArduinoToolbarContextMenu } from './arduino-file-menu';
2727
import { Sketch, SketchesService } from '../common/protocol/sketches-service';
2828
import { WindowService } from '@theia/core/lib/browser/window/window-service';
29-
import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution'
30-
import { BoardsToolBarItem } from './boards/boards-toolbar-item';
31-
import { SelectBoardDialog } from './boards/select-board-dialog';
29+
import { CommonCommands, CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
30+
import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
31+
import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution';
32+
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu';
33+
import {TerminalMenus} from '@theia/terminal/lib/browser/terminal-frontend-contribution';
34+
35+
export namespace ArduinoMenus {
36+
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
37+
export const TOOLS = [...MAIN_MENU_BAR, '4_tools'];
38+
}
3239

3340
@injectable()
34-
export class ArduinoFrontendContribution implements TabBarToolbarContribution, CommandContribution {
41+
export class ArduinoFrontendContribution implements TabBarToolbarContribution, CommandContribution, MenuContribution {
3542

3643
@inject(MessageService)
3744
protected readonly messageService: MessageService;
@@ -180,7 +187,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
180187
registerCommands(registry: CommandRegistry): void {
181188
registry.registerCommand(ArduinoCommands.VERIFY, {
182189
isVisible: widget => this.isArduinoToolbar(widget),
183-
isEnabled: widget => this.isArduinoToolbar(widget),
190+
isEnabled: widget => true,
184191
execute: async () => {
185192
const widget = this.getCurrentWidget();
186193
if (widget instanceof EditorWidget) {
@@ -201,7 +208,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
201208
});
202209
registry.registerCommand(ArduinoCommands.UPLOAD, {
203210
isVisible: widget => this.isArduinoToolbar(widget),
204-
isEnabled: widget => this.isArduinoToolbar(widget),
211+
isEnabled: widget => true,
205212
execute: async () => {
206213
const widget = this.getCurrentWidget();
207214
if (widget instanceof EditorWidget) {
@@ -292,6 +299,46 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
292299
}
293300
this.selectedBoard = board;
294301
}
302+
303+
registerMenus(registry: MenuModelRegistry) {
304+
registry.unregisterMenuAction(FileSystemCommands.UPLOAD);
305+
registry.unregisterMenuAction(FileDownloadCommands.DOWNLOAD);
306+
307+
registry.unregisterMenuAction(WorkspaceCommands.NEW_FILE);
308+
registry.unregisterMenuAction(WorkspaceCommands.NEW_FOLDER);
309+
310+
registry.unregisterMenuAction(WorkspaceCommands.OPEN_FOLDER);
311+
registry.unregisterMenuAction(WorkspaceCommands.OPEN_WORKSPACE);
312+
registry.unregisterMenuAction(WorkspaceCommands.OPEN_RECENT_WORKSPACE);
313+
registry.unregisterMenuAction(WorkspaceCommands.SAVE_WORKSPACE_AS);
314+
registry.unregisterMenuAction(WorkspaceCommands.CLOSE);
315+
316+
registry.getMenu(MAIN_MENU_BAR).removeNode(this.getMenuId(MonacoMenus.SELECTION));
317+
registry.getMenu(MAIN_MENU_BAR).removeNode(this.getMenuId(EditorMainMenu.GO));
318+
registry.getMenu(MAIN_MENU_BAR).removeNode(this.getMenuId(TerminalMenus.TERMINAL));
319+
registry.getMenu(MAIN_MENU_BAR).removeNode(this.getMenuId(CommonMenus.VIEW));
320+
registry.getMenu(MAIN_MENU_BAR).removeNode(this.getMenuId(CommonMenus.HELP));
321+
322+
registry.registerSubmenu(ArduinoMenus.SKETCH, 'Sketch');
323+
registry.registerMenuAction(ArduinoMenus.SKETCH, {
324+
commandId: ArduinoCommands.VERIFY.id,
325+
label: 'Verify/Compile',
326+
order: '1'
327+
});
328+
registry.registerMenuAction(ArduinoMenus.SKETCH, {
329+
commandId: ArduinoCommands.UPLOAD.id,
330+
label: 'Upload',
331+
order: '2'
332+
});
333+
334+
registry.registerSubmenu(ArduinoMenus.TOOLS, 'Tools');
335+
}
336+
337+
protected getMenuId(menuPath: string[]): string {
338+
const index = menuPath.length - 1;
339+
const menuId = menuPath[index];
340+
return menuId;
341+
}
295342

296343
protected async openSketchFilesInNewWindow(uri: string) {
297344
const location = new URL(window.location.href);

arduino-ide-extension/src/browser/arduino-frontend-module.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
5555
// Commands and toolbar items
5656
bind(ArduinoFrontendContribution).toSelf().inSingletonScope();
5757
bind(CommandContribution).toService(ArduinoFrontendContribution);
58+
bind(MenuContribution).toService(ArduinoFrontendContribution);
5859
bind(TabBarToolbarContribution).toService(ArduinoFrontendContribution);
5960
bind(FrontendApplicationContribution).toService(ArduinoFrontendContribution);
6061
bind(MenuContribution).to(ArduinoToolbarMenuContribution).inSingletonScope();

arduino-ide-extension/src/browser/boards/boards-widget-frontend-contribution.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { FrontendApplicationContribution } from '@theia/core/lib/browser/fronten
33
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
44
import { ListWidget } from './list-widget';
55
import { BoardsListWidget } from './boards-list-widget';
6+
import { MenuModelRegistry } from '@theia/core';
7+
import { ArduinoMenus } from '../arduino-frontend-contribution';
68

79
@injectable()
810
export abstract class ListWidgetFrontendContribution extends AbstractViewContribution<ListWidget> implements FrontendApplicationContribution {
@@ -16,6 +18,8 @@ export abstract class ListWidgetFrontendContribution extends AbstractViewContrib
1618
@injectable()
1719
export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendContribution {
1820

21+
static readonly OPEN_MANAGER = `${BoardsListWidget.WIDGET_ID}:toggle`;
22+
1923
constructor() {
2024
super({
2125
widgetId: BoardsListWidget.WIDGET_ID,
@@ -24,9 +28,18 @@ export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendCont
2428
area: 'left',
2529
rank: 600
2630
},
27-
toggleCommandId: `${BoardsListWidget.WIDGET_ID}:toggle`,
31+
toggleCommandId: BoardsListWidgetFrontendContribution.OPEN_MANAGER,
2832
toggleKeybinding: 'ctrlcmd+shift+b'
2933
});
3034
}
3135

36+
registerMenus(menus: MenuModelRegistry): void {
37+
if (this.toggleCommand) {
38+
menus.registerMenuAction(ArduinoMenus.TOOLS, {
39+
commandId: this.toggleCommand.id,
40+
label: 'Boards Manager...'
41+
});
42+
}
43+
}
44+
3245
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { injectable } from "inversify";
2+
import { CommonFrontendContribution, CommonMenus, CommonCommands } from "@theia/core/lib/browser";
3+
import { MenuModelRegistry } from "@theia/core";
4+
5+
@injectable()
6+
export class CustomCommonFrontendContribution extends CommonFrontendContribution {
7+
registerMenus(registry: MenuModelRegistry): void {
8+
registry.registerSubmenu(CommonMenus.FILE, 'File');
9+
registry.registerSubmenu(CommonMenus.EDIT, 'Edit');
10+
11+
registry.registerSubmenu(CommonMenus.FILE_SETTINGS_SUBMENU, 'Settings');
12+
13+
registry.registerMenuAction(CommonMenus.EDIT_UNDO, {
14+
commandId: CommonCommands.UNDO.id,
15+
order: '0'
16+
});
17+
registry.registerMenuAction(CommonMenus.EDIT_UNDO, {
18+
commandId: CommonCommands.REDO.id,
19+
order: '1'
20+
});
21+
22+
registry.registerMenuAction(CommonMenus.EDIT_FIND, {
23+
commandId: CommonCommands.FIND.id,
24+
order: '0'
25+
});
26+
registry.registerMenuAction(CommonMenus.EDIT_FIND, {
27+
commandId: CommonCommands.REPLACE.id,
28+
order: '1'
29+
});
30+
31+
registry.registerMenuAction(CommonMenus.EDIT_CLIPBOARD, {
32+
commandId: CommonCommands.CUT.id,
33+
order: '0'
34+
});
35+
registry.registerMenuAction(CommonMenus.EDIT_CLIPBOARD, {
36+
commandId: CommonCommands.COPY.id,
37+
order: '1'
38+
});
39+
registry.registerMenuAction(CommonMenus.EDIT_CLIPBOARD, {
40+
commandId: CommonCommands.PASTE.id,
41+
order: '2'
42+
});
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { injectable } from "inversify";
2+
import { FileMenuContribution } from "@theia/workspace/lib/browser";
3+
import { MenuModelRegistry } from "@theia/core";
4+
5+
@injectable()
6+
export class CustomFileMenuContribution extends FileMenuContribution {
7+
registerMenus(registry: MenuModelRegistry) {
8+
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { injectable } from "inversify";
2+
import { MonacoEditorMenuContribution } from "@theia/monaco/lib/browser/monaco-menu";
3+
import { MenuModelRegistry } from "@theia/core";
4+
5+
@injectable()
6+
export class CustomMonacoEditorMenuContribution extends MonacoEditorMenuContribution {
7+
registerMenus(registry: MenuModelRegistry) {
8+
9+
}
10+
}

arduino-ide-extension/src/browser/library/list-widget-frontend-contribution.ts

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { FrontendApplicationContribution } from '@theia/core/lib/browser/fronten
33
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
44
import { ListWidget } from './list-widget';
55
import { LibraryListWidget } from './library-list-widget';
6+
import { MenuModelRegistry } from '@theia/core';
7+
import { ArduinoMenus } from '../arduino-frontend-contribution';
68

79
@injectable()
810
export abstract class ListWidgetFrontendContribution extends AbstractViewContribution<ListWidget> implements FrontendApplicationContribution {
@@ -29,4 +31,13 @@ export class LibraryListWidgetFrontendContribution extends ListWidgetFrontendCon
2931
});
3032
}
3133

34+
registerMenus(menus: MenuModelRegistry): void {
35+
if (this.toggleCommand) {
36+
menus.registerMenuAction(ArduinoMenus.SKETCH, {
37+
commandId: this.toggleCommand.id,
38+
label: 'Manage Libraries...'
39+
});
40+
}
41+
}
42+
3243
}

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

+2-9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import { FrontendApplication } from "@theia/core/lib/browser";
55
@injectable()
66
export class ArduinoMenuContribution extends BrowserMenuBarContribution {
77
onStart(app: FrontendApplication): void {
8-
if (this.isProMode()) {
9-
const menu = this.factory.createMenuBar();
10-
app.shell.addWidget(menu, { area: 'top' });
11-
}
12-
}
13-
14-
protected isProMode(): boolean {
15-
// TODO ask for pro preference
16-
return false;
8+
const menu = this.factory.createMenuBar();
9+
app.shell.addWidget(menu, { area: 'top' });
1710
}
1811
}

arduino-ide-extension/src/browser/style/arduino.useable.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ is not optimized for dense, information rich UIs.
4949
/* Special font colors */
5050
--theia-ui-icon-font-color: #ffffff;
5151
--theia-ui-bar-font-color0: var(--theia-ui-font-color0);
52-
--theia-ui-bar-font-color1: var(--theia-ui-font-color1);
52+
--theia-ui-bar-font-color1: var(--theia-inverse-ui-font-color0); /* var(--theia-ui-font-color1); */
5353
/* Use the inverse UI colors against the brand/accent/warn/error colors. */
5454
--theia-inverse-ui-font-color0: rgba(255, 255, 255, 1.0);
5555
--theia-inverse-ui-font-color2: rgba(255, 255, 255, 0.7);

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

+13-19
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@ import { isOSX } from '@theia/core';
77
@injectable()
88
export class ElectronArduinoMenuContribution extends ElectronMenuContribution {
99
onStart(app: FrontendApplication): void {
10-
if (this.isProMode()) {
11-
const currentWindow = electron.remote.getCurrentWindow();
12-
const createdMenuBar = this.factory.createMenuBar();
10+
const currentWindow = electron.remote.getCurrentWindow();
11+
const createdMenuBar = this.factory.createMenuBar();
1312

14-
if (isOSX) {
15-
electron.remote.Menu.setApplicationMenu(createdMenuBar);
16-
currentWindow.on('focus', () =>
17-
// OSX: Recreate the menus when changing windows.
18-
// OSX only has one menu bar for all windows, so we need to swap
19-
// between them as the user switch windows.
20-
electron.remote.Menu.setApplicationMenu(this.factory.createMenuBar())
21-
);
13+
if (isOSX) {
14+
electron.remote.Menu.setApplicationMenu(createdMenuBar);
15+
currentWindow.on('focus', () =>
16+
// OSX: Recreate the menus when changing windows.
17+
// OSX only has one menu bar for all windows, so we need to swap
18+
// between them as the user switch windows.
19+
electron.remote.Menu.setApplicationMenu(this.factory.createMenuBar())
20+
);
2221

23-
} else {
24-
// Unix/Windows: Set the per-window menus
25-
currentWindow.setMenu(createdMenuBar);
26-
}
22+
} else {
23+
// Unix/Windows: Set the per-window menus
24+
currentWindow.setMenu(createdMenuBar);
2725
}
2826
}
29-
30-
protected isProMode(): boolean {
31-
return false;
32-
}
3327
}

0 commit comments

Comments
 (0)