diff --git a/core/tauri/src/api/dialog.rs b/core/tauri/src/api/dialog.rs index 40582594c..ebf243907 100644 --- a/core/tauri/src/api/dialog.rs +++ b/core/tauri/src/api/dialog.rs @@ -70,6 +70,12 @@ impl FileDialogBuilder { self } + /// Set the title of the dialog. + pub fn set_title(mut self, title: &str) -> Self { + self.0 = self.0.set_title(title); + self + } + /// Pick one file. pub fn pick_file) + Send + 'static>(self, f: F) { run_dialog!(self.0.pick_file(), f) diff --git a/core/tauri/src/endpoints/dialog.rs b/core/tauri/src/endpoints/dialog.rs index 5264cbaaf..e3c23b44f 100644 --- a/core/tauri/src/endpoints/dialog.rs +++ b/core/tauri/src/endpoints/dialog.rs @@ -26,6 +26,8 @@ pub struct DialogFilter { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct OpenDialogOptions { + /// The title of the dialog window. + pub title: Option, /// The filters of the dialog. #[serde(default)] pub filters: Vec, @@ -43,6 +45,8 @@ pub struct OpenDialogOptions { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct SaveDialogOptions { + /// The title of the dialog window. + pub title: Option, /// The filters of the dialog. #[serde(default)] pub filters: Vec, @@ -156,6 +160,9 @@ pub fn open( let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect(); dialog_builder = dialog_builder.add_filter(filter.name, &extensions); } + if let Some(title) = options.title { + dialog_builder = dialog_builder.set_title(&title); + } let (tx, rx) = channel(); @@ -189,6 +196,10 @@ pub fn save( let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect(); dialog_builder = dialog_builder.add_filter(filter.name, &extensions); } + if let Some(title) = options.title { + dialog_builder = dialog_builder.set_title(&title); + } + let (tx, rx) = channel(); dialog_builder.save_file(move |p| tx.send(p).unwrap()); Ok(rx.recv().unwrap().into()) diff --git a/examples/api/src-tauri/src/main.rs b/examples/api/src-tauri/src/main.rs index aa16f89f0..1661ef3c9 100644 --- a/examples/api/src-tauri/src/main.rs +++ b/examples/api/src-tauri/src/main.rs @@ -123,7 +123,8 @@ fn main() { }; item_handle.set_title(new_title).unwrap(); } - "new" => app + "new" => { + app .create_window( "new", WindowUrl::App("index.html".into()), @@ -131,7 +132,8 @@ fn main() { (window_builder.title("Tauri"), webview_attributes) }, ) - .unwrap(), + .unwrap(); + }, #[cfg(target_os = "macos")] "icon_1" => { app.tray_handle().set_icon_as_template(true).unwrap(); diff --git a/examples/api/src/components/Dialog.svelte b/examples/api/src/components/Dialog.svelte index 0d3fad0fc..76765f256 100644 --- a/examples/api/src/components/Dialog.svelte +++ b/examples/api/src/components/Dialog.svelte @@ -22,6 +22,7 @@ function openDialog() { open({ + title: 'My wonderful open dialog', defaultPath, filters: filter ? [ @@ -69,6 +70,7 @@ function saveDialog() { save({ + title: 'My wonderful save dialog', defaultPath, filters: filter ? [ diff --git a/tooling/api/src/dialog.ts b/tooling/api/src/dialog.ts index 6b4a3e918..554934096 100644 --- a/tooling/api/src/dialog.ts +++ b/tooling/api/src/dialog.ts @@ -43,6 +43,8 @@ interface DialogFilter { /** Options for the open dialog. */ interface OpenDialogOptions { + /** The title of the dialog window. */ + title?: string /** The filters of the dialog. */ filters?: DialogFilter[] /** Initial directory or file path. */ @@ -55,6 +57,8 @@ interface OpenDialogOptions { /** Options for the save dialog. */ interface SaveDialogOptions { + /** The title of the dialog window. */ + title?: string /** The filters of the dialog. */ filters?: DialogFilter[] /**