@@ -3,7 +3,7 @@ import { injectable, inject, postConstruct } from 'inversify';
3
3
import URI from '@theia/core/lib/common/uri' ;
4
4
import { EditorWidget } from '@theia/editor/lib/browser/editor-widget' ;
5
5
import { MessageService } from '@theia/core/lib/common/message-service' ;
6
- import { CommandContribution , CommandRegistry , Command } from '@theia/core/lib/common/command' ;
6
+ import { CommandContribution , CommandRegistry , Command , CommandHandler } from '@theia/core/lib/common/command' ;
7
7
import { TabBarToolbarContribution , TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar' ;
8
8
import { BoardsService } from '../common/protocol/boards-service' ;
9
9
import { ArduinoCommands } from './arduino-commands' ;
@@ -22,9 +22,11 @@ import {
22
22
OpenerService ,
23
23
Widget ,
24
24
StatusBar ,
25
- ShellLayoutRestorer ,
26
25
StatusBarAlignment ,
27
- QuickOpenService
26
+ QuickOpenService ,
27
+ ApplicationShell ,
28
+ FrontendApplicationContribution ,
29
+ FrontendApplication
28
30
} from '@theia/core/lib/browser' ;
29
31
import { OpenFileDialogProps , FileDialogService } from '@theia/filesystem/lib/browser/file-dialog' ;
30
32
import { FileSystem , FileStat } from '@theia/filesystem/lib/common' ;
@@ -44,6 +46,14 @@ import { ConfigService } from '../common/protocol/config-service';
44
46
import { MonitorConnection } from './monitor/monitor-connection' ;
45
47
import { MonitorViewContribution } from './monitor/monitor-view-contribution' ;
46
48
import { ArduinoWorkspaceService } from './arduino-workspace-service' ;
49
+ import { FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution' ;
50
+ import { OutlineViewContribution } from '@theia/outline-view/lib/browser/outline-view-contribution' ;
51
+ import { ProblemContribution } from '@theia/markers/lib/browser/problem/problem-contribution' ;
52
+ import { ScmContribution } from '@theia/scm/lib/browser/scm-contribution' ;
53
+ import { SearchInWorkspaceFrontendContribution } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution' ;
54
+ import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution' ;
55
+ import { ArduinoShellLayoutRestorer } from './shell/arduino-shell-layout-restorer' ;
56
+ import { EditorMode } from './editor-mode' ;
47
57
48
58
export namespace ArduinoMenus {
49
59
export const SKETCH = [ ...MAIN_MENU_BAR , '3_sketch' ] ;
@@ -57,16 +67,8 @@ export namespace ArduinoToolbarContextMenu {
57
67
export const EXAMPLE_SKETCHES_GROUP : MenuPath = [ ...OPEN_SKETCH_PATH , '3_examples' ] ;
58
68
}
59
69
60
- export namespace ArduinoAdvancedMode {
61
- export const LS_ID = 'arduino-advanced-mode' ;
62
- export const TOGGLED : boolean = ( ( ) => {
63
- const advancedModeStr = window . localStorage . getItem ( LS_ID ) ;
64
- return advancedModeStr === 'true' ;
65
- } ) ( ) ;
66
- }
67
-
68
70
@injectable ( )
69
- export class ArduinoFrontendContribution implements TabBarToolbarContribution , CommandContribution , MenuContribution {
71
+ export class ArduinoFrontendContribution implements FrontendApplicationContribution , TabBarToolbarContribution , CommandContribution , MenuContribution {
70
72
71
73
@inject ( MessageService )
72
74
protected readonly messageService : MessageService ;
@@ -126,13 +128,13 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
126
128
protected readonly menuRegistry : MenuModelRegistry ;
127
129
128
130
@inject ( CommandRegistry )
129
- protected readonly commands : CommandRegistry ;
131
+ protected readonly commandRegistry : CommandRegistry ;
130
132
131
133
@inject ( StatusBar )
132
134
protected readonly statusBar : StatusBar ;
133
135
134
- @inject ( ShellLayoutRestorer )
135
- protected readonly layoutRestorer : ShellLayoutRestorer ;
136
+ @inject ( ArduinoShellLayoutRestorer )
137
+ protected readonly layoutRestorer : ArduinoShellLayoutRestorer ;
136
138
137
139
@inject ( QuickOpenService )
138
140
protected readonly quickOpenService : QuickOpenService ;
@@ -146,8 +148,29 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
146
148
@inject ( MonitorConnection )
147
149
protected readonly monitorConnection : MonitorConnection ;
148
150
149
- protected boardsToolbarItem : BoardsToolBarItem | null ;
150
- protected wsSketchCount : number = 0 ;
151
+ @inject ( ApplicationShell )
152
+ protected readonly shell : ApplicationShell ;
153
+
154
+ @inject ( FileNavigatorContribution )
155
+ protected readonly fileNavigatorContributions : FileNavigatorContribution ;
156
+
157
+ @inject ( OutlineViewContribution )
158
+ protected readonly outlineContribution : OutlineViewContribution ;
159
+
160
+ @inject ( ProblemContribution )
161
+ protected readonly problemContribution : ProblemContribution ;
162
+
163
+ @inject ( ScmContribution )
164
+ protected readonly scmContribution : ScmContribution ;
165
+
166
+ @inject ( SearchInWorkspaceFrontendContribution )
167
+ protected readonly siwContribution : SearchInWorkspaceFrontendContribution ;
168
+
169
+ @inject ( EditorMode )
170
+ protected readonly editorMode : EditorMode ;
171
+
172
+ protected application : FrontendApplication ;
173
+ protected wsSketchCount : number = 0 ; // TODO: this does not belong here, does it?
151
174
152
175
@postConstruct ( )
153
176
protected async init ( ) : Promise < void > {
@@ -171,6 +194,22 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
171
194
] ) . then ( ( [ { boards } , { ports } ] ) => this . boardsServiceClient . tryReconnect ( boards , ports ) ) ;
172
195
}
173
196
197
+ onStart ( app : FrontendApplication ) : void {
198
+ this . application = app ;
199
+ // Initialize all `pro-mode` widgets. This is a NOOP if in normal mode.
200
+ for ( const viewContribution of [
201
+ this . fileNavigatorContributions ,
202
+ this . outlineContribution ,
203
+ this . problemContribution ,
204
+ this . scmContribution ,
205
+ this . siwContribution ] as Array < FrontendApplicationContribution > ) {
206
+
207
+ if ( viewContribution . initializeLayout ) {
208
+ viewContribution . initializeLayout ( this . application ) ;
209
+ }
210
+ }
211
+ }
212
+
174
213
registerToolbarItems ( registry : TabBarToolbarRegistry ) : void {
175
214
registry . registerItem ( {
176
215
id : ArduinoCommands . VERIFY . id ,
@@ -196,8 +235,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
196
235
id : BoardsToolBarItem . TOOLBAR_ID ,
197
236
render : ( ) => < BoardsToolBarItem
198
237
key = 'boardsToolbarItem'
199
- ref = { ref => this . boardsToolbarItem = ref }
200
- commands = { this . commands }
238
+ commands = { this . commandRegistry }
201
239
boardsServiceClient = { this . boardsServiceClient }
202
240
boardService = { this . boardsService } /> ,
203
241
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left'
@@ -213,12 +251,48 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
213
251
id : ArduinoCommands . TOGGLE_ADVANCED_MODE . id ,
214
252
command : ArduinoCommands . TOGGLE_ADVANCED_MODE . id ,
215
253
tooltip : 'Toggle Advanced Mode' ,
216
- text : ( ArduinoAdvancedMode . TOGGLED ? '$(toggle-on)' : '$(toggle-off)' ) ,
254
+ text : ( this . editorMode . proMode ? '$(toggle-on)' : '$(toggle-off)' ) ,
217
255
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'right'
218
256
} ) ;
219
257
}
220
258
221
259
registerCommands ( registry : CommandRegistry ) : void {
260
+ // TODO: use proper API https://github.com/eclipse-theia/theia/pull/6599
261
+ const allHandlers : { [ id : string ] : CommandHandler [ ] } = ( registry as any ) . _handlers ;
262
+ // Make sure to reveal the `Explorer` before executing `New File` and `New Folder`.
263
+ for ( const command of [ WorkspaceCommands . NEW_FILE , WorkspaceCommands . NEW_FOLDER ] ) {
264
+ const { id } = command ;
265
+ const handlers = allHandlers [ id ] . slice ( ) ;
266
+ registry . unregisterCommand ( id ) ;
267
+ registry . registerCommand ( command ) ;
268
+ for ( const handler of handlers ) {
269
+ const wrapper : CommandHandler = {
270
+ execute : ( ...args : any [ ] ) => {
271
+ this . fileNavigatorContributions . openView ( { reveal : true } ) . then ( ( ) => handler . execute ( args ) ) ;
272
+ } ,
273
+ isVisible : ( ...args : any [ ] ) => {
274
+ return handler . isVisible ! ( args ) ;
275
+ } ,
276
+ isEnabled : ( args : any [ ] ) => {
277
+ return handler . isEnabled ! ( args ) ;
278
+ } ,
279
+ isToggled : ( args : any [ ] ) => {
280
+ return handler . isToggled ! ( args ) ;
281
+ }
282
+ } ;
283
+ if ( ! handler . isEnabled ) {
284
+ delete wrapper . isEnabled ;
285
+ }
286
+ if ( ! handler . isToggled ) {
287
+ delete wrapper . isToggled ;
288
+ }
289
+ if ( ! handler . isVisible ) {
290
+ delete wrapper . isVisible ;
291
+ }
292
+ registry . registerHandler ( id , wrapper ) ;
293
+ }
294
+ }
295
+
222
296
registry . registerCommand ( ArduinoCommands . VERIFY , {
223
297
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
224
298
isEnabled : widget => true ,
@@ -296,7 +370,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
296
370
} ) ;
297
371
}
298
372
} else {
299
- this . commands . executeCommand ( ArduinoCommands . OPEN_FILE_NAVIGATOR . id ) ;
373
+ this . commandRegistry . executeCommand ( ArduinoCommands . OPEN_FILE_NAVIGATOR . id ) ;
300
374
}
301
375
}
302
376
} ) ;
@@ -342,18 +416,14 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
342
416
}
343
417
} )
344
418
registry . registerCommand ( ArduinoCommands . TOGGLE_ADVANCED_MODE , {
345
- execute : ( ) => {
346
- const oldModeState = ArduinoAdvancedMode . TOGGLED ;
347
- window . localStorage . setItem ( ArduinoAdvancedMode . LS_ID , oldModeState ? 'false' : 'true' ) ;
348
- registry . executeCommand ( 'reset.layout' ) ;
349
- } ,
419
+ execute : ( ) => this . editorMode . toggle ( ) ,
350
420
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'right' ,
351
- isToggled : ( ) => ArduinoAdvancedMode . TOGGLED
421
+ isToggled : ( ) => this . editorMode . proMode
352
422
} )
353
423
}
354
424
355
425
registerMenus ( registry : MenuModelRegistry ) {
356
- if ( ! ArduinoAdvancedMode . TOGGLED ) {
426
+ if ( ! this . editorMode . proMode ) {
357
427
// If are not in pro-mode, we have to disable the context menu for the tabs.
358
428
// Such as `Close`, `Close All`, etc.
359
429
for ( const command of [
@@ -362,16 +432,15 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
362
432
CommonCommands . CLOSE_RIGHT_TABS ,
363
433
CommonCommands . CLOSE_ALL_TABS ,
364
434
CommonCommands . COLLAPSE_PANEL ,
365
- CommonCommands . TOGGLE_MAXIMIZED
435
+ CommonCommands . TOGGLE_MAXIMIZED ,
436
+ FileNavigatorCommands . REVEAL_IN_NAVIGATOR
366
437
] ) {
367
438
registry . unregisterMenuAction ( command ) ;
368
439
}
369
440
370
441
registry . unregisterMenuAction ( FileSystemCommands . UPLOAD ) ;
371
442
registry . unregisterMenuAction ( FileDownloadCommands . DOWNLOAD ) ;
372
443
373
- registry . unregisterMenuAction ( WorkspaceCommands . NEW_FOLDER ) ;
374
-
375
444
registry . unregisterMenuAction ( WorkspaceCommands . OPEN_FOLDER ) ;
376
445
registry . unregisterMenuAction ( WorkspaceCommands . OPEN_WORKSPACE ) ;
377
446
registry . unregisterMenuAction ( WorkspaceCommands . OPEN_RECENT_WORKSPACE ) ;
@@ -425,8 +494,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
425
494
const command : Command = {
426
495
id : 'openSketch' + sketch . name
427
496
}
428
- this . commands . registerCommand ( command , {
429
- execute : ( ) => this . commands . executeCommand ( ArduinoCommands . OPEN_SKETCH . id , sketch )
497
+ this . commandRegistry . registerCommand ( command , {
498
+ execute : ( ) => this . commandRegistry . executeCommand ( ArduinoCommands . OPEN_SKETCH . id , sketch )
430
499
} ) ;
431
500
432
501
registry . registerMenuAction ( ArduinoToolbarContextMenu . WS_SKETCHES_GROUP , {
@@ -466,7 +535,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
466
535
if ( destinationFile && ! destinationFile . isDirectory ) {
467
536
const message = await this . validate ( destinationFile ) ;
468
537
if ( ! message ) {
469
- await this . workspaceService . open ( destinationFileUri ) ;
538
+ this . workspaceService . open ( destinationFileUri ) ;
470
539
return destinationFileUri ;
471
540
} else {
472
541
this . messageService . warn ( message ) ;
0 commit comments