pub struct FileDialog { /* private fields */ }Expand description
A modern, single-pane Open / Save file dialog.
Built on the general-purpose Modal, FileDialog presents
a file browser in its own top-level window: the current path along the top,
one combined list of folders (shown first) and files below it, a File
name field and a File types filter dropdown along the bottom, and
OK / Cancel to their right. That’s the arrangement modern KDE / Windows
pickers use, rather than the Win 3.1 two-column “Directories” / “Drives”
layout — a single flat pane with no separate drive selector.
Each section label carries a keyboard accelerator that moves focus to its control: Alt+L (“Location”) to the list, Alt+N to the File name field, Alt+T to the File types filter.
The application owns it as an overlay — typically Rc<RefCell<FileDialog>>
added with Column::add_overlay, exactly like
Dialog — and opens it with show_open
or show_save, passing a callback that receives the
chosen Path when the user confirms. Cancelling (the Cancel button,
Escape, or the window’s close button) simply closes the dialog without
calling back.
use std::cell::RefCell;
use std::rc::Rc;
use saudade::{FileDialog, FileFilter};
let dialog = Rc::new(RefCell::new(
FileDialog::new().with_filters(vec![
FileFilter::new("Text Files (*.txt)", ["*.txt"]),
FileFilter::all_files(),
]),
));
// From a menu / button handler:
dialog.borrow_mut().show_open(|cx, path| {
// load `path` …
cx.request_paint();
});Interaction:
- single-click a file to put its name in the File name field;
- double-click a file (or select it and press Enter / OK) to open it;
- double-click a folder — or
..— to descend / ascend (with a folder selected in the list, Enter navigates into it too); - type a name and press Enter / OK to accept it; type a wildcard pattern
(e.g.
*.rs) to re-filter the list; type a directory name to descend.
Implementations§
Source§impl FileDialog
impl FileDialog
pub fn new() -> Self
Sourcepub fn with_directory(self, dir: impl Into<PathBuf>) -> Self
pub fn with_directory(self, dir: impl Into<PathBuf>) -> Self
Set the directory the dialog opens at.
Sourcepub fn set_directory(&mut self, dir: impl Into<PathBuf>)
pub fn set_directory(&mut self, dir: impl Into<PathBuf>)
Set the directory the next show_* opens at, after construction —
handy for a shared dialog that should reopen near the current document.
Sourcepub fn with_filters(self, filters: Vec<FileFilter>) -> Self
pub fn with_filters(self, filters: Vec<FileFilter>) -> Self
Replace the file-type filters. The first becomes the initial selection; an empty list falls back to “All Files”.
Sourcepub fn show_open<F>(&mut self, on_open: F)
pub fn show_open<F>(&mut self, on_open: F)
Open the dialog to pick a file. on_open runs with the chosen path when
the user confirms (Open / double-click / Enter); Cancel or Escape close
it without calling back. The focused File name field starts empty —
the user picks a file from the list or types a name.
Sourcepub fn show_save<F>(&mut self, suggested_name: impl Into<String>, on_save: F)
pub fn show_save<F>(&mut self, suggested_name: impl Into<String>, on_save: F)
Open the dialog to choose a save destination. suggested_name pre-fills
the focused File name field (e.g. the current document’s name), fully
selected with the cursor at the end so it’s ready to keep, edit, or
replace by typing; on_save runs with the chosen path on confirm. The
path need not exist yet.
pub fn is_open(&self) -> bool
Trait Implementations§
Source§impl Default for FileDialog
impl Default for FileDialog
Source§impl Widget for FileDialog
impl Widget for FileDialog
Source§fn layout(&mut self, bounds: Rect)
fn layout(&mut self, bounds: Rect)
Source§fn paint(&mut self, painter: &mut Painter<'_>, theme: &Theme)
fn paint(&mut self, painter: &mut Painter<'_>, theme: &Theme)
Source§fn paint_overlay(&mut self, painter: &mut Painter<'_>, theme: &Theme)
fn paint_overlay(&mut self, painter: &mut Painter<'_>, theme: &Theme)
paint is finished. Default: no-op.Source§fn event(&mut self, event: &Event, ctx: &mut EventCtx)
fn event(&mut self, event: &Event, ctx: &mut EventCtx)
Source§fn captures_pointer(&self) -> bool
fn captures_pointer(&self) -> bool
Button override this so
pointer events keep flowing to them while a press is in progress, even
if the cursor leaves the widget’s bounds.Source§fn accepts_accelerators(&self) -> bool
fn accepts_accelerators(&self) -> bool
true if this widget should receive every keyboard event regardless
of focus. Used by menu bars so that Alt+letter accelerators reach
them even while a sibling (e.g., a text editor) holds focus.Source§fn popup_request(&self) -> Option<PopupRequest>
fn popup_request(&self) -> Option<PopupRequest>
Some makes the runtime open (or move) a borderless top-level
window at the indicated logical-coord rect so the popup can extend
past the main window’s edges. Container widgets propagate this from
their children. Default: no popup. Read moreSource§fn collect_popups(&self, out: &mut Vec<PopupRequest>)
fn collect_popups(&self, out: &mut Vec<PopupRequest>)
Source§fn wants_ticks(&self) -> bool
fn wants_ticks(&self) -> bool
true if this widget needs periodic Event::Tick
events to drive an animation. The runtime polls this after every
dispatch and, while any widget in the tree wants ticks, fires
Tick at roughly 60 Hz. Container widgets propagate from
children. Default: no animation.Source§fn on_cancel(&mut self, _ctx: &mut EventCtx)
fn on_cancel(&mut self, _ctx: &mut EventCtx)
Modal calls it on its content just before
tearing it down; the runtime calls it on the root widget when the main
window is closed, so a dialog used directly as the window root gets the
same hook. It does not fire when the content asked to be dismissed
itself (e.g. an OK / Cancel button calling
EventCtx::request_dismiss), since that path already chose what to
commit or revert. A dialog that previews edits live overrides this to
roll them back. Default: no-op.Source§fn focusable(&self) -> bool
fn focusable(&self) -> bool
true if this widget accepts keyboard focus. The parent container
remembers the last focusable widget the user clicked, and routes
keyboard events only there.Source§fn set_focused(&mut self, _focused: bool)
fn set_focused(&mut self, _focused: bool)
Source§fn focus_first(&mut self) -> bool
fn focus_first(&mut self) -> bool
true if a focusable target was located and now holds focus. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for FileDialog
impl !Send for FileDialog
impl !Sync for FileDialog
impl !UnwindSafe for FileDialog
impl Freeze for FileDialog
impl Unpin for FileDialog
impl UnsafeUnpin for FileDialog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.