From 6fc3c03c4b7ffb216c753ac62e609687cfe2bed9 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 21 Mar 2021 10:07:38 +1100 Subject: [PATCH] allow configuring to show file tree on startup --- docs/Config.md | 1 + pkg/config/user_config.go | 1 + pkg/gui/files_panel.go | 2 +- pkg/gui/gui.go | 4 +++- pkg/gui/status_line_manager.go | 8 ++++---- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index ac30d95aa..9a3f3976b 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -34,6 +34,7 @@ Default path for the config file: mouseEvents: true skipUnstageLineWarning: false skipStashWarning: true + showFileTree: false # for rendering changes files in a tree format git: paging: colorArg: always diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index c8093943e..73b19cc3b 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -35,6 +35,7 @@ type GuiConfig struct { Theme ThemeConfig `yaml:"theme"` CommitLength CommitLengthConfig `yaml:"commitLength"` SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"` + ShowFileTree bool `yaml:"showFileTree"` } type ThemeConfig struct { diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 4e207f84a..01ae3b14b 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -840,7 +840,7 @@ func (gui *Gui) handleToggleFileTreeView() error { if node != nil { path = node.Path } - gui.State.StatusLineManager.TreeMode = !gui.State.StatusLineManager.TreeMode + gui.State.StatusLineManager.ShowTree = !gui.State.StatusLineManager.ShowTree gui.State.StatusLineManager.SetTree() // find that same node in the new format and move the cursor to it diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 7c0606652..e7ca0bf5e 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -377,8 +377,10 @@ func (gui *Gui) resetState() { Diffing: prevDiff, } + showTree := gui.Config.GetUserConfig().Gui.ShowFileTree + gui.State = &guiState{ - StatusLineManager: NewStatusLineManager(make([]*models.File, 0), gui.Log), + StatusLineManager: NewStatusLineManager(make([]*models.File, 0), gui.Log, showTree), Commits: make([]*models.Commit, 0), FilteredReflogCommits: make([]*models.Commit, 0), ReflogCommits: make([]*models.Commit, 0), diff --git a/pkg/gui/status_line_manager.go b/pkg/gui/status_line_manager.go index 3631c338e..14300a0f8 100644 --- a/pkg/gui/status_line_manager.go +++ b/pkg/gui/status_line_manager.go @@ -15,16 +15,16 @@ const COLLAPSED_ARROW = "►" type StatusLineManager struct { Files []*models.File Tree *models.StatusLineNode - TreeMode bool + ShowTree bool Log *logrus.Entry CollapsedPaths map[string]bool } -func NewStatusLineManager(files []*models.File, log *logrus.Entry) *StatusLineManager { +func NewStatusLineManager(files []*models.File, log *logrus.Entry, showTree bool) *StatusLineManager { return &StatusLineManager{ Files: files, Log: log, - TreeMode: false, // always true for now + ShowTree: showTree, CollapsedPaths: map[string]bool{}, } } @@ -62,7 +62,7 @@ func (m *StatusLineManager) SetFiles(files []*models.File) { } func (m *StatusLineManager) SetTree() { - if m.TreeMode { + if m.ShowTree { m.Tree = GetTreeFromStatusFiles(m.Files, m.Log) } else { m.Tree = GetFlatTreeFromStatusFiles(m.Files)