diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-14 13:51:20 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-19 10:50:49 +1100 |
commit | 51fb82d6bf26153f294477883a1b2abd592441f9 (patch) | |
tree | 1be91ee6e52592f6d1eec311e26b22725237a200 /pkg/gui/global_handlers.go | |
parent | 280b4d60f893a0e20897091ab02617c32180b45d (diff) |
Enforce single-item selection in various actions
We want to show an error when the user tries to invoke an action that expects only
a single item to be selected.
We're using the GetDisabledReason field to enforce this (as well as DisabledReason
on menu items).
I've created a ListControllerTrait to store some shared convenience functions for this.
Diffstat (limited to 'pkg/gui/global_handlers.go')
-rw-r--r-- | pkg/gui/global_handlers.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index c537e8524..9513fff61 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -139,6 +139,28 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error { return nil } +func (gui *Gui) getCopySelectedSideContextItemToClipboardDisabledReason() *types.DisabledReason { + // important to note that this assumes we've selected an item in a side context + currentSideContext := gui.c.CurrentSideContext() + if currentSideContext == nil { + // This should never happen but if it does we'll just ignore the keypress + return nil + } + + listContext, ok := currentSideContext.(types.IListContext) + if !ok { + // This should never happen but if it does we'll just ignore the keypress + return nil + } + + startIdx, endIdx := listContext.GetList().GetSelectionRange() + if startIdx != endIdx { + return &types.DisabledReason{Text: gui.Tr.RangeSelectNotSupported} + } + + return nil +} + func (gui *Gui) setCaption(caption string) { gui.Views.Options.FgColor = gocui.ColorWhite gui.Views.Options.FgColor |= gocui.AttrBold |