pub struct FileSelection { /* private fields */ }Expand description
A file chooser dialog box.
This dialog box opens a file choser with an optional title in the specified path. If the path is not specified, it defaults to the user’s home directory.
The backends might support multiple operation modes, for example open or save dialogs. You can
select a mode using the FileSelectionMode enum, though the backend might ignore the mode
and just display a simple file dialog. Per default, the mode is set to Open.
§Example
use dialog::DialogBox;
let choice = dialog::FileSelection::new("Please select a file")
.title("File Selection")
.path("/home/user/Downloads")
.show()
.expect("Could not display dialog box");
println!("The user chose: {:?}", choice);Implementations§
Source§impl FileSelection
impl FileSelection
Sourcepub fn new(text: impl Into<String>) -> FileSelection
pub fn new(text: impl Into<String>) -> FileSelection
Creates a new file chooser with the given path.
Examples found in repository?
6fn main() -> dialog::Result<()> {
7 let choice = dialog::FileSelection::new("Please select a file")
8 .title("File Chooser Example (Open)")
9 .path("/etc")
10 .show()?;
11 println!("The user chose: {:?}", choice);
12
13 let choice = dialog::FileSelection::new("Please select a file")
14 .title("File Chooser Example (Save)")
15 .mode(dialog::FileSelectionMode::Save)
16 .path("/etc")
17 .show()?;
18 println!("The user chose: {:?}", choice);
19
20 Ok(())
21}Sourcepub fn title(&mut self, title: impl Into<String>) -> &mut FileSelection
pub fn title(&mut self, title: impl Into<String>) -> &mut FileSelection
Sets the title of this file chooser dialog box.
This method returns a reference to self to enable chaining.
Examples found in repository?
6fn main() -> dialog::Result<()> {
7 let choice = dialog::FileSelection::new("Please select a file")
8 .title("File Chooser Example (Open)")
9 .path("/etc")
10 .show()?;
11 println!("The user chose: {:?}", choice);
12
13 let choice = dialog::FileSelection::new("Please select a file")
14 .title("File Chooser Example (Save)")
15 .mode(dialog::FileSelectionMode::Save)
16 .path("/etc")
17 .show()?;
18 println!("The user chose: {:?}", choice);
19
20 Ok(())
21}Sourcepub fn path(&mut self, path: impl AsRef<Path>) -> &mut FileSelection
pub fn path(&mut self, path: impl AsRef<Path>) -> &mut FileSelection
Sets the path of this file chooser dialog box.
This method returns a reference to self to enable chaining.
Examples found in repository?
6fn main() -> dialog::Result<()> {
7 let choice = dialog::FileSelection::new("Please select a file")
8 .title("File Chooser Example (Open)")
9 .path("/etc")
10 .show()?;
11 println!("The user chose: {:?}", choice);
12
13 let choice = dialog::FileSelection::new("Please select a file")
14 .title("File Chooser Example (Save)")
15 .mode(dialog::FileSelectionMode::Save)
16 .path("/etc")
17 .show()?;
18 println!("The user chose: {:?}", choice);
19
20 Ok(())
21}Sourcepub fn path_to_string(&self) -> Option<String>
pub fn path_to_string(&self) -> Option<String>
Gets the path of this file chooser dialog box.
This method returns the validated directory as a String.
Sourcepub fn mode(&mut self, mode: FileSelectionMode) -> &mut FileSelection
pub fn mode(&mut self, mode: FileSelectionMode) -> &mut FileSelection
Sets the operation mode of the file chooser.
This method returns a reference to self to enable chaining.
Examples found in repository?
6fn main() -> dialog::Result<()> {
7 let choice = dialog::FileSelection::new("Please select a file")
8 .title("File Chooser Example (Open)")
9 .path("/etc")
10 .show()?;
11 println!("The user chose: {:?}", choice);
12
13 let choice = dialog::FileSelection::new("Please select a file")
14 .title("File Chooser Example (Save)")
15 .mode(dialog::FileSelectionMode::Save)
16 .path("/etc")
17 .show()?;
18 println!("The user chose: {:?}", choice);
19
20 Ok(())
21}