Documentation
¶
Overview ¶
Package filetree provides a GUI tree interface to a filesystem.
Index ¶
- Variables
- func IsAppBundle(path string, isDir bool) bool
- func NodeNameCountSort(ecs []NodeNameCount)
- type CopyFS
- type DirFlagMap
- type FileChange
- type Filer
- type Node
- func (fn *Node) AddToVCS()
- func (fn *Node) AsFileNode() *Node
- func (t *Node) AsNode() *Node
- func (fn *Node) CanOpen() bool
- func (fn *Node) Cut()
- func (fn *Node) DeleteFile() error
- func (fn *Node) DeleteFiles()
- func (fn *Node) DeleteFilesNoPrompts()
- func (fn *Node) DragDrop(e events.Event)
- func (fn *Node) DragFiles() []string
- func (fn *Node) DropDeleteSource(e events.Event)
- func (fn *Node) FileExtensionCounts(cat fileinfo.Categories) []NodeNameCount
- func (fn *Node) FileRoot() *Tree
- func (fn *Node) FindFile(fnm string) (*Node, bool)
- func (fn *Node) FirstVCS() (vcs.Repo, *Node)
- func (fn *Node) GetFileInfo() error
- func (fn *Node) Init()
- func (fn *Node) InitFileInfo() error
- func (fn *Node) IsApp() bool
- func (fn *Node) IsDir() bool
- func (fn *Node) IsExec() bool
- func (fn *Node) IsIrregular() bool
- func (fn *Node) LatestFileMod(cat fileinfo.Categories) time.Time
- func (fn *Node) LogVCS(allFiles bool, since string) (vcs.Log, error)
- func (fn *Node) MimeData(md *mimedata.Mimes)
- func (fn *Node) OnClose()
- func (fn *Node) OnOpen()
- func (fn *Node) OpenFile() error
- func (fn *Node) OpenFileDefault() error
- func (fn *Node) OpenFilesDefault()
- func (fn *Node) Paste()
- func (fn *Node) RelativePath() string
- func (fn *Node) RelativePathFrom(fpath core.Filename) string
- func (fn *Node) RenameFile(newpath string) error
- func (fn *Node) RenameFiles()
- func (fn *Node) Repo() (vcs.Repo, *Node)
- func (fn *Node) SelectedFunc(fun func(n *Node))
- func (fn *Node) SelectedPaths() []string
- func (t *Node) SetFileIsOpen(v bool) *Node
- func (fn *Node) UpdateAllVCS()
- func (fn *Node) VCSContextMenu(m *core.Scene, pos image.Point)
- type NodeEmbedder
- type NodeNameCount
- type Tree
- func (ft *Tree) AddExternalFile(fpath string) (*Node, error)
- func (ft *Tree) AsFileTree() *Tree
- func (ft *Tree) Destroy()
- func (ft *Tree) Init()
- func (ft *Tree) OpenPath(path string) *Tree
- func (ft *Tree) OpenPathFS(fsys fs.FS, path string) *Tree
- func (ft *Tree) OpenPaths() []string
- func (t *Tree) SetAppsAsDirs(v bool) *Tree
- func (t *Tree) SetDirsOnTop(v bool) *Tree
- func (t *Tree) SetFS(v fs.FS) *Tree
- func (t *Tree) SetFSSort(v dirsort.Sort) *Tree
- func (t *Tree) SetFileNodeType(v *types.Type) *Tree
- func (t *Tree) SetFilterFunc(v func(path string, info fs.FileInfo) bool) *Tree
- func (t *Tree) SetNoWatch(v bool) *Tree
- func (t *Tree) SetWatchFunc(v func(changes []FileChange)) *Tree
- func (ft *Tree) UpdatePath(path string)
- type Treer
- type VCSLog
Constants ¶
This section is empty.
Variables ¶
var AppBundles = runtime.GOOS == "darwin"
AppBundles is whether directories named *.app are app bundles, which are shown and opened as apps (see Node.IsApp): on macOS, as in the Finder.
var NodeHighlighting = highlighting.StyleDefault
NodeHighlighting is the default style for syntax highlighting to use for file node buffers
Functions ¶
func IsAppBundle ¶
IsAppBundle returns whether the given path, which is a directory if isDir, is an app bundle: a directory named *.app, when AppBundles.
func NodeNameCountSort ¶
func NodeNameCountSort(ecs []NodeNameCount)
Types ¶
type CopyFS ¶
type CopyFS interface {
fs.FS
// CopyPath copies the file or directory at the source path to the
// destination path, replacing anything there.
CopyPath(dst, src string) error
}
CopyFS is an fs.FS that copies its own files and directories, as for those that are more than their bytes, such as typed data. Those of another FS are copied by reading and writing them (see Tree.FS).
type DirFlagMap ¶
type DirFlagMap struct {
// map of paths and associated flags
Map map[string]dirFlags
// mutex for accessing map
sync.Mutex
}
DirFlagMap is a map for encoding open directories. The strings are typically relative paths. Map access is protected by Mutex.
func (*DirFlagMap) Copy ¶ added in v0.5.7
func (dm *DirFlagMap) Copy(cp *DirFlagMap)
Copy copies flag map from another map, safely avoiding copying the mutex.
type FileChange ¶ added in v0.5.9
type FileChange struct {
// Path is the absolute path of the file or directory.
Path string
// Removed is true if the path no longer exists
// (it was deleted or renamed to another path).
Removed bool
// IsDir is true if the path is a directory. Files within a changed
// directory may have changed without being listed separately,
// for example when the watcher could not keep up with all events.
IsDir bool
}
FileChange is a change to a file or directory on disk, detected by the file system watcher of a Tree. See Tree.WatchFunc.
type Filer ¶
type Filer interface {
core.Treer
// AsFileNode returns the [Node]
AsFileNode() *Node
// RenameFiles renames any selected files.
RenameFiles()
// DeleteFiles deletes any selected files.
DeleteFiles()
// GetFileInfo updates the .Info for this file
GetFileInfo() error
// OpenFile opens the file for node. This is called by OpenFilesDefault
OpenFile() error
}
Filer is an interface for file tree file actions that all [Node]s satisfy. This allows apps to intervene and apply any additional logic for these actions.
type Node ¶
type Node struct {
core.Tree
// Filepath is the full path to this file.
Filepath core.Filename `edit:"-" set:"-" json:"-" xml:"-" copier:"-"`
// Info is the full standard file info about this file.
Info fileinfo.FileInfo `edit:"-" set:"-" json:"-" xml:"-" copier:"-"`
// FileIsOpen indicates that this file has been opened, indicated by Italics.
FileIsOpen bool
// DirRepo is the version control system repository for this directory,
// only non-nil if this is the highest-level directory in the tree under vcs control.
DirRepo vcs.Repo `edit:"-" set:"-" json:"-" xml:"-" copier:"-"`
}
Node represents a file in the file system, as a core.Tree node. The name of the node is the name of the file. Folders have children containing further nodes.
func AsNode ¶
AsNode returns the given value as a value of type Node if the type of the given value embeds Node, or nil otherwise
func NewNode ¶
NewNode returns a new Node with the given optional parent: Node represents a file in the file system, as a core.Tree node. The name of the node is the name of the file. Folders have children containing further nodes.
func (*Node) AsFileNode ¶ added in v0.2.1
func (*Node) Cut ¶
func (fn *Node) Cut()
Cut copies the selected files to the clipboard and then deletes them.
func (*Node) DeleteFiles ¶
func (fn *Node) DeleteFiles()
DeleteFiles deletes any selected files or directories. If any directory is selected, all files and subdirectories in that directory are also deleted.
func (*Node) DeleteFilesNoPrompts ¶ added in v0.3.11
func (fn *Node) DeleteFilesNoPrompts()
DeleteFilesNoPrompts does the actual deletion, no prompts. Errors are reported in a snackbar.
func (*Node) DragFiles ¶ added in v0.5.12
DragFiles returns the files of this node and the other selected nodes, for dragging them to other apps (see core.FileDragger), which are none for those of a Tree.FS.
func (*Node) DropDeleteSource ¶
DropDeleteSource is called after target accepts the drop -- we just remove elements that were moved satisfies core.DragNDropper interface and can be overridden by subtypes
func (*Node) FileExtensionCounts ¶ added in v0.2.3
func (fn *Node) FileExtensionCounts(cat fileinfo.Categories) []NodeNameCount
FileExtensionCounts returns a count of all the different file extensions, sorted from highest to lowest. If cat is != fileinfo.Unknown then it only uses files of that type (e.g., fileinfo.Code to find any code files)
func (*Node) FindFile ¶
FindFile finds first node representing given file (false if not found) -- looks for full path names that have the given string as their suffix, so you can include as much of the path (including whole thing) as is relevant to disambiguate. See FilesMatching for a list of files that match a given string.
func (*Node) FirstVCS ¶
FirstVCS returns the first VCS repository starting from this node and going down. also returns the node having that repository
func (*Node) GetFileInfo ¶ added in v0.3.3
GetFileInfo is a Filer interface method that can be overwritten to do custom file info.
func (*Node) IsApp ¶
IsApp returns whether the node is an app bundle (see IsAppBundle), unless the tree shows them as directories (Tree.AppsAsDirs): it has the icon of an app, and double-clicking opens it as an app, without opening it in the tree, which its arrow does, for its files.
func (*Node) IsIrregular ¶
IsIrregular returns true if file is a special "Irregular" node
func (*Node) LatestFileMod ¶
func (fn *Node) LatestFileMod(cat fileinfo.Categories) time.Time
LatestFileMod returns the most recent mod time of files in the tree. If cat is != fileinfo.Unknown then it only uses files of that type (e.g., fileinfo.Code to find any code files)
func (*Node) LogVCS ¶
LogVCS shows the VCS log of commits for this file, optionally with a since date qualifier: If since is non-empty, it should be a date-like expression that the VCS will understand, such as 1/1/2020, yesterday, last year, etc. SVN only understands a number as a maximum number of items to return. If allFiles is true, then the log will show revisions for all files, not just this one. Returns the Log and also shows it in a VCSLog which supports further actions.
func (*Node) MimeData ¶
MimeData adds mimedata for this node: three items, a text/plain of the tree path, text/plain of the file path, and the file contents (or a text/plain message for a directory or a file that is too big or can't be read).
func (*Node) OpenFileDefault ¶
OpenFileDefault opens file with default app for that file type (os defined) runs open on Mac, xdg-open on Linux, and start on Windows
func (*Node) OpenFilesDefault ¶
func (fn *Node) OpenFilesDefault()
OpenFilesDefault opens selected files with default app for that file type (os defined). runs open on Mac, xdg-open on Linux, and start on Windows
func (*Node) Paste ¶
func (fn *Node) Paste()
Paste copies the files on the clipboard, from [Node.Copy] or as absolute paths in text, into this directory, or the directory of this file.
func (*Node) RelativePath ¶ added in v0.2.3
RelativePath returns the relative path from root for this node
func (*Node) RelativePathFrom ¶ added in v0.2.3
RelativePathFrom returns the relative path from node for given full path
func (*Node) RenameFile ¶
RenameFile renames file to new name
func (*Node) Repo ¶
Repo returns the version control repository associated with this file, and the node for the directory where the repo is based. Goes up the tree until a repository is found.
func (*Node) SelectedFunc ¶ added in v0.2.0
SelectedFunc runs the given function on all selected nodes in reverse order.
func (*Node) SelectedPaths ¶ added in v0.3.11
SelectedPaths returns the paths of selected nodes.
func (*Node) SetFileIsOpen ¶ added in v0.3.11
SetFileIsOpen sets the Node.FileIsOpen: FileIsOpen indicates that this file has been opened, indicated by Italics.
func (*Node) UpdateAllVCS ¶
func (fn *Node) UpdateAllVCS()
UpdateAllVCS does an update on any repositories below this one in file tree
type NodeEmbedder ¶
type NodeEmbedder interface {
AsNode() *Node
}
NodeEmbedder is an interface that all types that embed Node satisfy
type NodeNameCount ¶
NodeNameCount is used to report counts of different string-based things in the file tree
type Tree ¶
type Tree struct {
Node
// Dirs records state of directories within the tree (encoded using paths relative to root),
// e.g., open (have been opened by the user) -- can persist this to restore prior view of a tree
Dirs DirFlagMap `set:"-"`
// DirsOnTop indicates whether all directories are placed at the top of the tree.
// Otherwise everything is mixed. This is the default.
DirsOnTop bool
// FileNodeType is the type of node to create; defaults to [Node] but can use custom node types
FileNodeType *types.Type `display:"-" json:"-" xml:"-"`
// FilterFunc, if set, determines whether to include the given node in the tree.
// return true to include, false to not. This applies to files and directories alike.
FilterFunc func(path string, info fs.FileInfo) bool
// AppsAsDirs shows app bundles as directories, which open by clicking,
// instead of as apps, which open as apps by double-clicking
// (see [Node.IsApp]).
AppsAsDirs bool
// FS is the file system we are browsing, if it is an FS (nil = os filesystem).
// Its files can be changed, as those of the os, with the operations
// that it has, with the interfaces of hackpadfs (see [CopyFS]),
// and otherwise it is read-only.
FS fs.FS
// FSSort is the sort order of the directories of the [Tree.FS], other
// than those set with Sort by, which is by name by default. That of
// the directories of the os is shared by all apps (see [dirsort.For]).
FSSort dirsort.Sort
// NoWatch disables the file system watcher, which otherwise updates
// the tree when files change on disk. It must be set before [Tree.OpenPath].
NoWatch bool
// WatchFunc, if set, is called with each batch of changes detected by
// the file system watcher, after the tree has been updated for them.
// It is called under [core.WidgetBase.AsyncLock], so it can update the GUI
// directly. Only the files directly within the root and the open
// directories of the tree are watched, excluding hidden directories.
WatchFunc func(changes []FileChange) `display:"-" json:"-" xml:"-"`
// contains filtered or unexported fields
}
Tree is the root widget of a file tree representing files in a given directory (and subdirectories thereof), and has some overall management state for how to view things.
func AsTree ¶ added in v0.3.8
AsTree returns the given value as a Tree if it has an AsFileTree() method, or nil otherwise.
func NewTree ¶
NewTree returns a new Tree with the given optional parent: Tree is the root widget of a file tree representing files in a given directory (and subdirectories thereof), and has some overall management state for how to view things.
func (*Tree) AddExternalFile ¶ added in v0.2.0
AddExternalFile adds an external file outside of root of file tree and triggers an update, returning the Node for it, or error if filepath.Abs fails.
func (*Tree) AsFileTree ¶ added in v0.3.8
func (*Tree) OpenPath ¶
OpenPath opens the filetree at the given os file system directory path. It reads all the files at the given path into this tree. Only paths listed in Tree.Dirs will be opened.
func (*Tree) OpenPathFS ¶ added in v0.3.3
OpenPathFS opens the filetree at the given fs file system directory path. It reads all the files at the given path into this tree. Only paths listed in Tree.Dirs will be opened.
func (*Tree) SetAppsAsDirs ¶
SetAppsAsDirs sets the Tree.AppsAsDirs: AppsAsDirs shows app bundles as directories, which open by clicking, instead of as apps, which open as apps by double-clicking (see Node.IsApp).
func (*Tree) SetDirsOnTop ¶
SetDirsOnTop sets the Tree.DirsOnTop: DirsOnTop indicates whether all directories are placed at the top of the tree. Otherwise everything is mixed. This is the default.
func (*Tree) SetFS ¶ added in v0.3.8
SetFS sets the Tree.FS: FS is the file system we are browsing, if it is an FS (nil = os filesystem). Its files can be changed, as those of the os, with the operations that it has, with the interfaces of hackpadfs (see CopyFS), and otherwise it is read-only.
func (*Tree) SetFSSort ¶
SetFSSort sets the Tree.FSSort: FSSort is the sort order of the directories of the Tree.FS, other than those set with Sort by, which is by name by default. That of the directories of the os is shared by all apps (see dirsort.For).
func (*Tree) SetFileNodeType ¶ added in v0.0.10
SetFileNodeType sets the Tree.FileNodeType: FileNodeType is the type of node to create; defaults to Node but can use custom node types
func (*Tree) SetFilterFunc ¶ added in v0.3.8
SetFilterFunc sets the Tree.FilterFunc: FilterFunc, if set, determines whether to include the given node in the tree. return true to include, false to not. This applies to files and directories alike.
func (*Tree) SetNoWatch ¶ added in v0.5.9
SetNoWatch sets the Tree.NoWatch: NoWatch disables the file system watcher, which otherwise updates the tree when files change on disk. It must be set before Tree.OpenPath.
func (*Tree) SetWatchFunc ¶ added in v0.5.9
func (t *Tree) SetWatchFunc(v func(changes []FileChange)) *Tree
SetWatchFunc sets the Tree.WatchFunc: WatchFunc, if set, is called with each batch of changes detected by the file system watcher, after the tree has been updated for them. It is called under core.WidgetBase.AsyncLock, so it can update the GUI directly. Only the files directly within the root and the open directories of the tree are watched, excluding hidden directories.
func (*Tree) UpdatePath ¶
UpdatePath updates the tree at the directory level for given path and everything below it. It flags that it needs render update, but if a deletion or insertion happened, then NeedsLayout should also be called.
type Treer ¶ added in v0.3.8
type Treer interface {
AsFileTree() *Tree
}
Treer is an interface for getting the Root node if it implements Treer.
type VCSLog ¶ added in v0.2.0
type VCSLog struct {
core.Frame
// current log
Log vcs.Log
// file that this is a log of -- if blank then it is entire repository
File string
// date expression for how long ago to include log entries from
Since string
// version control system repository
Repo vcs.Repo `json:"-" xml:"-" copier:"-"`
// contains filtered or unexported fields
}
VCSLog is a widget that represents VCS log data.
func NewVCSLog ¶ added in v0.2.0
NewVCSLog returns a new VCSLog with the given optional parent: VCSLog is a widget that represents VCS log data.
func (*VCSLog) SetFile ¶ added in v0.2.0
SetFile sets the VCSLog.File: file that this is a log of -- if blank then it is entire repository
func (*VCSLog) SetLog ¶ added in v0.2.0
SetLog sets the VCSLog.Log: current log
func (*VCSLog) SetRepo ¶ added in v0.2.0
SetRepo sets the VCSLog.Repo: version control system repository