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
|
2023-03-23 09:47:29 +02:00
|
|
|
c *ControllerCommon
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ types.IController = &MenuController{}
|
|
|
|
|
|
|
|
func NewMenuController(
|
2023-03-23 09:47:29 +02:00
|
|
|
common *ControllerCommon,
|
2022-01-16 05:46:53 +02:00
|
|
|
) *MenuController {
|
|
|
|
return &MenuController{
|
2023-03-23 09:47:29 +02:00
|
|
|
baseController: baseController{},
|
|
|
|
c: common,
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-21 03:02:36 +02:00
|
|
|
// 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 {
|
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,
|
|
|
|
},
|
|
|
|
{
|
2023-03-21 11:57:52 +02:00
|
|
|
Key: opts.GetKey(opts.Config.Universal.Confirm),
|
|
|
|
Handler: self.press,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.Execute,
|
2023-03-21 11:57:52 +02:00
|
|
|
Display: true,
|
2022-01-16 05:46:53 +02:00
|
|
|
},
|
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,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.Close,
|
2023-03-21 11:57:52 +02:00
|
|
|
Display: true,
|
2022-03-26 06:34:15 +02:00
|
|
|
},
|
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
|
|
|
}
|
|
|
|
|
2022-02-27 02:42:22 +02:00
|
|
|
func (self *MenuController) GetOnClick() func() error {
|
|
|
|
return self.press
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
func (self *MenuController) press() error {
|
2022-03-27 08:15:17 +02:00
|
|
|
return self.context().OnMenuPress(self.context().GetSelected())
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
2022-03-26 06:34:15 +02:00
|
|
|
func (self *MenuController) close() error {
|
|
|
|
return self.c.PopContext()
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
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
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|