1
1
import * as React from 'react' ;
2
- import * as dateFormat from 'dateformat' ;
3
- import { remote } from 'electron' ;
4
2
import { injectable , inject , postConstruct } from 'inversify' ;
5
3
import URI from '@theia/core/lib/common/uri' ;
6
4
import { EditorWidget } from '@theia/editor/lib/browser/editor-widget' ;
7
5
import { MessageService } from '@theia/core/lib/common/message-service' ;
8
6
import { CommandContribution , CommandRegistry , Command , CommandHandler } from '@theia/core/lib/common/command' ;
9
7
import { TabBarToolbarContribution , TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar' ;
10
- import { BoardsService , BoardsServiceClient , CoreService , Sketch , SketchesService , ToolOutputServiceClient } from '../common/protocol' ;
8
+ import { BoardsService , BoardsServiceClient , CoreService , SketchesService , ToolOutputServiceClient } from '../common/protocol' ;
11
9
import { ArduinoCommands } from './arduino-commands' ;
12
10
import { BoardsServiceClientImpl } from './boards/boards-service-client-impl' ;
13
11
import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands' ;
14
- import { SelectionService , MenuContribution , MenuModelRegistry , MAIN_MENU_BAR , MenuPath , notEmpty } from '@theia/core' ;
12
+ import { SelectionService , MenuContribution , MenuModelRegistry , MAIN_MENU_BAR , MenuPath } from '@theia/core' ;
15
13
import { ArduinoToolbar } from './toolbar/arduino-toolbar' ;
16
14
import { EditorManager , EditorMainMenu } from '@theia/editor/lib/browser' ;
17
15
import {
18
- ContextMenuRenderer , Widget , StatusBar , StatusBarAlignment , FrontendApplicationContribution ,
16
+ ContextMenuRenderer , StatusBar , StatusBarAlignment , FrontendApplicationContribution ,
19
17
FrontendApplication , KeybindingContribution , KeybindingRegistry , OpenerService , open
20
18
} from '@theia/core/lib/browser' ;
21
19
import { OpenFileDialogProps , FileDialogService } from '@theia/filesystem/lib/browser/file-dialog' ;
22
20
import { FileSystem , FileStat } from '@theia/filesystem/lib/common' ;
23
21
import { CommonCommands , CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution' ;
24
- import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution' ;
25
- import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution' ;
26
22
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu' ;
27
23
import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution' ;
28
24
import { MaybePromise } from '@theia/core/lib/common/types' ;
@@ -47,6 +43,7 @@ import { ConfigService } from '../common/protocol/config-service';
47
43
import { BoardsConfigStore } from './boards/boards-config-store' ;
48
44
import { MainMenuManager } from './menu/main-menu-manager' ;
49
45
import { FileSystemExt } from '../common/protocol/filesystem-ext' ;
46
+ import { OpenSketch } from './contributions/open-sketch' ;
50
47
51
48
export namespace ArduinoMenus {
52
49
export const SKETCH = [ ...MAIN_MENU_BAR , '3_sketch' ] ;
@@ -209,24 +206,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
209
206
tooltip : 'Upload' ,
210
207
priority : 2
211
208
} ) ;
212
- registry . registerItem ( {
213
- id : ArduinoCommands . NEW_SKETCH . id ,
214
- command : ArduinoCommands . NEW_SKETCH_TOOLBAR . id ,
215
- tooltip : 'New' ,
216
- priority : 4 // Note: priority 3 was reserved by debug.
217
- } ) ;
218
- registry . registerItem ( {
219
- id : ArduinoCommands . SHOW_OPEN_CONTEXT_MENU . id ,
220
- command : ArduinoCommands . SHOW_OPEN_CONTEXT_MENU . id ,
221
- tooltip : 'Open' ,
222
- priority : 5
223
- } ) ;
224
- registry . registerItem ( {
225
- id : ArduinoCommands . SAVE_SKETCH . id ,
226
- command : ArduinoCommands . SAVE_SKETCH . id ,
227
- tooltip : 'Save' ,
228
- priority : 6
229
- } ) ;
230
209
registry . registerItem ( {
231
210
id : BoardsToolBarItem . TOOLBAR_ID ,
232
211
render : ( ) => < BoardsToolBarItem
@@ -308,101 +287,16 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
308
287
execute : this . upload . bind ( this )
309
288
} ) ;
310
289
311
- registry . registerCommand ( ArduinoCommands . SHOW_OPEN_CONTEXT_MENU , {
312
- isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
313
- execute : async ( widget : Widget , target : EventTarget ) => {
314
- if ( this . wsSketchCount ) {
315
- const el = ( target as HTMLElement ) . parentElement ;
316
- if ( el ) {
317
- this . contextMenuRenderer . render ( ArduinoToolbarContextMenu . OPEN_SKETCH_PATH , {
318
- x : el . getBoundingClientRect ( ) . left ,
319
- y : el . getBoundingClientRect ( ) . top + el . offsetHeight
320
- } ) ;
321
- }
322
- } else {
323
- this . commandRegistry . executeCommand ( ArduinoCommands . OPEN_FILE_NAVIGATOR . id ) ;
324
- }
325
- }
326
- } ) ;
327
-
328
290
registry . registerCommand ( ArduinoCommands . OPEN_FILE_NAVIGATOR , {
329
291
execute : ( ) => this . doOpenFile ( )
330
292
} ) ;
331
293
332
- registry . registerCommand ( ArduinoCommands . OPEN_SKETCH , {
333
- execute : async ( sketch : Sketch ) => {
334
- this . workspaceService . open ( new URI ( sketch . uri ) ) ;
335
- }
336
- } ) ;
337
-
338
294
registry . registerCommand ( ArduinoCommands . OPEN_SKETCH_FILES , {
339
295
execute : async ( uri : string ) => {
340
296
this . openSketchFiles ( uri ) ;
341
297
}
342
298
} ) ;
343
299
344
- registry . registerCommand ( ArduinoCommands . SAVE_SKETCH , {
345
- isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
346
- execute : ( sketch : Sketch ) => {
347
- registry . executeCommand ( CommonCommands . SAVE_ALL . id ) ;
348
- }
349
- } ) ;
350
-
351
- registry . registerCommand ( ArduinoCommands . SAVE_SKETCH_AS , {
352
- execute : async ( { execOnlyIfTemp } : { execOnlyIfTemp : boolean } = { execOnlyIfTemp : false } ) => {
353
- const sketches = ( await Promise . all ( this . workspaceService . tryGetRoots ( ) . map ( ( { uri } ) => this . sketchService . getSketchFolder ( uri ) ) ) ) . filter ( notEmpty ) ;
354
- if ( ! sketches . length ) {
355
- return ;
356
- }
357
- if ( sketches . length > 1 ) {
358
- console . log ( `Multiple sketch folders were found in the workspace. Falling back to the first one. Sketch folders: ${ JSON . stringify ( sketches ) } ` ) ;
359
- }
360
- const sketch = sketches [ 0 ] ;
361
- const isTemp = await this . sketchService . isTemp ( sketch ) ;
362
- if ( ! isTemp && ! ! execOnlyIfTemp ) {
363
- return ;
364
- }
365
-
366
- // If target does not exist, propose a `directories.user`/${sketch.name} path
367
- // If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
368
- const sketchDirUri = new URI ( ( await this . configService . getConfiguration ( ) ) . sketchDirUri ) ;
369
- const exists = await this . fileSystem . exists ( sketchDirUri . resolve ( sketch . name ) . toString ( ) ) ;
370
- const defaultUri = exists
371
- ? sketchDirUri . resolve ( sketchDirUri . resolve ( `${ sketch . name } _copy_${ dateFormat ( new Date ( ) , 'yyyymmddHHMMss' ) } ` ) . toString ( ) )
372
- : sketchDirUri . resolve ( sketch . name ) ;
373
- const defaultPath = await this . fileSystem . getFsPath ( defaultUri . toString ( ) ) ! ;
374
- const { filePath, canceled } = await remote . dialog . showSaveDialog ( { title : 'Save sketch folder as...' , defaultPath } ) ;
375
- if ( ! filePath || canceled ) {
376
- return ;
377
- }
378
- const destinationUri = await this . fileSystemExt . getUri ( filePath ) ;
379
- if ( ! destinationUri ) {
380
- return ;
381
- }
382
- const workspaceUri = await this . sketchService . copy ( sketch , { destinationUri } ) ;
383
- if ( workspaceUri ) {
384
- this . workspaceService . open ( new URI ( workspaceUri ) ) ;
385
- }
386
- }
387
- } ) ;
388
-
389
- registry . registerCommand ( ArduinoCommands . NEW_SKETCH , {
390
- execute : async ( ) => {
391
- try {
392
- const sketch = await this . sketchService . createNewSketch ( ) ;
393
- this . workspaceService . open ( new URI ( sketch . uri ) ) ;
394
- } catch ( e ) {
395
- await this . messageService . error ( e . toString ( ) ) ;
396
- }
397
- }
398
- } ) ;
399
- registry . registerCommand ( ArduinoCommands . NEW_SKETCH_TOOLBAR , {
400
- isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
401
- execute : async ( ) => {
402
- return registry . executeCommand ( ArduinoCommands . NEW_SKETCH . id ) ;
403
- }
404
- } ) ;
405
-
406
300
registry . registerCommand ( ArduinoCommands . OPEN_BOARDS_DIALOG , {
407
301
execute : async ( ) => {
408
302
const boardsConfig = await this . boardsConfigDialog . open ( ) ;
@@ -516,17 +410,18 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
516
410
CommonCommands . TOGGLE_MAXIMIZED ,
517
411
FileNavigatorCommands . REVEAL_IN_NAVIGATOR
518
412
] ) {
519
- registry . unregisterMenuAction ( command ) ;
413
+ if ( command ) { }
414
+ // registry.unregisterMenuAction(command);
520
415
}
521
416
522
- registry . unregisterMenuAction ( FileSystemCommands . UPLOAD ) ;
523
- registry . unregisterMenuAction ( FileDownloadCommands . DOWNLOAD ) ;
417
+ // registry.unregisterMenuAction(FileSystemCommands.UPLOAD);
418
+ // registry.unregisterMenuAction(FileDownloadCommands.DOWNLOAD);
524
419
525
- registry . unregisterMenuAction ( WorkspaceCommands . OPEN_FOLDER ) ;
526
- registry . unregisterMenuAction ( WorkspaceCommands . OPEN_WORKSPACE ) ;
527
- registry . unregisterMenuAction ( WorkspaceCommands . OPEN_RECENT_WORKSPACE ) ;
528
- registry . unregisterMenuAction ( WorkspaceCommands . SAVE_WORKSPACE_AS ) ;
529
- registry . unregisterMenuAction ( WorkspaceCommands . CLOSE ) ;
420
+ // registry.unregisterMenuAction(WorkspaceCommands.OPEN_FOLDER);
421
+ // registry.unregisterMenuAction(WorkspaceCommands.OPEN_WORKSPACE);
422
+ // registry.unregisterMenuAction(WorkspaceCommands.OPEN_RECENT_WORKSPACE);
423
+ // registry.unregisterMenuAction(WorkspaceCommands.SAVE_WORKSPACE_AS);
424
+ // registry.unregisterMenuAction(WorkspaceCommands.CLOSE);
530
425
531
426
registry . getMenu ( MAIN_MENU_BAR ) . removeNode ( this . getMenuId ( MonacoMenus . SELECTION ) ) ;
532
427
registry . getMenu ( MAIN_MENU_BAR ) . removeNode ( this . getMenuId ( EditorMainMenu . GO ) ) ;
@@ -549,10 +444,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
549
444
label : 'Upload' ,
550
445
order : '3'
551
446
} ) ;
552
- registry . registerMenuAction ( ArduinoToolbarContextMenu . OPEN_GROUP , {
553
- commandId : ArduinoCommands . OPEN_FILE_NAVIGATOR . id ,
554
- label : 'Open...'
555
- } ) ;
556
447
557
448
registry . registerSubmenu ( ArduinoMenus . TOOLS , 'Tools' ) ;
558
449
@@ -561,18 +452,10 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
561
452
label : 'Advanced Mode'
562
453
} ) ;
563
454
564
- registry . registerMenuAction ( [ ...CommonMenus . FILE , '0_new_sketch' ] , {
565
- commandId : ArduinoCommands . NEW_SKETCH . id
566
- } ) ;
567
-
568
455
registry . registerMenuAction ( [ ...CommonMenus . FILE_SETTINGS_SUBMENU , '3_settings_cli' ] , {
569
456
commandId : ArduinoCommands . OPEN_CLI_CONFIG . id
570
457
} ) ;
571
458
572
- registry . registerMenuAction ( CommonMenus . FILE_SAVE , {
573
- commandId : ArduinoCommands . SAVE_SKETCH_AS . id ,
574
- label : 'Save As...'
575
- } ) ;
576
459
}
577
460
578
461
protected getMenuId ( menuPath : string [ ] ) : string {
@@ -591,14 +474,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
591
474
command : ArduinoCommands . UPLOAD . id ,
592
475
keybinding : 'CtrlCmd+Alt+U'
593
476
} ) ;
594
- keybindings . registerKeybinding ( {
595
- command : ArduinoCommands . NEW_SKETCH . id ,
596
- keybinding : 'CtrlCmd+N'
597
- } ) ;
598
- keybindings . registerKeybinding ( {
599
- command : ArduinoCommands . SAVE_SKETCH_AS . id ,
600
- keybinding : 'CtrlCmd+Shift+S'
601
- } ) ;
602
477
}
603
478
604
479
protected async registerSketchesInMenu ( registry : MenuModelRegistry ) : Promise < void > {
@@ -609,7 +484,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
609
484
id : 'openSketch' + sketch . name
610
485
}
611
486
this . commandRegistry . registerCommand ( command , {
612
- execute : ( ) => this . commandRegistry . executeCommand ( ArduinoCommands . OPEN_SKETCH . id , sketch )
487
+ execute : ( ) => this . commandRegistry . executeCommand ( OpenSketch . Commands . OPEN_SKETCH . id , sketch )
613
488
} ) ;
614
489
615
490
registry . registerMenuAction ( ArduinoToolbarContextMenu . WS_SKETCHES_GROUP , {
0 commit comments