Skip to content

Commit d9f4adf

Browse files
author
Akos Kitta
committed
fixed menu updater.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent d51bf9f commit d9f4adf

8 files changed

+24
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { Command } from '@theia/core/lib/common/command';
22

3+
/**
4+
* @deprecated all these commands should go under contributions and have their command, menu, keybinding, and toolbar contributions.
5+
*/
36
export namespace ArduinoCommands {
47

5-
const category = 'Arduino';
6-
78
export const TOGGLE_COMPILE_FOR_DEBUG: Command = {
89
id: 'arduino-toggle-compile-for-debug'
910
};
1011

11-
export const OPEN_FILE_NAVIGATOR: Command = {
12-
id: 'arduino-open-file-navigator'
13-
};
14-
1512
/**
1613
* Unlike `OPEN_SKETCH`, it opens all files from a sketch folder. (ino, cpp, etc...)
1714
*/
@@ -30,10 +27,4 @@ export namespace ArduinoCommands {
3027
id: 'arduino-toggle-advanced-mode-toolbar'
3128
};
3229

33-
export const OPEN_CLI_CONFIG: Command = {
34-
id: 'arduino-open-cli-config',
35-
label: 'Open CLI Configuration',
36-
category
37-
};
38-
3930
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ArduinoToolbar } from './toolbar/arduino-toolbar';
1212
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
1313
import {
1414
ContextMenuRenderer, StatusBar, StatusBarAlignment, FrontendApplicationContribution,
15-
FrontendApplication, KeybindingContribution, KeybindingRegistry, OpenerService, open
15+
FrontendApplication, KeybindingContribution, KeybindingRegistry, OpenerService
1616
} from '@theia/core/lib/browser';
1717
import { FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
1818
import { FileSystem } from '@theia/filesystem/lib/common';
@@ -228,9 +228,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
228228
isToggled: () => this.editorMode.proMode,
229229
execute: () => this.editorMode.toggleProMode()
230230
});
231-
registry.registerCommand(ArduinoCommands.OPEN_CLI_CONFIG, {
232-
execute: () => this.configService.getCliConfigFileUri().then(uri => open(this.openerService, new URI(uri)))
233-
});
234231
}
235232

236233
registerMenus(registry: MenuModelRegistry) {

arduino-ide-extension/src/browser/boards/boards-data-menu-updater.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
2929

3030
protected readonly toDisposeOnBoardChange = new DisposableCollection();
3131

32-
onStart(): void {
33-
this.boardsDataStore.onChanged(() => this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard));
34-
this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) => this.updateMenuActions(selectedBoard));
35-
this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard);
32+
async onStart(): Promise<void> {
33+
await this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard);
34+
this.boardsDataStore.onChanged(async () => await this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard));
35+
this.boardsServiceClient.onBoardsConfigChanged(async ({ selectedBoard }) => await this.updateMenuActions(selectedBoard));
3636
}
3737

3838
protected async updateMenuActions(selectedBoard: Board | undefined): Promise<void> {
@@ -43,7 +43,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
4343
if (fqbn) {
4444
const { configOptions, programmers, selectedProgrammer } = await this.boardsDataStore.getData(fqbn);
4545
if (configOptions.length) {
46-
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS, 'z01_boardsConfig']; // `z_` is for ordering.
46+
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP, 'z01_boardsConfig']; // `z_` is for ordering.
4747
for (const { label, option, values } of configOptions.sort(ConfigOption.LABEL_COMPARATOR)) {
4848
const menuPath = [...boardsConfigMenuPath, `${option}`];
4949
const commands = new Map<string, Disposable & { label: string }>()
@@ -70,9 +70,10 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
7070
}
7171
}
7272
if (programmers.length) {
73-
const programmersMenuPath = [...ArduinoMenus.TOOLS, 'z02_programmers'];
73+
const programmersMenuPath = [...ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP, 'z02_programmers'];
7474
const label = selectedProgrammer ? `Programmer: "${selectedProgrammer.name}"` : 'Programmer'
7575
this.menuRegistry.registerSubmenu(programmersMenuPath, label);
76+
this.toDisposeOnBoardChange.push(Disposable.create(() => this.unregisterSubmenu(programmersMenuPath)));
7677
for (const programmer of programmers) {
7778
const { id, name } = programmer;
7879
const command = { id: `${fqbn}-programmer--${id}` };
@@ -81,10 +82,10 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
8182
isToggled: () => Programmer.equals(programmer, selectedProgrammer)
8283
};
8384
this.menuRegistry.registerMenuAction(programmersMenuPath, { commandId: command.id, label: name });
85+
this.commandRegistry.registerCommand(command, handler);
8486
this.toDisposeOnBoardChange.pushAll([
85-
this.commandRegistry.registerCommand(command, handler),
86-
Disposable.create(() => this.unregisterSubmenu(programmersMenuPath)),
87-
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command, programmersMenuPath))
87+
Disposable.create(() => this.commandRegistry.unregisterCommand(command)),
88+
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command.id))
8889
]);
8990
}
9091
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendCont
1919
rank: 600
2020
},
2121
toggleCommandId: BoardsListWidgetFrontendContribution.OPEN_MANAGER,
22-
toggleKeybinding: 'ctrlcmd+shift+b'
22+
toggleKeybinding: 'CtrlCmd+Shift+B'
2323
});
2424
}
2525

@@ -29,7 +29,7 @@ export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendCont
2929

3030
registerMenus(menus: MenuModelRegistry): void {
3131
if (this.toggleCommand) {
32-
menus.registerMenuAction(ArduinoMenus.TOOLS, {
32+
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
3333
commandId: this.toggleCommand.id,
3434
label: 'Boards Manager...',
3535
order: '4'

arduino-ide-extension/src/browser/config-service-client-impl.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Event, Emitter } from '@theia/core/lib/common/event';
44
import { CommandService } from '@theia/core/lib/common/command';
55
import { MessageService } from '@theia/core/lib/common/message-service';
66
import { ConfigServiceClient, Config } from '../common/protocol';
7-
import { ArduinoCommands } from './arduino-commands';
7+
import { Settings } from './contributions/settings';
88

99
@injectable()
1010
export class ConfigServiceClientImpl implements ConfigServiceClient {
@@ -32,7 +32,7 @@ export class ConfigServiceClientImpl implements ConfigServiceClient {
3232
this.invalidConfigPopup = this.messageService.error(`Your CLI configuration is invalid. Do you want to correct it now?`, 'No', 'Yes')
3333
.then(answer => {
3434
if (answer === 'Yes') {
35-
this.commandService.executeCommand(ArduinoCommands.OPEN_CLI_CONFIG.id)
35+
this.commandService.executeCommand(Settings.Commands.OPEN_CLI_CONFIG.id)
3636
}
3737
this.invalidConfigPopup = undefined;
3838
})

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.TOOLS, {
30+
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
3131
commandId: this.toggleCommand.id,
3232
label: 'Manage Libraries...',
3333
order: '3'

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

+3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export namespace ArduinoMenus {
2828

2929
// -- Tools
3030
export const TOOLS = [...MAIN_MENU_BAR, '4_tools'];
31+
// `Auto Format`, `Library Manager...`, `Boards Manager...`
3132
export const TOOLS__MAIN_GROUP = [...TOOLS, '0_main'];
33+
// Core settings, such as `Processor` and `Programmers` for the board.
34+
export const TOOLS__BOARD_SETTINGS_GROUP = [...TOOLS, '1_board_settings'];
3235

3336
// Context menu
3437
// -- Open

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ export class MonitorViewContribution extends AbstractViewContribution<MonitorWid
4242
area: 'bottom'
4343
},
4444
toggleCommandId: MonitorViewContribution.TOGGLE_SERIAL_MONITOR,
45-
toggleKeybinding: 'ctrlcmd+shift+m'
45+
toggleKeybinding: 'CtrlCmd+Shift+M'
4646
})
4747
}
4848

4949
registerMenus(menus: MenuModelRegistry): void {
5050
if (this.toggleCommand) {
51-
menus.registerMenuAction(ArduinoMenus.TOOLS, {
51+
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
5252
commandId: this.toggleCommand.id,
5353
label: 'Serial Monitor',
5454
order: '5'

0 commit comments

Comments
 (0)