1
1
import * as remote from '@theia/core/electron-shared/@electron/remote' ;
2
2
import { inject , injectable } from '@theia/core/shared/inversify' ;
3
- import { CommandRegistry } from '@theia/core/lib/common/command' ;
3
+ import { Command , CommandRegistry } from '@theia/core/lib/common/command' ;
4
4
import { MenuModelRegistry } from '@theia/core/lib/common/menu' ;
5
5
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service' ;
6
6
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution' ;
@@ -29,6 +29,10 @@ import {
29
29
} from '../../../common/protocol/sketches-service-client-impl' ;
30
30
import { FileService } from '@theia/filesystem/lib/browser/file-service' ;
31
31
import { URI } from '../../contributions/contribution' ;
32
+ import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state' ;
33
+ import { EditorManager } from '@theia/editor/lib/browser' ;
34
+ import { SketchControl } from '../../contributions/sketch-control' ;
35
+ import { CloudSketchbookCommands } from '../cloud-sketchbook/cloud-sketchbook-contributions' ;
32
36
33
37
export const SKETCHBOOK__CONTEXT = [ 'arduino-sketchbook--context' ] ;
34
38
@@ -67,6 +71,18 @@ export class SketchbookWidgetContribution
67
71
@inject ( FileService )
68
72
protected readonly fileService : FileService ;
69
73
74
+ @inject ( CommandRegistry )
75
+ protected readonly commandRegistry : CommandRegistry ;
76
+
77
+ @inject ( FrontendApplicationStateService )
78
+ private readonly app : FrontendApplicationStateService ;
79
+
80
+ @inject ( EditorManager )
81
+ protected readonly editorManager : EditorManager ;
82
+
83
+ @inject ( SketchControl )
84
+ protected readonly sketchControl : SketchControl ;
85
+
70
86
protected readonly toDisposeBeforeNewContextMenu = new DisposableCollection ( ) ;
71
87
72
88
constructor ( ) {
@@ -92,6 +108,12 @@ export class SketchbookWidgetContribution
92
108
this . mainMenuManager . update ( ) ;
93
109
}
94
110
} ) ;
111
+
112
+ this . app . reachedState ( 'ready' ) . then ( ( ) => this . onReady ( ) ) ;
113
+ }
114
+
115
+ onReady ( ) : void {
116
+ this . runEncodedCommands ( ) ;
95
117
}
96
118
97
119
async initializeLayout ( ) : Promise < void > {
@@ -104,9 +126,7 @@ export class SketchbookWidgetContribution
104
126
execute : ( ) => this . showSketchbookWidget ( ) ,
105
127
} ) ;
106
128
registry . registerCommand ( SketchbookCommands . OPEN_NEW_WINDOW , {
107
- execute : async ( arg ) => {
108
- return this . workspaceService . open ( arg . node . uri ) ;
109
- } ,
129
+ execute : ( arg ) => this . openSketchInNewWindow ( arg ) ,
110
130
isEnabled : ( arg ) =>
111
131
! ! arg && 'node' in arg && SketchbookTree . SketchDirNode . is ( arg . node ) ,
112
132
isVisible : ( arg ) =>
@@ -194,6 +214,15 @@ export class SketchbookWidgetContribution
194
214
} ) ;
195
215
}
196
216
217
+ openSketchInNewWindow ( arg : any ) : any {
218
+ const openSketchbookCommand = this . sketchControl . isCloudSketch ( arg . node . uri )
219
+ ? CloudSketchbookCommands . SHOW_CLOUD_SKETCHBOOK_WIDGET
220
+ : SketchbookCommands . SHOW_SKETCHBOOK_WIDGET ;
221
+ return this . workspaceService . open ( arg . node . uri , {
222
+ commands : [ openSketchbookCommand ] ,
223
+ } ) ;
224
+ }
225
+
197
226
override registerMenus ( registry : MenuModelRegistry ) : void {
198
227
super . registerMenus ( registry ) ;
199
228
@@ -234,8 +263,29 @@ export class SketchbookWidgetContribution
234
263
}
235
264
236
265
protected async showSketchbookWidget ( ) : Promise < void > {
237
- const widget = await this . widget ;
238
- await this . shell . activateWidget ( widget . id ) ;
239
- widget . activateTreeWidget ( widget . getTreeWidget ( ) . id ) ;
266
+ this . widget
267
+ . then ( ( widget ) => this . shell . activateWidget ( widget . id ) )
268
+ . then ( ( widget ) => {
269
+ if ( widget instanceof SketchbookWidget ) {
270
+ widget . activateTreeWidget ( widget . getTreeWidget ( ) . id ) ;
271
+ if ( this . editorManager . currentEditor )
272
+ this . shell . activateWidget ( this . editorManager . currentEditor . id ) ;
273
+ }
274
+ } ) ;
275
+ }
276
+
277
+ protected runEncodedCommands ( ) : void {
278
+ const params = new URLSearchParams ( window . location . search ) ;
279
+ const encoded = params . get ( 'commands' ) ;
280
+ if ( ! encoded ) return ;
281
+
282
+ const commands = JSON . parse ( decodeURIComponent ( encoded ) ) ;
283
+
284
+ if ( commands && Array . isArray ( commands ) ) {
285
+ commands . forEach ( ( c : Command ) => {
286
+ if ( this . commandRegistry . commandIds . includes ( c . id ) )
287
+ this . commandRegistry . executeCommand ( c . id ) ;
288
+ } ) ;
289
+ }
240
290
}
241
291
}
0 commit comments