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
- func BookmarksFile(env xdg.Env) string
- func FilterLabel(f Filter) string
- func FormatTime(t time.Time) string
- func HumanSize(n int64) string
- func MatchesFilter(db *mime.Database, name string, filters []Filter, active int) bool
- func RecentFile() string
- func SortEntries(entries []Entry, key SortColumn, asc bool)
- func SortSearch(entries []Entry, root, query string)
- func SystemLocations(home string) func() []Place
- func SystemTrashDirs(home string) func() []string
- func TrashDirs(dataHome string, mounts []string, uid int) []string
- func VisibleMounts(mounts io.Reader, home, user string) []string
- func WalkSearch(ctx context.Context, root, query string, showHidden bool, emit func([]string)) int
- func WatchMounts(changed func()) (stop func())
- func WatchSystemLocations(changed func()) (stop func())
- type Chooser
- type Client
- type Crumb
- type Daemon
- func (d *Daemon) Dismiss(handle string) *dbus.Error
- func (d *Daemon) Export(conn *dbus.Conn) (func(), error)
- func (d *Daemon) OpenFile(c portaldialogs.Caller, r OpenRequest) ([]string, Filter, []portaldialogs.Selection, *dbus.Error)
- func (d *Daemon) SaveFile(c portaldialogs.Caller, r SaveRequest) ([]string, Filter, []portaldialogs.Selection, *dbus.Error)
- type Deps
- type Entry
- type Filter
- type Host
- type Mode
- type OpenRequest
- type Place
- type Result
- type Rule
- type SaveRequest
- type SortColumn
- type Window
Constants ¶
const ( ServiceName = "dev.stubbe.lys.FileChooser1" ServicePath = dbus.ObjectPath("/dev/stubbe/lys/FileChooser") )
D-Bus identity (wayle-ipc file_chooser.rs).
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
BookmarksFile is GTK 3's bookmarks file, which GTK 4 reads too; "" without a config directory.
func FilterLabel ¶
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 ¶
FormatTime is a modification time in local time, "" for none.
func MatchesFilter ¶
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 ¶
SortSearch orders recursive hits by relevance, then by path so the order is stable.
func SystemLocations ¶
SystemLocations reads the mount table for OtherLocations, then the gvfs network shares.
func SystemTrashDirs ¶
SystemTrashDirs reads the data home and the mount table for TrashDirs: the home trash, then the user-visible mounts' trashes.
func TrashDirs ¶
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 ¶
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 ¶
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 (*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 ¶
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 (*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 Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon serves a Host as dev.stubbe.lys.FileChooser1.
func (*Daemon) Export ¶
Export serves the interface under its name; the returned release drops the name.
func (*Daemon) OpenFile ¶
func (d *Daemon) OpenFile(c portaldialogs.Caller, r OpenRequest) ([]string, Filter, []portaldialogs.Selection, *dbus.Error)
OpenFile opens existing files or directories.
func (*Daemon) SaveFile ¶
func (d *Daemon) SaveFile(c portaldialogs.Caller, r SaveRequest) ([]string, Filter, []portaldialogs.Selection, *dbus.Error)
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 ¶
ListRecent lists the recently used local files that still exist, the newest maxRecent of them; an unreadable list lists none.
func ListTrash ¶
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.
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 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 ¶
Place is a sidebar shortcut; Bookmark marks one from the GTK bookmarks file, which the sidebar can remove.
func NetworkLocations ¶
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 ¶
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 ¶
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 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.