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

69 lines
1.3 KiB
Go
Raw Normal View History

package controllers
import (
2022-02-05 08:04:10 +02:00
"github.com/jesseduffield/lazygit/pkg/gui/context"
"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
}
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,
) *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-02-05 01:31:07 +02:00
func (self *MenuController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
bindings := []*types.Binding{
{
2022-02-05 01:31:07 +02:00
Key: opts.GetKey(opts.Config.Universal.Select),
Handler: self.press,
},
{
2022-02-05 01:31:07 +02:00
Key: opts.GetKey(opts.Config.Universal.Confirm),
Handler: self.press,
},
{
2022-02-05 01:31:07 +02:00
Key: opts.GetKey(opts.Config.Universal.ConfirmAlt1),
Handler: self.press,
},
2022-02-05 08:04:10 +02:00
// {
// Key: gocui.MouseLeft,
// Handler: func() error { return self.context.HandleClick(self.press) },
// },
}
2022-02-05 01:31:07 +02:00
return bindings
}
func (self *MenuController) press() error {
2022-02-05 08:04:10 +02:00
selectedItem := self.context.GetSelected()
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
}