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 {
|
2024-01-14 13:51:20 +11:00
|
|
|
types.IListContext
|
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
|
|
|
}
|
|
|
|
|
2024-01-14 13:51:20 +11:00
|
|
|
// Not using our ListControllerTrait because our 'selected' item is not a list item
|
|
|
|
// but an attribute on it i.e. the ref of an item.
|
2022-03-26 17:03:30 +11:00
|
|
|
type SwitchToSubCommitsController struct {
|
2022-02-06 14:37:16 +11:00
|
|
|
baseController
|
2024-01-14 13:51:20 +11:00
|
|
|
*ListControllerTrait[types.Ref]
|
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(
|
2024-01-14 13:51:20 +11:00
|
|
|
c *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{},
|
2024-01-14 13:51:20 +11:00
|
|
|
ListControllerTrait: NewListControllerTrait[types.Ref](
|
|
|
|
c,
|
|
|
|
context,
|
|
|
|
context.GetSelectedRef,
|
|
|
|
),
|
|
|
|
c: c,
|
|
|
|
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{
|
|
|
|
{
|
2024-01-14 13:51:20 +11:00
|
|
|
Handler: self.viewCommits,
|
|
|
|
GetDisabledReason: self.require(self.singleItemSelected()),
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|