@@ -14,6 +14,7 @@ import { IAction, Separator, toAction } from 'vs/base/common/actions';
14
14
import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
15
15
import { removeFastWithoutKeepingOrder } from 'vs/base/common/arrays' ;
16
16
import { localize } from 'vs/nls' ;
17
+ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
17
18
18
19
export class MenuService implements IMenuService {
19
20
@@ -23,13 +24,14 @@ export class MenuService implements IMenuService {
23
24
24
25
constructor (
25
26
@ICommandService private readonly _commandService : ICommandService ,
27
+ @IKeybindingService private readonly _keybindingService : IKeybindingService ,
26
28
@IStorageService storageService : IStorageService ,
27
29
) {
28
30
this . _hiddenStates = new PersistedMenuHideState ( storageService ) ;
29
31
}
30
32
31
33
createMenu ( id : MenuId , contextKeyService : IContextKeyService , options ?: IMenuCreateOptions ) : IMenu {
32
- return new MenuImpl ( id , this . _hiddenStates , { emitEventsForSubmenuChanges : false , eventDebounceDelay : 50 , ...options } , this . _commandService , contextKeyService ) ;
34
+ return new MenuImpl ( id , this . _hiddenStates , { emitEventsForSubmenuChanges : false , eventDebounceDelay : 50 , ...options } , this . _commandService , this . _keybindingService , contextKeyService ) ;
33
35
}
34
36
35
37
resetHiddenStates ( ids ?: MenuId [ ] ) : void {
@@ -162,6 +164,7 @@ class MenuInfo {
162
164
private readonly _hiddenStates : PersistedMenuHideState ,
163
165
private readonly _collectContextKeysForSubmenus : boolean ,
164
166
@ICommandService private readonly _commandService : ICommandService ,
167
+ @IKeybindingService private readonly _keybindingService : IKeybindingService ,
165
168
@IContextKeyService private readonly _contextKeyService : IContextKeyService
166
169
) {
167
170
this . refresh ( ) ;
@@ -245,11 +248,11 @@ class MenuInfo {
245
248
const menuHide = createMenuHide ( this . _id , isMenuItem ? item . command : item , this . _hiddenStates ) ;
246
249
if ( isMenuItem ) {
247
250
// MenuItemAction
248
- const menuKeybinding = createMenuKeybindingAction ( this . _id , item . command , this . _commandService ) ;
251
+ const menuKeybinding = createMenuKeybindingAction ( this . _id , item . command , item . when , this . _commandService , this . _keybindingService ) ;
249
252
activeActions . push ( new MenuItemAction ( item . command , item . alt , options , menuHide , menuKeybinding , this . _contextKeyService , this . _commandService ) ) ;
250
253
} else {
251
254
// SubmenuItemAction
252
- const groups = new MenuInfo ( item . submenu , this . _hiddenStates , this . _collectContextKeysForSubmenus , this . _commandService , this . _contextKeyService ) . createActionGroups ( options ) ;
255
+ const groups = new MenuInfo ( item . submenu , this . _hiddenStates , this . _collectContextKeysForSubmenus , this . _commandService , this . _keybindingService , this . _contextKeyService ) . createActionGroups ( options ) ;
253
256
const submenuActions = Separator . join ( ...groups . map ( g => g [ 1 ] ) ) ;
254
257
if ( submenuActions . length > 0 ) {
255
258
activeActions . push ( new SubmenuItemAction ( item , menuHide , submenuActions ) ) ;
@@ -336,9 +339,10 @@ class MenuImpl implements IMenu {
336
339
hiddenStates : PersistedMenuHideState ,
337
340
options : Required < IMenuCreateOptions > ,
338
341
@ICommandService commandService : ICommandService ,
342
+ @IKeybindingService keybindingService : IKeybindingService ,
339
343
@IContextKeyService contextKeyService : IContextKeyService
340
344
) {
341
- this . _menuInfo = new MenuInfo ( id , hiddenStates , options . emitEventsForSubmenuChanges , commandService , contextKeyService ) ;
345
+ this . _menuInfo = new MenuInfo ( id , hiddenStates , options . emitEventsForSubmenuChanges , commandService , keybindingService , contextKeyService ) ;
342
346
343
347
// Rebuild this menu whenever the menu registry reports an event for this MenuId.
344
348
// This usually happen while code and extensions are loaded and affects the over
@@ -438,17 +442,17 @@ function createMenuHide(menu: MenuId, command: ICommandAction | ISubmenuItem, st
438
442
} ;
439
443
}
440
444
441
- function createMenuKeybindingAction ( menu : MenuId , command : ICommandAction | ISubmenuItem , commandService : ICommandService ) : IAction | undefined {
445
+ function createMenuKeybindingAction ( menu : MenuId , command : ICommandAction | ISubmenuItem , when : ContextKeyExpression | undefined = undefined , commandService : ICommandService , keybindingService : IKeybindingService ) : IAction | undefined {
442
446
if ( isISubmenuItem ( command ) ) {
443
447
return undefined ;
444
448
}
445
449
446
450
const configureKeybindingAction = toAction ( {
447
451
id : `configureKeybinding/${ menu . id } /${ command . id } ` ,
448
- label : localize ( 'configure keybinding' , "Configure Keybinding" ) ,
452
+ label : keybindingService . lookupKeybinding ( command . id ) ? localize ( 'change keybinding' , "Change Keybinding" ) : localize ( 'configure keybinding' , "Configure Keybinding" ) ,
449
453
run ( ) {
450
- const when = command . precondition ? .serialize ( ) ;
451
- commandService . executeCommand ( 'workbench.action.openGlobalKeybindings' , `@command:${ command . id } ` + ( when ? ` +when:${ when } ` : '' ) ) ;
454
+ const whenValue = when ? when . serialize ( ) : undefined ;
455
+ commandService . executeCommand ( 'workbench.action.openGlobalKeybindings' , `@command:${ command . id } ` + ( whenValue ? ` +when:${ whenValue } ` : '' ) ) ;
452
456
}
453
457
} ) ;
454
458
0 commit comments