mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-14 06:46:36 +00:00
Fix board selector synchronization (#1214)
* prevent deselecting a board from the board selctor * orrectly update board selector when baord config changes
This commit is contained in:
parent
1f7c2eb52c
commit
8610332afc
@ -516,6 +516,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
|
|||||||
for (let i = 0; !hasChanged && i < availableBoards.length; i++) {
|
for (let i = 0; !hasChanged && i < availableBoards.length; i++) {
|
||||||
const [left, right] = [availableBoards[i], currentAvailableBoards[i]];
|
const [left, right] = [availableBoards[i], currentAvailableBoards[i]];
|
||||||
hasChanged =
|
hasChanged =
|
||||||
|
left.fqbn !== right.fqbn ||
|
||||||
!!AvailableBoard.compare(left, right) ||
|
!!AvailableBoard.compare(left, right) ||
|
||||||
left.selected !== right.selected;
|
left.selected !== right.selected;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
} from './boards-service-provider';
|
} from './boards-service-provider';
|
||||||
import { nls } from '@theia/core/lib/common';
|
import { nls } from '@theia/core/lib/common';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { BoardsConfig } from './boards-config';
|
||||||
|
|
||||||
export interface BoardsDropDownListCoords {
|
export interface BoardsDropDownListCoords {
|
||||||
readonly top: number;
|
readonly top: number;
|
||||||
@ -199,18 +200,17 @@ export class BoardsToolBarItem extends React.Component<
|
|||||||
|
|
||||||
override render(): React.ReactNode {
|
override render(): React.ReactNode {
|
||||||
const { coords, availableBoards } = this.state;
|
const { coords, availableBoards } = this.state;
|
||||||
const selectedBoard = availableBoards.find(({ selected }) => selected);
|
const { selectedBoard, selectedPort } =
|
||||||
|
this.props.boardsServiceProvider.boardsConfig;
|
||||||
|
|
||||||
const boardLabel =
|
const boardLabel =
|
||||||
selectedBoard?.name ||
|
selectedBoard?.name ||
|
||||||
nls.localize('arduino/board/selectBoard', 'Select Board');
|
nls.localize('arduino/board/selectBoard', 'Select Board');
|
||||||
const selectedPortLabel = portLabel(selectedBoard?.port?.address);
|
const selectedPortLabel = portLabel(selectedPort?.address);
|
||||||
|
|
||||||
const isConnected = Boolean(
|
const isConnected = Boolean(selectedBoard && selectedPort);
|
||||||
selectedBoard && AvailableBoard.hasPort(selectedBoard)
|
|
||||||
);
|
|
||||||
const protocolIcon = isConnected
|
const protocolIcon = isConnected
|
||||||
? iconNameFromProtocol(selectedBoard?.port?.protocol || '')
|
? iconNameFromProtocol(selectedPort?.protocol || '')
|
||||||
: null;
|
: null;
|
||||||
const protocolIconClassNames = classNames(
|
const protocolIconClassNames = classNames(
|
||||||
'arduino-boards-toolbar-item--protocol',
|
'arduino-boards-toolbar-item--protocol',
|
||||||
@ -244,11 +244,13 @@ export class BoardsToolBarItem extends React.Component<
|
|||||||
.map((board) => ({
|
.map((board) => ({
|
||||||
...board,
|
...board,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
if (board.state === AvailableBoard.State.incomplete) {
|
if (!board.fqbn) {
|
||||||
|
const previousBoardConfig =
|
||||||
|
this.props.boardsServiceProvider.boardsConfig;
|
||||||
this.props.boardsServiceProvider.boardsConfig = {
|
this.props.boardsServiceProvider.boardsConfig = {
|
||||||
selectedPort: board.port,
|
selectedPort: board.port,
|
||||||
};
|
};
|
||||||
this.openDialog();
|
this.openDialog(previousBoardConfig);
|
||||||
} else {
|
} else {
|
||||||
this.props.boardsServiceProvider.boardsConfig = {
|
this.props.boardsServiceProvider.boardsConfig = {
|
||||||
selectedBoard: board,
|
selectedBoard: board,
|
||||||
@ -264,10 +266,20 @@ export class BoardsToolBarItem extends React.Component<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected openDialog = (): void => {
|
protected openDialog = async (
|
||||||
this.props.commands.executeCommand(
|
previousBoardConfig?: BoardsConfig.Config
|
||||||
OpenBoardsConfig.Commands.OPEN_DIALOG.id
|
): Promise<void> => {
|
||||||
);
|
const selectedBoardConfig =
|
||||||
|
await this.props.commands.executeCommand<BoardsConfig.Config>(
|
||||||
|
OpenBoardsConfig.Commands.OPEN_DIALOG.id
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
previousBoardConfig &&
|
||||||
|
(!selectedBoardConfig?.selectedPort ||
|
||||||
|
!selectedBoardConfig?.selectedBoard)
|
||||||
|
) {
|
||||||
|
this.props.boardsServiceProvider.boardsConfig = previousBoardConfig;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export namespace BoardsToolBarItem {
|
export namespace BoardsToolBarItem {
|
||||||
|
@ -17,7 +17,7 @@ export class OpenBoardsConfig extends Contribution {
|
|||||||
execute: async (query?: string | undefined) => {
|
execute: async (query?: string | undefined) => {
|
||||||
const boardsConfig = await this.boardsConfigDialog.open(query);
|
const boardsConfig = await this.boardsConfigDialog.open(query);
|
||||||
if (boardsConfig) {
|
if (boardsConfig) {
|
||||||
this.boardsServiceProvider.boardsConfig = boardsConfig;
|
return (this.boardsServiceProvider.boardsConfig = boardsConfig);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user