mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-25 20:26:38 +00:00
fixed menu updater.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
d51bf9fb40
commit
d9f4adfb78
@ -1,17 +1,14 @@
|
|||||||
import { Command } from '@theia/core/lib/common/command';
|
import { Command } from '@theia/core/lib/common/command';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated all these commands should go under contributions and have their command, menu, keybinding, and toolbar contributions.
|
||||||
|
*/
|
||||||
export namespace ArduinoCommands {
|
export namespace ArduinoCommands {
|
||||||
|
|
||||||
const category = 'Arduino';
|
|
||||||
|
|
||||||
export const TOGGLE_COMPILE_FOR_DEBUG: Command = {
|
export const TOGGLE_COMPILE_FOR_DEBUG: Command = {
|
||||||
id: 'arduino-toggle-compile-for-debug'
|
id: 'arduino-toggle-compile-for-debug'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const OPEN_FILE_NAVIGATOR: Command = {
|
|
||||||
id: 'arduino-open-file-navigator'
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlike `OPEN_SKETCH`, it opens all files from a sketch folder. (ino, cpp, etc...)
|
* Unlike `OPEN_SKETCH`, it opens all files from a sketch folder. (ino, cpp, etc...)
|
||||||
*/
|
*/
|
||||||
@ -30,10 +27,4 @@ export namespace ArduinoCommands {
|
|||||||
id: 'arduino-toggle-advanced-mode-toolbar'
|
id: 'arduino-toggle-advanced-mode-toolbar'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const OPEN_CLI_CONFIG: Command = {
|
|
||||||
id: 'arduino-open-cli-config',
|
|
||||||
label: 'Open CLI Configuration',
|
|
||||||
category
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
|||||||
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
|
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
|
||||||
import {
|
import {
|
||||||
ContextMenuRenderer, StatusBar, StatusBarAlignment, FrontendApplicationContribution,
|
ContextMenuRenderer, StatusBar, StatusBarAlignment, FrontendApplicationContribution,
|
||||||
FrontendApplication, KeybindingContribution, KeybindingRegistry, OpenerService, open
|
FrontendApplication, KeybindingContribution, KeybindingRegistry, OpenerService
|
||||||
} from '@theia/core/lib/browser';
|
} from '@theia/core/lib/browser';
|
||||||
import { FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
import { FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
||||||
import { FileSystem } from '@theia/filesystem/lib/common';
|
import { FileSystem } from '@theia/filesystem/lib/common';
|
||||||
@ -228,9 +228,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
|
|||||||
isToggled: () => this.editorMode.proMode,
|
isToggled: () => this.editorMode.proMode,
|
||||||
execute: () => this.editorMode.toggleProMode()
|
execute: () => this.editorMode.toggleProMode()
|
||||||
});
|
});
|
||||||
registry.registerCommand(ArduinoCommands.OPEN_CLI_CONFIG, {
|
|
||||||
execute: () => this.configService.getCliConfigFileUri().then(uri => open(this.openerService, new URI(uri)))
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry) {
|
registerMenus(registry: MenuModelRegistry) {
|
||||||
|
@ -29,10 +29,10 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
|
|||||||
|
|
||||||
protected readonly toDisposeOnBoardChange = new DisposableCollection();
|
protected readonly toDisposeOnBoardChange = new DisposableCollection();
|
||||||
|
|
||||||
onStart(): void {
|
async onStart(): Promise<void> {
|
||||||
this.boardsDataStore.onChanged(() => this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard));
|
await this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard);
|
||||||
this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) => this.updateMenuActions(selectedBoard));
|
this.boardsDataStore.onChanged(async () => await this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard));
|
||||||
this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard);
|
this.boardsServiceClient.onBoardsConfigChanged(async ({ selectedBoard }) => await this.updateMenuActions(selectedBoard));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async updateMenuActions(selectedBoard: Board | undefined): Promise<void> {
|
protected async updateMenuActions(selectedBoard: Board | undefined): Promise<void> {
|
||||||
@ -43,7 +43,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
|
|||||||
if (fqbn) {
|
if (fqbn) {
|
||||||
const { configOptions, programmers, selectedProgrammer } = await this.boardsDataStore.getData(fqbn);
|
const { configOptions, programmers, selectedProgrammer } = await this.boardsDataStore.getData(fqbn);
|
||||||
if (configOptions.length) {
|
if (configOptions.length) {
|
||||||
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS, 'z01_boardsConfig']; // `z_` is for ordering.
|
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP, 'z01_boardsConfig']; // `z_` is for ordering.
|
||||||
for (const { label, option, values } of configOptions.sort(ConfigOption.LABEL_COMPARATOR)) {
|
for (const { label, option, values } of configOptions.sort(ConfigOption.LABEL_COMPARATOR)) {
|
||||||
const menuPath = [...boardsConfigMenuPath, `${option}`];
|
const menuPath = [...boardsConfigMenuPath, `${option}`];
|
||||||
const commands = new Map<string, Disposable & { label: string }>()
|
const commands = new Map<string, Disposable & { label: string }>()
|
||||||
@ -70,9 +70,10 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (programmers.length) {
|
if (programmers.length) {
|
||||||
const programmersMenuPath = [...ArduinoMenus.TOOLS, 'z02_programmers'];
|
const programmersMenuPath = [...ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP, 'z02_programmers'];
|
||||||
const label = selectedProgrammer ? `Programmer: "${selectedProgrammer.name}"` : 'Programmer'
|
const label = selectedProgrammer ? `Programmer: "${selectedProgrammer.name}"` : 'Programmer'
|
||||||
this.menuRegistry.registerSubmenu(programmersMenuPath, label);
|
this.menuRegistry.registerSubmenu(programmersMenuPath, label);
|
||||||
|
this.toDisposeOnBoardChange.push(Disposable.create(() => this.unregisterSubmenu(programmersMenuPath)));
|
||||||
for (const programmer of programmers) {
|
for (const programmer of programmers) {
|
||||||
const { id, name } = programmer;
|
const { id, name } = programmer;
|
||||||
const command = { id: `${fqbn}-programmer--${id}` };
|
const command = { id: `${fqbn}-programmer--${id}` };
|
||||||
@ -81,10 +82,10 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
|
|||||||
isToggled: () => Programmer.equals(programmer, selectedProgrammer)
|
isToggled: () => Programmer.equals(programmer, selectedProgrammer)
|
||||||
};
|
};
|
||||||
this.menuRegistry.registerMenuAction(programmersMenuPath, { commandId: command.id, label: name });
|
this.menuRegistry.registerMenuAction(programmersMenuPath, { commandId: command.id, label: name });
|
||||||
|
this.commandRegistry.registerCommand(command, handler);
|
||||||
this.toDisposeOnBoardChange.pushAll([
|
this.toDisposeOnBoardChange.pushAll([
|
||||||
this.commandRegistry.registerCommand(command, handler),
|
Disposable.create(() => this.commandRegistry.unregisterCommand(command)),
|
||||||
Disposable.create(() => this.unregisterSubmenu(programmersMenuPath)),
|
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command.id))
|
||||||
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command, programmersMenuPath))
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendCont
|
|||||||
rank: 600
|
rank: 600
|
||||||
},
|
},
|
||||||
toggleCommandId: BoardsListWidgetFrontendContribution.OPEN_MANAGER,
|
toggleCommandId: BoardsListWidgetFrontendContribution.OPEN_MANAGER,
|
||||||
toggleKeybinding: 'ctrlcmd+shift+b'
|
toggleKeybinding: 'CtrlCmd+Shift+B'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendCont
|
|||||||
|
|
||||||
registerMenus(menus: MenuModelRegistry): void {
|
registerMenus(menus: MenuModelRegistry): void {
|
||||||
if (this.toggleCommand) {
|
if (this.toggleCommand) {
|
||||||
menus.registerMenuAction(ArduinoMenus.TOOLS, {
|
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
||||||
commandId: this.toggleCommand.id,
|
commandId: this.toggleCommand.id,
|
||||||
label: 'Boards Manager...',
|
label: 'Boards Manager...',
|
||||||
order: '4'
|
order: '4'
|
||||||
|
@ -4,7 +4,7 @@ import { Event, Emitter } from '@theia/core/lib/common/event';
|
|||||||
import { CommandService } from '@theia/core/lib/common/command';
|
import { CommandService } from '@theia/core/lib/common/command';
|
||||||
import { MessageService } from '@theia/core/lib/common/message-service';
|
import { MessageService } from '@theia/core/lib/common/message-service';
|
||||||
import { ConfigServiceClient, Config } from '../common/protocol';
|
import { ConfigServiceClient, Config } from '../common/protocol';
|
||||||
import { ArduinoCommands } from './arduino-commands';
|
import { Settings } from './contributions/settings';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ConfigServiceClientImpl implements ConfigServiceClient {
|
export class ConfigServiceClientImpl implements ConfigServiceClient {
|
||||||
@ -32,7 +32,7 @@ export class ConfigServiceClientImpl implements ConfigServiceClient {
|
|||||||
this.invalidConfigPopup = this.messageService.error(`Your CLI configuration is invalid. Do you want to correct it now?`, 'No', 'Yes')
|
this.invalidConfigPopup = this.messageService.error(`Your CLI configuration is invalid. Do you want to correct it now?`, 'No', 'Yes')
|
||||||
.then(answer => {
|
.then(answer => {
|
||||||
if (answer === 'Yes') {
|
if (answer === 'Yes') {
|
||||||
this.commandService.executeCommand(ArduinoCommands.OPEN_CLI_CONFIG.id)
|
this.commandService.executeCommand(Settings.Commands.OPEN_CLI_CONFIG.id)
|
||||||
}
|
}
|
||||||
this.invalidConfigPopup = undefined;
|
this.invalidConfigPopup = undefined;
|
||||||
})
|
})
|
||||||
|
@ -27,7 +27,7 @@ export class LibraryListWidgetFrontendContribution extends AbstractViewContribut
|
|||||||
|
|
||||||
registerMenus(menus: MenuModelRegistry): void {
|
registerMenus(menus: MenuModelRegistry): void {
|
||||||
if (this.toggleCommand) {
|
if (this.toggleCommand) {
|
||||||
menus.registerMenuAction(ArduinoMenus.TOOLS, {
|
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
||||||
commandId: this.toggleCommand.id,
|
commandId: this.toggleCommand.id,
|
||||||
label: 'Manage Libraries...',
|
label: 'Manage Libraries...',
|
||||||
order: '3'
|
order: '3'
|
||||||
|
@ -28,7 +28,10 @@ export namespace ArduinoMenus {
|
|||||||
|
|
||||||
// -- Tools
|
// -- Tools
|
||||||
export const TOOLS = [...MAIN_MENU_BAR, '4_tools'];
|
export const TOOLS = [...MAIN_MENU_BAR, '4_tools'];
|
||||||
|
// `Auto Format`, `Library Manager...`, `Boards Manager...`
|
||||||
export const TOOLS__MAIN_GROUP = [...TOOLS, '0_main'];
|
export const TOOLS__MAIN_GROUP = [...TOOLS, '0_main'];
|
||||||
|
// Core settings, such as `Processor` and `Programmers` for the board.
|
||||||
|
export const TOOLS__BOARD_SETTINGS_GROUP = [...TOOLS, '1_board_settings'];
|
||||||
|
|
||||||
// Context menu
|
// Context menu
|
||||||
// -- Open
|
// -- Open
|
||||||
|
@ -42,13 +42,13 @@ export class MonitorViewContribution extends AbstractViewContribution<MonitorWid
|
|||||||
area: 'bottom'
|
area: 'bottom'
|
||||||
},
|
},
|
||||||
toggleCommandId: MonitorViewContribution.TOGGLE_SERIAL_MONITOR,
|
toggleCommandId: MonitorViewContribution.TOGGLE_SERIAL_MONITOR,
|
||||||
toggleKeybinding: 'ctrlcmd+shift+m'
|
toggleKeybinding: 'CtrlCmd+Shift+M'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenus(menus: MenuModelRegistry): void {
|
registerMenus(menus: MenuModelRegistry): void {
|
||||||
if (this.toggleCommand) {
|
if (this.toggleCommand) {
|
||||||
menus.registerMenuAction(ArduinoMenus.TOOLS, {
|
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
||||||
commandId: this.toggleCommand.id,
|
commandId: this.toggleCommand.id,
|
||||||
label: 'Serial Monitor',
|
label: 'Serial Monitor',
|
||||||
order: '5'
|
order: '5'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user