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-02-06 06:54:26 +02:00
|
|
|
*controllerCommon
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ types.IController = &MenuController{}
|
|
|
|
|
|
|
|
func NewMenuController(
|
2022-02-06 06:54:26 +02:00
|
|
|
common *controllerCommon,
|
2022-01-16 05:46:53 +02:00
|
|
|
) *MenuController {
|
|
|
|
return &MenuController{
|
2022-02-06 06:54:26 +02:00
|
|
|
baseController: baseController{},
|
|
|
|
controllerCommon: common,
|
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 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-01-16 05:46:53 +02:00
|
|
|
func (self *MenuController) press() error {
|
2022-02-06 06:54:26 +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-02-06 06:54:26 +02:00
|
|
|
return self.context()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *MenuController) context() *context.MenuContext {
|
|
|
|
return self.contexts.Menu
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|