mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-01 03:02:28 +03:00
parent
9014fe88b6
commit
ce03909fb6
@ -70,6 +70,12 @@ impl FileDialogBuilder {
|
|||||||
self
|
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.
|
/// Pick one file.
|
||||||
pub fn pick_file<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F) {
|
pub fn pick_file<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F) {
|
||||||
run_dialog!(self.0.pick_file(), f)
|
run_dialog!(self.0.pick_file(), f)
|
||||||
|
@ -26,6 +26,8 @@ pub struct DialogFilter {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct OpenDialogOptions {
|
pub struct OpenDialogOptions {
|
||||||
|
/// The title of the dialog window.
|
||||||
|
pub title: Option<String>,
|
||||||
/// The filters of the dialog.
|
/// The filters of the dialog.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub filters: Vec<DialogFilter>,
|
pub filters: Vec<DialogFilter>,
|
||||||
@ -43,6 +45,8 @@ pub struct OpenDialogOptions {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct SaveDialogOptions {
|
pub struct SaveDialogOptions {
|
||||||
|
/// The title of the dialog window.
|
||||||
|
pub title: Option<String>,
|
||||||
/// The filters of the dialog.
|
/// The filters of the dialog.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub filters: Vec<DialogFilter>,
|
pub filters: Vec<DialogFilter>,
|
||||||
@ -156,6 +160,9 @@ pub fn open<R: Runtime>(
|
|||||||
let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect();
|
let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect();
|
||||||
dialog_builder = dialog_builder.add_filter(filter.name, &extensions);
|
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();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
@ -189,6 +196,10 @@ pub fn save<R: Runtime>(
|
|||||||
let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect();
|
let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect();
|
||||||
dialog_builder = dialog_builder.add_filter(filter.name, &extensions);
|
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();
|
let (tx, rx) = channel();
|
||||||
dialog_builder.save_file(move |p| tx.send(p).unwrap());
|
dialog_builder.save_file(move |p| tx.send(p).unwrap());
|
||||||
Ok(rx.recv().unwrap().into())
|
Ok(rx.recv().unwrap().into())
|
||||||
|
@ -123,7 +123,8 @@ fn main() {
|
|||||||
};
|
};
|
||||||
item_handle.set_title(new_title).unwrap();
|
item_handle.set_title(new_title).unwrap();
|
||||||
}
|
}
|
||||||
"new" => app
|
"new" => {
|
||||||
|
app
|
||||||
.create_window(
|
.create_window(
|
||||||
"new",
|
"new",
|
||||||
WindowUrl::App("index.html".into()),
|
WindowUrl::App("index.html".into()),
|
||||||
@ -131,7 +132,8 @@ fn main() {
|
|||||||
(window_builder.title("Tauri"), webview_attributes)
|
(window_builder.title("Tauri"), webview_attributes)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap();
|
||||||
|
},
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
"icon_1" => {
|
"icon_1" => {
|
||||||
app.tray_handle().set_icon_as_template(true).unwrap();
|
app.tray_handle().set_icon_as_template(true).unwrap();
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
function openDialog() {
|
function openDialog() {
|
||||||
open({
|
open({
|
||||||
|
title: 'My wonderful open dialog',
|
||||||
defaultPath,
|
defaultPath,
|
||||||
filters: filter
|
filters: filter
|
||||||
? [
|
? [
|
||||||
@ -69,6 +70,7 @@
|
|||||||
|
|
||||||
function saveDialog() {
|
function saveDialog() {
|
||||||
save({
|
save({
|
||||||
|
title: 'My wonderful save dialog',
|
||||||
defaultPath,
|
defaultPath,
|
||||||
filters: filter
|
filters: filter
|
||||||
? [
|
? [
|
||||||
|
@ -43,6 +43,8 @@ interface DialogFilter {
|
|||||||
|
|
||||||
/** Options for the open dialog. */
|
/** Options for the open dialog. */
|
||||||
interface OpenDialogOptions {
|
interface OpenDialogOptions {
|
||||||
|
/** The title of the dialog window. */
|
||||||
|
title?: string
|
||||||
/** The filters of the dialog. */
|
/** The filters of the dialog. */
|
||||||
filters?: DialogFilter[]
|
filters?: DialogFilter[]
|
||||||
/** Initial directory or file path. */
|
/** Initial directory or file path. */
|
||||||
@ -55,6 +57,8 @@ interface OpenDialogOptions {
|
|||||||
|
|
||||||
/** Options for the save dialog. */
|
/** Options for the save dialog. */
|
||||||
interface SaveDialogOptions {
|
interface SaveDialogOptions {
|
||||||
|
/** The title of the dialog window. */
|
||||||
|
title?: string
|
||||||
/** The filters of the dialog. */
|
/** The filters of the dialog. */
|
||||||
filters?: DialogFilter[]
|
filters?: DialogFilter[]
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user