pub struct FilePickerState {
pub current_dir: PathBuf,
pub entries: Vec<FileEntry>,
pub selected: usize,
pub selected_file: Option<PathBuf>,
pub show_hidden: bool,
pub extensions: Vec<String>,
pub dirty: bool,
/* private fields */
}Expand description
State for a file picker widget.
Tracks the current directory listing, filtering options, and selected file.
Fields§
§current_dir: PathBufCurrent directory being browsed.
entries: Vec<FileEntry>Visible entries in the current directory.
selected: usizeSelected entry index in entries.
selected_file: Option<PathBuf>Currently selected file path, if any.
Whether dotfiles are included in the listing.
extensions: Vec<String>Allowed file extensions (lowercase, no leading dot).
dirty: boolWhether the directory listing needs refresh.
Implementations§
Source§impl FilePickerState
impl FilePickerState
Configure whether hidden files should be shown.
Sourcepub fn extensions(self, exts: &[&str]) -> Self
pub fn extensions(self, exts: &[&str]) -> Self
Restrict visible files to the provided extensions.
Sourcepub fn scan_status(&self) -> FilePickerScanStatus
pub fn scan_status(&self) -> FilePickerScanStatus
Return the freshness of the current directory listing.
Sourcepub fn scan_errors(&self) -> &[FilePickerScanError]
pub fn scan_errors(&self) -> &[FilePickerScanError]
Return every failure captured by the most recent scan.
A root read_dir failure produces one error and retains the previous
listing. Per-entry and metadata failures produce a best-effort listing.
Sourcepub fn last_error(&self) -> Option<&FilePickerScanError>
pub fn last_error(&self) -> Option<&FilePickerScanError>
Return the most recent failure from the latest scan.
Sourcepub fn selected_file(&self) -> Option<&PathBuf>
pub fn selected_file(&self) -> Option<&PathBuf>
Return the currently selected file path, if any.
Disambiguates from the selected: usize field, which
is the entry index into entries. This method returns
the resolved file path that the user picked via Enter — None until a
file (not a directory) is selected.
§Example
let mut state = FilePickerState::new(".");
if ui.file_picker(&mut state).changed {
if let Some(path) = state.selected_file() {
println!("picked: {}", path.display());
}
}Sourcepub fn selected(&self) -> Option<&PathBuf>
👎Deprecated since 0.20.0: use selected_file() — disambiguates from the selected: usize field index
pub fn selected(&self) -> Option<&PathBuf>
use selected_file() — disambiguates from the selected: usize field index
Return the currently selected file path.
Deprecated alias for selected_file. The
shorter name conflicts visually with the selected: usize
field — a getter returning a path alongside a public field returning
an index made call sites ambiguous. Migrate to selected_file() for
new code; this stub stays callable until v1.0.
Sourcepub fn refresh(&mut self)
pub fn refresh(&mut self)
Re-scan the current directory, retaining failures in scan_errors.
This compatibility wrapper ignores the returned error. Use
try_refresh when the caller needs immediate
fallible control flow.
Sourcepub fn try_refresh(&mut self) -> Result<(), FilePickerScanError>
pub fn try_refresh(&mut self) -> Result<(), FilePickerScanError>
Re-scan the current directory and rebuild entries.
Root directory failures retain the previous listing. Entry-read and
file-type failures skip only the affected entry. Metadata failures keep
the file with FileEntry::size set to None. Any partial failure is
returned and remains inspectable through scan_errors.
Trait Implementations§
Source§impl Clone for FilePickerState
impl Clone for FilePickerState
Source§fn clone(&self) -> FilePickerState
fn clone(&self) -> FilePickerState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more