mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
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.
This commit is contained in:
@ -14,15 +14,21 @@ type CanViewWorktreeOptions interface {
|
||||
|
||||
type WorktreeOptionsController struct {
|
||||
baseController
|
||||
*ListControllerTrait[string]
|
||||
c *ControllerCommon
|
||||
context CanViewWorktreeOptions
|
||||
}
|
||||
|
||||
func NewWorktreeOptionsController(controllerCommon *ControllerCommon, context CanViewWorktreeOptions) *WorktreeOptionsController {
|
||||
func NewWorktreeOptionsController(c *ControllerCommon, context CanViewWorktreeOptions) *WorktreeOptionsController {
|
||||
return &WorktreeOptionsController{
|
||||
baseController: baseController{},
|
||||
c: controllerCommon,
|
||||
context: context,
|
||||
ListControllerTrait: NewListControllerTrait[string](
|
||||
c,
|
||||
context,
|
||||
context.GetSelectedItemId,
|
||||
),
|
||||
c: c,
|
||||
context: context,
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +36,7 @@ func (self *WorktreeOptionsController) GetKeybindings(opts types.KeybindingsOpts
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Worktrees.ViewWorktreeOptions),
|
||||
Handler: self.checkSelected(self.viewWorktreeOptions),
|
||||
Handler: self.withItem(self.viewWorktreeOptions),
|
||||
Description: self.c.Tr.ViewWorktreeOptions,
|
||||
OpensMenu: true,
|
||||
},
|
||||
@ -39,21 +45,6 @@ func (self *WorktreeOptionsController) GetKeybindings(opts types.KeybindingsOpts
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *WorktreeOptionsController) checkSelected(callback func(string) error) func() error {
|
||||
return func() error {
|
||||
ref := self.context.GetSelectedItemId()
|
||||
if ref == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return callback(ref)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *WorktreeOptionsController) Context() types.Context {
|
||||
return self.context
|
||||
}
|
||||
|
||||
func (self *WorktreeOptionsController) viewWorktreeOptions(ref string) error {
|
||||
return self.c.Helpers().Worktree.ViewWorktreeOptions(self.context, ref)
|
||||
}
|
||||
|
Reference in New Issue
Block a user