@@ -121,72 +121,67 @@ export interface IMenuService {
121121 createMenu ( id : MenuId , scopedKeybindingService : IContextKeyService ) : IMenu ;
122122}
123123
124+ export type ICommandsMap = Map < string , ICommandAction > ;
125+
124126export interface IMenuRegistry {
125127 addCommand ( userCommand : ICommandAction ) : IDisposable ;
126- getCommand ( id : string ) : ICommandAction ;
128+ getCommand ( id : string ) : ICommandAction | undefined ;
127129 getCommands ( ) : ICommandsMap ;
128130 appendMenuItem ( menu : MenuId , item : IMenuItem | ISubmenuItem ) : IDisposable ;
129131 getMenuItems ( loc : MenuId ) : Array < IMenuItem | ISubmenuItem > ;
130132 readonly onDidChangeMenu : Event < MenuId > ;
131133}
132134
133- export interface ICommandsMap {
134- [ id : string ] : ICommandAction ;
135- }
136-
137135export const MenuRegistry : IMenuRegistry = new class implements IMenuRegistry {
138136
139- private readonly _commands : { [ id : string ] : ICommandAction } = Object . create ( null ) ;
140- private readonly _menuItems : { [ loc : number ] : Array < IMenuItem | ISubmenuItem > } = Object . create ( null ) ;
137+ private readonly _commands = new Map < string , ICommandAction > ( ) ;
138+ private readonly _menuItems = new Map < number , Array < IMenuItem | ISubmenuItem > > ( ) ;
141139 private readonly _onDidChangeMenu = new Emitter < MenuId > ( ) ;
142140
143141 readonly onDidChangeMenu : Event < MenuId > = this . _onDidChangeMenu . event ;
144142
145143 addCommand ( command : ICommandAction ) : IDisposable {
146- this . _commands [ command . id ] = command ;
144+ this . _commands . set ( command . id , command ) ;
147145 this . _onDidChangeMenu . fire ( MenuId . CommandPalette ) ;
148146 return {
149147 dispose : ( ) => {
150- if ( delete this . _commands [ command . id ] ) {
148+ if ( this . _commands . delete ( command . id ) ) {
151149 this . _onDidChangeMenu . fire ( MenuId . CommandPalette ) ;
152150 }
153151 }
154152 } ;
155153 }
156154
157- getCommand ( id : string ) : ICommandAction {
158- return this . _commands [ id ] ;
155+ getCommand ( id : string ) : ICommandAction | undefined {
156+ return this . _commands . get ( id ) ;
159157 }
160158
161159 getCommands ( ) : ICommandsMap {
162- const result : ICommandsMap = Object . create ( null ) ;
163- for ( const key in this . _commands ) {
164- result [ key ] = this . getCommand ( key ) ;
165- }
166- return result ;
160+ return new Map < string , ICommandAction > ( this . _commands . entries ( ) ) ;
167161 }
168162
169163 appendMenuItem ( id : MenuId , item : IMenuItem | ISubmenuItem ) : IDisposable {
170- let array = this . _menuItems [ id ] ;
164+ let array = this . _menuItems . get ( id ) ;
171165 if ( ! array ) {
172- this . _menuItems [ id ] = array = [ item ] ;
166+ array = [ item ] ;
167+ this . _menuItems . set ( id , array ) ;
173168 } else {
174169 array . push ( item ) ;
175170 }
176171 this . _onDidChangeMenu . fire ( id ) ;
177172 return {
178173 dispose : ( ) => {
179- const idx = array . indexOf ( item ) ;
174+ const idx = array ! . indexOf ( item ) ;
180175 if ( idx >= 0 ) {
181- array . splice ( idx , 1 ) ;
176+ array ! . splice ( idx , 1 ) ;
182177 this . _onDidChangeMenu . fire ( id ) ;
183178 }
184179 }
185180 } ;
186181 }
187182
188183 getMenuItems ( id : MenuId ) : Array < IMenuItem | ISubmenuItem > {
189- const result = ( this . _menuItems [ id ] || [ ] ) . slice ( 0 ) ;
184+ const result = ( this . _menuItems . get ( id ) || [ ] ) . slice ( 0 ) ;
190185
191186 if ( id === MenuId . CommandPalette ) {
192187 // CommandPalette is special because it shows
@@ -207,9 +202,9 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
207202 set . add ( alt . id ) ;
208203 }
209204 }
210- for ( let id in this . _commands ) {
205+ for ( const [ id , command ] of this . _commands ) {
211206 if ( ! set . has ( id ) ) {
212- result . push ( { command : this . _commands [ id ] } ) ;
207+ result . push ( { command } ) ;
213208 }
214209 }
215210 }
0 commit comments