From 9de8d17d846f1309c4e89a8143f66d0116b0ed08 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 2 Jan 2025 19:43:32 +0100 Subject: [PATCH 1/2] Don't show error toast for disabled keybindings if DisabledReason text is empty This makes it possible to "silently" disable a keybinding. The effect is the same as putting the check in the handler and returning nil from there, except that doing it this way also hides it from the bottom line if DisplayOnScreen is true. --- pkg/gui/keybindings.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index c10f67623..371d039a6 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -453,7 +453,9 @@ func (gui *Gui) callKeybindingHandler(binding *types.Binding) error { return errors.New(disabledReason.Text) } - gui.c.ErrorToast(gui.Tr.DisabledMenuItemPrefix + disabledReason.Text) + if len(disabledReason.Text) > 0 { + gui.c.ErrorToast(gui.Tr.DisabledMenuItemPrefix + disabledReason.Text) + } return nil } return binding.Handler() From 928e76a82f45d52bbdbae415ffb3fed764b9e8cd Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 2 Jan 2025 19:46:16 +0100 Subject: [PATCH 2/2] Disable KeybindingsMenu using a DisabledReason when a panel is open This hides it from the options map at the bottom of the screen. --- pkg/gui/controllers/global_controller.go | 20 ++++++++++++++++---- pkg/gui/controllers/options_menu_action.go | 5 ----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/gui/controllers/global_controller.go b/pkg/gui/controllers/global_controller.go index 984ce3668..818a31178 100644 --- a/pkg/gui/controllers/global_controller.go +++ b/pkg/gui/controllers/global_controller.go @@ -69,10 +69,11 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type Modifier: gocui.ModNone, // we have the description on the alt key and not the main key for legacy reasons // (the original main key was 'x' but we've reassigned that to other purposes) - Description: self.c.Tr.OpenKeybindingsMenu, - Handler: self.createOptionsMenu, - ShortDescription: self.c.Tr.Keybindings, - DisplayOnScreen: true, + Description: self.c.Tr.OpenKeybindingsMenu, + Handler: self.createOptionsMenu, + ShortDescription: self.c.Tr.Keybindings, + DisplayOnScreen: true, + GetDisabledReason: self.optionsMenuDisabledReason, }, { ViewName: "", @@ -156,6 +157,17 @@ func (self *GlobalController) createOptionsMenu() error { return (&OptionsMenuAction{c: self.c}).Call() } +func (self *GlobalController) optionsMenuDisabledReason() *types.DisabledReason { + ctx := self.c.Context().Current() + // Don't show options menu while displaying popup. + if ctx.GetKind() == types.PERSISTENT_POPUP || ctx.GetKind() == types.TEMPORARY_POPUP { + // The empty error text is intentional. We don't want to show an error + // toast for this, but only hide it from the options map. + return &types.DisabledReason{Text: ""} + } + return nil +} + func (self *GlobalController) createFilteringMenu() error { return (&FilteringMenuAction{c: self.c}).Call() } diff --git a/pkg/gui/controllers/options_menu_action.go b/pkg/gui/controllers/options_menu_action.go index 7f3f1de64..8e3f1db9b 100644 --- a/pkg/gui/controllers/options_menu_action.go +++ b/pkg/gui/controllers/options_menu_action.go @@ -13,11 +13,6 @@ type OptionsMenuAction struct { func (self *OptionsMenuAction) Call() error { ctx := self.c.Context().Current() - // Don't show menu while displaying popup. - if ctx.GetKind() == types.PERSISTENT_POPUP || ctx.GetKind() == types.TEMPORARY_POPUP { - return nil - } - local, global, navigation := self.getBindings(ctx) menuItems := []*types.MenuItem{}