@@ -24,7 +24,9 @@ import { EditorManager } from '@theia/editor/lib/browser';
24
24
import { open , ContextMenuRenderer , OpenerService , Widget } from '@theia/core/lib/browser' ;
25
25
import { OpenFileDialogProps , FileDialogService } from '@theia/filesystem/lib/browser/file-dialog' ;
26
26
import { FileSystem } from '@theia/filesystem/lib/common' ;
27
- import { ArduinoOpenSketchContextMenu , SketchMenuEntry } from './arduino-file-menu' ;
27
+ import { ArduinoOpenSketchContextMenu } from './arduino-file-menu' ;
28
+ import { Sketch , SketchesService } from '../common/protocol/sketches-service' ;
29
+ import { WindowService } from '@theia/core/lib/browser/window/window-service' ;
28
30
29
31
@injectable ( )
30
32
export class ArduinoFrontendContribution extends DefaultFrontendApplicationContribution implements TabBarToolbarContribution , CommandContribution {
@@ -68,15 +70,22 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
68
70
@inject ( ContextMenuRenderer )
69
71
protected readonly contextMenuRenderer : ContextMenuRenderer ;
70
72
71
- @inject ( FileDialogService )
73
+ @inject ( FileDialogService )
72
74
protected readonly fileDialogService : FileDialogService ;
73
75
74
- @inject ( FileSystem )
76
+ @inject ( FileSystem )
75
77
protected readonly fileSystem : FileSystem ;
76
78
77
- @inject ( OpenerService )
79
+ @inject ( OpenerService )
78
80
protected readonly openerService : OpenerService ;
79
81
82
+ @inject ( SketchesService )
83
+ protected readonly sketches : SketchesService ;
84
+
85
+ @inject ( WindowService )
86
+ protected readonly windowService : WindowService ;
87
+
88
+
80
89
@postConstruct ( )
81
90
protected async init ( ) : Promise < void > {
82
91
// This is a hack. Otherwise, the backend services won't bind.
@@ -165,7 +174,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
165
174
isEnabled : widget => this . isArduinoToolbar ( widget ) ,
166
175
execute : async ( widget : Widget , event : React . MouseEvent < HTMLElement > ) => {
167
176
const el = ( event . target as HTMLElement ) . parentElement ;
168
- if ( el ) {
177
+ if ( el ) {
169
178
this . contextMenuRenderer . render ( ArduinoOpenSketchContextMenu . PATH , {
170
179
x : el . getBoundingClientRect ( ) . left ,
171
180
y : el . getBoundingClientRect ( ) . top + el . offsetHeight
@@ -179,8 +188,24 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
179
188
} )
180
189
registry . registerCommand ( ArduinoCommands . OPEN_SKETCH , {
181
190
isEnabled : ( ) => true ,
182
- execute : ( sketch : SketchMenuEntry ) => {
183
- console . log ( "OPEN SOME SKETCH" , sketch ) ;
191
+ execute : async ( sketch : Sketch ) => {
192
+ // const url = new URL(window.location.href);
193
+ // if (this.workspaceService.workspace) {
194
+ // const wsUri = this.workspaceService.workspace.uri;
195
+ // const path = new URI(wsUri).path;
196
+ // url.hash = path + '?sketch=' + sketch.name
197
+ // }
198
+ // this.windowService.openNewWindow(url.toString());
199
+
200
+ const fileStat = await this . fileSystem . getFileStat ( sketch . uri ) ;
201
+ if ( fileStat ) {
202
+ const sketchFiles = await this . sketches . getSketchFiles ( fileStat ) ;
203
+ sketchFiles . forEach ( sketchFile => {
204
+ const uri = new URI ( sketchFile ) ;
205
+ this . editorManager . open ( uri ) ;
206
+ } ) ;
207
+ }
208
+
184
209
}
185
210
} )
186
211
registry . registerCommand ( ArduinoCommands . NEW_SKETCH , new WorkspaceRootUriAwareCommandHandler ( this . workspaceService , this . selectionService , {
0 commit comments