1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-10 11:10:18 +02:00

cleaning up

This commit is contained in:
Jesse Duffield 2022-01-30 11:22:47 +11:00
parent e187293456
commit 09dc160da9
8 changed files with 34 additions and 54 deletions

View File

@ -445,3 +445,12 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
func sanitizedBranchName(input string) string {
return strings.Replace(input, " ", "-", -1)
}
func (gui *Gui) handleEnterBranch() error {
branch := gui.getSelectedBranch()
if branch == nil {
return nil
}
return gui.switchToSubCommitsContext(branch.RefName())
}

View File

@ -9,14 +9,8 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
type Thing interface {
// the boolean here tells us whether the item is nil. This is needed because you can't work it out on the calling end once the pointer is wrapped in an interface (unless you want to use reflection)
GetSelectedItem() (types.ListItem, bool)
}
type ListContextTrait struct {
base types.IBaseContext
thing Thing
listTrait *ListTrait
viewTrait *ViewTrait
@ -55,16 +49,6 @@ func formatListFooter(selectedLineIdx int, length int) string {
return fmt.Sprintf("%d of %d", selectedLineIdx+1, length)
}
func (self *ListContextTrait) GetSelectedItemId() string {
item, ok := self.thing.GetSelectedItem()
if !ok {
return ""
}
return item.ID()
}
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
func (self *ListContextTrait) HandleRender() error {
if self.GetDisplayStrings != nil {

View File

@ -7,7 +7,7 @@ import (
)
type TagsContext struct {
*TagsContextAux
*TagsList
*BaseContext
*ListContextTrait
}
@ -35,12 +35,11 @@ func NewTagsContext(
self := &TagsContext{}
takeFocus := func() error { return c.PushContext(self) }
aux := NewTagsContextAux(getModel)
list := NewTagsList(getModel)
viewTrait := NewViewTrait(getView)
listContextTrait := &ListContextTrait{
base: baseContext,
thing: aux,
listTrait: aux.list,
listTrait: list.ListTrait,
viewTrait: viewTrait,
GetDisplayStrings: getDisplayStrings,
@ -57,39 +56,39 @@ func NewTagsContext(
self.BaseContext = baseContext
self.ListContextTrait = listContextTrait
self.TagsContextAux = aux
self.TagsList = list
return self
}
type TagsContextAux struct {
list *ListTrait
type TagsList struct {
*ListTrait
getModel func() []*models.Tag
}
func (self *TagsContextAux) GetItemsLength() int {
func (self *TagsList) GetItemsLength() int {
return len(self.getModel())
}
func (self *TagsContextAux) GetSelectedTag() *models.Tag {
func (self *TagsList) GetSelectedTag() *models.Tag {
if self.GetItemsLength() == 0 {
return nil
}
return self.getModel()[self.list.GetSelectedLineIdx()]
return self.getModel()[self.GetSelectedLineIdx()]
}
func (self *TagsContextAux) GetSelectedItem() (types.ListItem, bool) {
func (self *TagsList) GetSelectedItem() (types.ListItem, bool) {
tag := self.GetSelectedTag()
return tag, tag != nil
}
func NewTagsContextAux(getModel func() []*models.Tag) *TagsContextAux {
self := &TagsContextAux{
func NewTagsList(getModel func() []*models.Tag) *TagsList {
self := &TagsList{
getModel: getModel,
}
self.list = &ListTrait{
self.ListTrait = &ListTrait{
selectedIdx: 0,
HasLength: self,
}

View File

@ -488,7 +488,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
ViewName: "branches",
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.GoInto),
Handler: gui.handleSwitchToSubCommits,
Handler: gui.handleEnterBranch,
Description: gui.c.Tr.LcViewCommits,
},
{
@ -510,7 +510,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
ViewName: "branches",
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.GoInto),
Handler: gui.handleSwitchToSubCommits,
Handler: gui.handleEnterRemoteBranch,
Description: gui.c.Tr.LcViewCommits,
},
{

View File

@ -60,16 +60,6 @@ func (self *ListContext) GetSelectedItem() (types.ListItem, bool) {
return self.SelectedItem()
}
func (self *ListContext) GetSelectedItemId() string {
item, ok := self.GetSelectedItem()
if !ok {
return ""
}
return item.ID()
}
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
func (self *ListContext) HandleRender() error {
view, err := self.Gui.g.View(self.ViewName)

View File

@ -109,3 +109,12 @@ func (gui *Gui) handleCreateResetToRemoteBranchMenu() error {
return gui.helpers.refs.CreateGitResetMenu(selectedBranch.FullName())
}
func (gui *Gui) handleEnterRemoteBranch() error {
selectedBranch := gui.getSelectedRemoteBranch()
if selectedBranch == nil {
return nil
}
return gui.switchToSubCommitsContext(selectedBranch.RefName())
}

View File

@ -102,12 +102,3 @@ func (gui *Gui) switchToSubCommitsContext(refName string) error {
return gui.c.PushContext(gui.State.Contexts.SubCommits)
}
func (gui *Gui) handleSwitchToSubCommits() error {
currentContext := gui.currentSideListContext()
if currentContext == nil {
return nil
}
return gui.switchToSubCommitsContext(currentContext.GetSelectedItemId())
}

View File

@ -62,21 +62,19 @@ type IController interface {
type IListContext interface {
HasKeybindings
GetSelectedItem() (ListItem, bool)
GetSelectedItemId() string
HandlePrevLine() error
HandleNextLine() error
HandleScrollLeft() error
HandleScrollRight() error
HandlePrevPage() error
HandleNextPage() error
HandleGotoTop() error
HandleGotoBottom() error
HandlePrevPage() error
HandleClick(onClick func() error) error
OnSearchSelect(selectedLineIdx int) error
FocusLine()
HandleRenderToMain() error
GetPanelState() IListPanelState