1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/controllers/confirmation_controller.go

66 lines
1.6 KiB
Go
Raw Normal View History

package controllers
import (
2023-03-21 11:57:52 +02:00
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type ConfirmationController struct {
baseController
2023-03-23 09:47:29 +02:00
c *ControllerCommon
}
var _ types.IController = &ConfirmationController{}
func NewConfirmationController(
2023-03-23 09:47:29 +02:00
common *ControllerCommon,
) *ConfirmationController {
return &ConfirmationController{
2023-03-23 09:47:29 +02:00
baseController: baseController{},
c: common,
}
}
func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
2023-03-21 11:57:52 +02:00
bindings := []*types.Binding{
{
Key: opts.GetKey(opts.Config.Universal.Confirm),
Handler: func() error { return self.context().State.OnConfirm() },
Description: self.c.Tr.Confirm,
2023-03-21 11:57:52 +02:00
Display: true,
},
{
Key: opts.GetKey(opts.Config.Universal.Return),
Handler: func() error { return self.context().State.OnClose() },
Description: self.c.Tr.CloseCancel,
2023-03-21 11:57:52 +02:00
Display: true,
},
{
Key: opts.GetKey(opts.Config.Universal.TogglePanel),
Handler: func() error {
2023-03-23 04:04:57 +02:00
if len(self.c.Contexts().Suggestions.State.Suggestions) > 0 {
return self.c.ReplaceContext(self.c.Contexts().Suggestions)
2023-03-21 11:57:52 +02:00
}
return nil
},
},
}
return bindings
}
func (self *ConfirmationController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(types.OnFocusLostOpts) error {
2023-03-23 09:47:29 +02:00
self.c.Helpers().Confirmation.DeactivateConfirmationPrompt()
return nil
}
}
func (self *ConfirmationController) Context() types.Context {
return self.context()
}
2023-03-21 11:57:52 +02:00
func (self *ConfirmationController) context() *context.ConfirmationContext {
2023-03-23 04:04:57 +02:00
return self.c.Contexts().Confirmation
}