mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-17 17:46:33 +00:00
fixed the programmer menu.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
e77c9721cd
commit
e1d86d0bda
@ -82,7 +82,7 @@ import {
|
|||||||
} from '@theia/core/lib/browser/connection-status-service';
|
} from '@theia/core/lib/browser/connection-status-service';
|
||||||
import { ConfigServiceClientImpl } from './config-service-client-impl';
|
import { ConfigServiceClientImpl } from './config-service-client-impl';
|
||||||
import { CoreServiceClientImpl } from './core-service-client-impl';
|
import { CoreServiceClientImpl } from './core-service-client-impl';
|
||||||
import { BoardsDataMenuUpdater } from './boards/boards-details-menu-updater';
|
import { BoardsDataMenuUpdater } from './boards/boards-data-menu-updater';
|
||||||
import { BoardsDataStore } from './boards/boards-data-store';
|
import { BoardsDataStore } from './boards/boards-data-store';
|
||||||
import { ILogger } from '@theia/core';
|
import { ILogger } from '@theia/core';
|
||||||
import { FileSystemExt, FileSystemExtPath } from '../common/protocol/filesystem-ext';
|
import { FileSystemExt, FileSystemExtPath } from '../common/protocol/filesystem-ext';
|
||||||
|
@ -3,7 +3,7 @@ import { CommandRegistry } from '@theia/core/lib/common/command';
|
|||||||
import { MenuModelRegistry, MenuNode } from '@theia/core/lib/common/menu';
|
import { MenuModelRegistry, MenuNode } from '@theia/core/lib/common/menu';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||||
import { BoardsServiceClientImpl } from './boards-service-client-impl';
|
import { BoardsServiceClientImpl } from './boards-service-client-impl';
|
||||||
import { Board, ConfigOption } from '../../common/protocol';
|
import { Board, ConfigOption, Programmer } from '../../common/protocol';
|
||||||
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
||||||
import { BoardsDataStore } from './boards-data-store';
|
import { BoardsDataStore } from './boards-data-store';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
@ -41,7 +41,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
|
|||||||
this.mainMenuManager.update();
|
this.mainMenuManager.update();
|
||||||
const { fqbn } = selectedBoard;
|
const { fqbn } = selectedBoard;
|
||||||
if (fqbn) {
|
if (fqbn) {
|
||||||
const { configOptions, programmers } = await this.boardsDataStore.getData(fqbn);
|
const { configOptions, programmers, selectedProgrammer } = await this.boardsDataStore.getData(fqbn);
|
||||||
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS, 'z01_boardsConfig']; // `z_` is for ordering.
|
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS, '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}`];
|
||||||
@ -60,24 +60,31 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
|
|||||||
this.toDisposeOnBoardChange.pushAll([
|
this.toDisposeOnBoardChange.pushAll([
|
||||||
...commands.values(),
|
...commands.values(),
|
||||||
Disposable.create(() => this.unregisterSubmenu(menuPath)), // We cannot dispose submenu entries: https://github.com/eclipse-theia/theia/issues/7299
|
Disposable.create(() => this.unregisterSubmenu(menuPath)), // We cannot dispose submenu entries: https://github.com/eclipse-theia/theia/issues/7299
|
||||||
...Array.from(commands.keys()).map((commandId, index) => {
|
...Array.from(commands.keys()).map((commandId, i) => {
|
||||||
const { label } = commands.get(commandId)!;
|
const { label } = commands.get(commandId)!;
|
||||||
this.menuRegistry.registerMenuAction(menuPath, { commandId, order: String(index), label });
|
this.menuRegistry.registerMenuAction(menuPath, { commandId, order: `${i}`, label });
|
||||||
return Disposable.create(() => this.menuRegistry.unregisterMenuAction(commandId));
|
return Disposable.create(() => this.menuRegistry.unregisterMenuAction(commandId));
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
const programmersMenuPath = [...ArduinoMenus.TOOLS, 'z02_programmers'];
|
if (programmers.length) {
|
||||||
for (const programmer of programmers) {
|
const programmersMenuPath = [...ArduinoMenus.TOOLS, 'z02_programmers'];
|
||||||
const { id, name } = programmer;
|
const label = selectedProgrammer ? `Programmer: ${selectedProgrammer.name}` : 'Programmer'
|
||||||
const menuPath = [...programmersMenuPath, `${name}`];
|
this.menuRegistry.registerSubmenu(programmersMenuPath, label);
|
||||||
const command = { id: `${fqbn}-programmer--${id}` };
|
for (const programmer of programmers) {
|
||||||
const handler = { execute: () => this.boardsDataStore.selectProgrammer({ fqbn, programmer }) };
|
const { id, name } = programmer;
|
||||||
this.menuRegistry.registerMenuAction(menuPath, { commandId: command.id, label: name });
|
const command = { id: `${fqbn}-programmer--${id}` };
|
||||||
this.toDisposeOnBoardChange.pushAll([
|
const handler = {
|
||||||
this.commandRegistry.registerCommand(command, handler),
|
execute: () => this.boardsDataStore.selectProgrammer({ fqbn, selectedProgrammer: programmer }),
|
||||||
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command, menuPath))
|
isToggled: () => Programmer.equals(programmer, selectedProgrammer)
|
||||||
]);
|
};
|
||||||
|
this.menuRegistry.registerMenuAction(programmersMenuPath, { commandId: command.id, label: name });
|
||||||
|
this.toDisposeOnBoardChange.pushAll([
|
||||||
|
this.commandRegistry.registerCommand(command, handler),
|
||||||
|
Disposable.create(() => this.unregisterSubmenu(programmersMenuPath)),
|
||||||
|
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command, programmersMenuPath))
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.mainMenuManager.update();
|
this.mainMenuManager.update();
|
||||||
}
|
}
|
@ -92,11 +92,12 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async selectProgrammer(
|
async selectProgrammer(
|
||||||
{ fqbn, programmer }: { fqbn: string, programmer: Programmer },
|
{ fqbn, selectedProgrammer }: { fqbn: string, selectedProgrammer: Programmer },
|
||||||
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<boolean> {
|
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<boolean> {
|
||||||
|
|
||||||
const { configOptions, programmers } = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
||||||
if (!programmers.find(p => Programmer.equals(programmer, p))) {
|
const { programmers } = data;
|
||||||
|
if (!programmers.find(p => Programmer.equals(selectedProgrammer, p))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +105,8 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
if (!version) {
|
if (!version) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await this.setData({ fqbn, data: { configOptions, programmers }, version });
|
|
||||||
|
await this.setData({ fqbn, data: { ...data, selectedProgrammer }, version });
|
||||||
this.fireChanged();
|
this.fireChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -113,7 +115,8 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
{ fqbn, option, selectedValue }: { fqbn: string, option: string, selectedValue: string },
|
{ fqbn, option, selectedValue }: { fqbn: string, option: string, selectedValue: string },
|
||||||
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<boolean> {
|
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<boolean> {
|
||||||
|
|
||||||
const { configOptions, programmers } = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
||||||
|
const { configOptions } = data;
|
||||||
const configOption = configOptions.find(c => c.option === option);
|
const configOption = configOptions.find(c => c.option === option);
|
||||||
if (!configOption) {
|
if (!configOption) {
|
||||||
return false;
|
return false;
|
||||||
@ -134,7 +137,8 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
if (!version) {
|
if (!version) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await this.setData({ fqbn, data: { configOptions, programmers }, version });
|
|
||||||
|
await this.setData({ fqbn, data, version });
|
||||||
this.fireChanged();
|
this.fireChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -185,6 +189,7 @@ export namespace BoardsDataStore {
|
|||||||
export interface Data {
|
export interface Data {
|
||||||
readonly configOptions: ConfigOption[];
|
readonly configOptions: ConfigOption[];
|
||||||
readonly programmers: Programmer[];
|
readonly programmers: Programmer[];
|
||||||
|
readonly selectedProgrammer?: Programmer;
|
||||||
}
|
}
|
||||||
export namespace Data {
|
export namespace Data {
|
||||||
export const EMPTY: Data = {
|
export const EMPTY: Data = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user