diff --git a/arduino-ide-extension/src/browser/boards/boards-service-provider.ts b/arduino-ide-extension/src/browser/boards/boards-service-provider.ts index 8765305d1..32e43dc47 100644 --- a/arduino-ide-extension/src/browser/boards/boards-service-provider.ts +++ b/arduino-ide-extension/src/browser/boards/boards-service-provider.ts @@ -1,4 +1,3 @@ -import type { Disposable } from '@theia/core/lib/common/disposable'; import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; import { @@ -7,8 +6,10 @@ import { CommandRegistry, CommandService, } from '@theia/core/lib/common/command'; +import type { Disposable } from '@theia/core/lib/common/disposable'; import { Emitter } from '@theia/core/lib/common/event'; import { ILogger } from '@theia/core/lib/common/logger'; +import { nls } from '@theia/core/lib/common/nls'; import type { Mutable } from '@theia/core/lib/common/types'; import { inject, @@ -534,18 +535,24 @@ const USE_INHERITED_CONFIG: Command = { const DUMP_BOARD_LIST: Command = { id: 'arduino-dump-board-list', - label: 'Dump the Board List', // TODO: if remains in IDE2, add translations. + label: nls.localize('arduino/developer/dumpBoardList', 'Dump the Board List'), category: 'Developer (Arduino)', }; const CLEAR_BOARD_LIST_HISTORY: Command = { id: 'arduino-clear-board-list-history', - label: 'Clear the Board List History', // TODO: if remains in IDE2, add translations. + label: nls.localize( + 'arduino/developer/clearBoardList', + 'Clear the Board List History' + ), category: 'Developer (Arduino)', }; const CLEAR_BOARDS_CONFIG: Command = { id: 'arduino-clear-boards-config', - label: 'Clear the Board and Port Configuration', // TODO: if remains in IDE2, add translations. + label: nls.localize( + 'arduino/developer/clearBoardsConfig', + ' Clear the Board and Port Configuration' + ), category: 'Developer (Arduino)', }; diff --git a/arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx b/arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx index ce2dedfac..a995fa075 100644 --- a/arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx +++ b/arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx @@ -1,6 +1,6 @@ -import { codicon } from '@theia/core/lib/browser/index'; import { TabBarToolbar } from '@theia/core/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar'; -import { CommandRegistry } from '@theia/core/lib/common/command'; +import { codicon } from '@theia/core/lib/browser/widgets/widget'; +import type { CommandRegistry } from '@theia/core/lib/common/command'; import { Disposable, DisposableCollection, @@ -12,7 +12,7 @@ import classNames from 'classnames'; import { unknownBoard } from '../../common/protocol'; import { BoardListItem, - getBoardListItemBoard, + getInferredBoardOrBoard, InferredBoardListItem, isInferredBoardListItem, } from '../../common/protocol/board-list'; @@ -35,6 +35,10 @@ export namespace BoardsDropDown { readonly coords: BoardsDropDownListCoords | 'hidden'; readonly boardList: BoardListUI; readonly openBoardsConfig: () => void; + /** + * Hides the board list dropdown, if it's visible. Otherwise, NOOP. + */ + readonly hide: () => void; } } @@ -67,7 +71,7 @@ export class BoardListDropDown extends React.Component { ); } - protected renderBoardListItems(): React.ReactNode { + private renderBoardListItems(): React.ReactNode { const { coords, boardList } = this.props; if (coords === 'hidden') { return ''; @@ -120,14 +124,10 @@ export class BoardListDropDown extends React.Component { onEdit: EditBoardsConfigAction; }): React.ReactNode { const port = item.port; - const boardLabel = isInferredBoardListItem(item) - ? item.inferredBoard.name - : item.board?.name ?? unknownBoard; - const boardFqbn = isInferredBoardListItem(item) - ? item.inferredBoard.fqbn - : item.board?.fqbn; + const board = getInferredBoardOrBoard(item); + const boardLabel = board?.name ?? unknownBoard; + const boardFqbn = board?.fqbn; const onDefaultAction = () => { - const board = getBoardListItemBoard(item, 'inferred'); if (board) { onSelect({ selectedBoard: board, selectedPort: port }); } else { @@ -218,6 +218,7 @@ export class BoardListDropDown extends React.Component { event.preventDefault(); event.stopPropagation(); onRevert({ selectedBoard: inferredItem.board, selectedPort: port }); + this.props.hide(); }} /> ) : undefined; @@ -289,6 +290,10 @@ export class BoardsToolBarItem extends React.Component< event.nativeEvent.stopImmediatePropagation(); }; + private readonly hide = () => { + this.setState({ coords: 'hidden' }); + }; + override render(): React.ReactNode { const { coords, boardList } = this.state; const { selectedBoard, selectedPort } = boardList.boardsConfig; @@ -333,6 +338,7 @@ export class BoardsToolBarItem extends React.Component< openBoardsConfig={() => boardList.onEdit({ query: { action: 'clear-if-not-empty' } }) } + hide={this.hide} > ); diff --git a/arduino-ide-extension/src/browser/dialogs/certificate-uploader/select-board-components.tsx b/arduino-ide-extension/src/browser/dialogs/certificate-uploader/select-board-components.tsx index 818de7f7c..bb2cf16f6 100644 --- a/arduino-ide-extension/src/browser/dialogs/certificate-uploader/select-board-components.tsx +++ b/arduino-ide-extension/src/browser/dialogs/certificate-uploader/select-board-components.tsx @@ -3,7 +3,7 @@ import * as React from '@theia/core/shared/react'; import { BoardList, BoardListItem, - getBoardListItemBoard, + getInferredBoardOrBoard, } from '../../../common/protocol/board-list'; import { boardIdentifierEquals } from '../../../common/protocol/boards-service'; import { ArduinoSelect } from '../../widgets/arduino-select'; @@ -57,7 +57,7 @@ export const SelectBoardComponent = ({ const selectedItem: BoardListItem | undefined = boardList[boardList.selectedIndex]; const selectedBoard = selectedItem - ? getBoardListItemBoard(selectedItem, 'inferred') + ? getInferredBoardOrBoard(selectedItem) : undefined; const boardsList: BoardOption[] = updatableBoards.map((item, i) => { if (!!selectedBoard && boardIdentifierEquals(item.board, selectedBoard)) { @@ -87,7 +87,7 @@ export const SelectBoardComponent = ({ if (selectedItem) { selBoard = boardsList .map((boardOpt) => boardOpt.value) - .indexOf(getBoardListItemBoard(selectedItem, 'inferred')?.fqbn || ''); + .indexOf(getInferredBoardOrBoard(selectedItem)?.fqbn || ''); } selectOption(boardsList[selBoard] || null); diff --git a/arduino-ide-extension/src/common/protocol/board-list.ts b/arduino-ide-extension/src/common/protocol/board-list.ts index 91563a7b2..33cc3b35f 100644 --- a/arduino-ide-extension/src/common/protocol/board-list.ts +++ b/arduino-ide-extension/src/common/protocol/board-list.ts @@ -31,32 +31,26 @@ export function isBoardListItem(arg: unknown): arg is BoardListItem { ); } -/** - * Gets the board or the inferred one if applicable. - * If `resolveStrategy` is `'default'`, and `item` has a `board`, the inferred is ignored. - * If the strategy is `'inferred'`, the inferred board has higher precedence. - */ -export function getBoardListItemBoard( - item: BoardListItem, - resolveStrategy: 'default' | 'inferred' +export function getBoardOrInferredBoard( + item: BoardListItem ): BoardIdentifier | undefined { let board: BoardIdentifier | undefined = undefined; - if (resolveStrategy === 'default') { - board = item.board; - if (!board && isInferredBoardListItem(item)) { - board = item.inferredBoard; - } - } else { - if (isInferredBoardListItem(item)) { - board = item.inferredBoard; - } - if (!board) { - board = item.board; - } + board = item.board; + if (!board && isInferredBoardListItem(item)) { + board = item.inferredBoard; } return board; } +export function getInferredBoardOrBoard( + item: BoardListItem +): BoardIdentifier | undefined { + if (isInferredBoardListItem(item)) { + return item.inferredBoard; + } + return item.board; +} + interface BoardSelectedBoardListItem extends BoardListItem { readonly inferredBoard: BoardIdentifier; readonly type: Extract; @@ -136,8 +130,8 @@ function boardListItemComparator( // compare by board result = boardIdentifierComparator( - getBoardListItemBoard(left, 'default'), - getBoardListItemBoard(right, 'default') + getBoardOrInferredBoard(left), + getBoardOrInferredBoard(right) ); if (result) { return result; diff --git a/arduino-ide-extension/src/common/protocol/boards-service.ts b/arduino-ide-extension/src/common/protocol/boards-service.ts index 9d10c2678..4f884c98e 100644 --- a/arduino-ide-extension/src/common/protocol/boards-service.ts +++ b/arduino-ide-extension/src/common/protocol/boards-service.ts @@ -165,9 +165,9 @@ export namespace Port { export namespace Properties { export function create( properties: [string, string][] | undefined - ): Properties { - if (!properties) { - return {}; + ): Properties | undefined { + if (!properties || !properties.length) { + return undefined; } return properties.reduce((acc, curr) => { const [key, value] = curr; @@ -303,10 +303,10 @@ export namespace BoardsPackage { } } -export interface Board { - readonly name: string; - readonly fqbn?: string; -} +/** + * @deprecated user `BoardIdentifier` instead. + */ +export type Board = BoardIdentifier; export interface BoardUserField { readonly toolId: string; diff --git a/arduino-ide-extension/src/node/board-discovery.ts b/arduino-ide-extension/src/node/board-discovery.ts index ec25d086b..851660ba1 100644 --- a/arduino-ide-extension/src/node/board-discovery.ts +++ b/arduino-ide-extension/src/node/board-discovery.ts @@ -269,12 +269,12 @@ export class BoardDiscovery protocol: rpcPort.getProtocol(), protocolLabel: rpcPort.getProtocolLabel(), properties: Port.Properties.create(rpcPort.getPropertiesMap().toObject()), - hardwareId: rpcPort.getHardwareId(), + hardwareId: rpcPort.getHardwareId() || undefined, // prefer undefined over empty string }; } - private fireSoonHandle?: NodeJS.Timeout; - private bufferedEvents: DetectedPortChangeEvent[] = []; + private fireSoonHandle: NodeJS.Timeout | undefined; + private readonly bufferedEvents: DetectedPortChangeEvent[] = []; private fireSoon(event: DetectedPortChangeEvent): void { this.bufferedEvents.push(event); clearTimeout(this.fireSoonHandle); diff --git a/i18n/en.json b/i18n/en.json index 8a1fabcae..18e10a569 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -212,6 +212,11 @@ "optimizeForDebugging": "Optimize for Debugging", "sketchIsNotCompiled": "Sketch '{0}' must be verified before starting a debug session. Please verify the sketch and start debugging again. Do you want to verify the sketch now?" }, + "developer": { + "clearBoardList": "Clear the Board List History", + "clearBoardsConfig": " Clear the Board and Port Configuration", + "dumpBoardList": "Dump the Board List" + }, "dialog": { "dontAskAgain": "Don't ask again" },