1- import { inject , injectable } from '@theia/core/shared/inversify' ;
21import { 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' ;
52import { ContextMenuRenderer } from '@theia/core/lib/browser/context-menu-renderer' ;
3+ import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell' ;
64import {
75 Disposable ,
86 DisposableCollection ,
97} 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' ;
1013import {
11- URI ,
12- SketchContribution ,
1314 Command ,
1415 CommandRegistry ,
15- MenuModelRegistry ,
1616 KeybindingRegistry ,
17- TabBarToolbarRegistry ,
17+ MenuModelRegistry ,
1818 open ,
19+ SketchContribution ,
20+ TabBarToolbarRegistry ,
21+ URI ,
1922} 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' ;
2323
2424@injectable ( )
2525export class SketchControl extends SketchContribution {
2626 @inject ( ApplicationShell )
2727 private readonly shell : ApplicationShell ;
28-
2928 @inject ( MenuModelRegistry )
3029 private readonly menuRegistry : MenuModelRegistry ;
31-
3230 @inject ( ContextMenuRenderer )
3331 private readonly contextMenuRenderer : ContextMenuRenderer ;
3432
@@ -43,97 +41,57 @@ export class SketchControl extends SketchContribution {
4341 this . shell . getWidgets ( 'main' ) . indexOf ( widget ) !== - 1 ,
4442 execute : async ( ) => {
4543 this . toDisposeBeforeCreateNewContextMenu . dispose ( ) ;
46- const sketch = await this . sketchServiceClient . currentSketch ( ) ;
47- if ( ! CurrentSketch . isValid ( sketch ) ) {
48- return ;
49- }
5044
45+ let parentElement : HTMLElement | undefined = undefined ;
5146 const target = document . getElementById (
5247 SketchControl . Commands . OPEN_SKETCH_CONTROL__TOOLBAR . id
5348 ) ;
54- if ( ! ( target instanceof HTMLElement ) ) {
55- return ;
49+ if ( target instanceof HTMLElement ) {
50+ parentElement = target . parentElement ?? undefined ;
5651 }
57- const { parentElement } = target ;
5852 if ( ! parentElement ) {
5953 return ;
6054 }
6155
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+ }
6460
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+ }
7068 ) ;
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
8773 )
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+ ) ;
10476
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
13389 )
134- ) ;
135- }
90+ )
91+ ) ;
13692
93+ const { mainFileUri, rootFolderFileUris } = sketch ;
94+ const uris = [ mainFileUri , ...rootFolderFileUris ] ;
13795 for ( let i = 0 ; i < uris . length ; i ++ ) {
13896 const uri = new URI ( uris [ i ] ) ;
13997
@@ -169,6 +127,7 @@ export class SketchControl extends SketchContribution {
169127 parentElement . getBoundingClientRect ( ) . top +
170128 parentElement . offsetHeight ,
171129 } ,
130+ showDisabled : true ,
172131 } ;
173132 this . contextMenuRenderer . render ( options ) ;
174133 } ,
0 commit comments