Refactor createConfigureKeybindingAction to support disabling keybinding configuration for SCM statusbar actions (#218372)

chore: refactor createConfigureKeybindingAction to support disabling keybinding configuration for scm statusbar actions
This commit is contained in:
Benjamin Christopher Simmonds 2024-06-26 15:01:21 +02:00 committed by GitHub
parent 7ebe6d364f
commit 85f13f93f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -202,7 +202,8 @@ export class WorkbenchToolBar extends ToolBar {
if (action instanceof MenuItemAction && action.menuKeybinding) {
primaryActions.push(action.menuKeybinding);
} else if (!(action instanceof SubmenuItemAction || action instanceof ToggleMenuAction)) {
primaryActions.push(createConfigureKeybindingAction(action.id, undefined, this._commandService, this._keybindingService));
const isDisabled = action.id.startsWith('statusbaraction'); // We can't support keybinding configuration for scm statusbar actions
primaryActions.push(createConfigureKeybindingAction(this._commandService, this._keybindingService, action.id, undefined, !isDisabled));
}
// -- Hide Actions --

View file

@ -248,7 +248,7 @@ class MenuInfo {
const menuHide = createMenuHide(this._id, isMenuItem ? item.command : item, this._hiddenStates);
if (isMenuItem) {
// MenuItemAction
const menuKeybinding = createConfigureKeybindingAction(item.command.id, item.when, this._commandService, this._keybindingService);
const menuKeybinding = createConfigureKeybindingAction(this._commandService, this._keybindingService, item.command.id, item.when);
(activeActions ??= []).push(new MenuItemAction(item.command, item.alt, options, menuHide, menuKeybinding, this._contextKeyService, this._commandService));
} else {
// SubmenuItemAction
@ -442,10 +442,11 @@ function createMenuHide(menu: MenuId, command: ICommandAction | ISubmenuItem, st
};
}
export function createConfigureKeybindingAction(commandId: string, when: ContextKeyExpression | undefined = undefined, commandService: ICommandService, keybindingService: IKeybindingService): IAction {
export function createConfigureKeybindingAction(commandService: ICommandService, keybindingService: IKeybindingService, commandId: string, when: ContextKeyExpression | undefined = undefined, enabled = true): IAction {
return toAction({
id: `configureKeybinding/${commandId}`,
label: localize('configure keybinding', "Configure Keybinding"),
enabled,
run() {
// Only set the when clause when there is no keybinding
// It is possible that the action and the keybinding have different when clauses