filetree

package
v0.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2023 License: MIT Imports: 12 Imported by: 0

README

FileTree Package

This package handles the representation of file trees. There are two ways to render files: one is to render them flat, so something like this:

dir1/file1
dir1/file2
file3

And the other is to render them as a tree

dir1/
  file1
  file2
file3

Internally we represent each of the above as a tree, but with the flat approach there's just a single root node and every path is a direct child of that root. Viewing in 'tree' mode (as opposed to 'flat' mode) allows for collapsing and expanding directories, and lets you perform actions on directories e.g. staging a whole directory. But it takes up more vertical space and sometimes you just want to have a flat view where you can go flick through your files one by one to see the diff.

This package is not concerned about rendering the tree: only representing its internal state.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CollapsedPaths

type CollapsedPaths struct {
	// contains filtered or unexported fields
}

func NewCollapsedPaths added in v0.35.0

func NewCollapsedPaths() *CollapsedPaths

func (*CollapsedPaths) Collapse added in v0.35.0

func (self *CollapsedPaths) Collapse(path string)

func (*CollapsedPaths) ExpandToPath

func (self *CollapsedPaths) ExpandToPath(path string)

func (*CollapsedPaths) IsCollapsed

func (self *CollapsedPaths) IsCollapsed(path string) bool

func (*CollapsedPaths) ToggleCollapsed

func (self *CollapsedPaths) ToggleCollapsed(path string)

type CommitFileNode

type CommitFileNode struct {
	*Node[models.CommitFile]
}

CommitFileNode wraps a node and provides some commit-file-specific methods for it.

func NewCommitFileNode added in v0.36.0

func NewCommitFileNode(node *Node[models.CommitFile]) *CommitFileNode

func (*CommitFileNode) Raw added in v0.36.0

func (self *CommitFileNode) Raw() *Node[models.CommitFile]

returns the underlying node, without any commit-file-specific methods attached

type CommitFileTree added in v0.35.0

type CommitFileTree struct {
	// contains filtered or unexported fields
}

func NewCommitFileTree added in v0.35.0

func NewCommitFileTree(getFiles func() []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileTree

func (*CommitFileTree) CollapsedPaths added in v0.35.0

func (self *CommitFileTree) CollapsedPaths() *CollapsedPaths

func (*CommitFileTree) ExpandToPath added in v0.35.0

func (self *CommitFileTree) ExpandToPath(path string)

func (*CommitFileTree) Get added in v0.35.0

func (self *CommitFileTree) Get(index int) *CommitFileNode

func (*CommitFileTree) GetAllFiles added in v0.35.0

func (self *CommitFileTree) GetAllFiles() []*models.CommitFile

func (*CommitFileTree) GetAllItems added in v0.35.0

func (self *CommitFileTree) GetAllItems() []*CommitFileNode

func (*CommitFileTree) GetFile added in v0.35.0

func (self *CommitFileTree) GetFile(path string) *models.CommitFile

func (*CommitFileTree) GetIndexForPath added in v0.35.0

func (self *CommitFileTree) GetIndexForPath(path string) (int, bool)

func (*CommitFileTree) GetRoot added in v0.36.0

func (self *CommitFileTree) GetRoot() *CommitFileNode

func (*CommitFileTree) InTreeMode added in v0.35.0

func (self *CommitFileTree) InTreeMode() bool

func (*CommitFileTree) IsCollapsed added in v0.35.0

func (self *CommitFileTree) IsCollapsed(path string) bool

func (*CommitFileTree) Len added in v0.35.0

func (self *CommitFileTree) Len() int

func (*CommitFileTree) SetTree added in v0.35.0

func (self *CommitFileTree) SetTree()

func (*CommitFileTree) ToggleCollapsed added in v0.35.0

func (self *CommitFileTree) ToggleCollapsed(path string)

func (*CommitFileTree) ToggleShowTree added in v0.35.0

func (self *CommitFileTree) ToggleShowTree()

type CommitFileTreeViewModel added in v0.35.0

type CommitFileTreeViewModel struct {
	sync.RWMutex
	ICommitFileTree
	types.IListCursor
	// contains filtered or unexported fields
}

func NewCommitFileTreeViewModel added in v0.35.0

func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileTreeViewModel

func (*CommitFileTreeViewModel) GetCanRebase added in v0.35.0

func (self *CommitFileTreeViewModel) GetCanRebase() bool

func (*CommitFileTreeViewModel) GetRef added in v0.35.0

func (self *CommitFileTreeViewModel) GetRef() types.Ref

func (*CommitFileTreeViewModel) GetSelected added in v0.35.0

func (self *CommitFileTreeViewModel) GetSelected() *CommitFileNode

func (*CommitFileTreeViewModel) GetSelectedFile added in v0.35.0

func (self *CommitFileTreeViewModel) GetSelectedFile() *models.CommitFile

func (*CommitFileTreeViewModel) GetSelectedPath added in v0.35.0

func (self *CommitFileTreeViewModel) GetSelectedPath() string

func (*CommitFileTreeViewModel) SetCanRebase added in v0.35.0

func (self *CommitFileTreeViewModel) SetCanRebase(canRebase bool)

func (*CommitFileTreeViewModel) SetRef added in v0.35.0

func (self *CommitFileTreeViewModel) SetRef(ref types.Ref)

func (*CommitFileTreeViewModel) ToggleShowTree added in v0.35.0

func (self *CommitFileTreeViewModel) ToggleShowTree()

duplicated from file_tree_view_model.go. Generics will help here

type FileNode

type FileNode struct {
	*Node[models.File]
}

FileNode wraps a node and provides some file-specific methods for it.

func NewFileNode added in v0.36.0

func NewFileNode(node *Node[models.File]) *FileNode

func (*FileNode) GetHasInlineMergeConflicts

func (self *FileNode) GetHasInlineMergeConflicts() bool

func (*FileNode) GetHasStagedChanges

func (self *FileNode) GetHasStagedChanges() bool

func (*FileNode) GetHasUnstagedChanges

func (self *FileNode) GetHasUnstagedChanges() bool

func (*FileNode) GetIsFile added in v0.36.0

func (self *FileNode) GetIsFile() bool

func (*FileNode) GetIsTracked

func (self *FileNode) GetIsTracked() bool

func (*FileNode) GetPreviousPath added in v0.35.0

func (self *FileNode) GetPreviousPath() string

func (*FileNode) Raw added in v0.36.0

func (self *FileNode) Raw() *Node[models.File]

returns the underlying node, without any file-specific methods attached

type FileTree added in v0.35.0

type FileTree struct {
	// contains filtered or unexported fields
}

func NewFileTree added in v0.35.0

func NewFileTree(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTree

func (*FileTree) CollapsedPaths added in v0.35.0

func (self *FileTree) CollapsedPaths() *CollapsedPaths

func (*FileTree) ExpandToPath added in v0.35.0

func (self *FileTree) ExpandToPath(path string)

func (*FileTree) FilterFiles added in v0.35.0

func (self *FileTree) FilterFiles(test func(*models.File) bool) []*models.File

func (*FileTree) Get added in v0.35.0

func (self *FileTree) Get(index int) *FileNode

func (*FileTree) GetAllFiles added in v0.35.0

func (self *FileTree) GetAllFiles() []*models.File

func (*FileTree) GetAllItems added in v0.35.0

func (self *FileTree) GetAllItems() []*FileNode

note: this gets all items when the filter is taken into consideration. There may be hidden files that aren't included here. Files off the screen however will be included

func (*FileTree) GetFile added in v0.35.0

func (self *FileTree) GetFile(path string) *models.File

func (*FileTree) GetFilter added in v0.35.0

func (self *FileTree) GetFilter() FileTreeDisplayFilter

func (*FileTree) GetIndexForPath added in v0.35.0

func (self *FileTree) GetIndexForPath(path string) (int, bool)

func (*FileTree) GetRoot added in v0.36.0

func (self *FileTree) GetRoot() *FileNode

func (*FileTree) InTreeMode added in v0.35.0

func (self *FileTree) InTreeMode() bool

func (*FileTree) IsCollapsed added in v0.35.0

func (self *FileTree) IsCollapsed(path string) bool

func (*FileTree) Len added in v0.35.0

func (self *FileTree) Len() int

func (*FileTree) SetStatusFilter added in v0.39.0

func (self *FileTree) SetStatusFilter(filter FileTreeDisplayFilter)

func (*FileTree) SetTree added in v0.35.0

func (self *FileTree) SetTree()

func (*FileTree) ToggleCollapsed added in v0.35.0

func (self *FileTree) ToggleCollapsed(path string)

func (*FileTree) ToggleShowTree added in v0.35.0

func (self *FileTree) ToggleShowTree()

func (*FileTree) Tree added in v0.35.0

func (self *FileTree) Tree() *FileNode

type FileTreeDisplayFilter added in v0.35.0

type FileTreeDisplayFilter int
const (
	DisplayAll FileTreeDisplayFilter = iota
	DisplayStaged
	DisplayUnstaged
	// this shows files with merge conflicts
	DisplayConflicted
)

type FileTreeViewModel added in v0.35.0

type FileTreeViewModel struct {
	sync.RWMutex
	IFileTree
	types.IListCursor
}

This combines our FileTree struct with a cursor that retains information about which item is selected. It also contains logic for repositioning that cursor after the files are refreshed

func NewFileTreeViewModel added in v0.35.0

func NewFileTreeViewModel(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTreeViewModel

func (*FileTreeViewModel) GetSelected added in v0.35.0

func (self *FileTreeViewModel) GetSelected() *FileNode

func (*FileTreeViewModel) GetSelectedFile added in v0.35.0

func (self *FileTreeViewModel) GetSelectedFile() *models.File

func (*FileTreeViewModel) GetSelectedPath added in v0.35.0

func (self *FileTreeViewModel) GetSelectedPath() string

func (*FileTreeViewModel) SetStatusFilter added in v0.39.0

func (self *FileTreeViewModel) SetStatusFilter(filter FileTreeDisplayFilter)

func (*FileTreeViewModel) SetTree added in v0.35.0

func (self *FileTreeViewModel) SetTree()

func (*FileTreeViewModel) ToggleShowTree added in v0.35.0

func (self *FileTreeViewModel) ToggleShowTree()

If we're going from flat to tree we want to select the same file. If we're going from tree to flat and we have a file selected we want to select that. If instead we've selected a directory we need to select the first file in that directory.

type ICommitFileTree added in v0.35.0

type ICommitFileTree interface {
	ITree[models.CommitFile]

	Get(index int) *CommitFileNode
	GetFile(path string) *models.CommitFile
	GetAllItems() []*CommitFileNode
	GetAllFiles() []*models.CommitFile
	GetRoot() *CommitFileNode
}

type ICommitFileTreeViewModel added in v0.35.0

type ICommitFileTreeViewModel interface {
	ICommitFileTree
	types.IListCursor

	GetRef() types.Ref
	SetRef(types.Ref)
	GetCanRebase() bool
	SetCanRebase(bool)
}

type IFileTree added in v0.35.0

type IFileTree interface {
	ITree[models.File]

	FilterFiles(test func(*models.File) bool) []*models.File
	SetStatusFilter(filter FileTreeDisplayFilter)
	Get(index int) *FileNode
	GetFile(path string) *models.File
	GetAllItems() []*FileNode
	GetAllFiles() []*models.File
	GetFilter() FileTreeDisplayFilter
	GetRoot() *FileNode
}

type IFileTreeViewModel added in v0.35.0

type IFileTreeViewModel interface {
	IFileTree
	types.IListCursor
}

type ITree added in v0.35.0

type ITree[T any] interface {
	InTreeMode() bool
	ExpandToPath(path string)
	ToggleShowTree()
	GetIndexForPath(path string) (int, bool)
	Len() int
	SetTree()
	IsCollapsed(path string) bool
	ToggleCollapsed(path string)
	CollapsedPaths() *CollapsedPaths
}

type Node added in v0.36.0

type Node[T any] struct {
	// File will be nil if the node is a directory.
	File *T

	// If the node is a directory, Children contains the contents of the directory,
	// otherwise it's nil.
	Children []*Node[T]

	// path of the file/directory
	Path string

	// rather than render a tree as:
	// a/
	//   b/
	//     file.blah
	//
	// we instead render it as:
	// a/b/
	//	 file.blah
	// This saves vertical space. The CompressionLevel of a node is equal to the
	// number of times a 'compression' like the above has happened, where two
	// nodes are squished into one.
	CompressionLevel int
}

Represents a file or directory in a file tree.

func BuildFlatTreeFromCommitFiles

func BuildFlatTreeFromCommitFiles(files []*models.CommitFile) *Node[models.CommitFile]

func BuildFlatTreeFromFiles

func BuildFlatTreeFromFiles(files []*models.File) *Node[models.File]

func BuildTreeFromCommitFiles

func BuildTreeFromCommitFiles(files []*models.CommitFile) *Node[models.CommitFile]

func BuildTreeFromFiles

func BuildTreeFromFiles(files []*models.File) *Node[models.File]

func (*Node[T]) Compress added in v0.36.0

func (self *Node[T]) Compress()

func (*Node[T]) Description added in v0.36.0

func (self *Node[T]) Description() string

func (*Node[T]) Every added in v0.36.0

func (self *Node[T]) Every(test func(*Node[T]) bool) bool

func (*Node[T]) EveryFile added in v0.36.0

func (self *Node[T]) EveryFile(test func(*T) bool) bool

func (*Node[T]) Flatten added in v0.36.0

func (self *Node[T]) Flatten(collapsedPaths *CollapsedPaths) []*Node[T]

func (*Node[T]) ForEachFile added in v0.36.0

func (self *Node[T]) ForEachFile(cb func(*T) error) error

func (*Node[T]) GetFilePathsMatching added in v0.36.0

func (self *Node[T]) GetFilePathsMatching(test func(*T) bool) []string

func (*Node[T]) GetIndexForPath added in v0.36.0

func (self *Node[T]) GetIndexForPath(path string, collapsedPaths *CollapsedPaths) (int, bool)

func (*Node[T]) GetLeaves added in v0.36.0

func (self *Node[T]) GetLeaves() []*Node[T]

func (*Node[T]) GetNodeAtIndex added in v0.36.0

func (self *Node[T]) GetNodeAtIndex(index int, collapsedPaths *CollapsedPaths) *Node[T]

func (*Node[T]) GetPath added in v0.36.0

func (self *Node[T]) GetPath() string

func (*Node[T]) GetPathsMatching added in v0.36.0

func (self *Node[T]) GetPathsMatching(test func(*Node[T]) bool) []string

func (*Node[T]) ID added in v0.36.0

func (self *Node[T]) ID() string

func (*Node[T]) IsFile added in v0.36.0

func (self *Node[T]) IsFile() bool

func (*Node[T]) Size added in v0.36.0

func (self *Node[T]) Size(collapsedPaths *CollapsedPaths) int

func (*Node[T]) Some added in v0.36.0

func (self *Node[T]) Some(test func(*Node[T]) bool) bool

func (*Node[T]) SomeFile added in v0.36.0

func (self *Node[T]) SomeFile(test func(*T) bool) bool

func (*Node[T]) Sort added in v0.36.0

func (self *Node[T]) Sort()

func (*Node[T]) SortChildren added in v0.36.0

func (self *Node[T]) SortChildren()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL