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

allow getting the current item generically

This commit is contained in:
Jesse Duffield 2020-08-22 09:01:14 +10:00
parent 974c6510b8
commit 0ac402792b
9 changed files with 49 additions and 31 deletions

View File

@ -16,3 +16,7 @@ type Branch struct {
func (b *Branch) RefName() string {
return b.Name
}
func (b *Branch) ID() string {
return b.RefName()
}

View File

@ -28,3 +28,7 @@ func (c *Commit) NameWithSha() string {
func (c *Commit) RefName() string {
return c.Sha
}
func (c *Commit) ID() string {
return c.RefName()
}

View File

@ -7,3 +7,7 @@ type CommitFile struct {
DisplayString string
Status int // one of 'WHOLE' 'PART' 'NONE'
}
func (f *CommitFile) ID() string {
return f.Name
}

View File

@ -10,3 +10,7 @@ type Remote struct {
func (r *Remote) RefName() string {
return r.Name
}
func (r *Remote) ID() string {
return r.RefName()
}

View File

@ -13,3 +13,7 @@ func (r *RemoteBranch) FullName() string {
func (r *RemoteBranch) RefName() string {
return r.FullName()
}
func (r *RemoteBranch) ID() string {
return r.RefName()
}

View File

@ -11,3 +11,7 @@ type StashEntry struct {
func (s *StashEntry) RefName() string {
return fmt.Sprintf("stash@{%d}", s.Index)
}
func (s *StashEntry) ID() string {
return s.RefName()
}

View File

@ -8,3 +8,7 @@ type Tag struct {
func (t *Tag) RefName() string {
return t.Name
}
func (t *Tag) ID() string {
return t.RefName()
}

View File

@ -3,7 +3,6 @@ package gui
import (
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/jesseduffield/gocui"
)
@ -530,7 +529,6 @@ func (gui *Gui) currentSideContext() *ListContext {
context := stack[len(stack)-1-i]
if context.GetKind() == SIDE_CONTEXT {
gui.Log.Warn(spew.Sdump(context.GetKey()))
return context.(*ListContext)
}
}

View File

@ -21,7 +21,7 @@ type ListContext struct {
OnFocus func() error
OnFocusLost func() error
OnClickSelectedItem func() error
GetItems func() []ListItem
GetSelectedItem func() ListItem
GetPanelState func() IListPanelState
Gui *Gui
@ -63,24 +63,6 @@ func (lc *ListContext) GetParentContext() Context {
return lc.ParentContext
}
func (lc *ListContext) GetSelectedItem() ListItem {
items := lc.GetItems()
if len(items) == 0 {
return nil
}
selectedLineIdx := lc.GetPanelState().GetSelectedLineIdx()
if selectedLineIdx > len(items)-1 {
return nil
}
item := items[selectedLineIdx]
return item
}
func (lc *ListContext) GetSelectedItemId() string {
item := lc.GetSelectedItem()
@ -287,7 +269,8 @@ func (gui *Gui) filesListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref)
},
Contains: CONTAINS_NOTHING,
Contains: CONTAINS_NOTHING,
GetSelectedItem: func() ListItem { return gui.getSelectedFile() },
}
}
@ -304,7 +287,8 @@ func (gui *Gui) branchesListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
},
Contains: CONTAINS_COMMITS,
Contains: CONTAINS_COMMITS,
GetSelectedItem: func() ListItem { return gui.getSelectedBranch() },
}
}
@ -322,7 +306,8 @@ func (gui *Gui) remotesListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Diff.Ref)
},
Contains: CONTAINS_BRANCHES,
Contains: CONTAINS_BRANCHES,
GetSelectedItem: func() ListItem { return gui.getSelectedRemote() },
}
}
@ -339,7 +324,8 @@ func (gui *Gui) remoteBranchesListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Diff.Ref)
},
Contains: CONTAINS_COMMITS,
Contains: CONTAINS_COMMITS,
GetSelectedItem: func() ListItem { return gui.getSelectedRemoteBranch() },
}
}
@ -356,7 +342,8 @@ func (gui *Gui) tagsListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Diff.Ref)
},
Contains: CONTAINS_COMMITS,
Contains: CONTAINS_COMMITS,
GetSelectedItem: func() ListItem { return gui.getSelectedTag() },
}
}
@ -374,7 +361,8 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
},
Contains: CONTAINS_FILES,
Contains: CONTAINS_FILES,
GetSelectedItem: func() ListItem { return gui.getSelectedCommit() },
}
}
@ -391,7 +379,8 @@ func (gui *Gui) reflogCommitsListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
},
Contains: CONTAINS_FILES,
Contains: CONTAINS_FILES,
GetSelectedItem: func() ListItem { return gui.getSelectedReflogCommit() },
}
}
@ -408,7 +397,8 @@ func (gui *Gui) subCommitsListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetCommitListDisplayStrings(gui.State.SubCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
},
Contains: CONTAINS_COMMITS,
Contains: CONTAINS_COMMITS,
GetSelectedItem: func() ListItem { return gui.getSelectedSubCommit() },
}
}
@ -425,7 +415,8 @@ func (gui *Gui) stashListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Diff.Ref)
},
Contains: CONTAINS_FILES,
Contains: CONTAINS_FILES,
GetSelectedItem: func() ListItem { return gui.getSelectedStashEntry() },
}
}
@ -443,7 +434,8 @@ func (gui *Gui) commitFilesListContext() *ListContext {
GetDisplayStrings: func() [][]string {
return presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
},
Contains: CONTAINS_NOTHING,
Contains: CONTAINS_NOTHING,
GetSelectedItem: func() ListItem { return gui.getSelectedCommitFile() },
}
}