1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-12 04:23:03 +02:00
lazygit/pkg/gui/controllers/reflog_controller.go

104 lines
2.8 KiB
Go
Raw Normal View History

2022-02-13 08:13:09 +02:00
package controllers
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type ReflogController struct {
baseController
*controllerCommon
}
var _ types.IController = &ReflogController{}
func NewReflogController(
common *controllerCommon,
) *ReflogController {
return &ReflogController{
2022-02-22 11:13:11 +02:00
baseController: baseController{},
controllerCommon: common,
2022-02-13 08:13:09 +02:00
}
}
func (self *ReflogController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
bindings := []*types.Binding{
{
Key: opts.GetKey(opts.Config.Universal.Select),
2022-02-13 08:24:37 +02:00
Handler: self.checkSelected(self.checkout),
2022-02-13 08:13:09 +02:00
Description: self.c.Tr.LcCheckoutCommit,
},
{
Key: opts.GetKey(opts.Config.Commits.ViewResetOptions),
2022-02-13 08:24:37 +02:00
Handler: self.checkSelected(self.openResetMenu),
2022-02-13 08:13:09 +02:00
Description: self.c.Tr.LcViewResetOptions,
OpensMenu: true,
},
{
Key: opts.GetKey(opts.Config.Commits.CherryPickCopy),
2022-02-13 08:24:37 +02:00
Handler: opts.Guards.OutsideFilterMode(self.checkSelected(self.copy)),
2022-02-13 08:13:09 +02:00
Description: self.c.Tr.LcCherryPickCopy,
},
{
Key: opts.GetKey(opts.Config.Commits.CherryPickCopyRange),
2022-02-13 08:24:37 +02:00
Handler: opts.Guards.OutsideFilterMode(self.checkSelected(self.copyRange)),
2022-02-13 08:13:09 +02:00
Description: self.c.Tr.LcCherryPickCopyRange,
},
{
Key: opts.GetKey(opts.Config.Commits.ResetCherryPick),
Handler: self.helpers.CherryPick.Reset,
Description: self.c.Tr.LcResetCherryPick,
},
}
return bindings
}
func (self *ReflogController) checkSelected(callback func(*models.Commit) error) func() error {
return func() error {
commit := self.context().GetSelected()
if commit == nil {
return nil
}
return callback(commit)
}
}
func (self *ReflogController) Context() types.Context {
return self.context()
}
func (self *ReflogController) context() *context.ReflogCommitsContext {
return self.contexts.ReflogCommits
}
2022-02-13 08:24:37 +02:00
func (self *ReflogController) checkout(commit *models.Commit) error {
2022-02-13 08:13:09 +02:00
err := self.c.Ask(types.AskOpts{
Title: self.c.Tr.LcCheckoutCommit,
Prompt: self.c.Tr.SureCheckoutThisCommit,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.CheckoutReflogCommit)
return self.helpers.Refs.CheckoutRef(commit.Sha, types.CheckoutRefOptions{})
},
})
if err != nil {
return err
}
return nil
}
2022-02-13 08:24:37 +02:00
func (self *ReflogController) openResetMenu(commit *models.Commit) error {
2022-02-13 08:13:09 +02:00
return self.helpers.Refs.CreateGitResetMenu(commit.Sha)
}
2022-02-13 08:24:37 +02:00
func (self *ReflogController) copy(commit *models.Commit) error {
2022-02-13 08:13:09 +02:00
return self.helpers.CherryPick.Copy(commit, self.model.FilteredReflogCommits, self.context())
}
2022-02-13 08:24:37 +02:00
func (self *ReflogController) copyRange(commit *models.Commit) error {
2022-02-13 08:13:09 +02:00
return self.helpers.CherryPick.CopyRange(self.context().GetSelectedLineIdx(), self.model.FilteredReflogCommits, self.context())
}