1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-08 04:04:22 +02:00
lazygit/pkg/gui/controllers/switch_to_sub_commits_controller.go

66 lines
1.6 KiB
Go

package controllers
import (
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
var _ types.IController = &SwitchToSubCommitsController{}
type CanSwitchToSubCommits interface {
types.Context
GetSelectedRef() types.Ref
ShowBranchHeadsInSubCommits() bool
}
type SwitchToSubCommitsController struct {
baseController
c *ControllerCommon
context CanSwitchToSubCommits
}
func NewSwitchToSubCommitsController(
controllerCommon *ControllerCommon,
context CanSwitchToSubCommits,
) *SwitchToSubCommitsController {
return &SwitchToSubCommitsController{
baseController: baseController{},
c: controllerCommon,
context: context,
}
}
func (self *SwitchToSubCommitsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
bindings := []*types.Binding{
{
Handler: self.viewCommits,
Key: opts.GetKey(opts.Config.Universal.GoInto),
Description: self.c.Tr.ViewCommits,
},
}
return bindings
}
func (self *SwitchToSubCommitsController) GetOnClick() func() error {
return self.viewCommits
}
func (self *SwitchToSubCommitsController) viewCommits() error {
ref := self.context.GetSelectedRef()
if ref == nil {
return nil
}
return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{
Ref: ref,
TitleRef: ref.RefName(),
Context: self.context,
ShowBranchHeads: self.context.ShowBranchHeadsInSubCommits(),
})
}
func (self *SwitchToSubCommitsController) Context() types.Context {
return self.context
}