diff options
author | Liberatys <nick.flueckiger@renuo.ch> | 2021-06-20 16:55:50 +0200 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-08-25 20:13:50 +1000 |
commit | 2dc6f5f07971dc5a8ed6cc22151b81fe659ba326 (patch) | |
tree | 553341841998b81109da9f1d6bfa6cfffdd9193d /pkg/gui/filetree | |
parent | bdea3b7dcfc6da36d8bb52fca0bc9dc32027320b (diff) |
Implement state filtering for commit files
Diffstat (limited to 'pkg/gui/filetree')
-rw-r--r-- | pkg/gui/filetree/file_manager.go | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/pkg/gui/filetree/file_manager.go b/pkg/gui/filetree/file_manager.go index 825ee0b01..699e20332 100644 --- a/pkg/gui/filetree/file_manager.go +++ b/pkg/gui/filetree/file_manager.go @@ -8,11 +8,20 @@ import ( "github.com/sirupsen/logrus" ) +type FileManagerDisplayFilter int + +const ( + DisplayAll FileManagerDisplayFilter = iota + DisplayStaged + DisplayUnstaged +) + type FileManager struct { files []*models.File tree *FileNode showTree bool log *logrus.Entry + filter FileManagerDisplayFilter collapsedPaths CollapsedPaths sync.RWMutex } @@ -22,6 +31,7 @@ func NewFileManager(files []*models.File, log *logrus.Entry, showTree bool) *Fil files: files, log: log, showTree: showTree, + filter: DisplayAll, collapsedPaths: CollapsedPaths{}, RWMutex: sync.RWMutex{}, } @@ -35,6 +45,35 @@ func (m *FileManager) ExpandToPath(path string) { m.collapsedPaths.ExpandToPath(path) } +func (m *FileManager) GetFilesForDisplay() []*models.File { + files := m.files + if m.filter == DisplayAll { + return files + } + + result := make([]*models.File, 0) + if m.filter == DisplayStaged { + for _, file := range files { + if file.HasStagedChanges { + result = append(result, file) + } + } + } else { + for _, file := range files { + if !file.HasStagedChanges { + result = append(result, file) + } + } + } + + return result +} + +func (m *FileManager) SetDisplayFilter(filter FileManagerDisplayFilter) { + m.filter = filter + m.SetTree() +} + func (m *FileManager) ToggleShowTree() { m.showTree = !m.showTree m.SetTree() @@ -73,10 +112,11 @@ func (m *FileManager) SetFiles(files []*models.File) { } func (m *FileManager) SetTree() { + filesForDisplay := m.GetFilesForDisplay() if m.showTree { - m.tree = BuildTreeFromFiles(m.files) + m.tree = BuildTreeFromFiles(filesForDisplay) } else { - m.tree = BuildFlatTreeFromFiles(m.files) + m.tree = BuildFlatTreeFromFiles(filesForDisplay) } } |