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:
parent
974c6510b8
commit
0ac402792b
@ -16,3 +16,7 @@ type Branch struct {
|
||||
func (b *Branch) RefName() string {
|
||||
return b.Name
|
||||
}
|
||||
|
||||
func (b *Branch) ID() string {
|
||||
return b.RefName()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -7,3 +7,7 @@ type CommitFile struct {
|
||||
DisplayString string
|
||||
Status int // one of 'WHOLE' 'PART' 'NONE'
|
||||
}
|
||||
|
||||
func (f *CommitFile) ID() string {
|
||||
return f.Name
|
||||
}
|
||||
|
@ -10,3 +10,7 @@ type Remote struct {
|
||||
func (r *Remote) RefName() string {
|
||||
return r.Name
|
||||
}
|
||||
|
||||
func (r *Remote) ID() string {
|
||||
return r.RefName()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -8,3 +8,7 @@ type Tag struct {
|
||||
func (t *Tag) RefName() string {
|
||||
return t.Name
|
||||
}
|
||||
|
||||
func (t *Tag) ID() string {
|
||||
return t.RefName()
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
||||
@ -288,6 +270,7 @@ func (gui *Gui) filesListContext() *ListContext {
|
||||
return presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_NOTHING,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedFile() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,6 +288,7 @@ func (gui *Gui) branchesListContext() *ListContext {
|
||||
return presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_COMMITS,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedBranch() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,6 +307,7 @@ func (gui *Gui) remotesListContext() *ListContext {
|
||||
return presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_BRANCHES,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedRemote() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,6 +325,7 @@ func (gui *Gui) remoteBranchesListContext() *ListContext {
|
||||
return presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_COMMITS,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedRemoteBranch() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,6 +343,7 @@ func (gui *Gui) tagsListContext() *ListContext {
|
||||
return presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_COMMITS,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedTag() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,6 +362,7 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
|
||||
return presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_FILES,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedCommit() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -392,6 +380,7 @@ func (gui *Gui) reflogCommitsListContext() *ListContext {
|
||||
return presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_FILES,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedReflogCommit() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,6 +398,7 @@ func (gui *Gui) subCommitsListContext() *ListContext {
|
||||
return presentation.GetCommitListDisplayStrings(gui.State.SubCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_COMMITS,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedSubCommit() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,6 +416,7 @@ func (gui *Gui) stashListContext() *ListContext {
|
||||
return presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_FILES,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedStashEntry() },
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,6 +435,7 @@ func (gui *Gui) commitFilesListContext() *ListContext {
|
||||
return presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
|
||||
},
|
||||
Contains: CONTAINS_NOTHING,
|
||||
GetSelectedItem: func() ListItem { return gui.getSelectedCommitFile() },
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user