1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-26 05:37:18 +02:00
lazygit/pkg/gui/controllers/switch_to_sub_commits_controller.go

66 lines
1.6 KiB
Go
Raw Normal View History

2022-02-06 14:37:16 +11:00
package controllers
import (
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
2022-02-06 14:37:16 +11:00
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
2022-03-26 17:03:30 +11:00
var _ types.IController = &SwitchToSubCommitsController{}
2022-02-06 14:37:16 +11:00
2022-03-26 17:08:23 +11:00
type CanSwitchToSubCommits interface {
2022-02-06 14:37:16 +11:00
types.Context
2022-03-26 22:18:08 +09:00
GetSelectedRef() types.Ref
ShowBranchHeadsInSubCommits() bool
2022-02-06 14:37:16 +11:00
}
2022-03-26 17:03:30 +11:00
type SwitchToSubCommitsController struct {
2022-02-06 14:37:16 +11:00
baseController
2023-03-23 18:47:29 +11:00
c *ControllerCommon
2022-03-26 17:08:23 +11:00
context CanSwitchToSubCommits
2022-02-06 14:37:16 +11:00
}
2022-03-26 17:03:30 +11:00
func NewSwitchToSubCommitsController(
2023-03-23 18:47:29 +11:00
controllerCommon *ControllerCommon,
2022-03-26 17:08:23 +11:00
context CanSwitchToSubCommits,
2022-03-26 17:03:30 +11:00
) *SwitchToSubCommitsController {
return &SwitchToSubCommitsController{
2023-03-23 18:47:29 +11:00
baseController: baseController{},
c: controllerCommon,
context: context,
2022-02-06 14:37:16 +11:00
}
}
2022-03-26 17:03:30 +11:00
func (self *SwitchToSubCommitsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
2022-02-06 14:37:16 +11:00
bindings := []*types.Binding{
{
Handler: self.viewCommits,
Key: opts.GetKey(opts.Config.Universal.GoInto),
Description: self.c.Tr.ViewCommits,
2022-02-06 14:37:16 +11:00
},
}
return bindings
}
2022-03-26 17:03:30 +11:00
func (self *SwitchToSubCommitsController) GetOnClick() func() error {
2022-02-27 11:42:22 +11:00
return self.viewCommits
}
2022-03-26 17:03:30 +11:00
func (self *SwitchToSubCommitsController) viewCommits() error {
2022-03-26 22:18:08 +09:00
ref := self.context.GetSelectedRef()
if ref == nil {
2022-02-06 14:37:16 +11:00
return nil
}
return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{
Ref: ref,
TitleRef: ref.RefName(),
Context: self.context,
ShowBranchHeads: self.context.ShowBranchHeadsInSubCommits(),
})
2022-02-06 14:37:16 +11:00
}
2022-03-26 17:03:30 +11:00
func (self *SwitchToSubCommitsController) Context() types.Context {
2022-02-06 14:37:16 +11:00
return self.context
}