mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
start moving commit panel handlers into controller
more and more move rebase commit refreshing into existing abstraction and more and more WIP and more handling clicks properly fix merge conflicts update cheatsheet lots more preparation to start moving things into controllers WIP better typing expand on remotes controller moving more code into controllers
This commit is contained in:
70
pkg/gui/controllers/menu_controller.go
Normal file
70
pkg/gui/controllers/menu_controller.go
Normal file
@ -0,0 +1,70 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/popup"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
type MenuController struct {
|
||||
c *ControllerCommon
|
||||
context types.IListContext
|
||||
|
||||
getSelectedMenuItem func() *popup.MenuItem
|
||||
}
|
||||
|
||||
var _ types.IController = &MenuController{}
|
||||
|
||||
func NewMenuController(
|
||||
c *ControllerCommon,
|
||||
context types.IListContext,
|
||||
getSelectedMenuItem func() *popup.MenuItem,
|
||||
) *MenuController {
|
||||
return &MenuController{
|
||||
c: c,
|
||||
context: context,
|
||||
getSelectedMenuItem: getSelectedMenuItem,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *MenuController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: getKey(config.Universal.Select),
|
||||
Handler: self.press,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Confirm),
|
||||
Handler: self.press,
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.ConfirmAlt1),
|
||||
Handler: self.press,
|
||||
},
|
||||
{
|
||||
Key: gocui.MouseLeft,
|
||||
Handler: func() error { return self.context.HandleClick(self.press) },
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *MenuController) press() error {
|
||||
selectedItem := self.getSelectedMenuItem()
|
||||
|
||||
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 {
|
||||
return self.context
|
||||
}
|
Reference in New Issue
Block a user