filetree

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: BSD-3-Clause Imports: 40 Imported by: 2

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
	// contains filtered or unexported fields
}

DirFlagMap is a map for encoding directories that are open in the file tree. The strings are typically relative paths. The bool value is used to mark active paths and inactive (unmarked) ones can be removed. 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()

	// 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.

type FindLocation added in v0.2.3

type FindLocation int32 //enums:enum -trim-prefix FindLocation

FindLocation corresponds to the search scope

const (
	// FindOpen finds in all open folders in the left file browser
	FindLocationOpen FindLocation = iota

	// FindLocationAll finds in all directories under the root path. can be slow for large file trees
	FindLocationAll

	// FindLocationFile only finds in the current active file
	FindLocationFile

	// FindLocationDir only finds in the directory of the current active file
	FindLocationDir

	// FindLocationNotTop finds in all open folders *except* the top-level folder
	FindLocationNotTop
)
const FindLocationN FindLocation = 5

FindLocationN is the highest valid value for type FindLocation, plus one.

func FindLocationValues added in v0.2.3

func FindLocationValues() []FindLocation

FindLocationValues returns all possible values for the type FindLocation.

func (FindLocation) Desc added in v0.2.3

func (i FindLocation) Desc() string

Desc returns the description of the FindLocation value.

func (FindLocation) Int64 added in v0.2.3

func (i FindLocation) Int64() int64

Int64 returns the FindLocation value as an int64.

func (FindLocation) MarshalText added in v0.2.3

func (i FindLocation) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*FindLocation) SetInt64 added in v0.2.3

func (i *FindLocation) SetInt64(in int64)

SetInt64 sets the FindLocation value from an int64.

func (*FindLocation) SetString added in v0.2.3

func (i *FindLocation) SetString(s string) error

SetString sets the FindLocation value from its string representation, and returns an error if the string is invalid.

func (FindLocation) String added in v0.2.3

func (i FindLocation) String() string

String returns the string representation of this FindLocation value.

func (*FindLocation) UnmarshalText added in v0.2.3

func (i *FindLocation) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (FindLocation) Values added in v0.2.3

func (i FindLocation) Values() []enums.Enum

Values returns all possible values for the type FindLocation.

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:"-"`

	// Buffer is the file buffer for editing this file.
	Buffer *texteditor.Buffer `edit:"-" set:"-" json:"-" xml:"-" copier:"-"`

	// FileRoot is the root [Tree] of the tree, which has global state.
	FileRoot *Tree `edit:"-" set:"-" json:"-" xml:"-" copier:"-"`

	// 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:"-"`
	// contains filtered or unexported fields
}

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 added in v0.2.1

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

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 added in v0.3.3

func (fn *Node) GetFileInfo() error

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

func (*Node) Init added in v0.2.0

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

func (fn *Node) IsNotSaved() bool

IsNotSaved returns true if the file is open and has been changed (edited) since last Save

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

func (fn *Node) OpenBuf() (bool, error)

OpenBuf opens the file in its buffer if it is not already open. returns true if file is newly opened

func (*Node) OpenFile added in v0.3.3

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 added in v0.2.3

func (fn *Node) RelativePath() string

RelativePath returns the relative path from root for this node

func (*Node) RelativePathFrom added in v0.2.3

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 added in v0.2.0

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

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

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 SearchResults added in v0.2.0

type SearchResults struct {
	Node    *Node
	Count   int
	Matches []text.Match
}

SearchResults is used to report search results

func Search(start *Node, find string, ignoreCase, regExp bool, loc FindLocation, activeDir string, langs []fileinfo.Known, openPath func(path string) *Node) []SearchResults

Search returns list of all nodes starting at given node of given language(s) that contain the given string, sorted in descending order by number of occurrences; ignoreCase transforms everything into lowercase

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 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 added in v0.2.0

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

func (fv *Tree) Destroy()

func (*Tree) Init added in v0.2.0

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 added in v0.3.3

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

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

SetDirsOnTop sets the [Tree.DirsOnTop]: if true, then all directories are placed at the top of the tree. Otherwise everything is mixed.

func (*Tree) SetFileNodeType added in v0.0.10

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

SetFileNodeType sets the [Tree.FileNodeType]: type of node to create; defaults to Node but can use custom node types

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

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 added in v0.2.0

func (lv *VCSLog) Init()

func (*VCSLog) SetFile added in v0.2.0

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 added in v0.2.0

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

SetLog sets the [VCSLog.Log]: current log

func (*VCSLog) SetRepo added in v0.2.0

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

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

func (*VCSLog) SetSince added in v0.2.0

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