Expand description
Choosing files, as a plugin (FilesPlugin, in DefaultPlugins):
egui-pop’s in-app picker, or, as a fallback an application allows, the
system’s chooser off the interface thread.
Files::choose returns a Pending (the host contract’s, ADR
0010): the frame never waits. In-app pickers open in a modal of their
own, or inside the caller’s dialog (Files::choose_inline, as a
form’s path field does). The result is { "paths": [...] }, or
null when the person cancelled; chosen reads it. A choice
belongs to the window it was asked from (Files::owner): its
in-app picker’s modal is drawn over that application window and blocks
it alone; the window closed, the choice is cancelled.
A choice under way is on the bus (ADR 0029): started, it asks its
pop.popup.open (file:<id>, owned by this plugin, its parent the window
it was asked from), or, for the system’s chooser, the pop.window.open of
a native window; ended, their close. Its window closing closes it
(parent-closed), and this plugin’s listener (CHOICE_LISTENER)
cancels the choice in that call.
- The system’s chooser (feature
native-dialogs, throughrfd): a fallback kept in case an application cannot do with the in-app picker, off at build time and at run time. Used only when the feature is compiled in and the application allows it (AppBuilder::system_file_chooser) and the person’sfiles.nativesetting is on and a portal answers; never under tests (system_chooser_refused). The xdg desktop portal on Linux, the common dialogs on Windows, the open and save panels on macOS. It is created on the interface thread and awaited on a thread of its own. It is attached to the window it was asked from (the portal’s parent window, the owner window on Windows, a sheet on macOS) when that window’s handle is known (set_parent_window; the main window’s is recorded byAppBuilder::run_native); else to none, never to another window. - The in-app picker (
FilePicker), in every other case: a click selects and a double click or Enter opens, keyboard navigation (arrows, Enter, Backspace orAlt+Upfor the parent folder,Ctrl+Enterto choose the folder or the selection,Ctrl+Dto bookmark), several files selected withCtrlorShiftand a click,Shiftand the arrows,Ctrl+SpaceandCtrl+A(CMD_TOGGLE_SELECTION,CMD_SELECT_ALL), a typed path with completion (Tab), the fuzzy filter of the choice dialog, the request’s filters, the system’s folders and volumes (places), recent places and bookmarks (renamed and moved from their menu) kept in the host store (settings/files.recent,settings/files.bookmarks), and the last folder per purpose (settings/files.last_folders). Saving, it appends the filter’s extension to a name without one and follows the filter when it changes, selects the name’s stem, asks before replacing a file (FileRequest::confirm_overwrite, through the dialogs plugin), and makes folders (CMD_NEW_FOLDER). It reads through afs::FileSystem: the system’s by default, or a folder held in memory (fs::MemoryFs; the web build has no file system), given withFilesPlugin::file_systemorFiles::set_file_system. - Previews come from pluggable providers (
preview): plugins register theirs withFiles::previews; they are made off the interface thread, cancelled when the highlight moves, and cached. The in-app picker shows the highlighted entry’s preview and facts in a pane beside the list (Alt+Pshows or hides it; thefiles.previewsetting remembers). Built in (providers): images (PNG and JPEG, featureimage-previews), text and code, Markdown drawn simply, folders with their first images. - The in-app picker’s size is the person’s: its modal is resized
by its edges and corners, a splitter sets the pane’s width, and
both are kept in the host store (
DIALOG_SIZE,PANE_WIDTH). - The in-app picker’s order: a click on a column’s header sorts by it
(
sort), in the list and the grid alike; it is kept in the host store (SORT), andSETTING_FOLDERS_FIRSTkeeps folders first. - The in-app picker’s view, with previews: a list, or a grid of
thumbnails from the same providers (
PickerView), whose zoom (how many thumbnails fill a row, one across at most, kept through a resize) is a slider,Ctrland the wheel, orCtrland+or-; only the cells in view ask for a thumbnail (Previews::want), a placeholder stands in until it is made, and the arrows move in two dimensions. Both are kept in the host store (VIEW,THUMBNAILS_PER_ROW). - The in-app picker’s folder reads as breadcrumbs: each segment opens its
folder, the chevron after it lists its subfolders, and with too little room
the start collapses behind a menu, the deepest segments staying.
CMD_EDIT_PATH(Ctrl+L), or typing/or~on an entry, puts a path into the field, which takes both. - Grouped files (
groups): with a grouping declared by the application (FilesPlugin::grouping,Files::groupings), files that go together are one entry of the in-app picker, a RAW with its sidecars, with a badge (+XMP). Choosing it gives the main file, andchosen_groupsthe others. - The application’s options (
FileRequest::choice,FileRequest::check): combo boxes and check boxes above the in-app picker’s buttons, in the desktop portal’s shape; the choice gives their values back (chosen_choices).rfdcannot show them, so a request with choices opens the in-app picker.
Steps (ADR 0011):
| Step | Arguments | Default |
|---|---|---|
file.choose | { "id", "request" } | opens the system’s chooser or the in-app picker |
file.chosen | { "id", "request", "paths", "origin" }, "groups" when some are, "choices" when the request has some | remembers the places, gives the paths, their groups and the choices |
A run-hook on file.choose replaces the whole chooser: it answers
{ "paths": [...] } or { "cancelled": true } at once, or anything
else and later Files::deliver. A before-hook on file.chosen may
veto the choice (the result is the reason, as an error) or redirect
it to other paths. The journal says file.cancelled when the choice
is cancelled, from whoever cancelled it. The debug bridge’s files
collector shows the choices open and answers them (answer, the
user’s unless offered to agents), as its caller: the result carries
the origin (chosen_origin), and so does file.chosen (origin,
as the journal writes it), so a hook may refuse a choice no person
made. The file.preview
command gives agents a path’s preview metadata (preview_metadata).
The question before replacing a file is the in-app picker’s own: the
system’s choosers ask theirs, a run-hook on file.choose and
Files::deliver answer for themselves, and none of them is asked
again.
use egui_pop_api::files::{self, FileRequest, FilesPlugin, FILES};
use egui_pop_api::App;
let app = App::builder().plugin(FilesPlugin::in_app()).build(&egui::Context::default()).unwrap();
let h = app.handle();
let f = h.service(&FILES).unwrap();
let pending = f.choose(&h, FileRequest::open("Open an image").filter("Images", &["png", "jpg"]));
// Nothing yet: the picker is open, the frame goes on.
assert!(pending.take().is_none());
assert_eq!(f.describe()["open"][0]["via"], "in_app");Modules§
- browser
- A file browser with pluggable view modes (design).
- fs
- Where the in-app picker reads: the system’s file system (
StdFs, the default), or a folder held in memory (MemoryFs), for the web build, which has no file system, and for tests. - groups
- Grouped files: files that go together show as one entry of the in-app picker (a RAW with its sidecars, Lightroom’s and digiKam’s habit), and choosing it gives the main file, with the others beside it.
- places
- The system’s places the in-app picker lists beside home: its folders (Desktop, Documents, Downloads, Pictures, Music, Videos) and the volumes mounted, removable cards among them, the first place of a photo import.
- preview
- Previews of files, from pluggable providers.
- providers
- The built-in preview providers, registered by the files plugin
unless it is told not to (
FilesPlugin::without_builtin_previews): - sort
- The order of the in-app picker’s entries: by which column, up or down, folders first or among the files, names read naturally.
Structs§
- Entry
- One entry of a folder.
- File
Choice - An option of the application’s, shown by the in-app picker beside its
buttons and given back with the paths (
chosen_choices): a combo box of values, or a check box. Its shape is the desktop portal’schoices: an id, a label, the values offered as(id, label), and the value it starts with; no values make a check box, whose value is"true"or"false". - File
Filter - Files a filter shows: a name and extensions (without the dot).
- File
Picker - The in-app picker: a folder’s entries, a field that filters them
(fuzzy) or takes a typed path (with completion), places, filters.
Usable on its own:
FilePicker::showin anyUi. - File
Request - What a choice asks for. Built with its constructors (
FileRequest::openand the others) and their builders: a field added later breaks nobody. - Files
- The choices open, as a service.
- Files
Plugin - The plugin.
- Places
- Places the picker lists beside the folder: home, the system’s folders,
the volumes mounted, recent places and bookmarks. Made with
Places::default()and its fields. - Primary
- What the in-app picker’s primary button does now (
FilePicker::primary).
Enums§
- Choose
Kind - What is chosen.
- Chosen
- How a choice ended.
- Empty
State - Why the in-app picker’s list shows nothing (
FilePicker::empty_state). - Picker
Answer - What the picker answers.
- Picker
View - How the in-app picker shows a folder’s entries: the file browser’s
modes it draws (
browser::MODE_DETAILS,browser::MODE_THUMBNAILS,browser::MODE_COLUMNS). - Via
- Who answers a choice.
Constants§
- BOOKMARKS
- Where bookmarks are kept (a JSON list of folders).
- BOOKMARK_
NAMES - Where the names given to bookmarks are kept (a JSON list of
[folder, name]pairs). Seerename_bookmark. - CHOICE_
LISTENER - The files plugin’s listener on
pop.popup.closeandpop.window.close: the choice of that popup or native window is cancelled, whoever asked (its window closing, among others). - CMD_
BACK - The open in-app picker goes back to the folder it showed before (Alt+Left).
- CMD_
EDIT_ PATH - The open in-app picker’s folder goes into its field, as a path to edit (Ctrl+L). Saving, the name stays at its end.
- CMD_
FORWARD - The open in-app picker goes forward again after going back (Alt+Right).
- CMD_
NEW_ FOLDER - A new folder in the open in-app picker (Ctrl+Shift+N): asks its name,
or makes it at once with
{ "name" }. - CMD_
PREVIEW - A path’s preview metadata, for agents (
{ "path" }). - CMD_
RELOAD - The open in-app picker reads its folder again (F5).
- CMD_
REPLACE - The answer to the question before replacing a file: the choice ends
with that file (
{ "id", "path" }). - CMD_
SELECT_ ALL - Every file shown in the open in-app picker is selected (Ctrl+A, choosing several files, unless the field holds a path: the key is then the field’s).
- CMD_
TOGGLE_ HIDDEN - The open in-app picker shows or hides hidden files (Ctrl+H, as GTK and KDE).
- CMD_
TOGGLE_ PREVIEW - The in-app picker’s preview pane is shown or hidden (Alt+P, as the Windows file explorer’s), and kept so.
- CMD_
TOGGLE_ SELECTION - The highlighted entry of the open in-app picker is selected or unselected (Ctrl+Space, choosing several files or a folder).
- CMD_
VIEW_ MODE - The prefix of the mode keys’ commands:
file.view.mode1(Ctrl+1) tofile.view.mode9. - DIALOG_
SIZE - Where the in-app picker’s size is kept (width and height of its content, in points).
- FILES
- The file chooser, as a service.
- GROUPED
- Where it is kept whether the in-app picker groups files, with groupings
declared (
groups). Not a setting of the settings window: without a grouping it would do nothing. - LAST_
FOLDERS - Where the last folder of each purpose is kept (a JSON list of
[purpose, folder]pairs, newest first). SeeFileRequest::purpose. - LAST_
FOLDERS_ KEPT - How many purposes keep a last folder: the one chosen in the longest ago goes first.
- LIST_
HEIGHT - The list’s height when the picker is not given a height to fill.
- LIST_
MIN_ WIDTH - The narrowest the picker’s list gets for the preview pane: under it, the pane shrinks instead.
- NAME_
MIN_ WIDTH - The narrowest the name’s column gets: with less room, the other columns go, the type first and the modification time last.
- PANE_
MIN_ WIDTH - The narrowest preview pane drawn: with less room, it is not shown.
- PANE_
WIDTH - Where the width of the in-app picker’s preview pane is kept.
- PICKER_
HEIGHT - The height of the in-app picker’s modal at first: the list has its
usual height (
LIST_HEIGHT). - PICKER_
MIN_ SIZE - The least size the in-app picker’s modal is dragged to: the row of its filters and buttons fits, and a few entries.
- PICKER_
WIDTH - The width of the in-app picker’s modal at first, the preview pane shown or not: wide enough for the places, the list with all its columns and the full pane.
- PLUGIN
- The plugin’s id.
- POPUP_
PREFIX - A choice’s id in the registry:
file:<id>. - RECENT
- Where recent places are kept (a JSON list of folders, newest first).
- RECENT_
KEPT - How many recent places are kept.
- SETTING_
FOLDERS_ FIRST - Whether the in-app picker keeps folders before files in every order.
- SETTING_
NATIVE - The setting: use the system’s chooser when there is one. Declared only
when the application allows that chooser
(
AppBuilder::system_file_chooser); on by default there. - SETTING_
PREVIEW - The setting: the in-app picker shows its preview pane.
- SORT
- Where the in-app picker’s order is kept:
name,-name(descending), andsize,modifiedortypethe same way (sort::PickerSort). - STEP_
CHOOSE - A choice starts: the system’s chooser or the in-app picker opens.
- STEP_
CHOSEN - Paths were chosen.
- TEST_
ENV - The environment variable that refuses the system’s chooser to a process,
whatever its value: for test runs that drive an application without
egui_pop_test(egui-pop’s CI sets it). - THUMBNAILS_
PER_ ROW - How many thumbnails fill a row of the in-app picker’s grid; 0 (the
default) until the person zooms: an older size in points
(
THUMBNAIL_SIZE), elsebrowser::ThumbZoom::DEFAULT_PER_ROW. - THUMBNAIL_
DEFAULT_ SIZE - The size of the picker’s thumbnails an older version started at, in points.
- THUMBNAIL_
MAX_ SIZE - The side previews are made at by default (
preview::MAX_SIDE); the grid’s thumbnails follow its zoom, one across at most. - THUMBNAIL_
MIN_ SIZE - The smallest thumbnails of the picker’s grid, in points: its zoom shows no more per row than fit.
- THUMBNAIL_
POINTS - The size of the in-app picker’s thumbnails, in points, when its grid
keeps the size on a resize (
FilesPlugin::grid_resizewithbrowser::GridResize::FixedSize); 0 (the default) until the person zooms: the count per row kept (THUMBNAILS_PER_ROW) converted. - THUMBNAIL_
SIZE - Where an older version kept the size of the in-app picker’s thumbnails,
in points. No longer declared: a value saved there is read until
THUMBNAILS_PER_ROWis set, converted at the grid’s width (thumbnail_zoom). - VIEW
- Where the in-app picker’s view last used is kept: a mode id of
browser::ViewModes(details,thumbnails); a dialog never seen opens in it. - VIEWS
- The mode each dialog was last shown in, by dialog (a request’s purpose,
else its kind): a JSON list of pairs (
view_for). - VIEWS_
KEPT - How many dialogs’ modes are kept.
- WHEN_
BROWSER - A file browser holds the keyboard (an in-app picker with previews open,
or a
browser::FileBrowser’s entries): the mode keys work.
Traits§
- Parent
Window - A window the system’s chooser can be attached to: what gives its
native handles, such as winit’s window (eframe’s
CreationContext::winit_window).
Functions§
- bookmark_
names - The names given to bookmarks, by folder.
- bookmarks
- The bookmarked folders.
- chooser_
parent - The window a system chooser asked from
owneris attached to: the application windowownerbelongs to (AppHandle::window_group) when its handles are recorded, else none. Never the main window for a choice asked from another window: attached there, the chooser would come up over the wrong window and block it. - chosen
- Reads a choice’s result (what its
Pendinggives). - chosen_
choices - The application’s choices a choice ended with (
FileRequest::choice): each id with its value, empty when cancelled or without choices. - chosen_
groups - The groups a choice’s result holds (
groups): one for each path chosen that heads a group, none otherwise.chosengives the paths, each group’s main among them; the members come from here. - chosen_
origin - Who answered a choice, from its result: the user (the picker, the system’s chooser, a plugin’s) unless an agent or a script answered it through the debug bridge. A consumer that should act only on a person’s choice checks it.
- dialog_
of - The dialog a request’s view is kept under: its purpose, else its kind.
- dialog_
size - The in-app picker’s size, as kept (it may not fit the window now).
- folders_
first - Whether the in-app picker keeps folders first (the setting).
- forget_
parent_ window - Forgets the handles recorded for
viewport(set_parent_window). - grouped
- Whether the in-app picker groups files, with groupings declared.
- has_
parent_ window - Whether handles are recorded for
viewport(set_parent_window). - home
- The home folder, if known.
- last_
folder - The last folder of a purpose (
FileRequest::purpose), whether or not it still exists. - move_
bookmark - Moves a bookmark to
toin the list (clamped to its end). - native_
available - Whether the system’s chooser can be used here: the feature is on and, on Linux and the BSDs, a session bus is there for the portal.
- pane_
width - The width of the in-app picker’s preview pane, as kept (the room in the dialog may hold it smaller).
- preview_
metadata - A path’s preview metadata, as
file.previewgives it: made now from the providers if it is not in the cache. Metadata only: no pixels and no text. - preview_
wanted - Whether the in-app picker shows its preview pane (the setting).
- recent
- The recent places, newest first.
- refuse_
system_ chooser - Refuses the system’s chooser in this process from now on, whatever the
feature, the application and the setting say: the in-app picker answers
every choice. One way.
egui_pop_test’s harnesses call it, so that an application’s own tests never open a dialog on the desktop. - remember
- Remembers the folders of chosen paths as recent places.
- rename_
bookmark - Gives a bookmark a name of its own in the picker’s side bar; an empty name (or only spaces) gives it back its folder’s.
- set_
bookmark - Bookmarks a folder, or removes its bookmark (and the name it was given).
- set_
parent_ window - Records
window’s native handles as the windowviewport’s: a system chooser asked from that window (or a panel detached from it) is attached to it.AppBuilder::run_nativerecords the main window’s (frame::record_native_window); an application that has another window’s handles records them, and forgets them when it closes (forget_parent_window). Without a window’s handles, its chooser is attached to no window, never to another one. - sort_
order - The in-app picker’s order, as kept.
- system_
chooser_ refusal - Why the system’s chooser is refused here, the first reason found, or
None: - system_
chooser_ refused - Whether the system’s chooser is refused here, whatever the feature, the
application and the setting say: under tests, or with no window.
system_chooser_refusalsays why. - thumbnail_
zoom - The zoom of the in-app picker’s grid, as kept: the count per row once
set (
THUMBNAILS_PER_ROW); before, the size in points an older version kept (THUMBNAIL_SIZE), which the grid converts at its width when next drawn; elsebrowser::ThumbZoom::DEFAULT_PER_ROW. - thumbnail_
zoom_ under - The zoom of the in-app picker’s grid, as kept for
resize: underbrowser::GridResize::FixedSize, the size kept (THUMBNAIL_POINTS) once set, elsethumbnail_zoom(converted into a size at the grid’s width when next drawn). - view
- The in-app picker’s view last used, as kept.
- view_
for - The mode a dialog was last shown in (a mode id:
details,thumbnails), kept in the host’s store;Nonefor a dialog never shown. - want_
dialog_ size - Keeps the in-app picker’s size.
- want_
folders_ first - Keeps folders first in the in-app picker, or not (the setting).
- want_
grouped - Keeps whether the in-app picker groups files.
- want_
pane_ width - Keeps the width of the in-app picker’s preview pane.
- want_
preview - Shows or hides the in-app picker’s preview pane (the setting, kept).
- want_
sort_ order - Keeps the in-app picker’s order.
- want_
thumbnail_ points - Keeps the size of the in-app picker’s thumbnails, in points (its grid keeping the size on a resize).
- want_
thumbnails_ per_ row - Keeps the zoom of the in-app picker’s grid: this many per row.
- want_
view - Keeps the in-app picker’s view last used.
- want_
view_ for - Keeps the mode a dialog is shown in, and as the view last used.
Type Aliases§
- Choice
Values - The application’s choices as a choice ends with them: each id with its
value (
chosen_choices).