From 2855b5b4d5eb757c4b6eb359b862ebb6fa9dffb4 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 19 Aug 2020 22:27:31 +1000 Subject: [PATCH] standardise diffmode --- pkg/gui/branches_panel.go | 8 ------- pkg/gui/commit_files_panel.go | 8 +------ pkg/gui/commits_panel.go | 8 ------- pkg/gui/files_panel.go | 4 ---- pkg/gui/list_context.go | 40 +++++++++++++------------------- pkg/gui/reflog_panel.go | 4 ---- pkg/gui/remote_branches_panel.go | 8 ------- pkg/gui/remotes_panel.go | 8 ------- pkg/gui/stash_panel.go | 8 ------- pkg/gui/status_panel.go | 10 ++++---- pkg/gui/tags_panel.go | 8 ------- 11 files changed, 23 insertions(+), 91 deletions(-) diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 92bc5e660..1d617ba8e 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -24,14 +24,6 @@ func (gui *Gui) getSelectedBranch() *commands.Branch { } func (gui *Gui) handleBranchSelect() error { - if gui.popupPanelFocused() { - return nil - } - - if gui.inDiffMode() { - return gui.renderDiff() - } - var task updateTask branch := gui.getSelectedBranch() if branch == nil { diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index b781131cb..f09201f55 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -16,13 +16,7 @@ func (gui *Gui) getSelectedCommitFile() *commands.CommitFile { } func (gui *Gui) handleCommitFileSelect() error { - if gui.popupPanelFocused() { - return nil - } - - if gui.currentViewName() == "commitFiles" { - gui.handleEscapeLineByLinePanel() - } + gui.handleEscapeLineByLinePanel() commitFile := gui.getSelectedCommitFile() if commitFile == nil { diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 425f6bbdb..cbcfb91b3 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -20,14 +20,6 @@ func (gui *Gui) getSelectedCommit() *commands.Commit { } func (gui *Gui) handleCommitSelect() error { - if gui.popupPanelFocused() { - return nil - } - - if gui.inDiffMode() { - return gui.renderDiff() - } - state := gui.State.Panels.Commits if state.SelectedLine > 290 && state.LimitCommits { state.LimitCommits = false diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 440c0675c..0015c563c 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -30,10 +30,6 @@ func (gui *Gui) getSelectedFile() *commands.File { func (gui *Gui) selectFile(alreadySelected bool) error { gui.getFilesView().FocusPoint(0, gui.State.Panels.Files.SelectedLine) - if gui.inDiffMode() { - return gui.renderDiff() - } - file := gui.getSelectedFile() if file == nil { return gui.refreshMain(refreshMainOpts{ diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 3cbbf1efd..98e62cbc1 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -13,7 +13,6 @@ type ListContext struct { GetDisplayStrings func() [][]string OnFocus func() error OnFocusLost func() error - OnItemSelect func() error OnClickSelectedItem func() error Gui *Gui @@ -57,7 +56,19 @@ func (lc *ListContext) HandleFocusLost() error { } func (lc *ListContext) HandleFocus() error { - return lc.OnFocus() + if lc.Gui.popupPanelFocused() { + return nil + } + + if lc.Gui.inDiffMode() { + return lc.Gui.renderDiff() + } + + if lc.OnFocus != nil { + return lc.OnFocus() + } + + return nil } func (lc *ListContext) HandleRender() error { @@ -94,10 +105,7 @@ func (lc *ListContext) handleLineChange(change int) error { } } - if lc.OnItemSelect != nil { - return lc.OnItemSelect() - } - return nil + return lc.HandleFocus() } func (lc *ListContext) handleNextPage(g *gocui.Gui, v *gocui.View) error { @@ -158,18 +166,12 @@ func (lc *ListContext) handleClick(g *gocui.Gui, v *gocui.View) error { if prevSelectedLineIdx == newSelectedLineIdx && prevViewName == lc.ViewName && lc.OnClickSelectedItem != nil { return lc.OnClickSelectedItem() } - if lc.OnItemSelect != nil { - return lc.OnItemSelect() - } - return nil + return lc.HandleFocus() } func (lc *ListContext) onSearchSelect(selectedLineIdx int) error { *lc.GetSelectedLineIdxPtr() = selectedLineIdx - if lc.OnItemSelect != nil { - return lc.OnItemSelect() - } - return nil + return lc.HandleFocus() } func (gui *Gui) menuListContext() *ListContext { @@ -179,7 +181,6 @@ func (gui *Gui) menuListContext() *ListContext { GetItemsLength: func() int { return gui.getMenuView().LinesHeight() }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Menu.SelectedLine }, OnFocus: gui.handleMenuSelect, - OnItemSelect: gui.handleMenuSelect, // 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, @@ -197,7 +198,6 @@ func (gui *Gui) filesListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.Files) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Files.SelectedLine }, OnFocus: gui.focusAndSelectFile, - OnItemSelect: gui.focusAndSelectFile, OnClickSelectedItem: gui.handleFilePress, Gui: gui, RendersToMainView: false, @@ -215,7 +215,6 @@ func (gui *Gui) branchesListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.Branches) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Branches.SelectedLine }, OnFocus: gui.handleBranchSelect, - OnItemSelect: gui.handleBranchSelect, Gui: gui, RendersToMainView: true, Kind: SIDE_CONTEXT, @@ -232,7 +231,6 @@ func (gui *Gui) remotesListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.Remotes) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Remotes.SelectedLine }, OnFocus: gui.handleRemoteSelect, - OnItemSelect: gui.handleRemoteSelect, OnClickSelectedItem: gui.handleRemoteEnter, Gui: gui, RendersToMainView: true, @@ -250,7 +248,6 @@ func (gui *Gui) remoteBranchesListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.RemoteBranches) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.RemoteBranches.SelectedLine }, OnFocus: gui.handleRemoteBranchSelect, - OnItemSelect: gui.handleRemoteBranchSelect, Gui: gui, RendersToMainView: true, Kind: SIDE_CONTEXT, @@ -267,7 +264,6 @@ func (gui *Gui) tagsListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.Tags) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Tags.SelectedLine }, OnFocus: gui.handleTagSelect, - OnItemSelect: gui.handleTagSelect, Gui: gui, RendersToMainView: true, Kind: SIDE_CONTEXT, @@ -284,7 +280,6 @@ func (gui *Gui) branchCommitsListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.Commits) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Commits.SelectedLine }, OnFocus: gui.handleCommitSelect, - OnItemSelect: gui.handleCommitSelect, OnClickSelectedItem: gui.handleSwitchToCommitFilesPanel, Gui: gui, RendersToMainView: true, @@ -302,7 +297,6 @@ func (gui *Gui) reflogCommitsListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.FilteredReflogCommits) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine }, OnFocus: gui.handleReflogCommitSelect, - OnItemSelect: gui.handleReflogCommitSelect, Gui: gui, RendersToMainView: true, Kind: SIDE_CONTEXT, @@ -319,7 +313,6 @@ func (gui *Gui) stashListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.StashEntries) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Stash.SelectedLine }, OnFocus: gui.handleStashEntrySelect, - OnItemSelect: gui.handleStashEntrySelect, Gui: gui, RendersToMainView: true, Kind: SIDE_CONTEXT, @@ -337,7 +330,6 @@ func (gui *Gui) commitFilesListContext() *ListContext { GetItemsLength: func() int { return len(gui.State.CommitFiles) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine }, OnFocus: gui.handleCommitFileSelect, - OnItemSelect: gui.handleCommitFileSelect, Gui: gui, RendersToMainView: true, Kind: SIDE_CONTEXT, diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index 534d18e22..bf3c91baf 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -18,10 +18,6 @@ func (gui *Gui) getSelectedReflogCommit() *commands.Commit { } func (gui *Gui) handleReflogCommitSelect() error { - if gui.inDiffMode() { - return gui.renderDiff() - } - commit := gui.getSelectedReflogCommit() var task updateTask if commit == nil { diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index 876ff197b..da8e8bbc2 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -19,14 +19,6 @@ func (gui *Gui) getSelectedRemoteBranch() *commands.RemoteBranch { } func (gui *Gui) handleRemoteBranchSelect() error { - if gui.popupPanelFocused() { - return nil - } - - if gui.inDiffMode() { - return gui.renderDiff() - } - var task updateTask remoteBranch := gui.getSelectedRemoteBranch() if remoteBranch == nil { diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index 18dc10ea3..7a3bdcca1 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -22,14 +22,6 @@ func (gui *Gui) getSelectedRemote() *commands.Remote { } func (gui *Gui) handleRemoteSelect() error { - if gui.popupPanelFocused() { - return nil - } - - if gui.inDiffMode() { - return gui.renderDiff() - } - var task updateTask remote := gui.getSelectedRemote() if remote == nil { diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index 660b3552d..42a37cace 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -17,14 +17,6 @@ func (gui *Gui) getSelectedStashEntry() *commands.StashEntry { } func (gui *Gui) handleStashEntrySelect() error { - if gui.popupPanelFocused() { - return nil - } - - if gui.inDiffMode() { - return gui.renderDiff() - } - var task updateTask stashEntry := gui.getSelectedStashEntry() if stashEntry == nil { diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index 0a33b84ff..6159907e9 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -61,6 +61,11 @@ func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error { + // TODO: move into some abstraction (status is currently not a listViewContext where a lot of this code lives) + if gui.popupPanelFocused() { + return nil + } + currentBranch := gui.currentBranch() if err := gui.switchContext(gui.Contexts.Status.Context); err != nil { @@ -89,14 +94,11 @@ func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleStatusSelect() error { + // TODO: move into some abstraction (status is currently not a listViewContext where a lot of this code lives) if gui.popupPanelFocused() { return nil } - if gui.inDiffMode() { - return gui.renderDiff() - } - magenta := color.New(color.FgMagenta) dashboardString := strings.Join( diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go index 5ae5c5efe..e1b9d02ee 100644 --- a/pkg/gui/tags_panel.go +++ b/pkg/gui/tags_panel.go @@ -17,14 +17,6 @@ func (gui *Gui) getSelectedTag() *commands.Tag { } func (gui *Gui) handleTagSelect() error { - if gui.popupPanelFocused() { - return nil - } - - if gui.inDiffMode() { - return gui.renderDiff() - } - var task updateTask tag := gui.getSelectedTag() if tag == nil {