@@ -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' ;
@@ -257,6 +257,42 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
257
257
}
258
258
259
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
+
260
296
registry . registerCommand ( ArduinoCommands . VERIFY , {
261
297
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
262
298
isEnabled : widget => true ,
@@ -398,16 +434,13 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
398
434
CommonCommands . COLLAPSE_PANEL ,
399
435
CommonCommands . TOGGLE_MAXIMIZED ,
400
436
FileNavigatorCommands . REVEAL_IN_NAVIGATOR
401
-
402
437
] ) {
403
438
registry . unregisterMenuAction ( command ) ;
404
439
}
405
440
406
441
registry . unregisterMenuAction ( FileSystemCommands . UPLOAD ) ;
407
442
registry . unregisterMenuAction ( FileDownloadCommands . DOWNLOAD ) ;
408
443
409
- registry . unregisterMenuAction ( WorkspaceCommands . NEW_FOLDER ) ;
410
-
411
444
registry . unregisterMenuAction ( WorkspaceCommands . OPEN_FOLDER ) ;
412
445
registry . unregisterMenuAction ( WorkspaceCommands . OPEN_WORKSPACE ) ;
413
446
registry . unregisterMenuAction ( WorkspaceCommands . OPEN_RECENT_WORKSPACE ) ;
@@ -502,7 +535,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
502
535
if ( destinationFile && ! destinationFile . isDirectory ) {
503
536
const message = await this . validate ( destinationFile ) ;
504
537
if ( ! message ) {
505
- await this . workspaceService . open ( destinationFileUri ) ;
538
+ this . workspaceService . open ( destinationFileUri ) ;
506
539
return destinationFileUri ;
507
540
} else {
508
541
this . messageService . warn ( message ) ;
0 commit comments