diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-19 18:41:57 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-23 14:29:18 +1000 |
commit | 2f5d5034dbe4523c44faa58ba6f30c2fef06c128 (patch) | |
tree | bce2590230ef9bc560da11f376c4187c9db0067a | |
parent | a32947e7a777cb1f1bc16ea9693bd3d01519ea4b (diff) |
good progress
-rw-r--r-- | pkg/gui/branches_panel.go | 15 | ||||
-rw-r--r-- | pkg/gui/commit_files_panel.go | 10 | ||||
-rw-r--r-- | pkg/gui/context.go | 53 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 17 | ||||
-rw-r--r-- | pkg/gui/layout.go | 4 | ||||
-rw-r--r-- | pkg/gui/list_context.go | 17 | ||||
-rw-r--r-- | pkg/gui/stash_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/view_helpers.go | 4 |
8 files changed, 98 insertions, 28 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 79b436c4e..a783f49fe 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -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 } diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 27f02297c..a56f29dad 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -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 { diff --git a/pkg/gui/context.go b/pkg/gui/context.go index e41224d2a..a54625306 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -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 + +} diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index b116271db..b3b9b8b70 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -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 { diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index bc59bb5e2..96144df98 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -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 } diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 9454aadf9..69ed01ef6 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -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, diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index 24a136331..523ee88cd 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -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() diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 3d5353ea9..db5e32848 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -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() }() |