filepicker

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 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

Overview

Package filepicker is a modal file and folder picker, or a browser for copying paths, over a file system the app lists, possibly on another machine: places and disks in a sidebar, the browsed folder's entries in an icon or list view, and the folder's address, shown as breadcrumbs and typed into on request. The app loads folders and supplies every label, icon and place, and decides what may be chosen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Size

func Size(n int64) string

Size is n bytes in decimal units.

Types

type Crumb

type Crumb struct{ Name, Path string }

Crumb is a folder of the address's breadcrumbs.

type Dialog

type Dialog struct {
	State  *State
	Open   func() bool
	OnOpen func(open bool)
	// OnClose follows the dialog being gone, once its motion ended.
	OnClose func()
	Labels  Labels
	// Device names the machine browsed, leading the breadcrumbs.
	Device string
	// Hint is a sentence beside the dialog's buttons, such as what the
	// chosen folder is for.
	Hint     string
	Sections []Section
	// SectionsFunc, when set, gives Sections as they change, which keeps
	// the dialog as they load.
	SectionsFunc func() []Section
	// Files lets files be chosen. Otherwise only folders are: Choose takes
	// the selected folder, or the one shown, and files show dimmed.
	Files bool
	// Icon draws an entry's icon at size; nil draws a folder or file icon.
	Icon func(cx *core.Scope, e Entry, size core.Points) core.Node
	// FormatTime and FormatSize format an entry's details; nil uses a
	// numeric date and decimal units.
	FormatTime func(time.Time) string
	FormatSize func(int64) string
	// Choose receives the chosen path; the dialog closes first. Without it
	// the dialog only browses: its header closes it, it has no buttons and
	// no entry shows dimmed.
	Choose func(path string)
	TestID string
}

Dialog shows the picker in a modal dialog while Open. Choosing closes it and calls Choose. With CopyPath labeled, Command-C (Control-C elsewhere) copies the selected entry's path, or the folder's.

func (Dialog) Render

func (p Dialog) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Entry

type Entry struct {
	Name, Path string
	Dir        bool
	Size       int64
	Modified   time.Time
	// Hidden marks an entry the system hides, shown only on request.
	Hidden bool
	// Data is the app's own value for the entry, for its Icon.
	Data any
}

Entry is a file or folder of a listed folder.

type Folder

type Folder struct {
	Path, Parent string
	Trail        []Crumb
	Entries      []Entry
}

Folder is a listed folder. Parent is empty at a root; Trail leads from the root to the folder itself, and without it the address shows the path.

type Labels

type Labels struct {
	Title, Address        string
	Icons, List, Hidden   string
	Name, Modified, Size  string
	Empty, Cancel, Choose string
	Close, CopyPath       string
}

Labels are the picker's texts. Title and Address name the dialog and the address field. Close names a browser's close button; CopyPath, when set, is the menu item copying an entry's or the folder's path.

type Place

type Place struct {
	Name, Path string
	Icon       func() *core.SVG
}

Place is a folder the sidebar opens.

type Section

type Section struct {
	Label  string
	Places []Place
}

Section is a headed group of the sidebar's places.

type State

type State struct {
	// Load lists path, the app's starting folder when empty, and calls done
	// with the result on the engine.
	Load func(path string, done func(Folder, error))
	// contains filtered or unexported fields
}

State keeps a picker's folder, selection and view. Make it with NewState.

func NewState

func NewState(cx *core.Scope, view ViewMode, hidden bool, width core.Points) *State

NewState makes a picker's state, showing view with hidden entries as shown and a sidebar width wide, its default when not positive.

func (*State) Open

func (s *State) Open(path string)

Open lists path, the starting folder when empty.

func (*State) ShowHidden

func (s *State) ShowHidden() bool

func (*State) SidebarWidth

func (s *State) SidebarWidth() core.Points

func (*State) View

func (s *State) View() ViewMode

View, ShowHidden and SidebarWidth are what the app keeps of the picker.

type ViewMode

type ViewMode int

ViewMode is how a folder's entries are shown.

const (
	// Icons shows entries as a grid of large icons with their names.
	Icons ViewMode = iota
	// List shows entries as rows with their modification time and size.
	List
)

Jump to

Keyboard shortcuts

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