2022-02-06 14:37:16 +11:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2023-08-05 11:19:16 +02:00
|
|
|
"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
|
2023-07-25 11:33:39 +02:00
|
|
|
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),
|
2023-05-25 21:11:51 +10:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-08-05 11:19:16 +02:00
|
|
|
return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{
|
|
|
|
Ref: ref,
|
2023-08-05 12:06:37 +02:00
|
|
|
TitleRef: ref.RefName(),
|
2023-08-05 11:19:16 +02:00
|
|
|
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
|
|
|
|
}
|