mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 12:27:16 +03:00
parent
9014fe88b6
commit
ce03909fb6
@ -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)
|
||||
|
@ -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())
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
? [
|
||||
|
@ -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[]
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user