filechooser

package
v0.3.20 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 65 Imported by: 1 module, 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 filechooser is the shell's dev.stubbe.lys.FileChooser1 host (lys-shell services/file_chooser and shell/file_chooser): the file dialog behind the portal backend's FileChooser.

Index

Constants

View Source
const (
	ServiceName = "dev.stubbe.lys.FileChooser1"
	ServicePath = dbus.ObjectPath("/dev/stubbe/lys/FileChooser")
)

D-Bus identity (wayle-ipc file_chooser.rs).

View Source
const (
	RuleGlob uint32 = 0
	RuleMIME uint32 = 1
)

Rule kinds of a Filter.

Variables

This section is empty.

Functions

func BookmarksFile added in v0.3.15

func BookmarksFile(env xdg.Env) string

BookmarksFile is GTK 3's bookmarks file, which GTK 4 reads too; "" without a config directory.

func FilterLabel

func FilterLabel(f Filter) string

FilterLabel is a filter's name. Apps that want the patterns seen put them in the name; GTK's case-insensitive suffix globs (*.[pP][nN][gG]) would read as noise. Only a nameless filter shows its patterns, MIME types as their *.ext.

func FormatTime

func FormatTime(t time.Time) string

FormatTime is a modification time in local time, "" for none.

func HumanSize

func HumanSize(n int64) string

HumanSize is a byte count in binary units (1.5 KB).

func MatchesFilter

func MatchesFilter(db *mime.Database, name string, filters []Filter, active int) bool

MatchesFilter reports whether name passes the active filter: no filters, an out-of-range index or an empty rule set pass everything; otherwise any one rule must match, a glob by pattern, a MIME rule against the type guessed from the name.

func RecentFile

func RecentFile() string

RecentFile is the recently-used list GTK writes, $XDG_DATA_HOME/recently-used.xbel; "" without a data home.

func SortEntries

func SortEntries(entries []Entry, key SortColumn, asc bool)

SortEntries orders directories first, then by the column.

func SortSearch

func SortSearch(entries []Entry, root, query string)

SortSearch orders recursive hits by relevance, then by path so the order is stable.

func SystemLocations

func SystemLocations(home string) func() []Place

SystemLocations reads the mount table for OtherLocations, then the gvfs network shares.

func SystemTrashDirs

func SystemTrashDirs(home string) func() []string

SystemTrashDirs reads the data home and the mount table for TrashDirs: the home trash, then the user-visible mounts' trashes.

func TrashDirs

func TrashDirs(dataHome string, mounts []string, uid int) []string

TrashDirs are the trash directories of the freedesktop trash spec: the home trash under dataHome, then for each mount point its $topdir/.Trash/$uid when .Trash is a real, sticky directory, and its $topdir/.Trash-$uid.

func VisibleMounts

func VisibleMounts(mounts io.Reader, home, user string) []string

VisibleMounts are the user-visible mount points in a /proc/self/mounts listing, each once, in its order; none for a nil listing.

func WalkSearch

func WalkSearch(ctx context.Context, root, query string, showHidden bool, emit func([]string)) int

WalkSearch walks root depth first, handing every path whose name matches query to emit in batches as they are found, and returns the match count. Hidden entries (GTK's rule) are skipped, and their subtrees not entered, unless showHidden; symlinked directories are not entered, which keeps the walk out of loops. A cancelled ctx stops the walk, mid-directory too.

func WatchMounts

func WatchMounts(changed func()) (stop func())

WatchMounts calls changed (off the loop) each time the mount table changes, until stop is called: the kernel flags /proc/self/mounts with POLLPRI on every mount and unmount, and reading it again rearms the flag. A table that cannot be watched watches nothing.

func WatchSystemLocations

func WatchSystemLocations(changed func()) (stop func())

WatchSystemLocations calls changed (off the loop) whenever SystemLocations may have changed, until stop is called: a mount came or went (WatchMounts), or gvfs mounted or unmounted a share under $XDG_RUNTIME_DIR/gvfs, which the mount table does not show.

Types

type Chooser

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

Chooser is the dev.stubbe.lys.FileChooser1 host: one overlay showing one request; requests arriving meanwhile wait their turn, and dismissing a request answers it with nothing, showing or waiting. Open and Save may be called from any goroutine; the rest runs on the loop.

func New

func New(d Deps) *Chooser

New builds the host; nothing maps until a request.

func (*Chooser) Close added in v0.2.0

func (c *Chooser) Close()

Close ends the host once the loop has ended: the request's lookups give up, the thumbnails it found are freed, and so is every one a lookup still running makes.

func (*Chooser) Dismiss

func (c *Chooser) Dismiss(handle string)

Dismiss answers the request at handle with nothing: the dialog showing for it is taken down, a waiting one never shows. Another request's dialog stays.

func (*Chooser) Open

func (c *Chooser) Open(caller portaldialogs.Caller, r OpenRequest) Result

Open shows the open dialog.

func (*Chooser) Save

func (c *Chooser) Save(caller portaldialogs.Caller, r SaveRequest) Result

Save shows the save dialog seeded with the suggested name.

type Client

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

Client calls the shell's dialog; it waits on the user, so it is bounded only by ctx.

func NewClient

func NewClient(conn *dbus.Conn) *Client

NewClient addresses the host over conn.

func (*Client) Dismiss

func (c *Client) Dismiss(ctx context.Context, handle string) error

Dismiss takes down the dialog showing for the request at handle.

func (*Client) Open

func (c *Client) Open(ctx context.Context, caller portaldialogs.Caller, r OpenRequest) (res Result, err error)

Open shows the open dialog.

func (*Client) Save

func (c *Client) Save(ctx context.Context, caller portaldialogs.Caller, r SaveRequest) (res Result, err error)

Save shows the save dialog.

type Crumb

type Crumb struct {
	Label, Path string
	Current     bool
}

Crumb is one breadcrumb button.

func Crumbs

func Crumbs(dir, home string) []Crumb

Crumbs is dir's breadcrumb trail: Home for the home directory (else /), its named segments, and past maxCrumbTail of them a … crumb standing for (and jumping to) the deepest collapsed one. Recent is one crumb.

type Daemon

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

Daemon serves a Host as dev.stubbe.lys.FileChooser1.

func NewDaemon

func NewDaemon(host Host) *Daemon

NewDaemon wraps the host for export.

func (*Daemon) Dismiss

func (d *Daemon) Dismiss(handle string) *dbus.Error

Dismiss takes down the dialog showing for the request at handle.

func (*Daemon) Export

func (d *Daemon) Export(conn *dbus.Conn) (func(), error)

Export serves the interface under its name; the returned release drops the name.

func (*Daemon) OpenFile

OpenFile opens existing files or directories.

func (*Daemon) SaveFile

SaveFile chooses a save destination.

type Deps

type Deps struct {
	// Config is the live config (the chooser's reveal animation).
	Config func() *config.Config
	// Open maps the dialog; Invoke runs on the UI loop; KeySym reads
	// its keys through the seat's keymap.
	Open   func(dialogsurface.Spec) (Window, error)
	Invoke func(func())
	KeySym keys.Translator
	// Font shapes the text; Sheet styles the surface, the labels'
	// and entries' ink included.
	Font  render.Font
	Sheet *widget.Stylesheet
	// MIME guesses types for filters and icons.
	MIME *mime.Database
	// Home is where a request without a folder starts and what the
	// breadcrumbs shorten to Home.
	Home string
	// Places and Locations fill the sidebar for each request;
	// WatchLocations calls changed (off the loop) whenever the
	// locations may have changed (a mount came or went) until its stop
	// is called; nil watches nothing.
	Places, Locations func() []Place
	WatchLocations    func(changed func()) (stop func())
	// Drives is the UDisks2 client the Locations list the volumes of,
	// mounted or not, through; nil, or a nil client while the system
	// bus is not up, lists the mounts alone.
	Drives func() *udisks.Client
	// ViewFile persists the sort and layout, and beside it the folder
	// each app last picked in; "" keeps them in memory.
	ViewFile string
	// BookmarksFile is the GTK bookmarks file Ctrl+D and a folder
	// dropped on the sidebar add to, and a bookmark's menu removes
	// from (BookmarksFile); "" offers no editing.
	BookmarksFile string
	// RecentFile is the recently-used list the Recent place lists
	// (RecentFile()); "" offers no Recent.
	RecentFile string
	// TrashDirs are the trash directories the Trash place lists
	// (SystemTrashDirs); nil offers no Trash.
	TrashDirs func() []string
	// Target is the output a dialog maps on (the focused one, else the
	// first); nil while none is known, when the compositor picks one.
	Target func() *app.Output
	// ForgetImage drops the renderer's copy of a thumbnail nothing
	// draws any more (app.Application.ForgetImage).
	ForgetImage func(render.ImageID)
}

Deps are the chooser's collaborators.

type Entry

type Entry struct {
	Path     string
	IsDir    bool
	Size     int64
	Modified time.Time
	// Label is the name shown in place of the basename: a trashed
	// file's original name; "" shows the basename.
	Label string
}

Entry is one listed file or directory.

func ListRecent

func ListRecent(path string, mode Mode) ([]Entry, error)

ListRecent lists the recently used local files that still exist, the newest maxRecent of them; an unreadable list lists none.

func ListTrash

func ListTrash(dirs []string, mode Mode) ([]Entry, error)

ListTrash lists the files in each trash directory's files/, each named by the original basename its info/<name>.trashinfo records. A file without readable, well-formed info is left out (the spec's orphan), a trash directory that does not exist lists nothing, and one that cannot be read is an error naming it.

func (Entry) Kind

func (e Entry) Kind() string

Kind is the displayed type: Folder, the uppercased extension (PNG), or File without one.

func (Entry) Name

func (e Entry) Name() string

Name is the entry's shown name: its label, else its basename.

type Filter

type Filter struct {
	Name  string
	Rules []Rule
}

Filter is a named list of rules, the portal's (sa(us)).

type Host

type Host interface {
	Open(portaldialogs.Caller, OpenRequest) Result
	Save(portaldialogs.Caller, SaveRequest) Result
	// Dismiss takes down the dialog showing for the request at handle.
	Dismiss(handle string)
}

Host shows the dialogs; each blocks until the user answers.

type Mode

type Mode uint8

Mode is what the chooser is doing.

const (
	ModeOpenFile Mode = iota
	ModeOpenMultiple
	ModeFolder
	ModeFolders
	ModeSave
)

The chooser's modes.

type OpenRequest

type OpenRequest struct {
	Title               string
	Multiple, Directory bool
	Filters             []Filter
	// CurrentFolder seeds the starting directory ("" is the default).
	CurrentFolder string
	// AcceptLabel names the confirm button ("" for the mode's own).
	AcceptLabel string
	// CurrentFilter is the index of the filter to start on (the
	// first by default).
	CurrentFilter int32
	// Choices are extra questions shown with the dialog.
	Choices []portaldialogs.Choice
}

OpenRequest is one open dialog.

type Place

type Place struct {
	Label, Path, Icon string
	Bookmark          bool
}

Place is a sidebar shortcut; Bookmark marks one from the GTK bookmarks file, which the sidebar can remove.

func NetworkLocations

func NetworkLocations(runtimeDir string) []Place

NetworkLocations are the network shares gvfs mounted, as its FUSE daemon shows them under runtimeDir/gvfs, one folder each named "<type>:<key>=<value>,...": labelled by share and server, else by user and host; none without gvfsd-fuse running.

func OtherLocations

func OtherLocations(mounts io.Reader, home, user string) []Place

OtherLocations is Computer (/) plus the user-visible mounts in a /proc/self/mounts listing: what gio's volume monitor shows for unix mounts, those under /media, /run/media/<user> and the home directory (not hidden ones).

func UserPlaces

func UserPlaces(env xdg.Env, home string) ([]Place, error)

UserPlaces is Home, the user directories that exist (where env's user-dirs.dirs puts them, under their localized names), then the GTK bookmarks. A user directory user-dirs.dirs cannot say, or a bookmarks file that cannot be read, is left out, and the error names it.

type Result

type Result struct {
	URIs    []string
	Filter  Filter
	Choices []portaldialogs.Selection
}

Result is what a dialog answers, (asa(sa(us))a(ss)) on the wire as three values: the chosen file:// URIs (none on a cancel or a dismissal), the filter active at the end (a nameless empty one for none), and what was picked for each choice.

type Rule

type Rule struct {
	Kind  uint32
	Value string
}

Rule is one (kind, value) of a filter: a glob or a MIME type.

type SaveRequest

type SaveRequest struct {
	Title         string
	CurrentName   string
	Filters       []Filter
	CurrentFolder string
	AcceptLabel   string
	CurrentFilter int32
	Choices       []portaldialogs.Choice
}

SaveRequest is one save dialog.

type SortColumn

type SortColumn uint8

SortColumn is a list view column.

const (
	SortName SortColumn = iota
	SortSize
	SortModified
	SortKind
)

The sortable columns.

type Window

type Window interface {
	Close()
	SetFocus(widget.Widget) error
}

Window is the overlay surface the chooser maps (app.LayerWindow).

Jump to

Keyboard shortcuts

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