Support filtering files

This commit is contained in:
Jesse Duffield
2023-05-27 19:58:48 +10:00
parent 84870d4503
commit 13326344f0
9 changed files with 72 additions and 19 deletions

View File

@@ -34,7 +34,7 @@ type IFileTree interface {
ITree[models.File]
FilterFiles(test func(*models.File) bool) []*models.File
SetFilter(filter FileTreeDisplayFilter)
SetStatusFilter(filter FileTreeDisplayFilter)
Get(index int) *FileNode
GetFile(path string) *models.File
GetAllItems() []*FileNode
@@ -91,7 +91,7 @@ func (self *FileTree) FilterFiles(test func(*models.File) bool) []*models.File {
return slices.Filter(self.getFiles(), test)
}
func (self *FileTree) SetFilter(filter FileTreeDisplayFilter) {
func (self *FileTree) SetStatusFilter(filter FileTreeDisplayFilter) {
self.filter = filter
self.SetTree()
}
@@ -102,7 +102,7 @@ func (self *FileTree) ToggleShowTree() {
}
func (self *FileTree) Get(index int) *FileNode {
// need to traverse the three depth first until we get to the index.
// need to traverse the tree depth first until we get to the index.
return NewFileNode(self.tree.GetNodeAtIndex(index+1, self.collapsedPaths)) // ignoring root
}

View File

@@ -26,8 +26,6 @@ type FileTreeViewModel struct {
var _ IFileTreeViewModel = &FileTreeViewModel{}
// how to tackle this? We could just filter down the list of files at a high point and then the rest will take care of itself.
func NewFileTreeViewModel(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTreeViewModel {
fileTree := NewFileTree(getFiles, log, showTree)
listCursor := traits.NewListCursor(fileTree)
@@ -128,8 +126,8 @@ func (self *FileTreeViewModel) findNewSelectedIdx(prevNodes []*FileNode, currNod
return -1
}
func (self *FileTreeViewModel) SetFilter(filter FileTreeDisplayFilter) {
self.IFileTree.SetFilter(filter)
func (self *FileTreeViewModel) SetStatusFilter(filter FileTreeDisplayFilter) {
self.IFileTree.SetStatusFilter(filter)
self.IListCursor.SetSelectedLineIdx(0)
}