pub struct FileBox { /* private fields */ }Expand description
Represents a Save or Open File Dialog.
This is a builder struct, all functions return self, except the open or save method.
§Examples
Generic open file:
use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;
let result = FileBox::new().open();
println!("{}", result.expect("The file was not opened!").to_str().unwrap());Generic save file:
use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;
let result = FileBox::new().save("example.txt");
println!("{}", result.expect("The file was not saved!").to_str().unwrap());Filters:
use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;
let result = FileBox::new()
.filter("PNG", "*.png")
.filter("JPG", "*.jpg")
.filter("GIF", "*.gif")
.open();
println!("{}", result.expect("The file was not opened!").to_str().unwrap());Save a file with a default directory:
use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;
let result = FileBox::new()
.filter("Text", "*.txt")
.directory(Path::new("D:\\"))
.save("example.txt");
println!("{}", result.expect("The file was not saved!").to_str().unwrap());Implementations§
Source§impl FileBox
impl FileBox
Sourcepub fn new() -> FileBox
pub fn new() -> FileBox
Create a new FileBox to open or save files.
§Default Values
By default the Filter is set to a Vector with the all filter inside. (‘All’, ‘.’) By default there is not default directory.
Sourcepub fn clear_filters(self) -> Self
pub fn clear_filters(self) -> Self
Clear the current filters. This is useful if you don’t want the ‘All’ filter.
Sourcepub fn set_filters(self, filters: Vec<Filter>) -> Self
pub fn set_filters(self, filters: Vec<Filter>) -> Self
Sourcepub fn directory(self, path: &'static Path) -> Self
pub fn directory(self, path: &'static Path) -> Self
Set the default directory for the save or open dialog to display.
Not setting this causes the dialog to open the last displayed directory or
the documents folder.
§Params
path: &`static Path -> The path of the directory to display.
Sourcepub fn open(self) -> Option<PathBuf>
pub fn open(self) -> Option<PathBuf>
Display the open file dialog.
§Returns
Option<PathBuf> -> The Path to the opened file. An empty Option means that the window was closed
without opening anything.