@@ -10,6 +10,7 @@ import {
10
10
} from './boards-service-provider' ;
11
11
import { nls } from '@theia/core/lib/common' ;
12
12
import classNames from 'classnames' ;
13
+ import { BoardsConfig } from './boards-config' ;
13
14
14
15
export interface BoardsDropDownListCoords {
15
16
readonly top : number ;
@@ -199,18 +200,17 @@ export class BoardsToolBarItem extends React.Component<
199
200
200
201
override render ( ) : React . ReactNode {
201
202
const { coords, availableBoards } = this . state ;
202
- const selectedBoard = availableBoards . find ( ( { selected } ) => selected ) ;
203
+ const { selectedBoard, selectedPort } =
204
+ this . props . boardsServiceProvider . boardsConfig ;
203
205
204
206
const boardLabel =
205
207
selectedBoard ?. name ||
206
208
nls . localize ( 'arduino/board/selectBoard' , 'Select Board' ) ;
207
- const selectedPortLabel = portLabel ( selectedBoard ?. port ?. address ) ;
209
+ const selectedPortLabel = portLabel ( selectedPort ?. address ) ;
208
210
209
- const isConnected = Boolean (
210
- selectedBoard && AvailableBoard . hasPort ( selectedBoard )
211
- ) ;
211
+ const isConnected = Boolean ( selectedBoard && selectedPort ) ;
212
212
const protocolIcon = isConnected
213
- ? iconNameFromProtocol ( selectedBoard ?. port ?. protocol || '' )
213
+ ? iconNameFromProtocol ( selectedPort ?. protocol || '' )
214
214
: null ;
215
215
const protocolIconClassNames = classNames (
216
216
'arduino-boards-toolbar-item--protocol' ,
@@ -244,11 +244,13 @@ export class BoardsToolBarItem extends React.Component<
244
244
. map ( ( board ) => ( {
245
245
...board ,
246
246
onClick : ( ) => {
247
- if ( board . state === AvailableBoard . State . incomplete ) {
247
+ if ( ! board . fqbn ) {
248
+ const previousBoardConfig =
249
+ this . props . boardsServiceProvider . boardsConfig ;
248
250
this . props . boardsServiceProvider . boardsConfig = {
249
251
selectedPort : board . port ,
250
252
} ;
251
- this . openDialog ( ) ;
253
+ this . openDialog ( previousBoardConfig ) ;
252
254
} else {
253
255
this . props . boardsServiceProvider . boardsConfig = {
254
256
selectedBoard : board ,
@@ -264,10 +266,20 @@ export class BoardsToolBarItem extends React.Component<
264
266
) ;
265
267
}
266
268
267
- protected openDialog = ( ) : void => {
268
- this . props . commands . executeCommand (
269
- OpenBoardsConfig . Commands . OPEN_DIALOG . id
270
- ) ;
269
+ protected openDialog = async (
270
+ previousBoardConfig ?: BoardsConfig . Config
271
+ ) : Promise < void > => {
272
+ const selectedBoardConfig =
273
+ await this . props . commands . executeCommand < BoardsConfig . Config > (
274
+ OpenBoardsConfig . Commands . OPEN_DIALOG . id
275
+ ) ;
276
+ if (
277
+ previousBoardConfig &&
278
+ ( ! selectedBoardConfig ?. selectedPort ||
279
+ ! selectedBoardConfig ?. selectedBoard )
280
+ ) {
281
+ this . props . boardsServiceProvider . boardsConfig = previousBoardConfig ;
282
+ }
271
283
} ;
272
284
}
273
285
export namespace BoardsToolBarItem {
0 commit comments