From 8dee06f83a1aebe9eb085e67b790f166f9d205af Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 31 Mar 2021 23:20:36 +1100 Subject: allow toggling tree view for commit files panel --- pkg/gui/commit_files_panel.go | 24 ++++++++++++++++++++++++ pkg/gui/files_panel.go | 11 ++--------- pkg/gui/keybindings.go | 18 ++++++++++++------ pkg/gui/view_helpers.go | 7 +++++-- 4 files changed, 43 insertions(+), 17 deletions(-) (limited to 'pkg') diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index d0c0228ec..aa95b0862 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -275,3 +275,27 @@ func (gui *Gui) switchToCommitFilesContext(refName string, canRebase bool, conte return gui.pushContext(gui.Contexts.CommitFiles.Context) } + +// NOTE: this is very similar to handleToggleFileTreeView, could be DRY'd with generics +func (gui *Gui) handleToggleCommitFileTreeView() error { + path := gui.getSelectedCommitFilePath() + + gui.State.CommitFileChangeManager.ToggleShowTree() + + // find that same node in the new format and move the cursor to it + if path != "" { + gui.State.CommitFileChangeManager.ExpandToPath(path) + index, found := gui.State.CommitFileChangeManager.GetIndexForPath(path) + if found { + gui.commitFilesListContext().GetPanelState().SetSelectedLineIdx(index) + } + } + + if gui.getCommitFilesView().Context == COMMIT_FILES_CONTEXT_KEY { + if err := gui.Contexts.CommitFiles.Context.HandleRender(); err != nil { + return err + } + } + + return nil +} diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index dce047470..c244c46e8 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -850,20 +850,13 @@ func (gui *Gui) handleToggleDirCollapsed() error { func (gui *Gui) handleToggleFileTreeView() error { // get path of currently selected file - node := gui.getSelectedFileChangeNode() - path := "" - if node != nil { - path = node.Path - } + path := gui.getSelectedPath() gui.State.FileChangeManager.ToggleShowTree() - if path != "" { - gui.State.FileChangeManager.ExpandToPath(path) - } - // find that same node in the new format and move the cursor to it if path != "" { + gui.State.FileChangeManager.ExpandToPath(path) index, found := gui.State.FileChangeManager.GetIndexForPath(path) if found { gui.filesListContext().GetPanelState().SetSelectedLineIdx(index) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index e9924f55e..493b94396 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -910,12 +910,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.wrappedHandler(gui.handleCopySelectedSideContextItemToClipboard), Description: gui.Tr.LcCopyCommitShaToClipboard, }, - { - ViewName: "commitFiles", - Key: gui.getKey(config.Universal.CopyToClipboard), - Handler: gui.wrappedHandler(gui.handleCopySelectedSideContextItemToClipboard), - Description: gui.Tr.LcCopyCommitFileNameToClipboard, - }, { ViewName: "branches", Contexts: []string{SUB_COMMITS_CONTEXT_KEY}, @@ -1039,6 +1033,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Modifier: gocui.ModNone, Handler: gui.handleInfoClick, }, + { + ViewName: "commitFiles", + Key: gui.getKey(config.Universal.CopyToClipboard), + Handler: gui.wrappedHandler(gui.handleCopySelectedSideContextItemToClipboard), + Description: gui.Tr.LcCopyCommitFileNameToClipboard, + }, { ViewName: "commitFiles", Key: gui.getKey(config.CommitFiles.CheckoutCommitFile), @@ -1075,6 +1075,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.handleEnterCommitFile, Description: gui.Tr.LcEnterFile, }, + { + ViewName: "commitFiles", + Key: gui.getKey(config.Files.ToggleTreeView), + Handler: gui.wrappedHandler(gui.handleToggleCommitFileTreeView), + Description: gui.Tr.LcToggleTreeView, + }, { ViewName: "", Key: gui.getKey(config.Universal.FilteringMenu), diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 51947837d..9a9017d14 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -237,13 +237,16 @@ func (gui *Gui) renderOptionsMap(optionsMap map[string]string) { gui.renderString("options", gui.optionsMapToString(optionsMap)) } -// TODO: refactor properly -// i'm so sorry but had to add this getBranchesView func (gui *Gui) getFilesView() *gocui.View { v, _ := gui.g.View("files") return v } +func (gui *Gui) getCommitFilesView() *gocui.View { + v, _ := gui.g.View("commitFiles") + return v +} + func (gui *Gui) getCommitMessageView() *gocui.View { v, _ := gui.g.View("commitMessage") return v -- cgit v1.2.3