@@ -5,22 +5,21 @@ import { EditorWidget } from '@theia/editor/lib/browser/editor-widget';
5
5
import { MessageService } from '@theia/core/lib/common/message-service' ;
6
6
import { CommandContribution , CommandRegistry , Command } from '@theia/core/lib/common/command' ;
7
7
import { TabBarToolbarContribution , TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar' ;
8
- import { BoardsService , Board } from '../common/protocol/boards-service' ;
8
+ import { BoardsService } from '../common/protocol/boards-service' ;
9
9
import { ArduinoCommands } from './arduino-commands' ;
10
- import { ConnectedBoards } from './components/connected-boards' ;
11
10
import { CoreService } from '../common/protocol/core-service' ;
12
11
import { WorkspaceServiceExt } from './workspace-service-ext' ;
13
12
import { ToolOutputServiceClient } from '../common/protocol/tool-output-service' ;
14
13
import { QuickPickService } from '@theia/core/lib/common/quick-pick-service' ;
15
14
import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-frontend-contribution' ;
16
- import { BoardsNotificationService } from './boards-notification- service' ;
15
+ import { BoardsServiceClientImpl } from './boards/boards- service-client-impl ' ;
17
16
import { WorkspaceRootUriAwareCommandHandler , WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands' ;
18
17
import { SelectionService , MenuContribution , MenuModelRegistry , MAIN_MENU_BAR } from '@theia/core' ;
19
18
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service' ;
20
19
import { SketchFactory } from './sketch-factory' ;
21
20
import { ArduinoToolbar } from './toolbar/arduino-toolbar' ;
22
21
import { EditorManager , EditorMainMenu } from '@theia/editor/lib/browser' ;
23
- import { ContextMenuRenderer , OpenerService , Widget , StatusBar , ShellLayoutRestorer } from '@theia/core/lib/browser' ;
22
+ import { ContextMenuRenderer , OpenerService , Widget , StatusBar , ShellLayoutRestorer , StatusBarAlignment } from '@theia/core/lib/browser' ;
24
23
import { OpenFileDialogProps , FileDialogService } from '@theia/filesystem/lib/browser/file-dialog' ;
25
24
import { FileSystem , FileStat } from '@theia/filesystem/lib/common' ;
26
25
import { ArduinoToolbarContextMenu } from './arduino-file-menu' ;
@@ -32,17 +31,17 @@ import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/fil
32
31
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu' ;
33
32
import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution' ;
34
33
import { MaybePromise } from '@theia/core/lib/common/types' ;
35
- import { SelectBoardDialog } from './boards/select-board -dialog' ;
34
+ import { BoardsConfigDialog } from './boards/boards-config -dialog' ;
36
35
import { BoardsToolBarItem } from './boards/boards-toolbar-item' ;
36
+ import { BoardsConfig } from './boards/boards-config' ;
37
37
38
38
export namespace ArduinoMenus {
39
39
export const SKETCH = [ ...MAIN_MENU_BAR , '3_sketch' ] ;
40
40
export const TOOLS = [ ...MAIN_MENU_BAR , '4_tools' ] ;
41
41
}
42
42
43
43
export const ARDUINO_PRO_MODE : boolean = ( ( ) => {
44
- const proModeStr = window . localStorage . getItem ( 'arduino-pro-mode' ) ;
45
- return proModeStr === 'true' ;
44
+ return window . localStorage . getItem ( 'arduino-pro-mode' ) === 'true' ;
46
45
} ) ( ) ;
47
46
48
47
@injectable ( )
@@ -52,7 +51,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
52
51
protected readonly messageService : MessageService ;
53
52
54
53
@inject ( BoardsService )
55
- protected readonly boardService : BoardsService ;
54
+ protected readonly boardsService : BoardsService ;
56
55
57
56
@inject ( CoreService )
58
57
protected readonly coreService : CoreService ;
@@ -69,8 +68,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
69
68
@inject ( BoardsListWidgetFrontendContribution )
70
69
protected readonly boardsListWidgetFrontendContribution : BoardsListWidgetFrontendContribution ;
71
70
72
- @inject ( BoardsNotificationService )
73
- protected readonly boardsNotificationService : BoardsNotificationService ;
71
+ @inject ( BoardsServiceClientImpl )
72
+ protected readonly boardsServiceClient : BoardsServiceClientImpl ;
74
73
75
74
@inject ( SelectionService )
76
75
protected readonly selectionService : SelectionService ;
@@ -99,8 +98,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
99
98
@inject ( SketchesService )
100
99
protected readonly sketches : SketchesService ;
101
100
102
- @inject ( SelectBoardDialog )
103
- protected readonly selectBoardsDialog : SelectBoardDialog ;
101
+ @inject ( BoardsConfigDialog )
102
+ protected readonly boardsConfigDialog : BoardsConfigDialog ;
104
103
105
104
@inject ( MenuModelRegistry )
106
105
protected readonly menuRegistry : MenuModelRegistry ;
@@ -129,6 +128,15 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
129
128
protected async init ( ) : Promise < void > {
130
129
// This is a hack. Otherwise, the backend services won't bind.
131
130
await this . workspaceServiceExt . roots ( ) ;
131
+
132
+ const updateStatusBar = ( config : BoardsConfig . Config ) => {
133
+ this . statusBar . setElement ( 'arduino-selected-board' , {
134
+ alignment : StatusBarAlignment . RIGHT ,
135
+ text : BoardsConfig . Config . toString ( config )
136
+ } ) ;
137
+ }
138
+ this . boardsServiceClient . onBoardsConfigChanged ( updateStatusBar ) ;
139
+ updateStatusBar ( this . boardsServiceClient . boardsConfig ) ;
132
140
}
133
141
134
142
registerToolbarItems ( registry : TabBarToolbarRegistry ) : void {
@@ -157,15 +165,13 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
157
165
text : '$(arrow-down)'
158
166
} ) ;
159
167
registry . registerItem ( {
160
- id : ConnectedBoards . TOOLBAR_ID ,
168
+ id : BoardsToolBarItem . TOOLBAR_ID ,
161
169
render : ( ) => < BoardsToolBarItem
162
170
key = 'boardsToolbarItem'
163
171
ref = { ref => this . boardsToolbarItem = ref }
164
172
commands = { this . commands }
165
- statusBar = { this . statusBar }
166
- contextMenuRenderer = { this . contextMenuRenderer }
167
- boardsNotificationService = { this . boardsNotificationService }
168
- boardService = { this . boardService } /> ,
173
+ boardsServiceClient = { this . boardsServiceClient }
174
+ boardService = { this . boardsService } /> ,
169
175
isVisible : widget => this . isArduinoToolbar ( widget )
170
176
} )
171
177
}
@@ -186,7 +192,14 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
186
192
}
187
193
188
194
try {
189
- await this . coreService . compile ( { uri : uri . toString ( ) } ) ;
195
+ const { boardsConfig } = this . boardsServiceClient ;
196
+ if ( ! boardsConfig || ! boardsConfig . selectedBoard ) {
197
+ throw new Error ( 'No boards selected. Please select a board.' ) ;
198
+ }
199
+ if ( ! boardsConfig . selectedBoard . fqbn ) {
200
+ throw new Error ( `No core is installed for ${ boardsConfig . selectedBoard . name } . Please install the board.` ) ;
201
+ }
202
+ await this . coreService . compile ( { uri : uri . toString ( ) , board : boardsConfig . selectedBoard } ) ;
190
203
} catch ( e ) {
191
204
await this . messageService . error ( e . toString ( ) ) ;
192
205
}
@@ -207,7 +220,15 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
207
220
}
208
221
209
222
try {
210
- await this . coreService . upload ( { uri : uri . toString ( ) } ) ;
223
+ const { boardsConfig } = this . boardsServiceClient ;
224
+ if ( ! boardsConfig || ! boardsConfig . selectedBoard ) {
225
+ throw new Error ( 'No boards selected. Please select a board.' ) ;
226
+ }
227
+ const { selectedPort } = boardsConfig ;
228
+ if ( ! selectedPort ) {
229
+ throw new Error ( 'No ports selected. Please select a port.' ) ;
230
+ }
231
+ await this . coreService . upload ( { uri : uri . toString ( ) , board : boardsConfig . selectedBoard , port : selectedPort } ) ;
211
232
} catch ( e ) {
212
233
await this . messageService . error ( e . toString ( ) ) ;
213
234
}
@@ -261,26 +282,16 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
261
282
}
262
283
}
263
284
} ) ) ;
264
- registry . registerCommand ( ArduinoCommands . REFRESH_BOARDS , {
265
- isEnabled : ( ) => true ,
266
- execute : ( ) => this . boardsNotificationService . notifyBoardsInstalled ( )
267
- } ) ;
268
- registry . registerCommand ( ArduinoCommands . SELECT_BOARD , {
269
- isEnabled : ( ) => true ,
270
- execute : async ( board : Board ) => {
271
- this . selectBoard ( board ) ;
272
- }
273
- } )
274
285
registry . registerCommand ( ArduinoCommands . OPEN_BOARDS_DIALOG , {
275
286
isEnabled : ( ) => true ,
276
287
execute : async ( ) => {
277
- const boardAndPort = await this . selectBoardsDialog . open ( ) ;
278
- if ( boardAndPort && boardAndPort . board ) {
279
- this . selectBoard ( boardAndPort . board ) ;
288
+ const boardsConfig = await this . boardsConfigDialog . open ( ) ;
289
+ if ( boardsConfig ) {
290
+ this . boardsServiceClient . boardsConfig = boardsConfig ;
280
291
}
281
292
}
282
293
} )
283
- registry . registerCommand ( ArduinoCommands . TOGGLE_PROMODE , {
294
+ registry . registerCommand ( ArduinoCommands . TOGGLE_PRO_MODE , {
284
295
execute : ( ) => {
285
296
const oldModeState = ARDUINO_PRO_MODE ;
286
297
window . localStorage . setItem ( 'arduino-pro-mode' , oldModeState ? 'false' : 'true' ) ;
@@ -290,13 +301,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
290
301
} )
291
302
}
292
303
293
- protected async selectBoard ( board : Board ) {
294
- await this . boardService . selectBoard ( board ) ;
295
- if ( this . boardsToolbarItem ) {
296
- this . boardsToolbarItem . setSelectedBoard ( board ) ;
297
- }
298
- }
299
-
300
304
registerMenus ( registry : MenuModelRegistry ) {
301
305
if ( ! ARDUINO_PRO_MODE ) {
302
306
registry . unregisterMenuAction ( FileSystemCommands . UPLOAD ) ;
@@ -335,7 +339,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
335
339
registry . registerSubmenu ( ArduinoMenus . TOOLS , 'Tools' ) ;
336
340
337
341
registry . registerMenuAction ( CommonMenus . HELP , {
338
- commandId : ArduinoCommands . TOGGLE_PROMODE . id ,
342
+ commandId : ArduinoCommands . TOGGLE_PRO_MODE . id ,
339
343
label : 'Advanced Mode'
340
344
} )
341
345
}
0 commit comments