Show "Open File" Dialog From Rust? #3275
-
I am diving into implementing my own menus as described here https://tauri.studio/docs/guides/menu So far, I defined a Is this the way to go, or is there a more elegant way where I show the file dialog "directly" from within Rust-world, without a detour to JS-land first? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Use the Dialog APIs from rust: The Dialog API module allows you to show messages and prompt for file paths. |
Beta Was this translation helpful? Give feedback.
-
After RTFM, this is what I ended up with: use tauri::api::dialog;
use tauri::{CustomMenuItem, Menu, MenuItem, Submenu};
fn main() {
let open = CustomMenuItem::new("open".to_string(), "Open");
let fileMenu = Submenu::new("File", Menu::new().add_item(open));
let menu = Menu::new()
.add_submenu(fileMenu)
.add_native_item(MenuItem::Separator)
.add_native_item(MenuItem::Quit);
tauri::Builder::default()
.menu(menu)
.on_menu_event(|event| match event.menu_item_id() {
"open" => {
dialog::FileDialogBuilder::default()
.add_filter("Markdown", &["md"])
.pick_file(|path_buf| match path_buf {
Some(p) => {}
_ => {}
});
}
_ => {}
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
} Please bear with me... Still new to Rust 🦀😇 |
Beta Was this translation helpful? Give feedback.
Use the Dialog APIs from rust: The Dialog API module allows you to show messages and prompt for file paths.