2022-12-30 14:24:24 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2023-03-21 11:57:52 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
2022-12-30 14:24:24 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ConfirmationController struct {
|
|
|
|
baseController
|
2023-03-23 09:47:29 +02:00
|
|
|
c *ControllerCommon
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ types.IController = &ConfirmationController{}
|
|
|
|
|
|
|
|
func NewConfirmationController(
|
2023-03-23 09:47:29 +02:00
|
|
|
common *ControllerCommon,
|
2022-12-30 14:24:24 +02:00
|
|
|
) *ConfirmationController {
|
|
|
|
return &ConfirmationController{
|
2023-03-23 09:47:29 +02:00
|
|
|
baseController: baseController{},
|
|
|
|
c: common,
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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() },
|
2023-05-25 13:11:51 +02:00
|
|
|
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() },
|
2023-05-25 13:11:51 +02:00
|
|
|
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
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-12-30 14:24:24 +02:00
|
|
|
|
|
|
|
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()
|
2022-12-30 14:24:24 +02:00
|
|
|
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
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|