2022-02-05 02:00:57 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2023-03-23 13:21:42 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
2022-02-05 02:00:57 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GlobalController struct {
|
2022-02-05 05:42:56 +02:00
|
|
|
baseController
|
2023-03-23 09:47:29 +02:00
|
|
|
c *ControllerCommon
|
2022-02-05 02:00:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewGlobalController(
|
2023-03-23 09:47:29 +02:00
|
|
|
common *ControllerCommon,
|
2022-02-05 02:00:57 +02:00
|
|
|
) *GlobalController {
|
|
|
|
return &GlobalController{
|
2023-03-23 09:47:29 +02:00
|
|
|
baseController: baseController{},
|
|
|
|
c: common,
|
2022-02-05 02:00:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
|
|
|
return []*types.Binding{
|
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.ExecuteCustomCommand),
|
|
|
|
Handler: self.customCommand,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.ExecuteCustomCommand,
|
2022-02-05 02:00:57 +02:00
|
|
|
},
|
2023-03-23 12:39:30 +02:00
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.CreatePatchOptionsMenu),
|
|
|
|
Handler: self.createCustomPatchOptionsMenu,
|
|
|
|
Description: self.c.Tr.ViewPatchOptions,
|
|
|
|
OpensMenu: true,
|
|
|
|
},
|
2023-03-23 13:05:25 +02:00
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.CreateRebaseOptionsMenu),
|
|
|
|
Handler: self.c.Helpers().MergeAndRebase.CreateRebaseOptionsMenu,
|
|
|
|
Description: self.c.Tr.ViewMergeRebaseOptions,
|
|
|
|
OpensMenu: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.Refresh),
|
|
|
|
Handler: self.refresh,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.Refresh,
|
2023-03-23 13:05:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.NextScreenMode),
|
|
|
|
Handler: self.nextScreenMode,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.NextScreenMode,
|
2023-03-23 13:05:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.PrevScreenMode),
|
|
|
|
Handler: self.prevScreenMode,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.PrevScreenMode,
|
2023-03-23 13:05:25 +02:00
|
|
|
},
|
2023-03-23 13:21:42 +02:00
|
|
|
{
|
|
|
|
ViewName: "",
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.OptionMenu),
|
|
|
|
Handler: self.createOptionsMenu,
|
|
|
|
OpensMenu: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ViewName: "",
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.OptionMenuAlt1),
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
// we have the description on the alt key and not the main key for legacy reasons
|
|
|
|
// (the original main key was 'x' but we've reassigned that to other purposes)
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.OpenMenu,
|
2023-03-23 13:21:42 +02:00
|
|
|
Handler: self.createOptionsMenu,
|
|
|
|
},
|
2023-03-23 13:29:46 +02:00
|
|
|
{
|
|
|
|
ViewName: "",
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.FilteringMenu),
|
|
|
|
Handler: self.createFilteringMenu,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.OpenFilteringMenu,
|
2023-03-23 13:29:46 +02:00
|
|
|
OpensMenu: true,
|
|
|
|
},
|
2023-03-23 13:32:41 +02:00
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.DiffingMenu),
|
|
|
|
Handler: self.createDiffingMenu,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.OpenDiffingMenu,
|
2023-03-23 13:32:41 +02:00
|
|
|
OpensMenu: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.DiffingMenuAlt),
|
|
|
|
Handler: self.createDiffingMenu,
|
2023-05-25 13:11:51 +02:00
|
|
|
Description: self.c.Tr.OpenDiffingMenu,
|
2023-03-23 13:32:41 +02:00
|
|
|
OpensMenu: true,
|
|
|
|
},
|
2023-03-26 06:38:18 +02:00
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.Quit),
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: self.quit,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.QuitAlt1),
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: self.quit,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.QuitWithoutChangingDirectory),
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: self.quitWithoutChangingDirectory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.Return),
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: self.escape,
|
|
|
|
},
|
2023-03-26 07:00:40 +02:00
|
|
|
{
|
|
|
|
Key: opts.GetKey(opts.Config.Universal.ToggleWhitespaceInDiffView),
|
|
|
|
Handler: self.toggleWhitespace,
|
|
|
|
Description: self.c.Tr.ToggleWhitespaceInDiffView,
|
|
|
|
},
|
2022-02-05 02:00:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-23 13:05:25 +02:00
|
|
|
func (self *GlobalController) Context() types.Context {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:00:57 +02:00
|
|
|
func (self *GlobalController) customCommand() error {
|
2023-03-23 12:35:11 +02:00
|
|
|
return (&CustomCommandAction{c: self.c}).Call()
|
2022-02-05 02:00:57 +02:00
|
|
|
}
|
|
|
|
|
2023-03-23 12:39:30 +02:00
|
|
|
func (self *GlobalController) createCustomPatchOptionsMenu() error {
|
|
|
|
return (&CustomPatchOptionsMenuAction{c: self.c}).Call()
|
|
|
|
}
|
|
|
|
|
2023-03-23 13:05:25 +02:00
|
|
|
func (self *GlobalController) refresh() error {
|
|
|
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GlobalController) nextScreenMode() error {
|
|
|
|
return (&ScreenModeActions{c: self.c}).Next()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GlobalController) prevScreenMode() error {
|
|
|
|
return (&ScreenModeActions{c: self.c}).Prev()
|
2022-02-05 02:00:57 +02:00
|
|
|
}
|
2023-03-23 13:21:42 +02:00
|
|
|
|
|
|
|
func (self *GlobalController) createOptionsMenu() error {
|
|
|
|
return (&OptionsMenuAction{c: self.c}).Call()
|
|
|
|
}
|
2023-03-23 13:29:46 +02:00
|
|
|
|
|
|
|
func (self *GlobalController) createFilteringMenu() error {
|
|
|
|
return (&FilteringMenuAction{c: self.c}).Call()
|
|
|
|
}
|
2023-03-23 13:32:41 +02:00
|
|
|
|
|
|
|
func (self *GlobalController) createDiffingMenu() error {
|
|
|
|
return (&DiffingMenuAction{c: self.c}).Call()
|
|
|
|
}
|
2023-03-26 06:38:18 +02:00
|
|
|
|
|
|
|
func (self *GlobalController) quit() error {
|
|
|
|
return (&QuitActions{c: self.c}).Quit()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GlobalController) quitWithoutChangingDirectory() error {
|
|
|
|
return (&QuitActions{c: self.c}).QuitWithoutChangingDirectory()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GlobalController) escape() error {
|
|
|
|
return (&QuitActions{c: self.c}).Escape()
|
|
|
|
}
|
2023-03-26 07:00:40 +02:00
|
|
|
|
|
|
|
func (self *GlobalController) toggleWhitespace() error {
|
|
|
|
return (&ToggleWhitespaceAction{c: self.c}).Call()
|
|
|
|
}
|