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:
parent
f26b6fb66a
commit
d836f91425
1 changed files with 22 additions and 0 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue