Skip to main content

Module files

Module files 

Source
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.

Experimental: may change in any release (docs/stability.md).

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, through rfd): 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’s files.native setting 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 by AppBuilder::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 or Alt+Up for the parent folder, Ctrl+Enter to choose the folder or the selection, Ctrl+D to bookmark), several files selected with Ctrl or Shift and a click, Shift and the arrows, Ctrl+Space and Ctrl+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 a fs::FileSystem: the system’s by default, or a folder held in memory (fs::MemoryFs; the web build has no file system), given with FilesPlugin::file_system or Files::set_file_system.
  • Previews come from pluggable providers (preview): plugins register theirs with Files::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+P shows or hides it; the files.preview setting remembers). Built in (providers): images (PNG and JPEG, feature image-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), and SETTING_FOLDERS_FIRST keeps 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, Ctrl and the wheel, or Ctrl and + 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, and chosen_groups the 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). rfd cannot show them, so a request with choices opens the in-app picker.

Steps (ADR 0011):

StepArgumentsDefault
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 someremembers 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.
FileChoice
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’s choices: 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".
FileFilter
Files a filter shows: a name and extensions (without the dot).
FilePicker
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::show in any Ui.
FileRequest
What a choice asks for. Built with its constructors (FileRequest::open and the others) and their builders: a field added later breaks nobody.
Files
The choices open, as a service.
FilesPlugin
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§

ChooseKind
What is chosen.
Chosen
How a choice ended.
EmptyState
Why the in-app picker’s list shows nothing (FilePicker::empty_state).
PickerAnswer
What the picker answers.
PickerView
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). See rename_bookmark.
CHOICE_LISTENER
The files plugin’s listener on pop.popup.close and pop.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) to file.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). See FileRequest::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), and size, modified or type the 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), else browser::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_resize with browser::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_ROW is 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§

ParentWindow
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 owner is attached to: the application window owner belongs 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 Pending gives).
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. chosen gives 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 to in 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.preview gives 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 window viewport’s: a system chooser asked from that window (or a panel detached from it) is attached to it. AppBuilder::run_native records 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_refusal says 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; else browser::ThumbZoom::DEFAULT_PER_ROW.
thumbnail_zoom_under
The zoom of the in-app picker’s grid, as kept for resize: under browser::GridResize::FixedSize, the size kept (THUMBNAIL_POINTS) once set, else thumbnail_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; None for 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§

ChoiceValues
The application’s choices as a choice ends with them: each id with its value (chosen_choices).