mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
good progress
This commit is contained in:
parent
a32947e7a7
commit
2f5d5034db
@ -76,9 +76,8 @@ func (gui *Gui) refreshBranches() {
|
||||
}
|
||||
gui.State.Branches = builder.Build()
|
||||
|
||||
// TODO: if we're in the remotes view and we've just deleted a remote we need to refresh accordingly
|
||||
if gui.getBranchesView().Context == "local-branches" {
|
||||
_ = gui.renderLocalBranchesWithSelection()
|
||||
if err := gui.rerenderIfVisible(gui.Contexts.Branches.Context); err != nil {
|
||||
gui.Log.Error(err)
|
||||
}
|
||||
|
||||
gui.refreshStatus()
|
||||
@ -90,11 +89,11 @@ func (gui *Gui) renderLocalBranchesWithSelection() error {
|
||||
gui.refreshSelectedLine(&gui.State.Panels.Branches.SelectedLine, len(gui.State.Branches))
|
||||
displayStrings := presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
|
||||
gui.renderDisplayStrings(branchesView, displayStrings)
|
||||
if gui.g.CurrentView() == branchesView {
|
||||
if err := gui.handleBranchSelect(); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
}
|
||||
// if gui.g.CurrentView() == branchesView {
|
||||
// if err := gui.handleBranchSelect(); err != nil {
|
||||
// return gui.surfaceError(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -102,13 +102,21 @@ func (gui *Gui) refreshCommitFilesView() error {
|
||||
}
|
||||
gui.State.CommitFiles = files
|
||||
|
||||
if err := gui.renderCommitFiles(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return gui.handleCommitFileSelect()
|
||||
}
|
||||
|
||||
func (gui *Gui) renderCommitFiles() error {
|
||||
gui.refreshSelectedLine(&gui.State.Panels.CommitFiles.SelectedLine, len(gui.State.CommitFiles))
|
||||
|
||||
commitsFileView := gui.getCommitFilesView()
|
||||
displayStrings := presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
|
||||
gui.renderDisplayStrings(commitsFileView, displayStrings)
|
||||
|
||||
return gui.handleCommitFileSelect()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
|
||||
|
@ -168,18 +168,42 @@ func (gui *Gui) deactivateContext(c Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) rerenderIfVisible(c Context) error {
|
||||
v, err := gui.g.View(c.GetViewName())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if v.Context == c.GetKey() {
|
||||
if err := c.HandleRender(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) activateContext(c Context) error {
|
||||
gui.Log.Warn(spew.Sdump(gui.renderContextStack()))
|
||||
|
||||
viewName := c.GetViewName()
|
||||
_, err := gui.g.View(viewName)
|
||||
v, err := gui.g.View(viewName)
|
||||
// if view no longer exists, pop again
|
||||
if err != nil {
|
||||
return gui.returnFromContext()
|
||||
}
|
||||
|
||||
// if the new context's view was previously displaying another context, render the new context
|
||||
if v.Context != c.GetKey() {
|
||||
if err := c.HandleRender(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if viewName == "main" {
|
||||
gui.changeMainViewsContext(c.GetKey())
|
||||
} else {
|
||||
gui.changeMainViewsContext("normal")
|
||||
}
|
||||
|
||||
gui.setViewTabForContext(c)
|
||||
@ -421,11 +445,6 @@ func (gui *Gui) onViewFocusLost(v *gocui.View, newView *gocui.View) error {
|
||||
}
|
||||
}
|
||||
|
||||
if v.Name() == "main" {
|
||||
// if we have lost focus to a first-class panel, we need to do some cleanup
|
||||
gui.changeMainViewsContext("normal")
|
||||
}
|
||||
|
||||
gui.Log.Info(v.Name() + " focus lost")
|
||||
return nil
|
||||
}
|
||||
@ -458,9 +477,9 @@ func (gui *Gui) changeMainViewsContext(context string) {
|
||||
|
||||
func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
||||
return map[string][]tabContext{
|
||||
"branches": []tabContext{
|
||||
"branches": {
|
||||
{
|
||||
tab: "Branches",
|
||||
tab: "Local Branches",
|
||||
contexts: []Context{gui.Contexts.Branches.Context},
|
||||
},
|
||||
{
|
||||
@ -475,7 +494,7 @@ func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
||||
contexts: []Context{gui.Contexts.Tags.Context},
|
||||
},
|
||||
},
|
||||
"commits": []tabContext{
|
||||
"commits": {
|
||||
{
|
||||
tab: "Commits",
|
||||
contexts: []Context{gui.Contexts.BranchCommits.Context},
|
||||
@ -490,6 +509,17 @@ func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) viewTabNames(viewName string) []string {
|
||||
tabContexts := gui.ViewTabContextMap[viewName]
|
||||
|
||||
result := make([]string, len(tabContexts))
|
||||
for i, tabContext := range tabContexts {
|
||||
result[i] = tabContext.tab
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (gui *Gui) setViewTabForContext(c Context) {
|
||||
gui.Log.Warnf("in set view tab: %s", c.GetKey())
|
||||
|
||||
@ -522,3 +552,8 @@ type tabContext struct {
|
||||
tab string
|
||||
contexts []Context
|
||||
}
|
||||
|
||||
func (gui *Gui) handleContextRefresh(c Context) {
|
||||
// if context is not the current context of it's view, return
|
||||
|
||||
}
|
||||
|
@ -102,8 +102,9 @@ func (gui *Gui) refreshFiles() error {
|
||||
}
|
||||
|
||||
gui.g.Update(func(g *gocui.Gui) error {
|
||||
displayStrings := presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref)
|
||||
gui.renderDisplayStrings(filesView, displayStrings)
|
||||
if err := gui.renderFiles(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if g.CurrentView() == filesView || (g.CurrentView() == gui.getMainView() && g.CurrentView().Context == "merging") {
|
||||
newSelectedFile := gui.getSelectedFile()
|
||||
@ -116,6 +117,18 @@ func (gui *Gui) refreshFiles() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) renderFiles() error {
|
||||
filesView := gui.getFilesView()
|
||||
if filesView == nil {
|
||||
// if the filesView hasn't been instantiated yet we just return
|
||||
return nil
|
||||
}
|
||||
|
||||
displayStrings := presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref)
|
||||
gui.renderDisplayStrings(filesView, displayStrings)
|
||||
return nil
|
||||
}
|
||||
|
||||
// specific functions
|
||||
|
||||
func (gui *Gui) stagedFiles() []*commands.File {
|
||||
|
@ -147,7 +147,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||
return err
|
||||
}
|
||||
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
|
||||
branchesView.Tabs = []string{"Local Branches", "Remotes", "Tags"}
|
||||
branchesView.Tabs = gui.viewTabNames("branches")
|
||||
branchesView.FgColor = textColor
|
||||
branchesView.ContainsList = true
|
||||
}
|
||||
@ -168,7 +168,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||
return err
|
||||
}
|
||||
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
||||
commitsView.Tabs = []string{"Commits", "Reflog"}
|
||||
commitsView.Tabs = gui.viewTabNames("commits")
|
||||
commitsView.FgColor = textColor
|
||||
commitsView.ContainsList = true
|
||||
}
|
||||
|
@ -163,6 +163,8 @@ func (gui *Gui) menuListContext() *ListContext {
|
||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Menu.SelectedLine },
|
||||
OnFocus: gui.handleMenuSelect,
|
||||
OnItemSelect: gui.handleMenuSelect,
|
||||
// rendering the menu happens on creation
|
||||
OnRender: func() error { return nil },
|
||||
// need to add a layer of indirection here because the callback changes during runtime
|
||||
OnClickSelectedItem: func() error { return gui.State.Panels.Menu.OnPress(gui.g, nil) },
|
||||
Gui: gui,
|
||||
@ -180,6 +182,7 @@ func (gui *Gui) filesListContext() *ListContext {
|
||||
OnFocus: gui.focusAndSelectFile,
|
||||
OnItemSelect: gui.focusAndSelectFile,
|
||||
OnClickSelectedItem: gui.handleFilePress,
|
||||
OnRender: gui.renderFiles,
|
||||
Gui: gui,
|
||||
RendersToMainView: false,
|
||||
Kind: SIDE_CONTEXT,
|
||||
@ -194,9 +197,10 @@ func (gui *Gui) branchesListContext() *ListContext {
|
||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Branches.SelectedLine },
|
||||
OnFocus: gui.handleBranchSelect,
|
||||
OnItemSelect: gui.handleBranchSelect,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
OnRender: gui.renderLocalBranchesWithSelection,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,6 +213,7 @@ func (gui *Gui) remotesListContext() *ListContext {
|
||||
OnFocus: gui.renderRemotesWithSelection,
|
||||
OnItemSelect: gui.handleRemoteSelect,
|
||||
OnClickSelectedItem: gui.handleRemoteEnter,
|
||||
OnRender: gui.renderRemotesWithSelection,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
@ -223,6 +228,7 @@ func (gui *Gui) remoteBranchesListContext() *ListContext {
|
||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.RemoteBranches.SelectedLine },
|
||||
OnFocus: gui.handleRemoteBranchSelect,
|
||||
OnItemSelect: gui.handleRemoteBranchSelect,
|
||||
OnRender: gui.renderRemoteBranchesWithSelection,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
@ -237,6 +243,7 @@ func (gui *Gui) tagsListContext() *ListContext {
|
||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Tags.SelectedLine },
|
||||
OnFocus: gui.handleTagSelect,
|
||||
OnItemSelect: gui.handleTagSelect,
|
||||
OnRender: gui.renderTagsWithSelection,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
@ -252,6 +259,7 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
|
||||
OnFocus: gui.handleCommitSelect,
|
||||
OnItemSelect: gui.handleCommitSelect,
|
||||
OnClickSelectedItem: gui.handleSwitchToCommitFilesPanel,
|
||||
OnRender: gui.renderBranchCommitsWithSelection,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
@ -266,6 +274,7 @@ func (gui *Gui) reflogCommitsListContext() *ListContext {
|
||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine },
|
||||
OnFocus: gui.handleReflogCommitSelect,
|
||||
OnItemSelect: gui.handleReflogCommitSelect,
|
||||
OnRender: gui.renderReflogCommitsWithSelection,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
@ -280,6 +289,7 @@ func (gui *Gui) stashListContext() *ListContext {
|
||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Stash.SelectedLine },
|
||||
OnFocus: gui.handleStashEntrySelect,
|
||||
OnItemSelect: gui.handleStashEntrySelect,
|
||||
OnRender: gui.renderStash,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
@ -294,6 +304,7 @@ func (gui *Gui) commitFilesListContext() *ListContext {
|
||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine },
|
||||
OnFocus: gui.handleCommitFileSelect,
|
||||
OnItemSelect: gui.handleCommitFileSelect,
|
||||
OnRender: gui.renderCommitFiles,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
|
@ -45,9 +45,13 @@ func (gui *Gui) handleStashEntrySelect() error {
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) refreshStashEntries(g *gocui.Gui) error {
|
||||
func (gui *Gui) refreshStashEntries() error {
|
||||
gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.FilterPath)
|
||||
|
||||
return gui.renderStash()
|
||||
}
|
||||
|
||||
func (gui *Gui) renderStash() error {
|
||||
gui.refreshSelectedLine(&gui.State.Panels.Stash.SelectedLine, len(gui.State.StashEntries))
|
||||
|
||||
stashView := gui.getStashView()
|
||||
|
@ -86,9 +86,9 @@ func (gui *Gui) refreshSidePanels(options refreshOptions) error {
|
||||
wg.Add(1)
|
||||
func() {
|
||||
if options.mode == ASYNC {
|
||||
go gui.refreshStashEntries(gui.g)
|
||||
go gui.refreshStashEntries()
|
||||
} else {
|
||||
gui.refreshStashEntries(gui.g)
|
||||
gui.refreshStashEntries()
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
Loading…
x
Reference in New Issue
Block a user