@@ -17,6 +17,7 @@ import {
17
17
Navigatable ,
18
18
RenderContextMenuOptions ,
19
19
SelectableTreeNode ,
20
+ TreeNode ,
20
21
Widget ,
21
22
} from '@theia/core/lib/browser' ;
22
23
import {
@@ -29,9 +30,9 @@ import {
29
30
} from '../../../common/protocol/sketches-service-client-impl' ;
30
31
import { FileService } from '@theia/filesystem/lib/browser/file-service' ;
31
32
import { URI } from '../../contributions/contribution' ;
32
- import { EditorManager } from '@theia/editor/lib/browser' ;
33
33
import { SketchControl } from '../../contributions/sketch-control' ;
34
- import { CloudSketchbookCommands } from '../cloud-sketchbook/cloud-sketchbook-contributions' ;
34
+ import { SketchbookTreeWidget } from './sketchbook-tree-widget' ;
35
+ import { EncodableCommad } from './encoded-commands-contribution' ;
35
36
36
37
export const SKETCHBOOK__CONTEXT = [ 'arduino-sketchbook--context' ] ;
37
38
@@ -70,9 +71,6 @@ export class SketchbookWidgetContribution
70
71
@inject ( FileService )
71
72
protected readonly fileService : FileService ;
72
73
73
- @inject ( EditorManager )
74
- protected readonly editorManager : EditorManager ;
75
-
76
74
@inject ( SketchControl )
77
75
protected readonly sketchControl : SketchControl ;
78
76
@@ -110,7 +108,8 @@ export class SketchbookWidgetContribution
110
108
override registerCommands ( registry : CommandRegistry ) : void {
111
109
super . registerCommands ( registry ) ;
112
110
registry . registerCommand ( SketchbookCommands . SHOW_SKETCHBOOK_WIDGET , {
113
- execute : ( ) => this . showLocalSketchbookWidget ( ) ,
111
+ execute : ( treeWidget : SketchbookTreeWidget , node : TreeNode ) =>
112
+ this . showSketchbookWidget ( treeWidget , node ) ,
114
113
} ) ;
115
114
registry . registerCommand ( SketchbookCommands . OPEN_NEW_WINDOW , {
116
115
execute : ( arg ) => this . openSketchInNewWindow ( arg ) ,
@@ -201,12 +200,16 @@ export class SketchbookWidgetContribution
201
200
} ) ;
202
201
}
203
202
204
- openSketchInNewWindow ( arg : any ) : any {
205
- const openSketchbookCommand = this . sketchControl . isCloudSketch ( arg . node . uri )
206
- ? CloudSketchbookCommands . SHOW_CLOUD_SKETCHBOOK_WIDGET
207
- : SketchbookCommands . SHOW_SKETCHBOOK_WIDGET ;
203
+ async openSketchInNewWindow ( arg : any ) : Promise < any > {
204
+ const treeWidget : SketchbookTreeWidget = (
205
+ await this . widget
206
+ ) . getTreeWidget ( ) ;
207
+ const command : EncodableCommad = {
208
+ id : SketchbookCommands . SHOW_SKETCHBOOK_WIDGET . id ,
209
+ args : [ treeWidget , arg . node ] ,
210
+ } ;
208
211
return this . workspaceService . openWithCommands ( arg . node . uri , {
209
- commands : [ openSketchbookCommand ] ,
212
+ commands : [ command ] ,
210
213
} ) ;
211
214
}
212
215
@@ -249,13 +252,19 @@ export class SketchbookWidgetContribution
249
252
this . selectWidgetFileNode ( this . shell . currentWidget ) ;
250
253
}
251
254
252
- protected async showLocalSketchbookWidget ( ) : Promise < void > {
255
+ protected async showSketchbookWidget (
256
+ treeWidget : SketchbookTreeWidget ,
257
+ node : TreeNode
258
+ ) : Promise < void > {
253
259
this . widget
254
260
. then ( ( widget ) => this . shell . activateWidget ( widget . id ) )
255
261
. then ( ( widget ) => {
256
262
if ( widget instanceof SketchbookWidget ) {
257
- widget . activateTreeWidget ( widget . getTreeWidget ( ) . id ) ;
258
- this . selectWidgetFileNode ( this . editorManager . currentEditor ) ;
263
+ widget . activateTreeWidget ( treeWidget . id ) ;
264
+ if ( SelectableTreeNode . is ( node ) ) {
265
+ const { model } = treeWidget ;
266
+ model . selectNode ( node ) ;
267
+ }
259
268
}
260
269
} ) ;
261
270
}
0 commit comments