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

76 lines
1.7 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
2023-03-23 09:47:29 +02:00
c *ControllerCommon
}
var _ types.IController = &MenuController{}
func NewMenuController(
2023-03-23 09:47:29 +02:00
common *ControllerCommon,
) *MenuController {
return &MenuController{
2023-03-23 09:47:29 +02:00
baseController: baseController{},
c: common,
}
}
// NOTE: if you add a new keybinding here, you'll also need to add it to
// `reservedKeys` in `pkg/gui/context/menu_context.go`
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,
},
{
2023-03-21 11:57:52 +02:00
Key: opts.GetKey(opts.Config.Universal.Confirm),
Handler: self.press,
Description: self.c.Tr.Execute,
2023-03-21 11:57:52 +02:00
Display: true,
},
2022-03-26 06:34:15 +02:00
{
2023-03-21 11:57:52 +02:00
Key: opts.GetKey(opts.Config.Universal.Return),
Handler: self.close,
Description: self.c.Tr.Close,
2023-03-21 11:57:52 +02:00
Display: true,
2022-03-26 06:34:15 +02:00
},
}
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) GetOnFocus() func(types.OnFocusOpts) error {
return func(types.OnFocusOpts) error {
selectedMenuItem := self.context().GetSelected()
self.c.Views().Tooltip.SetContent(selectedMenuItem.Tooltip)
return nil
}
}
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 {
2023-03-23 04:04:57 +02:00
return self.c.Contexts().Menu
}