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:
Alberto Iannaccone 2022-07-19 14:25:23 +02:00 committed by GitHub
parent 1f7c2eb52c
commit 8610332afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 13 deletions

View File

@ -516,6 +516,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
for (let i = 0; !hasChanged && i < availableBoards.length; i++) {
const [left, right] = [availableBoards[i], currentAvailableBoards[i]];
hasChanged =
left.fqbn !== right.fqbn ||
!!AvailableBoard.compare(left, right) ||
left.selected !== right.selected;
}

View File

@ -10,6 +10,7 @@ import {
} from './boards-service-provider';
import { nls } from '@theia/core/lib/common';
import classNames from 'classnames';
import { BoardsConfig } from './boards-config';
export interface BoardsDropDownListCoords {
readonly top: number;
@ -199,18 +200,17 @@ export class BoardsToolBarItem extends React.Component<
override render(): React.ReactNode {
const { coords, availableBoards } = this.state;
const selectedBoard = availableBoards.find(({ selected }) => selected);
const { selectedBoard, selectedPort } =
this.props.boardsServiceProvider.boardsConfig;
const boardLabel =
selectedBoard?.name ||
nls.localize('arduino/board/selectBoard', 'Select Board');
const selectedPortLabel = portLabel(selectedBoard?.port?.address);
const selectedPortLabel = portLabel(selectedPort?.address);
const isConnected = Boolean(
selectedBoard && AvailableBoard.hasPort(selectedBoard)
);
const isConnected = Boolean(selectedBoard && selectedPort);
const protocolIcon = isConnected
? iconNameFromProtocol(selectedBoard?.port?.protocol || '')
? iconNameFromProtocol(selectedPort?.protocol || '')
: null;
const protocolIconClassNames = classNames(
'arduino-boards-toolbar-item--protocol',
@ -244,11 +244,13 @@ export class BoardsToolBarItem extends React.Component<
.map((board) => ({
...board,
onClick: () => {
if (board.state === AvailableBoard.State.incomplete) {
if (!board.fqbn) {
const previousBoardConfig =
this.props.boardsServiceProvider.boardsConfig;
this.props.boardsServiceProvider.boardsConfig = {
selectedPort: board.port,
};
this.openDialog();
this.openDialog(previousBoardConfig);
} else {
this.props.boardsServiceProvider.boardsConfig = {
selectedBoard: board,
@ -264,10 +266,20 @@ export class BoardsToolBarItem extends React.Component<
);
}
protected openDialog = (): void => {
this.props.commands.executeCommand(
OpenBoardsConfig.Commands.OPEN_DIALOG.id
);
protected openDialog = async (
previousBoardConfig?: BoardsConfig.Config
): 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 {

View File

@ -17,7 +17,7 @@ export class OpenBoardsConfig extends Contribution {
execute: async (query?: string | undefined) => {
const boardsConfig = await this.boardsConfigDialog.open(query);
if (boardsConfig) {
this.boardsServiceProvider.boardsConfig = boardsConfig;
return (this.boardsServiceProvider.boardsConfig = boardsConfig);
}
},
});