1
- import { inject , injectable } from '@theia/core/shared/inversify' ;
2
1
import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution' ;
3
- import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell' ;
4
- import { WorkspaceCommands } from '@theia/workspace/lib/browser' ;
5
2
import { ContextMenuRenderer } from '@theia/core/lib/browser/context-menu-renderer' ;
3
+ import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell' ;
6
4
import {
7
5
Disposable ,
8
6
DisposableCollection ,
9
7
} from '@theia/core/lib/common/disposable' ;
8
+ import { nls } from '@theia/core/lib/common/nls' ;
9
+ import { inject , injectable } from '@theia/core/shared/inversify' ;
10
+ import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands' ;
11
+ import { ArduinoMenus } from '../menu/arduino-menus' ;
12
+ import { CurrentSketch } from '../sketches-service-client-impl' ;
10
13
import {
11
- URI ,
12
- SketchContribution ,
13
14
Command ,
14
15
CommandRegistry ,
15
- MenuModelRegistry ,
16
16
KeybindingRegistry ,
17
- TabBarToolbarRegistry ,
17
+ MenuModelRegistry ,
18
18
open ,
19
+ SketchContribution ,
20
+ TabBarToolbarRegistry ,
21
+ URI ,
19
22
} from './contribution' ;
20
- import { ArduinoMenus , PlaceholderMenuNode } from '../menu/arduino-menus' ;
21
- import { CurrentSketch } from '../sketches-service-client-impl' ;
22
- import { nls } from '@theia/core/lib/common' ;
23
23
24
24
@injectable ( )
25
25
export class SketchControl extends SketchContribution {
26
26
@inject ( ApplicationShell )
27
27
private readonly shell : ApplicationShell ;
28
-
29
28
@inject ( MenuModelRegistry )
30
29
private readonly menuRegistry : MenuModelRegistry ;
31
-
32
30
@inject ( ContextMenuRenderer )
33
31
private readonly contextMenuRenderer : ContextMenuRenderer ;
34
32
@@ -43,97 +41,57 @@ export class SketchControl extends SketchContribution {
43
41
this . shell . getWidgets ( 'main' ) . indexOf ( widget ) !== - 1 ,
44
42
execute : async ( ) => {
45
43
this . toDisposeBeforeCreateNewContextMenu . dispose ( ) ;
46
- const sketch = await this . sketchServiceClient . currentSketch ( ) ;
47
- if ( ! CurrentSketch . isValid ( sketch ) ) {
48
- return ;
49
- }
50
44
45
+ let parentElement : HTMLElement | undefined = undefined ;
51
46
const target = document . getElementById (
52
47
SketchControl . Commands . OPEN_SKETCH_CONTROL__TOOLBAR . id
53
48
) ;
54
- if ( ! ( target instanceof HTMLElement ) ) {
55
- return ;
49
+ if ( target instanceof HTMLElement ) {
50
+ parentElement = target . parentElement ?? undefined ;
56
51
}
57
- const { parentElement } = target ;
58
52
if ( ! parentElement ) {
59
53
return ;
60
54
}
61
55
62
- const { mainFileUri, rootFolderFileUris } = sketch ;
63
- const uris = [ mainFileUri , ...rootFolderFileUris ] ;
56
+ const sketch = await this . sketchServiceClient . currentSketch ( ) ;
57
+ if ( ! CurrentSketch . isValid ( sketch ) ) {
58
+ return ;
59
+ }
64
60
65
- const parentSketchUri = this . editorManager . currentEditor
66
- ?. getResourceUri ( )
67
- ?. toString ( ) ;
68
- const parentSketch = await this . sketchesService . getSketchFolder (
69
- parentSketchUri || ''
61
+ this . menuRegistry . registerMenuAction (
62
+ ArduinoMenus . SKETCH_CONTROL__CONTEXT__MAIN_GROUP ,
63
+ {
64
+ commandId : WorkspaceCommands . FILE_RENAME . id ,
65
+ label : nls . localize ( 'vscode/fileActions/rename' , 'Rename' ) ,
66
+ order : '1' ,
67
+ }
70
68
) ;
71
-
72
- // if the current file is in the current opened sketch, show extra menus
73
- if ( sketch && parentSketch && parentSketch . uri === sketch . uri ) {
74
- this . menuRegistry . registerMenuAction (
75
- ArduinoMenus . SKETCH_CONTROL__CONTEXT__MAIN_GROUP ,
76
- {
77
- commandId : WorkspaceCommands . FILE_RENAME . id ,
78
- label : nls . localize ( 'vscode/fileActions/rename' , 'Rename' ) ,
79
- order : '1' ,
80
- }
81
- ) ;
82
- this . toDisposeBeforeCreateNewContextMenu . push (
83
- Disposable . create ( ( ) =>
84
- this . menuRegistry . unregisterMenuAction (
85
- WorkspaceCommands . FILE_RENAME
86
- )
69
+ this . toDisposeBeforeCreateNewContextMenu . push (
70
+ Disposable . create ( ( ) =>
71
+ this . menuRegistry . unregisterMenuAction (
72
+ WorkspaceCommands . FILE_RENAME
87
73
)
88
- ) ;
89
- } else {
90
- const renamePlaceholder = new PlaceholderMenuNode (
91
- ArduinoMenus . SKETCH_CONTROL__CONTEXT__MAIN_GROUP ,
92
- nls . localize ( 'vscode/fileActions/rename' , 'Rename' )
93
- ) ;
94
- this . menuRegistry . registerMenuNode (
95
- ArduinoMenus . SKETCH_CONTROL__CONTEXT__MAIN_GROUP ,
96
- renamePlaceholder
97
- ) ;
98
- this . toDisposeBeforeCreateNewContextMenu . push (
99
- Disposable . create ( ( ) =>
100
- this . menuRegistry . unregisterMenuNode ( renamePlaceholder . id )
101
- )
102
- ) ;
103
- }
74
+ )
75
+ ) ;
104
76
105
- if ( sketch && parentSketch && parentSketch . uri === sketch . uri ) {
106
- this . menuRegistry . registerMenuAction (
107
- ArduinoMenus . SKETCH_CONTROL__CONTEXT__MAIN_GROUP ,
108
- {
109
- commandId : WorkspaceCommands . FILE_DELETE . id , // TODO: customize delete. Wipe sketch if deleting main file. Close window.
110
- label : nls . localize ( 'vscode/fileActions/delete' , 'Delete' ) ,
111
- order : '2' ,
112
- }
113
- ) ;
114
- this . toDisposeBeforeCreateNewContextMenu . push (
115
- Disposable . create ( ( ) =>
116
- this . menuRegistry . unregisterMenuAction (
117
- WorkspaceCommands . FILE_DELETE
118
- )
119
- )
120
- ) ;
121
- } else {
122
- const deletePlaceholder = new PlaceholderMenuNode (
123
- ArduinoMenus . SKETCH_CONTROL__CONTEXT__MAIN_GROUP ,
124
- nls . localize ( 'vscode/fileActions/delete' , 'Delete' )
125
- ) ;
126
- this . menuRegistry . registerMenuNode (
127
- ArduinoMenus . SKETCH_CONTROL__CONTEXT__MAIN_GROUP ,
128
- deletePlaceholder
129
- ) ;
130
- this . toDisposeBeforeCreateNewContextMenu . push (
131
- Disposable . create ( ( ) =>
132
- this . menuRegistry . unregisterMenuNode ( deletePlaceholder . id )
77
+ this . menuRegistry . registerMenuAction (
78
+ ArduinoMenus . SKETCH_CONTROL__CONTEXT__MAIN_GROUP ,
79
+ {
80
+ commandId : WorkspaceCommands . FILE_DELETE . id ,
81
+ label : nls . localize ( 'vscode/fileActions/delete' , 'Delete' ) ,
82
+ order : '2' ,
83
+ }
84
+ ) ;
85
+ this . toDisposeBeforeCreateNewContextMenu . push (
86
+ Disposable . create ( ( ) =>
87
+ this . menuRegistry . unregisterMenuAction (
88
+ WorkspaceCommands . FILE_DELETE
133
89
)
134
- ) ;
135
- }
90
+ )
91
+ ) ;
136
92
93
+ const { mainFileUri, rootFolderFileUris } = sketch ;
94
+ const uris = [ mainFileUri , ...rootFolderFileUris ] ;
137
95
for ( let i = 0 ; i < uris . length ; i ++ ) {
138
96
const uri = new URI ( uris [ i ] ) ;
139
97
@@ -169,6 +127,7 @@ export class SketchControl extends SketchContribution {
169
127
parentElement . getBoundingClientRect ( ) . top +
170
128
parentElement . offsetHeight ,
171
129
} ,
130
+ showDisabled : true ,
172
131
} ;
173
132
this . contextMenuRenderer . render ( options ) ;
174
133
} ,
0 commit comments