[feat] add dialog title option. closes #3232 (#3233)

This commit is contained in:
Jonas Kruckenberg 2022-01-16 19:41:11 +01:00 committed by GitHub
parent 9014fe88b6
commit ce03909fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 2 deletions

View File

@ -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<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F) {
run_dialog!(self.0.pick_file(), f)

View File

@ -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<String>,
/// The filters of the dialog.
#[serde(default)]
pub filters: Vec<DialogFilter>,
@ -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<String>,
/// The filters of the dialog.
#[serde(default)]
pub filters: Vec<DialogFilter>,
@ -156,6 +160,9 @@ pub fn open<R: Runtime>(
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<R: Runtime>(
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())

View File

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

View File

@ -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
? [

View File

@ -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[]
/**