Available on crate features
xdg-portal or rfd only.Expand description
Dialogs for opening and save files.
§Features
- On Linux, the
xdg-portalfeature will use XDG Portal dialogs. - Alternatively,
rfdcan be used for platform support beyond Linux.
§Open a file
cosmic::task::future(async {
use cosmic::dialog::file_chooser;
let dialog = file_chooser::open::Dialog::new()
.title("Choose a file");
match dialog.open_file().await {
Ok(response) => println!("selected to open {:?}", response.url()),
Err(file_chooser::Error::Cancelled) => (),
Err(why) => eprintln!("error selecting file to open: {why:?}")
}
});§Open multiple files
cosmic::task::future(async {
use cosmic::dialog::file_chooser;
let dialog = file_chooser::open::Dialog::new()
.title("Choose multiple files");
match dialog.open_files().await {
Ok(response) => println!("selected to open {:?}", response.urls()),
Err(file_chooser::Error::Cancelled) => (),
Err(why) => eprintln!("error selecting file(s) to open: {why:?}")
}
});§Open a folder
cosmic::task::future(async {
use cosmic::dialog::file_chooser;
let dialog = file_chooser::open::Dialog::new()
.title("Choose a folder");
match dialog.open_folder().await {
Ok(response) => println!("selected to open {:?}", response.url()),
Err(file_chooser::Error::Cancelled) => (),
Err(why) => eprintln!("error selecting folder to open: {why:?}")
}
});§Open multiple folders
cosmic::task::future(async {
use cosmic::dialog::file_chooser;
let dialog = file_chooser::open::Dialog::new()
.title("Choose a folder");
match dialog.open_folders().await {
Ok(response) => println!("selected to open {:?}", response.urls()),
Err(file_chooser::Error::Cancelled) => (),
Err(why) => eprintln!("error selecting folder(s) to open: {why:?}")
}
});Modules§
- open
- Open file dialog. Request to open files and/or directories.
- save
- Save file dialog. Choose a location to save a file to.
Structs§
- Choice
xdg-portal - Presents the user with a choice to select from or as a checkbox.
- File
Filter xdg-portal - A file filter, to limit the available file choices to a mimetype or a glob pattern.
Enums§
- Error
- Errors that my occur when interacting with the file chooser subscription
Type Aliases§
- Dialog
Error xdg-portal