1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::path::PathBuf;
use tfd::MessageBoxIcon;
use {WVResult, WebView};
#[deprecated(
note = "Please use crates like 'tinyfiledialogs' for dialog handling, see example in examples/dialog.rs"
)]
#[derive(Debug)]
pub struct DialogBuilder<'a: 'b, 'b, T: 'a> {
webview: &'b mut WebView<'a, T>,
}
impl<'a: 'b, 'b, T: 'a> DialogBuilder<'a, 'b, T> {
pub fn new(webview: &'b mut WebView<'a, T>) -> DialogBuilder<'a, 'b, T> {
DialogBuilder { webview }
}
pub fn open_file<S, P>(&mut self, title: S, default_file: P) -> WVResult<Option<PathBuf>>
where
S: Into<String>,
P: Into<PathBuf>,
{
let default_file = default_file.into().into_os_string();
let default_file = default_file
.to_str()
.expect("default_file is not valid utf-8");
let result = tfd::open_file_dialog(&title.into(), default_file, None).map(|p| p.into());
Ok(result)
}
pub fn save_file(&mut self) -> WVResult<Option<PathBuf>> {
Ok(tfd::save_file_dialog("", "").map(|p| p.into()))
}
pub fn choose_directory<S, P>(
&mut self,
title: S,
default_directory: P,
) -> WVResult<Option<PathBuf>>
where
S: Into<String>,
P: Into<PathBuf>,
{
let default_directory = default_directory.into().into_os_string();
let default_directory = default_directory
.to_str()
.expect("default_directory is not valid utf-8");
let result = tfd::select_folder_dialog(&title.into(), default_directory).map(|p| p.into());
Ok(result)
}
pub fn info<TS, MS>(&mut self, title: TS, message: MS) -> WVResult
where
TS: Into<String>,
MS: Into<String>,
{
tfd::message_box_ok(&title.into(), &message.into(), MessageBoxIcon::Info);
Ok(())
}
pub fn warning<TS, MS>(&mut self, title: TS, message: MS) -> WVResult
where
TS: Into<String>,
MS: Into<String>,
{
tfd::message_box_ok(&title.into(), &message.into(), MessageBoxIcon::Warning);
Ok(())
}
pub fn error<TS, MS>(&mut self, title: TS, message: MS) -> WVResult
where
TS: Into<String>,
MS: Into<String>,
{
tfd::message_box_ok(&title.into(), &message.into(), MessageBoxIcon::Error);
Ok(())
}
}