1
- import { inject , injectable } from '@theia/core/shared/inversify' ;
2
1
import * as remote from '@theia/core/electron-shared/@electron/remote' ;
3
- import { Widget , ContextMenuRenderer } from '@theia/core/lib/browser' ;
4
- import {
5
- Disposable ,
6
- DisposableCollection ,
7
- } from '@theia/core/lib/common/disposable' ;
2
+ import { nls } from '@theia/core/lib/common/nls' ;
3
+ import { injectable } from '@theia/core/shared/inversify' ;
4
+ import { SketchesError , SketchRef } from '../../common/protocol' ;
8
5
import { ArduinoMenus } from '../menu/arduino-menus' ;
9
- import { ArduinoToolbar } from '../toolbar/arduino-toolbar' ;
10
6
import {
11
- SketchContribution ,
12
- Sketch ,
13
- URI ,
14
7
Command ,
15
8
CommandRegistry ,
16
- MenuModelRegistry ,
17
9
KeybindingRegistry ,
10
+ MenuModelRegistry ,
11
+ Sketch ,
12
+ SketchContribution ,
13
+ URI ,
18
14
} from './contribution' ;
19
- import { ExamplesService } from '../../common/protocol/examples-service' ;
20
- import { BuiltInExamples } from './examples' ;
21
- import { Sketchbook } from './sketchbook' ;
22
- import {
23
- SketchContainer ,
24
- SketchesError ,
25
- SketchRef ,
26
- } from '../../common/protocol' ;
27
- import { nls } from '@theia/core/lib/common/nls' ;
28
15
29
- export type SketchLocation = string | URI | SketchRef | Sketch ;
16
+ export type SketchLocation = string | URI | SketchRef ;
30
17
export namespace SketchLocation {
31
18
export function toUri ( location : SketchLocation ) : URI {
32
19
if ( typeof location === 'string' ) {
33
20
return new URI ( location ) ;
34
21
} else if ( SketchRef . is ( location ) ) {
35
22
return toUri ( location . uri ) ;
36
- } else if ( Sketch . is ( location ) ) {
37
- return toUri ( location . uri ) ;
38
23
} else {
39
24
return location ;
40
25
}
@@ -61,32 +46,12 @@ export namespace OpenSketchParams {
61
46
62
47
@injectable ( )
63
48
export class OpenSketch extends SketchContribution {
64
- @inject ( MenuModelRegistry )
65
- private readonly menuRegistry : MenuModelRegistry ;
66
-
67
- @inject ( ContextMenuRenderer )
68
- private readonly contextMenuRenderer : ContextMenuRenderer ;
69
-
70
- @inject ( BuiltInExamples )
71
- private readonly builtInExamples : BuiltInExamples ;
72
-
73
- @inject ( ExamplesService )
74
- private readonly examplesService : ExamplesService ;
75
-
76
- @inject ( Sketchbook )
77
- private readonly sketchbook : Sketchbook ;
78
-
79
- private readonly toDispose = new DisposableCollection ( ) ;
80
-
81
49
override registerCommands ( registry : CommandRegistry ) : void {
82
50
registry . registerCommand ( OpenSketch . Commands . OPEN_SKETCH , {
83
51
execute : async ( arg ) => {
84
- let toOpen : string | URI | SketchRef | Sketch | undefined = undefined ;
85
- if ( ! OpenSketchParams . is ( arg ) ) {
86
- toOpen = await this . selectSketch ( ) ;
87
- } else {
88
- toOpen = arg . toOpen ;
89
- }
52
+ const toOpen = ! OpenSketchParams . is ( arg )
53
+ ? await this . selectSketch ( )
54
+ : arg . toOpen ;
90
55
if ( toOpen ) {
91
56
return this . openSketch (
92
57
toOpen ,
@@ -95,72 +60,6 @@ export class OpenSketch extends SketchContribution {
95
60
}
96
61
} ,
97
62
} ) ;
98
- registry . registerCommand ( OpenSketch . Commands . OPEN_SKETCH__TOOLBAR , {
99
- isVisible : ( widget ) =>
100
- ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
101
- execute : async ( _ : Widget , target : EventTarget ) => {
102
- const container = await this . sketchService . getSketches ( {
103
- exclude : [ '**/hardware/**' ] ,
104
- } ) ;
105
- if ( SketchContainer . isEmpty ( container ) ) {
106
- this . selectSketch ( ) . then ( ( sketch ) => this . openSketch ( sketch ) ) ;
107
- } else {
108
- this . toDispose . dispose ( ) ;
109
- if ( ! ( target instanceof HTMLElement ) ) {
110
- return ;
111
- }
112
- const { parentElement } = target ;
113
- if ( ! parentElement ) {
114
- return ;
115
- }
116
-
117
- this . menuRegistry . registerMenuAction (
118
- ArduinoMenus . OPEN_SKETCH__CONTEXT__OPEN_GROUP ,
119
- {
120
- commandId : OpenSketch . Commands . OPEN_SKETCH . id ,
121
- label : nls . localize (
122
- 'vscode/workspaceActions/openFileFolder' ,
123
- 'Open...'
124
- ) ,
125
- }
126
- ) ;
127
- this . toDispose . push (
128
- Disposable . create ( ( ) =>
129
- this . menuRegistry . unregisterMenuAction (
130
- OpenSketch . Commands . OPEN_SKETCH
131
- )
132
- )
133
- ) ;
134
- this . sketchbook . registerRecursively (
135
- [ ...container . children , ...container . sketches ] ,
136
- ArduinoMenus . OPEN_SKETCH__CONTEXT__RECENT_GROUP ,
137
- this . toDispose
138
- ) ;
139
- try {
140
- const containers = await this . examplesService . builtIns ( ) ;
141
- for ( const container of containers ) {
142
- this . builtInExamples . registerRecursively (
143
- container ,
144
- ArduinoMenus . OPEN_SKETCH__CONTEXT__EXAMPLES_GROUP ,
145
- this . toDispose
146
- ) ;
147
- }
148
- } catch ( e ) {
149
- console . error ( 'Error when collecting built-in examples.' , e ) ;
150
- }
151
- const options = {
152
- menuPath : ArduinoMenus . OPEN_SKETCH__CONTEXT ,
153
- anchor : {
154
- x : parentElement . getBoundingClientRect ( ) . left ,
155
- y :
156
- parentElement . getBoundingClientRect ( ) . top +
157
- parentElement . offsetHeight ,
158
- } ,
159
- } ;
160
- this . contextMenuRenderer . render ( options ) ;
161
- }
162
- } ,
163
- } ) ;
164
63
}
165
64
166
65
override registerMenus ( registry : MenuModelRegistry ) : void {
@@ -277,8 +176,5 @@ export namespace OpenSketch {
277
176
export const OPEN_SKETCH : Command = {
278
177
id : 'arduino-open-sketch' ,
279
178
} ;
280
- export const OPEN_SKETCH__TOOLBAR : Command = {
281
- id : 'arduino-open-sketch--toolbar' ,
282
- } ;
283
179
}
284
180
}
0 commit comments