summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-03-31 23:20:36 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-04-02 11:00:15 +1100
commit8dee06f83a1aebe9eb085e67b790f166f9d205af (patch)
tree620c8ef558e6d38d82c2565ca854c0b22d1e6f0f /pkg
parent82fe4aa6c0e24852f4c73030447fdd99deda5e66 (diff)
allow toggling tree view for commit files panel
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/commit_files_panel.go24
-rw-r--r--pkg/gui/files_panel.go11
-rw-r--r--pkg/gui/keybindings.go18
-rw-r--r--pkg/gui/view_helpers.go7
4 files changed, 43 insertions, 17 deletions
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
@@ -911,12 +911,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
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},
Key: gui.getKey(config.Universal.GoInto),
@@ -1041,6 +1035,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
},
{
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),
Handler: gui.handleCheckoutCommitFile,
Description: gui.Tr.LcCheckoutCommitFile,
@@ -1076,6 +1076,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
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),
Handler: gui.handleCreateFilteringMenuPanel,
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