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.
This commit is contained in:
Chris Cochrun 2023-09-21 17:11:02 -05:00
parent f26b6fb66a
commit d836f91425

View file

@ -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()
}
}
}
}