filetree

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: BSD-3-Clause Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NodeHighlighting = highlighting.StyleDefault

NodeHighlighting is the default style for syntax highlighting to use for file node buffers

Functions

func NodeNameCountSort

func NodeNameCountSort(ecs []NodeNameCount)

Types

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 and sorting preferences. The strings are typically relative paths. Map access is protected by Mutex.

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

func AsNode(n tree.Node) *Node

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

func NewNode(parent ...tree.Node) *Node

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) AddToVCS

func (fn *Node) AddToVCS()

AddToVCS adds file to version control

func (*Node) AsFileNode

func (fn *Node) AsFileNode() *Node

func (*Node) AsNode

func (t *Node) AsNode() *Node

AsNode satisfies the NodeEmbedder interface

func (*Node) CanOpen

func (fn *Node) CanOpen() bool

func (*Node) Cut

func (fn *Node) Cut()

Cut copies the selected files to the clipboard and then deletes them.

func (*Node) DeleteFile

func (fn *Node) DeleteFile() error

DeleteFile deletes this file

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

func (fn *Node) DeleteFilesNoPrompts()

DeleteFilesNoPrompts does the actual deletion, no prompts.

func (*Node) DragDrop

func (fn *Node) DragDrop(e events.Event)

func (*Node) DropDeleteSource

func (fn *Node) DropDeleteSource(e events.Event)

Dragged 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

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) FileRoot

func (fn *Node) FileRoot() *Tree

FileRoot returns the Root node as a Tree.

func (*Node) FindFile

func (fn *Node) FindFile(fnm string) (*Node, bool)

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

func (fn *Node) FirstVCS() (vcs.Repo, *Node)

FirstVCS returns the first VCS repository starting from this node and going down. also returns the node having that repository

func (*Node) GetFileInfo

func (fn *Node) GetFileInfo() error

GetFileInfo is a Filer interface method that can be overwritten to do custom file info.

func (*Node) Init

func (fn *Node) Init()

func (*Node) InitFileInfo

func (fn *Node) InitFileInfo() error

InitFileInfo initializes file info

func (*Node) IsDir

func (fn *Node) IsDir() bool

IsDir returns true if file is a directory (folder)

func (*Node) IsExec

func (fn *Node) IsExec() bool

IsExec returns true if file is an executable file

func (*Node) IsIrregular

func (fn *Node) IsIrregular() bool

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

func (fn *Node) LogVCS(allFiles bool, since string) (vcs.Log, error)

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

func (fn *Node) MimeData(md *mimedata.Mimes)

MimeData adds mimedata for this node: a text/plain of the Path, text/plain of filename, and text/

func (*Node) OnClose

func (fn *Node) OnClose()

func (*Node) OnOpen

func (fn *Node) OnOpen()

func (*Node) OpenFile

func (fn *Node) OpenFile() error

OpenFile just does OpenFileDefault

func (*Node) OpenFileDefault

func (fn *Node) OpenFileDefault() error

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 inserts files from the clipboard.

func (*Node) RelativePath

func (fn *Node) RelativePath() string

RelativePath returns the relative path from root for this node

func (*Node) RelativePathFrom

func (fn *Node) RelativePathFrom(fpath core.Filename) string

RelativePathFrom returns the relative path from node for given full path

func (*Node) RenameFile

func (fn *Node) RenameFile(newpath string) error

RenameFile renames file to new name

func (*Node) RenameFiles

func (fn *Node) RenameFiles()

renames any selected files

func (*Node) Repo

func (fn *Node) Repo() (vcs.Repo, *Node)

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

func (fn *Node) SelectedFunc(fun func(n *Node))

SelectedFunc runs the given function on all selected nodes in reverse order.

func (*Node) SelectedPaths

func (fn *Node) SelectedPaths() []string

SelectedPaths returns the paths of selected nodes.

func (*Node) SetFileIsOpen

func (t *Node) SetFileIsOpen(v bool) *Node

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

func (*Node) VCSContextMenu

func (fn *Node) VCSContextMenu(m *core.Scene)

type NodeEmbedder

type NodeEmbedder interface {
	AsNode() *Node
}

NodeEmbedder is an interface that all types that embed Node satisfy

type NodeNameCount

type NodeNameCount struct {
	Name  string
	Count int
}

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

	// SortByModTime causes files to be sorted by modification time by default.
	// Otherwise it is a per-directory option.
	SortByModTime 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

	// FS is the file system we are browsing, if it is an FS (nil = os filesystem)
	FS fs.FS
	// 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

func AsTree(n tree.Node) *Tree

AsTree returns the given value as a Tree if it has an AsFileTree() method, or nil otherwise.

func NewTree

func NewTree(parent ...tree.Node) *Tree

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

func (ft *Tree) AddExternalFile(fpath string) (*Node, error)

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

func (ft *Tree) AsFileTree() *Tree

func (*Tree) Destroy

func (fv *Tree) Destroy()

func (*Tree) Init

func (ft *Tree) Init()

func (*Tree) OpenPath

func (ft *Tree) OpenPath(path string) *Tree

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

func (ft *Tree) OpenPathFS(fsys fs.FS, path string) *Tree

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) OpenPaths

func (ft *Tree) OpenPaths() []string

OpenPaths returns a list of open paths.

func (*Tree) SetDirsOnTop

func (t *Tree) SetDirsOnTop(v bool) *Tree

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

func (t *Tree) SetFS(v fs.FS) *Tree

SetFS sets the [Tree.FS]: FS is the file system we are browsing, if it is an FS (nil = os filesystem)

func (*Tree) SetFileNodeType

func (t *Tree) SetFileNodeType(v *types.Type) *Tree

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

func (t *Tree) SetFilterFunc(v func(path string, info fs.FileInfo) bool) *Tree

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) SetSortByModTime

func (t *Tree) SetSortByModTime(v bool) *Tree

SetSortByModTime sets the [Tree.SortByModTime]: SortByModTime causes files to be sorted by modification time by default. Otherwise it is a per-directory option.

func (*Tree) UpdatePath

func (ft *Tree) UpdatePath(path string)

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

type Treer interface {
	AsFileTree() *Tree
}

Treer is an interface for getting the Root node if it implements Treer.

type VCSLog

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

func NewVCSLog(parent ...tree.Node) *VCSLog

NewVCSLog returns a new VCSLog with the given optional parent: VCSLog is a widget that represents VCS log data.

func (*VCSLog) Init

func (lv *VCSLog) Init()

func (*VCSLog) SetFile

func (t *VCSLog) SetFile(v string) *VCSLog

SetFile sets the [VCSLog.File]: file that this is a log of -- if blank then it is entire repository

func (*VCSLog) SetLog

func (t *VCSLog) SetLog(v vcs.Log) *VCSLog

SetLog sets the [VCSLog.Log]: current log

func (*VCSLog) SetRepo

func (t *VCSLog) SetRepo(v vcs.Repo) *VCSLog

SetRepo sets the [VCSLog.Repo]: version control system repository

func (*VCSLog) SetSince

func (t *VCSLog) SetSince(v string) *VCSLog

SetSince sets the [VCSLog.Since]: date expression for how long ago to include log entries from

Jump to

Keyboard shortcuts

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