2021-03-31 13:08:55 +02:00
|
|
|
package filetree
|
|
|
|
|
2022-03-19 03:26:30 +02:00
|
|
|
import "github.com/jesseduffield/generics/set"
|
2021-03-31 13:08:55 +02:00
|
|
|
|
2022-03-19 03:26:30 +02:00
|
|
|
type CollapsedPaths struct {
|
|
|
|
collapsedPaths *set.Set[string]
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCollapsedPaths() *CollapsedPaths {
|
|
|
|
return &CollapsedPaths{
|
|
|
|
collapsedPaths: set.New[string](),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *CollapsedPaths) ExpandToPath(path string) {
|
2021-03-31 13:08:55 +02:00
|
|
|
// need every directory along the way
|
2021-04-08 13:24:49 +02:00
|
|
|
splitPath := split(path)
|
|
|
|
for i := range splitPath {
|
|
|
|
dir := join(splitPath[0 : i+1])
|
2022-03-19 03:26:30 +02:00
|
|
|
self.collapsedPaths.Remove(dir)
|
2021-03-31 13:08:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-19 03:26:30 +02:00
|
|
|
func (self *CollapsedPaths) IsCollapsed(path string) bool {
|
|
|
|
return self.collapsedPaths.Includes(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *CollapsedPaths) Collapse(path string) {
|
|
|
|
self.collapsedPaths.Add(path)
|
2021-03-31 13:08:55 +02:00
|
|
|
}
|
|
|
|
|
2022-03-19 03:26:30 +02:00
|
|
|
func (self *CollapsedPaths) ToggleCollapsed(path string) {
|
|
|
|
if self.collapsedPaths.Includes(path) {
|
|
|
|
self.collapsedPaths.Remove(path)
|
|
|
|
} else {
|
|
|
|
self.collapsedPaths.Add(path)
|
|
|
|
}
|
2021-03-31 13:08:55 +02:00
|
|
|
}
|