1
1
import * as PQueue from 'p-queue' ;
2
2
import { inject , injectable } from 'inversify' ;
3
3
import { CommandRegistry } from '@theia/core/lib/common/command' ;
4
- import { MenuModelRegistry , MenuNode } from '@theia/core/lib/common/menu' ;
4
+ import { MenuModelRegistry } from '@theia/core/lib/common/menu' ;
5
5
import { Disposable , DisposableCollection } from '@theia/core/lib/common/disposable' ;
6
6
import { BoardsServiceProvider } from './boards-service-provider' ;
7
7
import { Board , ConfigOption , Programmer } from '../../common/protocol' ;
8
8
import { FrontendApplicationContribution } from '@theia/core/lib/browser' ;
9
9
import { BoardsDataStore } from './boards-data-store' ;
10
10
import { MainMenuManager } from '../../common/main-menu-manager' ;
11
- import { ArduinoMenus } from '../menu/arduino-menus' ;
11
+ import { ArduinoMenus , unregisterSubmenu } from '../menu/arduino-menus' ;
12
12
13
13
@injectable ( )
14
14
export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
@@ -63,7 +63,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
63
63
this . menuRegistry . registerSubmenu ( menuPath , label ) ;
64
64
this . toDisposeOnBoardChange . pushAll ( [
65
65
...commands . values ( ) ,
66
- Disposable . create ( ( ) => this . unregisterSubmenu ( menuPath ) ) , // We cannot dispose submenu entries: https://github.com/eclipse-theia/theia/issues/7299
66
+ Disposable . create ( ( ) => unregisterSubmenu ( menuPath , this . menuRegistry ) ) ,
67
67
...Array . from ( commands . keys ( ) ) . map ( ( commandId , i ) => {
68
68
const { label } = commands . get ( commandId ) ! ;
69
69
this . menuRegistry . registerMenuAction ( menuPath , { commandId, order : `${ i } ` , label } ) ;
@@ -76,7 +76,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
76
76
const programmersMenuPath = [ ...ArduinoMenus . TOOLS__BOARD_SETTINGS_GROUP , 'z02_programmers' ] ;
77
77
const label = selectedProgrammer ? `Programmer: "${ selectedProgrammer . name } "` : 'Programmer'
78
78
this . menuRegistry . registerSubmenu ( programmersMenuPath , label ) ;
79
- this . toDisposeOnBoardChange . push ( Disposable . create ( ( ) => this . unregisterSubmenu ( programmersMenuPath ) ) ) ;
79
+ this . toDisposeOnBoardChange . push ( Disposable . create ( ( ) => unregisterSubmenu ( programmersMenuPath , this . menuRegistry ) ) ) ;
80
80
for ( const programmer of programmers ) {
81
81
const { id, name } = programmer ;
82
82
const command = { id : `${ fqbn } -programmer--${ id } ` } ;
@@ -98,20 +98,4 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
98
98
} ) ;
99
99
}
100
100
101
- protected unregisterSubmenu ( menuPath : string [ ] ) : void {
102
- if ( menuPath . length < 2 ) {
103
- throw new Error ( `Expected at least two item as a menu-path. Got ${ JSON . stringify ( menuPath ) } instead.` ) ;
104
- }
105
- const toRemove = menuPath [ menuPath . length - 1 ] ;
106
- const parentMenuPath = menuPath . slice ( 0 , menuPath . length - 1 ) ;
107
- // This is unsafe. Calling `getMenu` with a non-existing menu-path will result in a new menu creation.
108
- // https://github.com/eclipse-theia/theia/issues/7300
109
- const parent = this . menuRegistry . getMenu ( parentMenuPath ) ;
110
- const index = parent . children . findIndex ( ( { id } ) => id === toRemove ) ;
111
- if ( index === - 1 ) {
112
- throw new Error ( `Could not find menu with menu-path: ${ JSON . stringify ( menuPath ) } .` ) ;
113
- }
114
- ( parent . children as Array < MenuNode > ) . splice ( index , 1 ) ;
115
- }
116
-
117
101
}
0 commit comments