Skip to content

Commit a039597

Browse files
committed
Select Board Dialog Style and Layout
Signed-off-by: jbicker <jan.bicker@typefox.io>
1 parent 4429094 commit a039597

10 files changed

+348
-166
lines changed

arduino-ide-extension/src/browser/arduino-file-menu.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class ArduinoToolbarMenuContribution implements MenuContribution {
5454
});
5555
registry.registerMenuAction(ArduinoToolbarContextMenu.CONNECTED_GROUP, {
5656
commandId: command.id,
57-
label: board.name + (selectedPort === port ? '*' : '')
57+
label: board.name + ' at ' + port + (selectedPort === port ? '*' : '')
5858
});
5959
});
6060
}

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+35-32
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
9090
@inject(SelectBoardsDialog)
9191
protected readonly selectBoardsDialog: SelectBoardsDialog;
9292

93+
protected boardsToolbarItem: BoardsToolBarItem | null;
94+
9395
@postConstruct()
9496
protected async init(): Promise<void> {
9597
// This is a hack. Otherwise, the backend services won't bind.
@@ -124,15 +126,10 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
124126
registry.registerItem({
125127
id: ConnectedBoards.TOOLBAR_ID,
126128
render: () => <BoardsToolBarItem
129+
ref={ref => this.boardsToolbarItem = ref}
127130
contextMenuRenderer={this.contextMenuRenderer}
128-
onNoBoardsInstalled={this.onNoBoardsInstalled.bind(this)}
129-
onUnknownBoard={this.onUnknownBoard.bind(this)} />,
130-
// render: () => <ConnectedBoards
131-
// boardsService={this.boardService}
132-
// boardsNotificationService={this.boardsNotificationService}
133-
// quickPickService={this.quickPickService}
134-
// onNoBoardsInstalled={this.onNoBoardsInstalled.bind(this)}
135-
// onUnknownBoard={this.onUnknownBoard.bind(this)} />,
131+
boardsNotificationService={this.boardsNotificationService}
132+
boardService={this.boardService} />,
136133
isVisible: widget => this.isArduinoToolbar(widget)
137134
})
138135
}
@@ -230,31 +227,37 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
230227
});
231228
registry.registerCommand(ArduinoCommands.SELECT_BOARD, {
232229
isEnabled: () => true,
233-
execute: (board: Board) => {
234-
this.boardService.selectBoard(board).then(() => {
235-
return this.boardService.getSelectBoard();
236-
}).then(board => {
237-
console.log("and the selected board is", board);
238-
})
230+
execute: async (board: Board) => {
231+
this.selectBoard(board);
239232
}
240233
})
241234
registry.registerCommand(ArduinoCommands.OPEN_BOARDS_DIALOG, {
242235
isEnabled: () => true,
243236
execute: async () => {
244237
const boardAndPort = await this.selectBoardsDialog.open();
245-
if(boardAndPort && boardAndPort.board){
238+
if (boardAndPort && boardAndPort.board) {
246239
const selectedBoard = {
247240
fqbn: boardAndPort.board.fqbn,
248241
name: boardAndPort.board.name,
249242
port: boardAndPort.port
250243
}
251-
this.boardService.selectBoard(selectedBoard);
252-
244+
this.selectBoard(selectedBoard);
253245
}
254246
}
255247
})
256248
}
257249

250+
protected async selectBoard(board: Board) {
251+
const attached = await this.boardService.getAttachedBoards();
252+
if(attached.boards.length) {
253+
board = attached.boards.find(b => b.name === board.name && b.fqbn === board.fqbn) || board;
254+
}
255+
await this.boardService.selectBoard(board)
256+
if (this.boardsToolbarItem) {
257+
this.boardsToolbarItem.setSelectedBoard(board);
258+
}
259+
}
260+
258261
protected async openSketchFilesInNewWindow(uri: string) {
259262
const location = new URL(window.location.href);
260263
location.searchParams.set('sketch', uri);
@@ -309,24 +312,24 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
309312
return widget;
310313
}
311314

312-
private async onNoBoardsInstalled() {
313-
const action = await this.messageService.info("You have no boards installed. Use the boards mangager to install one.", "Open Boards Manager");
314-
if (!action) {
315-
return;
316-
}
315+
// private async onNoBoardsInstalled() {
316+
// const action = await this.messageService.info("You have no boards installed. Use the boards mangager to install one.", "Open Boards Manager");
317+
// if (!action) {
318+
// return;
319+
// }
317320

318-
this.boardsListWidgetFrontendContribution.openView({ reveal: true });
319-
}
321+
// this.boardsListWidgetFrontendContribution.openView({ reveal: true });
322+
// }
320323

321-
private async onUnknownBoard() {
322-
const action = await this.messageService.warn("There's a board connected for which you need to install software." +
323-
" If this were not a PoC we would offer you the right package now.", "Open Boards Manager");
324-
if (!action) {
325-
return;
326-
}
324+
// private async onUnknownBoard() {
325+
// const action = await this.messageService.warn("There's a board connected for which you need to install software." +
326+
// " If this were not a PoC we would offer you the right package now.", "Open Boards Manager");
327+
// if (!action) {
328+
// return;
329+
// }
327330

328-
this.boardsListWidgetFrontendContribution.openView({ reveal: true });
329-
}
331+
// this.boardsListWidgetFrontendContribution.openView({ reveal: true });
332+
// }
330333

331334
private isArduinoToolbar(maybeToolbarWidget: any): boolean {
332335
if (maybeToolbarWidget instanceof ArduinoToolbar) {

arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx

+40-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
11
import * as React from 'react';
2-
import { Board } from '../../common/protocol/boards-service';
2+
import { BoardsService, Board } from '../../common/protocol/boards-service';
33
import { ContextMenuRenderer } from '@theia/core/lib/browser';
44
import { ArduinoToolbarContextMenu } from '../arduino-file-menu';
5+
import { BoardsNotificationService } from '../boards-notification-service';
56

67
export namespace BoardsToolBarItem {
78
export interface Props {
8-
readonly onNoBoardsInstalled: () => void;
9-
readonly onUnknownBoard: (board: Board) => void;
109
readonly contextMenuRenderer: ContextMenuRenderer;
10+
readonly boardsNotificationService: BoardsNotificationService;
11+
readonly boardService: BoardsService;
12+
}
13+
14+
export interface State {
15+
selectedBoard?: Board;
16+
selectedIsAttached: boolean
1117
}
1218
}
1319

14-
export class BoardsToolBarItem extends React.Component<BoardsToolBarItem.Props, {}> {
20+
export class BoardsToolBarItem extends React.Component<BoardsToolBarItem.Props, BoardsToolBarItem.State> {
21+
22+
protected attachedBoards: Board[];
1523

1624
constructor(props: BoardsToolBarItem.Props) {
1725
super(props);
26+
27+
this.state = {
28+
selectedBoard: undefined,
29+
selectedIsAttached: true
30+
};
31+
}
32+
33+
componentDidMount() {
34+
this.setAttachedBoards();
35+
}
36+
37+
protected async setAttachedBoards() {
38+
const { boards } = await this.props.boardService.getAttachedBoards();
39+
this.attachedBoards = boards;
40+
if(this.attachedBoards.length){
41+
await this.props.boardService.selectBoard(this.attachedBoards[0]);
42+
this.setSelectedBoard(this.attachedBoards[0]);
43+
}
44+
}
45+
46+
setSelectedBoard(board: Board) {
47+
if (this.attachedBoards.length) {
48+
this.setState({ selectedIsAttached: !!this.attachedBoards.find(attachedBoard => attachedBoard.name === board.name) });
49+
}
50+
this.setState({ selectedBoard: board });
1851
}
1952

2053
protected readonly doShowSelectBoardsMenu = (event: React.MouseEvent<HTMLElement>) => this.showSelectBoardsMenu(event);
@@ -29,12 +62,13 @@ export class BoardsToolBarItem extends React.Component<BoardsToolBarItem.Props,
2962
}
3063

3164
render(): React.ReactNode {
32-
3365
return <React.Fragment>
3466
<div className='arduino-boards-toolbar-item-container' onClick={this.doShowSelectBoardsMenu}>
3567
<div className='arduino-boards-toolbar-item'>
3668
<div className='inner-container'>
37-
<div className='label'>Show selected Board here</div>
69+
<span className={!this.state.selectedBoard || !this.state.selectedIsAttached ? 'fa fa-times notAttached' : ''}></span>
70+
<div className='label'>{this.state.selectedBoard ? this.state.selectedBoard.name : 'no board selected'}</div>
71+
<span className='fa fa-caret-down'></span>
3872
</div>
3973
</div>
4074
</div>

0 commit comments

Comments
 (0)