GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Add standardized XDG portal file dialog module using rfd
Cargo.toml | 1 +
src/file_dialog.rs | 19 +++++++++++++++++++
src/lib.rs | 1 +
3 files changed, 21 insertions(+)
diff --git a/Cargo.toml b/Cargo.toml
index 9e659f1..47ab128 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,5 +27,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
libc = "0.2"
log = "0.4"
+rfd = "0.15"
diff --git a/src/file_dialog.rs b/src/file_dialog.rs
new file mode 100644
index 0000000..cfde95c
--- /dev/null
+++ b/src/file_dialog.rs
@@ -0,0 +1,19 @@
+use std::path::PathBuf;
+
+/// Opens a portal file chooser dialog for selecting a file.
+pub fn pick_file(title: &str, filters: &[(&str, &[&str])]) -> Option<PathBuf> {
+ let mut dialog = rfd::FileDialog::new().set_title(title);
+ for (name, exts) in filters {
+ dialog = dialog.add_filter(*name, *exts);
+ }
+ dialog.pick_file()
+}
+
+/// Opens a portal file chooser dialog for saving a file.
+pub fn save_file(title: &str, filters: &[(&str, &[&str])]) -> Option<PathBuf> {
+ let mut dialog = rfd::FileDialog::new().set_title(title);
+ for (name, exts) in filters {
+ dialog = dialog.add_filter(*name, *exts);
+ }
+ dialog.save_file()
+}
diff --git a/src/lib.rs b/src/lib.rs
index 4d242fc..cfcab14 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,6 +9,7 @@ pub mod scale;
pub mod backend;
pub mod context;
pub mod process;
+pub mod file_dialog;
pub mod colors {
pub use crate::color::*;