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

66 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-02-06 06:54:26 +02:00
*controllerCommon
}
var _ types.IController = &MenuController{}
func NewMenuController(
2022-02-06 06:54:26 +02:00
common *controllerCommon,
) *MenuController {
return &MenuController{
2022-02-06 06:54:26 +02:00
baseController: baseController{},
controllerCommon: common,
}
}
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-03-26 06:34:15 +02:00
{
Key: opts.GetKey(opts.Config.Universal.Return),
Handler: self.close,
},
}
2022-02-05 01:31:07 +02:00
return bindings
}
2022-02-27 02:42:22 +02:00
func (self *MenuController) GetOnClick() func() error {
return self.press
}
func (self *MenuController) press() error {
return self.context().OnMenuPress(self.context().GetSelected())
}
2022-03-26 06:34:15 +02:00
func (self *MenuController) close() error {
return self.c.PopContext()
}
func (self *MenuController) Context() types.Context {
2022-02-06 06:54:26 +02:00
return self.context()
}
func (self *MenuController) context() *context.MenuContext {
return self.contexts.Menu
}