Skip to content

Commit d569622

Browse files
committed
Fixed: Commands that are registered to toolbar did not show up in Electron menu
1 parent 69c7383 commit d569622

File tree

5 files changed

+131
-98
lines changed

5 files changed

+131
-98
lines changed

arduino-ide-extension/src/browser/arduino-commands.ts

+9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ export namespace ArduinoCommands {
66
id: 'arduino-verify',
77
label: 'Verify Sketch'
88
}
9+
export const VERIFY_TOOLBAR: Command = {
10+
id: 'arduino-verify-toolbar',
11+
}
912

1013
export const UPLOAD: Command = {
1114
id: 'arduino-upload',
1215
label: 'Upload Sketch'
1316
}
17+
export const UPLOAD_TOOLBAR: Command = {
18+
id: 'arduino-upload-toolbar',
19+
}
1420

1521
export const TOGGLE_COMPILE_FOR_DEBUG: Command = {
1622
id: "arduino-toggle-compile-for-debug"
@@ -46,4 +52,7 @@ export namespace ArduinoCommands {
4652
export const TOGGLE_ADVANCED_MODE: Command = {
4753
id: "arduino-toggle-advanced-mode"
4854
}
55+
export const TOGGLE_ADVANCED_MODE_TOOLBAR: Command = {
56+
id: "arduino-toggle-advanced-mode-toolbar"
57+
}
4958
}

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

+93-88
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
181181
registerToolbarItems(registry: TabBarToolbarRegistry): void {
182182
registry.registerItem({
183183
id: ArduinoCommands.VERIFY.id,
184-
command: ArduinoCommands.VERIFY.id,
184+
command: ArduinoCommands.VERIFY_TOOLBAR.id,
185185
tooltip: 'Verify'
186186
});
187187
registry.registerItem({
188188
id: ArduinoCommands.UPLOAD.id,
189-
command: ArduinoCommands.UPLOAD.id,
189+
command: ArduinoCommands.UPLOAD_TOOLBAR.id,
190190
tooltip: 'Upload'
191191
});
192192
registry.registerItem({
@@ -213,17 +213,15 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
213213
});
214214
registry.registerItem({
215215
id: 'toggle-serial-monitor',
216-
command: MonitorViewContribution.OPEN_SERIAL_MONITOR,
217-
tooltip: 'Toggle Serial Monitor',
218-
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right'
216+
command: MonitorViewContribution.TOGGLE_SERIAL_MONITOR_TOOLBAR,
217+
tooltip: 'Toggle Serial Monitor'
219218
});
220219

221220
registry.registerItem({
222221
id: ArduinoCommands.TOGGLE_ADVANCED_MODE.id,
223-
command: ArduinoCommands.TOGGLE_ADVANCED_MODE.id,
222+
command: ArduinoCommands.TOGGLE_ADVANCED_MODE_TOOLBAR.id,
224223
tooltip: 'Toggle Advanced Mode',
225-
text: (this.editorMode.proMode ? '$(toggle-on)' : '$(toggle-off)'),
226-
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right'
224+
text: (this.editorMode.proMode ? '$(toggle-on)' : '$(toggle-off)')
227225
});
228226
}
229227

@@ -266,38 +264,11 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
266264
}
267265

268266
registry.registerCommand(ArduinoCommands.VERIFY, {
267+
execute: this.verify.bind(this)
268+
});
269+
registry.registerCommand(ArduinoCommands.VERIFY_TOOLBAR, {
269270
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
270-
isEnabled: widget => true,
271-
execute: async () => {
272-
const widget = this.getCurrentWidget();
273-
if (widget instanceof EditorWidget) {
274-
await widget.saveable.save();
275-
}
276-
277-
const uri = this.toUri(widget);
278-
if (!uri) {
279-
return;
280-
}
281-
282-
try {
283-
const { boardsConfig } = this.boardsServiceClient;
284-
if (!boardsConfig || !boardsConfig.selectedBoard) {
285-
throw new Error('No boards selected. Please select a board.');
286-
}
287-
if (!boardsConfig.selectedBoard.fqbn) {
288-
throw new Error(`No core is installed for ${boardsConfig.selectedBoard.name}. Please install the board.`);
289-
}
290-
// Reveal the Output view asynchronously (don't await it)
291-
this.outputContribution.openView({ reveal: true });
292-
await this.coreService.compile({
293-
uri: uri.toString(),
294-
board: boardsConfig.selectedBoard,
295-
optimizeForDebug: this.editorMode.compileForDebug
296-
});
297-
} catch (e) {
298-
await this.messageService.error(e.toString());
299-
}
300-
}
271+
execute: this.verify.bind(this)
301272
});
302273

303274
registry.registerCommand(ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG, {
@@ -309,54 +280,15 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
309280
});
310281

311282
registry.registerCommand(ArduinoCommands.UPLOAD, {
283+
execute: this.upload.bind(this)
284+
});
285+
registry.registerCommand(ArduinoCommands.UPLOAD_TOOLBAR, {
312286
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
313-
isEnabled: widget => true,
314-
execute: async () => {
315-
const widget = this.getCurrentWidget();
316-
if (widget instanceof EditorWidget) {
317-
await widget.saveable.save();
318-
}
319-
320-
const uri = this.toUri(widget);
321-
if (!uri) {
322-
return;
323-
}
324-
325-
const monitorConfig = this.monitorConnection.monitorConfig;
326-
if (monitorConfig) {
327-
await this.monitorConnection.disconnect();
328-
}
329-
330-
try {
331-
const { boardsConfig } = this.boardsServiceClient;
332-
if (!boardsConfig || !boardsConfig.selectedBoard) {
333-
throw new Error('No boards selected. Please select a board.');
334-
}
335-
const { selectedPort } = boardsConfig;
336-
if (!selectedPort) {
337-
throw new Error('No ports selected. Please select a port.');
338-
}
339-
// Reveal the Output view asynchronously (don't await it)
340-
this.outputContribution.openView({ reveal: true });
341-
await this.coreService.upload({
342-
uri: uri.toString(),
343-
board: boardsConfig.selectedBoard,
344-
port: selectedPort.address,
345-
optimizeForDebug: this.editorMode.compileForDebug
346-
});
347-
} catch (e) {
348-
await this.messageService.error(e.toString());
349-
} finally {
350-
if (monitorConfig) {
351-
await this.monitorConnection.connect(monitorConfig);
352-
}
353-
}
354-
}
287+
execute: this.upload.bind(this)
355288
});
356289

357290
registry.registerCommand(ArduinoCommands.SHOW_OPEN_CONTEXT_MENU, {
358291
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
359-
isEnabled: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
360292
execute: async (widget: Widget, target: EventTarget) => {
361293
if (this.wsSketchCount) {
362294
const el = (target as HTMLElement).parentElement;
@@ -385,7 +317,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
385317
});
386318

387319
registry.registerCommand(ArduinoCommands.SAVE_SKETCH, {
388-
isEnabled: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
389320
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
390321
execute: async (sketch: Sketch) => {
391322
registry.executeCommand(CommonCommands.SAVE_ALL.id);
@@ -419,15 +350,89 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
419350
});
420351

421352
registry.registerCommand(ArduinoCommands.TOGGLE_ADVANCED_MODE, {
422-
execute: () => {
423-
this.editorMode.toggleProMode();
424-
this.editorMode.menuContentChanged.fire();
425-
},
353+
isToggled: () => this.editorMode.proMode,
354+
execute: () => this.editorMode.toggleProMode()
355+
});
356+
registry.registerCommand(ArduinoCommands.TOGGLE_ADVANCED_MODE_TOOLBAR, {
426357
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right',
427-
isToggled: () => this.editorMode.proMode
358+
isToggled: () => this.editorMode.proMode,
359+
execute: () => this.editorMode.toggleProMode()
428360
});
429361
}
430362

363+
protected async verify() {
364+
const widget = this.getCurrentWidget();
365+
if (widget instanceof EditorWidget) {
366+
await widget.saveable.save();
367+
}
368+
369+
const uri = this.toUri(widget);
370+
if (!uri) {
371+
return;
372+
}
373+
374+
try {
375+
const { boardsConfig } = this.boardsServiceClient;
376+
if (!boardsConfig || !boardsConfig.selectedBoard) {
377+
throw new Error('No boards selected. Please select a board.');
378+
}
379+
if (!boardsConfig.selectedBoard.fqbn) {
380+
throw new Error(`No core is installed for ${boardsConfig.selectedBoard.name}. Please install the board.`);
381+
}
382+
// Reveal the Output view asynchronously (don't await it)
383+
this.outputContribution.openView({ reveal: true });
384+
await this.coreService.compile({
385+
uri: uri.toString(),
386+
board: boardsConfig.selectedBoard,
387+
optimizeForDebug: this.editorMode.compileForDebug
388+
});
389+
} catch (e) {
390+
await this.messageService.error(e.toString());
391+
}
392+
}
393+
394+
protected async upload() {
395+
const widget = this.getCurrentWidget();
396+
if (widget instanceof EditorWidget) {
397+
await widget.saveable.save();
398+
}
399+
400+
const uri = this.toUri(widget);
401+
if (!uri) {
402+
return;
403+
}
404+
405+
const monitorConfig = this.monitorConnection.monitorConfig;
406+
if (monitorConfig) {
407+
await this.monitorConnection.disconnect();
408+
}
409+
410+
try {
411+
const { boardsConfig } = this.boardsServiceClient;
412+
if (!boardsConfig || !boardsConfig.selectedBoard) {
413+
throw new Error('No boards selected. Please select a board.');
414+
}
415+
const { selectedPort } = boardsConfig;
416+
if (!selectedPort) {
417+
throw new Error('No ports selected. Please select a port.');
418+
}
419+
// Reveal the Output view asynchronously (don't await it)
420+
this.outputContribution.openView({ reveal: true });
421+
await this.coreService.upload({
422+
uri: uri.toString(),
423+
board: boardsConfig.selectedBoard,
424+
port: selectedPort.address,
425+
optimizeForDebug: this.editorMode.compileForDebug
426+
});
427+
} catch (e) {
428+
await this.messageService.error(e.toString());
429+
} finally {
430+
if (monitorConfig) {
431+
await this.monitorConnection.connect(monitorConfig);
432+
}
433+
}
434+
}
435+
431436
registerMenus(registry: MenuModelRegistry) {
432437
if (!this.editorMode.proMode) {
433438
// If are not in pro-mode, we have to disable the context menu for the tabs.

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { injectable } from 'inversify';
22
import { Emitter } from '@theia/core/lib/common/event';
3-
import { ApplicationShell, FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser';
4-
import { ArduinoShellLayoutRestorer } from './shell/arduino-shell-layout-restorer';
3+
import { ApplicationShell, FrontendApplicationContribution, FrontendApplication, Widget } from '@theia/core/lib/browser';
54
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
65
import { EditorWidget } from '@theia/editor/lib/browser';
6+
import { ArduinoShellLayoutRestorer } from './shell/arduino-shell-layout-restorer';
7+
import { BoardsListWidget } from './boards/boards-list-widget';
8+
import { LibraryListWidget } from './library/library-list-widget';
79

810
@injectable()
911
export class EditorMode implements FrontendApplicationContribution {
@@ -31,9 +33,9 @@ export class EditorMode implements FrontendApplicationContribution {
3133
window.localStorage.setItem(EditorMode.PRO_MODE_KEY, String(inAdvancedMode));
3234
if (!inAdvancedMode) {
3335
const { shell } = this.app;
34-
// Close all widget that is neither editor nor `Output`.
36+
// Close all widgets that are neither editor nor `Output` / `Boards Manager` / `Library Manager`.
3537
for (const area of ['left', 'right', 'bottom', 'main'] as Array<ApplicationShell.Area>) {
36-
shell.closeTabs(area, ({ owner }) => !(owner instanceof EditorWidget || owner instanceof OutputWidget));
38+
shell.closeTabs(area, title => !this.isInSimpleMode(title.owner));
3739
}
3840
}
3941
// `storeLayout` has a sync API but the implementation is async, we store the layout manually before we reload the page.
@@ -44,6 +46,13 @@ export class EditorMode implements FrontendApplicationContribution {
4446
window.location.reload(true);
4547
}
4648

49+
protected isInSimpleMode(widget: Widget): boolean {
50+
return widget instanceof EditorWidget
51+
|| widget instanceof OutputWidget
52+
|| widget instanceof BoardsListWidget
53+
|| widget instanceof LibraryListWidget;
54+
}
55+
4756
get compileForDebug(): boolean {
4857
const value = window.localStorage.getItem(EditorMode.COMPILE_FOR_DEBUG_KEY);
4958
return value === 'true';

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class LibraryListWidgetFrontendContribution extends AbstractViewContribut
2727

2828
registerMenus(menus: MenuModelRegistry): void {
2929
if (this.toggleCommand) {
30-
menus.registerMenuAction(ArduinoMenus.SKETCH, {
30+
menus.registerMenuAction(ArduinoMenus.TOOLS, {
3131
commandId: this.toggleCommand.id,
3232
label: 'Manage Libraries...'
3333
});

arduino-ide-extension/src/browser/monitor/monitor-view-contribution.tsx

+15-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { MonitorWidget } from "./monitor-widget";
55
import { MenuModelRegistry, Command, CommandRegistry } from "@theia/core";
66
import { ArduinoMenus } from "../arduino-frontend-contribution";
77
import { TabBarToolbarContribution, TabBarToolbarRegistry } from "@theia/core/lib/browser/shell/tab-bar-toolbar";
8-
import { MonitorModel } from './monitor-model';
98
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
9+
import { MonitorModel } from './monitor-model';
1010

1111
export namespace SerialMonitor {
1212
export namespace Commands {
@@ -29,7 +29,8 @@ export namespace SerialMonitor {
2929
@injectable()
3030
export class MonitorViewContribution extends AbstractViewContribution<MonitorWidget> implements TabBarToolbarContribution {
3131

32-
static readonly OPEN_SERIAL_MONITOR = MonitorWidget.ID + ':toggle';
32+
static readonly TOGGLE_SERIAL_MONITOR = MonitorWidget.ID + ':toggle';
33+
static readonly TOGGLE_SERIAL_MONITOR_TOOLBAR = MonitorWidget.ID + ':toggle-toolbar';
3334

3435
@inject(MonitorModel) protected readonly model: MonitorModel;
3536

@@ -40,7 +41,7 @@ export class MonitorViewContribution extends AbstractViewContribution<MonitorWid
4041
defaultWidgetOptions: {
4142
area: 'bottom'
4243
},
43-
toggleCommandId: MonitorViewContribution.OPEN_SERIAL_MONITOR,
44+
toggleCommandId: MonitorViewContribution.TOGGLE_SERIAL_MONITOR,
4445
toggleKeybinding: 'ctrlcmd+shift+m'
4546
})
4647
}
@@ -89,8 +90,17 @@ export class MonitorViewContribution extends AbstractViewContribution<MonitorWid
8990
execute: () => this.openView({
9091
toggle: true,
9192
activate: true
92-
}),
93-
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right'
93+
})
94+
});
95+
const toolbarCmd = {
96+
id: MonitorViewContribution.TOGGLE_SERIAL_MONITOR_TOOLBAR
97+
}
98+
commands.registerCommand(toolbarCmd, {
99+
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right',
100+
execute: () => this.openView({
101+
toggle: true,
102+
activate: true
103+
})
94104
});
95105
}
96106
}

0 commit comments

Comments
 (0)