@@ -26,6 +26,7 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
26
26
import { IThemeService , ThemeIcon } from 'vs/platform/theme/common/themeService' ;
27
27
import { isDark } from 'vs/platform/theme/common/theme' ;
28
28
import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate' ;
29
+ import { assertType } from 'vs/base/common/types' ;
29
30
30
31
export function createAndFillInContextMenuActions ( menu : IMenu , options : IMenuActionOptions | undefined , target : IAction [ ] | { primary : IAction [ ] ; secondary : IAction [ ] } , primaryGroup ?: string ) : IDisposable {
31
32
const groups = menu . getActions ( options ) ;
@@ -129,6 +130,23 @@ export interface IMenuEntryActionViewItemOptions {
129
130
hoverDelegate ?: IHoverDelegate ;
130
131
}
131
132
133
+ function registerConfigureMenu ( contextMenuService : IContextMenuService , item : BaseActionViewItem , action : MenuItemAction | SubmenuItemAction ) : IDisposable {
134
+ assertType ( item . element ) ;
135
+ return addDisposableListener ( item . element , 'contextmenu' , event => {
136
+ if ( ! action . hideActions ) {
137
+ return ;
138
+ }
139
+
140
+ event . preventDefault ( ) ;
141
+ event . stopPropagation ( ) ;
142
+
143
+ contextMenuService . showContextMenu ( {
144
+ getAnchor : ( ) => item . element ! ,
145
+ getActions : ( ) => action . hideActions ! . asList ( )
146
+ } ) ;
147
+ } , true ) ;
148
+ }
149
+
132
150
export class MenuEntryActionViewItem extends ActionViewItem {
133
151
134
152
private _wantsAltCommand : boolean = false ;
@@ -204,20 +222,7 @@ export class MenuEntryActionViewItem extends ActionViewItem {
204
222
updateAltState ( ) ;
205
223
} ) ) ;
206
224
207
-
208
- this . _register ( addDisposableListener ( container , 'contextmenu' , event => {
209
- if ( ! this . _menuItemAction . hideActions ) {
210
- return ;
211
- }
212
-
213
- event . preventDefault ( ) ;
214
- event . stopPropagation ( ) ;
215
-
216
- this . _contextMenuService . showContextMenu ( {
217
- getAnchor : ( ) => container ,
218
- getActions : ( ) => this . _menuItemAction . hideActions ! . asList ( )
219
- } ) ;
220
- } , true ) ) ;
225
+ this . _register ( registerConfigureMenu ( this . _contextMenuService , this , this . _menuItemAction ) ) ;
221
226
}
222
227
223
228
override updateLabel ( ) : void {
@@ -308,40 +313,43 @@ export class SubmenuEntryActionViewItem extends DropdownMenuActionViewItem {
308
313
constructor (
309
314
action : SubmenuItemAction ,
310
315
options : IDropdownMenuActionViewItemOptions | undefined ,
311
- @IContextMenuService contextMenuService : IContextMenuService ,
316
+ @IContextMenuService protected _contextMenuService : IContextMenuService ,
312
317
@IThemeService protected _themeService : IThemeService
313
318
) {
314
319
const dropdownOptions = Object . assign ( { } , options ?? Object . create ( null ) , {
315
320
menuAsChild : options ?. menuAsChild ?? false ,
316
321
classNames : options ?. classNames ?? ( ThemeIcon . isThemeIcon ( action . item . icon ) ? ThemeIcon . asClassName ( action . item . icon ) : undefined ) ,
317
322
} ) ;
318
323
319
- super ( action , { getActions : ( ) => action . actions } , contextMenuService , dropdownOptions ) ;
324
+ super ( action , { getActions : ( ) => action . actions } , _contextMenuService , dropdownOptions ) ;
320
325
}
321
326
322
327
override render ( container : HTMLElement ) : void {
323
328
super . render ( container ) ;
324
- if ( this . element ) {
325
- container . classList . add ( 'menu-entry' ) ;
326
- const { icon } = ( < SubmenuItemAction > this . _action ) . item ;
327
- if ( icon && ! ThemeIcon . isThemeIcon ( icon ) ) {
328
- this . element . classList . add ( 'icon' ) ;
329
- const setBackgroundImage = ( ) => {
330
- if ( this . element ) {
331
- this . element . style . backgroundImage = (
332
- isDark ( this . _themeService . getColorTheme ( ) . type )
333
- ? asCSSUrl ( icon . dark )
334
- : asCSSUrl ( icon . light )
335
- ) ;
336
- }
337
- } ;
329
+ assertType ( this . element ) ;
330
+
331
+ container . classList . add ( 'menu-entry' ) ;
332
+ const action = < SubmenuItemAction > this . _action ;
333
+ const { icon } = action . item ;
334
+ if ( icon && ! ThemeIcon . isThemeIcon ( icon ) ) {
335
+ this . element . classList . add ( 'icon' ) ;
336
+ const setBackgroundImage = ( ) => {
337
+ if ( this . element ) {
338
+ this . element . style . backgroundImage = (
339
+ isDark ( this . _themeService . getColorTheme ( ) . type )
340
+ ? asCSSUrl ( icon . dark )
341
+ : asCSSUrl ( icon . light )
342
+ ) ;
343
+ }
344
+ } ;
345
+ setBackgroundImage ( ) ;
346
+ this . _register ( this . _themeService . onDidColorThemeChange ( ( ) => {
347
+ // refresh when the theme changes in case we go between dark <-> light
338
348
setBackgroundImage ( ) ;
339
- this . _register ( this . _themeService . onDidColorThemeChange ( ( ) => {
340
- // refresh when the theme changes in case we go between dark <-> light
341
- setBackgroundImage ( ) ;
342
- } ) ) ;
343
- }
349
+ } ) ) ;
344
350
}
351
+
352
+ this . _register ( registerConfigureMenu ( this . _contextMenuService , this , action ) ) ;
345
353
}
346
354
}
347
355
@@ -461,6 +469,8 @@ export class DropdownWithDefaultActionViewItem extends BaseActionViewItem {
461
469
event . stopPropagation ( ) ;
462
470
}
463
471
} ) ) ;
472
+
473
+ this . _register ( registerConfigureMenu ( this . _contextMenuService , this , ( < SubmenuItemAction > this . action ) ) ) ;
464
474
}
465
475
466
476
override focus ( fromRight ?: boolean ) : void {
0 commit comments