1
1
import { injectable } from '@theia/core/shared/inversify' ;
2
- import { Disposable } from '@theia/core/lib/common/disposable' ;
3
2
import { CommandHandler } from '@theia/core/lib/common/command' ;
3
+ import { MenuModelRegistry } from './contribution' ;
4
4
import { ArduinoMenus } from '../menu/arduino-menus' ;
5
5
import { Examples } from './examples' ;
6
- import { SketchesError } from '../../common/protocol' ;
6
+ import { SketchContainer , SketchesError } from '../../common/protocol' ;
7
7
import { OpenSketch } from './open-sketch' ;
8
8
import { nls } from '@theia/core/lib/common/nls' ;
9
9
@@ -19,39 +19,27 @@ export class Sketchbook extends Examples {
19
19
}
20
20
21
21
protected override update ( ) : void {
22
- this . toDispose . dispose ( ) ;
23
- this . menuRegistry . registerSubmenu (
22
+ this . sketchService . getSketches ( { } ) . then ( ( container ) => {
23
+ this . register ( container ) ;
24
+ this . menuManager . update ( ) ;
25
+ } ) ;
26
+ }
27
+
28
+ override registerMenus ( registry : MenuModelRegistry ) : void {
29
+ registry . registerSubmenu (
24
30
ArduinoMenus . FILE__SKETCHBOOK_SUBMENU ,
25
31
nls . localize ( 'arduino/sketch/sketchbook' , 'Sketchbook' ) ,
26
32
{ order : '3' }
27
33
) ;
28
- this . toDispose . push (
29
- Disposable . create ( ( ) =>
30
- this . menuRegistry . unregisterMenuNode (
31
- ArduinoMenus . FILE__SKETCHBOOK_SUBMENU [
32
- ArduinoMenus . FILE__SKETCHBOOK_SUBMENU . length - 1
33
- ]
34
- // It's not possible to unregister submenu in Theia https://github.com/eclipse-theia/theia/issues/7300
35
- // This workaround relies on how Theia calculates menu ID from the menu path.
36
- )
37
- )
34
+ }
35
+
36
+ private register ( container : SketchContainer ) : void {
37
+ this . toDispose . dispose ( ) ;
38
+ this . registerRecursively (
39
+ [ ...container . children , ...container . sketches ] ,
40
+ ArduinoMenus . FILE__SKETCHBOOK_SUBMENU ,
41
+ this . toDispose
38
42
) ;
39
- const sketchDirUri = this . configService . tryGetSketchDirUri ( ) ;
40
- const messages = this . configService . tryGetMessages ( ) ;
41
- if ( ! sketchDirUri || messages ?. length ) {
42
- this . menuManager . update ( ) ;
43
- return ;
44
- }
45
- this . sketchService
46
- . getSketches ( { uri : sketchDirUri ?. toString ( ) } )
47
- . then ( ( container ) => {
48
- this . registerRecursively (
49
- [ ...container . children , ...container . sketches ] ,
50
- ArduinoMenus . FILE__SKETCHBOOK_SUBMENU ,
51
- this . toDispose
52
- ) ;
53
- this . menuManager . update ( ) ;
54
- } ) ;
55
43
}
56
44
57
45
protected override createHandler ( uri : string ) : CommandHandler {
0 commit comments