explorer

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 43 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// For DnD use.
	EntryMIME = "gioview/file-entry"
)

Variables

View Source
var (
	// Icons used in file tree.
	FolderIcon, _     = widget.NewIcon(icons.FileFolder)
	FolderOpenIcon, _ = widget.NewIcon(icons.FileFolderOpen)
	FileIcon, _       = widget.NewIcon(icons.ActionDescription)
	// File tree icon size
	IconSize = unit.Dp(14)
)
View Source
var (
	// DuplicatedEntryErr is returned by UpdateName when the target name already exists.
	// AddChild, Copy, and Move auto-resolve name conflicts instead of returning this error.
	DuplicatedEntryErr = errors.New("duplicated file/folder name")
)

Functions

func EncodeClipboardData added in v0.8.1

func EncodeClipboardData(src *EntryNavItem, data string, isCut bool) io.Reader

Types

type C

type C = layout.Context

type ClipboardData added in v0.8.1

type ClipboardData struct {
	IsCut bool    `json:"isCut"`
	Data  string  `json:"data"`
	Src   uintptr `json:"src"`
}

ClipboardData is exported to enable in-app copy&paste.

func ParseClipboardData added in v0.8.1

func ParseClipboardData(buf []byte) (*ClipboardData, error)

func (*ClipboardData) GetSrc added in v0.8.1

func (p *ClipboardData) GetSrc() *EntryNavItem

type D

type D = layout.Dimensions

type EntryFilter

type EntryFilter func(info fs.FileInfo) bool

A filter is used to decide which files/folders are retained when buiding a EntryNode's children. Returning false will remove the current entry from from the children.

func AggregatedFilters

func AggregatedFilters(filters ...EntryFilter) EntryFilter

type EntryNavItem

type EntryNavItem struct {

	// Used to set context menu options.
	MenuOptionFunc MenuOptionFunc
	// Used to set what to be done when a item is clicked.
	OnSelectFunc OnSelectFunc
	// Used to decide whether the DnD drop can continue.
	OnDropConfirmFunc OnDropConfirmFunc
	// contains filtered or unexported fields
}

EntryNavItem is a navigable file node. When used with navi.NavTree, it renders a file tree, and an optional context menu. Supported features:

  1. in-place edit/rename, press ESC to escape editing.
  2. context menu.
  3. Shortcuts: ctlr/cmd+c, ctrl/cmd+v, ctrl/cmd+p.
  4. copy from external file/folder.
  5. Delete files/folders by moving them to trash bin.
  6. Drag & Drop support. External components can also subscribe the transfer events by using transfer.TargetFilter with the EntryMIME type.
  7. Restore states from states data.

func NewEntryNavItem

func NewEntryNavItem(rootDir string) (*EntryNavItem, error)

Construct a file tree object that loads files and folders from rootDir.

func (*EntryNavItem) Children

func (eitem *EntryNavItem) Children() ([]navi.NavItem, bool)

func (*EntryNavItem) Close added in v0.8.0

func (eitem *EntryNavItem) Close() error

func (*EntryNavItem) ContextMenuOptions

func (eitem *EntryNavItem) ContextMenuOptions(gtx C) ([][]menu.MenuOption, bool)

func (*EntryNavItem) CreateChild

func (eitem *EntryNavItem) CreateChild(gtx C, kind NodeKind, postAction func(node *EntryNode)) error

Create file or subfolder under the current folder. File or subfolder is inserted at the beginning of the children.

func (*EntryNavItem) Expanded added in v0.8.0

func (eitem *EntryNavItem) Expanded() bool

func (*EntryNavItem) IsDir

func (eitem *EntryNavItem) IsDir() bool

func (*EntryNavItem) Kind

func (eitem *EntryNavItem) Kind() NodeKind

EntryNode kind of this node

func (*EntryNavItem) Layout

func (eitem *EntryNavItem) Layout(gtx layout.Context, th *theme.Theme, textColor color.NRGBA) D

func (*EntryNavItem) Name

func (eitem *EntryNavItem) Name() string

File or folder name of this node

func (*EntryNavItem) OnCopyOrCut

func (eitem *EntryNavItem) OnCopyOrCut(gtx C, isCut bool)

func (*EntryNavItem) OnPaste

func (eitem *EntryNavItem) OnPaste(data string, removeOld bool, src *EntryNavItem) error

Move file to the current dir or the dir of the current file. Set removeOld to false to simulate a copy OP.

func (*EntryNavItem) OnSelect

func (eitem *EntryNavItem) OnSelect()

func (*EntryNavItem) Parent added in v0.7.1

func (eitem *EntryNavItem) Parent() *EntryNavItem

func (*EntryNavItem) Path

func (eitem *EntryNavItem) Path() string

File or folder path of this node

func (*EntryNavItem) Read added in v0.8.0

func (eitem *EntryNavItem) Read(p []byte) (n int, err error)

Implelments io.ReadCloser for widget.Draggable.

func (*EntryNavItem) Refresh

func (eitem *EntryNavItem) Refresh()

func (*EntryNavItem) Remove

func (eitem *EntryNavItem) Remove() error

func (*EntryNavItem) Restore added in v0.8.0

func (eitem *EntryNavItem) Restore(state *TreeState)

Restore restores the tree states by applying state to the current node and its children.

func (*EntryNavItem) SetExpanded added in v0.8.0

func (eitem *EntryNavItem) SetExpanded(expanded bool)

func (*EntryNavItem) SetMenuOptions

func (eitem *EntryNavItem) SetMenuOptions(menuOptionFunc MenuOptionFunc)

func (*EntryNavItem) Snapshot added in v0.8.0

func (eitem *EntryNavItem) Snapshot() *TreeState

Snapshot saves states of the expanded EntryNavItem node, and the states of its children.

func (*EntryNavItem) StartEditing

func (eitem *EntryNavItem) StartEditing(gtx C)

StartEditing inits and focused on the editor to accept user input.

func (*EntryNavItem) Update

func (eitem *EntryNavItem) Update(gtx C) error

type EntryNode

type EntryNode struct {
	Path string
	fs.FileInfo
	// parent must be of folder kind.
	Parent *EntryNode
	// contains filtered or unexported fields
}

func NewFileTree

func NewFileTree(rootDir string) (*EntryNode, error)

Create a new file tree with a relative or absolute rootDir. A filter is used to decide which files/folders are retained.

func (*EntryNode) AddChild

func (n *EntryNode) AddChild(name string, kind NodeKind) error

Add new file or folder.

func (*EntryNode) Children

func (n *EntryNode) Children() []*EntryNode

func (*EntryNode) Copy

func (n *EntryNode) Copy(nodePath string) error

Copy copies the file at nodePath to the current folder. If an entry with the same name already exists, a unique name is generated (e.g., "file-copy.txt", "file-copy-2.txt") to avoid conflicts.

func (*EntryNode) Delete

func (n *EntryNode) Delete() error

Delete removes the current file/folders to the system Trash bin.

func (*EntryNode) FileType

func (n *EntryNode) FileType() string

what type of the file, e.g, pdf, png。 This is for file nodes only

func (*EntryNode) Kind

func (n *EntryNode) Kind() NodeKind

func (*EntryNode) Move

func (n *EntryNode) Move(nodePath string) error

Move moves the file at nodePath to the current folder. If an entry with the same name already exists, a unique name is generated (e.g., "file-copy.txt", "file-copy-2.txt") to avoid conflicts.

func (*EntryNode) Print

func (n *EntryNode) Print()

Print the entire tree in console.

func (*EntryNode) Refresh

func (n *EntryNode) Refresh(filterFunc EntryFilter) error

Refresh reload child entries of the current entry node

func (*EntryNode) UpdateName

func (n *EntryNode) UpdateName(newName string) error

Update set a new name for the current file/folder.

type FileChooser

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

func NewFileChooser

func NewFileChooser(vm view.ViewManager) (*FileChooser, error)

func (*FileChooser) ChooseFile

func (fc *FileChooser) ChooseFile(extensions ...string) (io.ReadCloser, error)

ChooseFile shows the file chooser, allowing the user to select a single file. It returns the file as a reader to user.

This is a blocking call, you should call it in a seperated goroutine.

Optionally, it's possible to set which file extensions is supported to be selected (such as `.jpg`, `.png`).

func (*FileChooser) ChooseFiles

func (fc *FileChooser) ChooseFiles(extensions ...string) ([]io.ReadCloser, error)

ChooseFile shows the file chooser, allowing the user to select multiple files. It returns the files as a list of reader to user. This is a blocking call, you should call it in a seperated goroutine.

Optionally, it's possible to set which file extensions is supported to be selected (such as `.jpg`, `.png`).

func (*FileChooser) ChooseFolder

func (fc *FileChooser) ChooseFolder() (string, error)

ChooseFolder shows the file chooser, allowing the user to select a single folder. It returns the folder path to user. This is a blocking call, you should call it in a seperated goroutine.

func (*FileChooser) CreateFile

func (fc *FileChooser) CreateFile(name string) (io.WriteCloser, error)

CreateFile opens the file chooser, and writes the given content into some file, which the use can choose the location. It's important to close the `io.WriteCloser`.

It's a blocking call, you should call it on a separated goroutine.

type FileChooserDialog

type FileChooserDialog struct {
	*view.BaseView
	// contains filtered or unexported fields
}

func (*FileChooserDialog) ID

func (d *FileChooserDialog) ID() view.ViewID

func (*FileChooserDialog) Layout

func (*FileChooserDialog) OnNavTo

func (vw *FileChooserDialog) OnNavTo(intent view.Intent) error

func (*FileChooserDialog) Title

func (vw *FileChooserDialog) Title() string

type FileExplorer

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

func (*FileExplorer) Layout

func (exp *FileExplorer) Layout(gtx C, th *theme.Theme) D

func (*FileExplorer) Update

func (exp *FileExplorer) Update(gtx C)
type MenuOptionFunc func(gtx C, item *EntryNavItem) [][]menu.MenuOption

func DefaultFileMenuOptions

func DefaultFileMenuOptions(vm view.ViewManager) MenuOptionFunc

Default operation for file tree nodes. Support file/folder copy, cut, paste, rename, delete and new file/folder creation. This should better be used as an example. Feel free to copy and build your own.

type NodeKind

type NodeKind uint8
const (
	FileNode NodeKind = iota
	FolderNode
)

type OnDropConfirmFunc added in v0.8.0

type OnDropConfirmFunc func(srcPath string, dest *EntryNode, onConfirmed func())

type OnSelectFunc

type OnSelectFunc func(item *EntryNode)

type TreeState added in v0.8.0

type TreeState struct {
	Path     string
	Expanded bool
	Children []*TreeState
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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