2022-01-16 05:46:53 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2022-02-05 08:04:10 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
2022-01-16 05:46:53 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MenuController struct {
|
2022-02-05 05:42:56 +02:00
|
|
|
baseController
|
|
|
|
|
2022-01-31 13:20:28 +02:00
|
|
|
c *types.ControllerCommon
|
2022-02-05 08:04:10 +02:00
|
|
|
context *context.MenuContext
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ types.IController = &MenuController{}
|
|
|
|
|
|
|
|
func NewMenuController(
|
2022-01-29 10:09:20 +02:00
|
|
|
c *types.ControllerCommon,
|
2022-02-05 08:04:10 +02:00
|
|
|
context *context.MenuContext,
|
2022-01-16 05:46:53 +02:00
|
|
|
) *MenuController {
|
|
|
|
return &MenuController{
|
2022-02-05 05:42:56 +02:00
|
|
|
baseController: baseController{},
|
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
c: c,
|
|
|
|
context: context,
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 01:31:07 +02:00
|
|
|
func (self *MenuController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
2022-01-16 05:46:53 +02:00
|
|
|
bindings := []*types.Binding{
|
|
|
|
{
|
2022-02-05 01:31:07 +02:00
|
|
|
Key: opts.GetKey(opts.Config.Universal.Select),
|
2022-01-16 05:46:53 +02:00
|
|
|
Handler: self.press,
|
|
|
|
},
|
|
|
|
{
|
2022-02-05 01:31:07 +02:00
|
|
|
Key: opts.GetKey(opts.Config.Universal.Confirm),
|
2022-01-16 05:46:53 +02:00
|
|
|
Handler: self.press,
|
|
|
|
},
|
|
|
|
{
|
2022-02-05 01:31:07 +02:00
|
|
|
Key: opts.GetKey(opts.Config.Universal.ConfirmAlt1),
|
2022-01-16 05:46:53 +02:00
|
|
|
Handler: self.press,
|
|
|
|
},
|
2022-02-05 08:04:10 +02:00
|
|
|
// {
|
|
|
|
// Key: gocui.MouseLeft,
|
|
|
|
// Handler: func() error { return self.context.HandleClick(self.press) },
|
|
|
|
// },
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
2022-02-05 01:31:07 +02:00
|
|
|
return bindings
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *MenuController) press() error {
|
2022-02-05 08:04:10 +02:00
|
|
|
selectedItem := self.context.GetSelected()
|
2022-01-16 05:46:53 +02:00
|
|
|
|
|
|
|
if err := self.c.PopContext(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := selectedItem.OnPress(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *MenuController) Context() types.Context {
|
2022-01-31 13:20:28 +02:00
|
|
|
return self.context
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|