From d836f91425f5a5fa0ca3bb6e7a1a31bd923a3702 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 21 Sep 2023 17:11:02 -0500 Subject: [PATCH] saving file with file_helper to use rfd for portals Using portals and rfd as our file selector to make sure that we can utilize the appropriate file dialog on various platforms from rust. This will eliminate some extra tomfoolery in QML. --- src/rust/file_helper.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/rust/file_helper.rs b/src/rust/file_helper.rs index b278511..5a41dfc 100644 --- a/src/rust/file_helper.rs +++ b/src/rust/file_helper.rs @@ -3,6 +3,7 @@ #[cxx_qt::bridge] mod file_helper { use cxx_qt_lib::QVariantValue; + use rfd::FileDialog; use std::path::Path; unsafe extern "C++" { @@ -69,5 +70,26 @@ mod file_helper { } } } + + #[qinvokable] + pub fn save_file(self: Pin<&mut Self>) -> QUrl { + let file = FileDialog::new() + .set_file_name("NVTFC.pres") + .set_title("Save Presentation") + .save_file(); + if let Some(file) = file { + println!("saving-file: {:?}", file); + let mut string = + String::from(file.to_str().unwrap_or("")); + if string.is_empty() { + QUrl::default() + } else { + string.insert_str(0, "file://"); + QUrl::from(string.as_str()) + } + } else { + QUrl::default() + } + } } }