11import * as React from 'react' ;
2- import * as dateFormat from 'dateformat' ;
3- import { remote } from 'electron' ;
42import { injectable , inject , postConstruct } from 'inversify' ;
53import URI from '@theia/core/lib/common/uri' ;
64import { EditorWidget } from '@theia/editor/lib/browser/editor-widget' ;
75import { MessageService } from '@theia/core/lib/common/message-service' ;
86import { CommandContribution , CommandRegistry , Command , CommandHandler } from '@theia/core/lib/common/command' ;
97import { 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' ;
119import { ArduinoCommands } from './arduino-commands' ;
1210import { BoardsServiceClientImpl } from './boards/boards-service-client-impl' ;
1311import { 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' ;
1513import { ArduinoToolbar } from './toolbar/arduino-toolbar' ;
1614import { EditorManager , EditorMainMenu } from '@theia/editor/lib/browser' ;
1715import {
18- ContextMenuRenderer , Widget , StatusBar , StatusBarAlignment , FrontendApplicationContribution ,
16+ ContextMenuRenderer , StatusBar , StatusBarAlignment , FrontendApplicationContribution ,
1917 FrontendApplication , KeybindingContribution , KeybindingRegistry , OpenerService , open
2018} from '@theia/core/lib/browser' ;
2119import { OpenFileDialogProps , FileDialogService } from '@theia/filesystem/lib/browser/file-dialog' ;
2220import { FileSystem , FileStat } from '@theia/filesystem/lib/common' ;
2321import { 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' ;
2622import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu' ;
2723import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution' ;
2824import { MaybePromise } from '@theia/core/lib/common/types' ;
@@ -47,6 +43,7 @@ import { ConfigService } from '../common/protocol/config-service';
4743import { BoardsConfigStore } from './boards/boards-config-store' ;
4844import { MainMenuManager } from './menu/main-menu-manager' ;
4945import { FileSystemExt } from '../common/protocol/filesystem-ext' ;
46+ import { OpenSketch } from './contributions/open-sketch' ;
5047
5148export namespace ArduinoMenus {
5249 export const SKETCH = [ ...MAIN_MENU_BAR , '3_sketch' ] ;
@@ -209,24 +206,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
209206 tooltip : 'Upload' ,
210207 priority : 2
211208 } ) ;
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- } ) ;
230209 registry . registerItem ( {
231210 id : BoardsToolBarItem . TOOLBAR_ID ,
232211 render : ( ) => < BoardsToolBarItem
@@ -308,101 +287,16 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
308287 execute : this . upload . bind ( this )
309288 } ) ;
310289
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-
328290 registry . registerCommand ( ArduinoCommands . OPEN_FILE_NAVIGATOR , {
329291 execute : ( ) => this . doOpenFile ( )
330292 } ) ;
331293
332- registry . registerCommand ( ArduinoCommands . OPEN_SKETCH , {
333- execute : async ( sketch : Sketch ) => {
334- this . workspaceService . open ( new URI ( sketch . uri ) ) ;
335- }
336- } ) ;
337-
338294 registry . registerCommand ( ArduinoCommands . OPEN_SKETCH_FILES , {
339295 execute : async ( uri : string ) => {
340296 this . openSketchFiles ( uri ) ;
341297 }
342298 } ) ;
343299
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-
406300 registry . registerCommand ( ArduinoCommands . OPEN_BOARDS_DIALOG , {
407301 execute : async ( ) => {
408302 const boardsConfig = await this . boardsConfigDialog . open ( ) ;
@@ -516,17 +410,18 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
516410 CommonCommands . TOGGLE_MAXIMIZED ,
517411 FileNavigatorCommands . REVEAL_IN_NAVIGATOR
518412 ] ) {
519- registry . unregisterMenuAction ( command ) ;
413+ if ( command ) { }
414+ // registry.unregisterMenuAction(command);
520415 }
521416
522- registry . unregisterMenuAction ( FileSystemCommands . UPLOAD ) ;
523- registry . unregisterMenuAction ( FileDownloadCommands . DOWNLOAD ) ;
417+ // registry.unregisterMenuAction(FileSystemCommands.UPLOAD);
418+ // registry.unregisterMenuAction(FileDownloadCommands.DOWNLOAD);
524419
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);
530425
531426 registry . getMenu ( MAIN_MENU_BAR ) . removeNode ( this . getMenuId ( MonacoMenus . SELECTION ) ) ;
532427 registry . getMenu ( MAIN_MENU_BAR ) . removeNode ( this . getMenuId ( EditorMainMenu . GO ) ) ;
@@ -549,10 +444,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
549444 label : 'Upload' ,
550445 order : '3'
551446 } ) ;
552- registry . registerMenuAction ( ArduinoToolbarContextMenu . OPEN_GROUP , {
553- commandId : ArduinoCommands . OPEN_FILE_NAVIGATOR . id ,
554- label : 'Open...'
555- } ) ;
556447
557448 registry . registerSubmenu ( ArduinoMenus . TOOLS , 'Tools' ) ;
558449
@@ -561,18 +452,10 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
561452 label : 'Advanced Mode'
562453 } ) ;
563454
564- registry . registerMenuAction ( [ ...CommonMenus . FILE , '0_new_sketch' ] , {
565- commandId : ArduinoCommands . NEW_SKETCH . id
566- } ) ;
567-
568455 registry . registerMenuAction ( [ ...CommonMenus . FILE_SETTINGS_SUBMENU , '3_settings_cli' ] , {
569456 commandId : ArduinoCommands . OPEN_CLI_CONFIG . id
570457 } ) ;
571458
572- registry . registerMenuAction ( CommonMenus . FILE_SAVE , {
573- commandId : ArduinoCommands . SAVE_SKETCH_AS . id ,
574- label : 'Save As...'
575- } ) ;
576459 }
577460
578461 protected getMenuId ( menuPath : string [ ] ) : string {
@@ -591,14 +474,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
591474 command : ArduinoCommands . UPLOAD . id ,
592475 keybinding : 'CtrlCmd+Alt+U'
593476 } ) ;
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- } ) ;
602477 }
603478
604479 protected async registerSketchesInMenu ( registry : MenuModelRegistry ) : Promise < void > {
@@ -609,7 +484,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
609484 id : 'openSketch' + sketch . name
610485 }
611486 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 )
613488 } ) ;
614489
615490 registry . registerMenuAction ( ArduinoToolbarContextMenu . WS_SKETCHES_GROUP , {
0 commit comments