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
//! File dialog prompt options shared by `gpui` and its platform backends.
use gpui_shared_string::SharedString;
/// The options that can be configured for a file dialog prompt
#[derive(Clone, Debug)]
pub struct PathPromptOptions {
/// Should the prompt allow files to be selected?
pub files: bool,
/// Should the prompt allow directories to be selected?
pub directories: bool,
/// Should the prompt allow multiple files to be selected?
pub multiple: bool,
/// The prompt to show to a user when selecting a path
pub prompt: Option<SharedString>,
}
/// The options that can be configured for a file dialog prompt
/// What kind of prompt styling to show
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum PromptLevel {
/// A prompt that is shown when the user should be notified of something
Info,
/// A prompt that is shown when the user needs to be warned of a potential problem
Warning,
/// A prompt that is shown when a critical problem has occurred
Critical,
}
/// Prompt Button
#[derive(Clone, Debug, PartialEq)]
pub enum PromptButton {
/// Ok button
Ok(SharedString),
/// Cancel button
Cancel(SharedString),
/// Other button
Other(SharedString),
}
impl PromptButton {
/// Create a button with label
pub fn new(label: impl Into<SharedString>) -> Self {
PromptButton::Other(label.into())
}
/// Create an Ok button
pub fn ok(label: impl Into<SharedString>) -> Self {
PromptButton::Ok(label.into())
}
/// Create a Cancel button
pub fn cancel(label: impl Into<SharedString>) -> Self {
PromptButton::Cancel(label.into())
}
/// Returns true if this button is a cancel button.
#[allow(dead_code)]
pub fn is_cancel(&self) -> bool {
matches!(self, PromptButton::Cancel(_))
}
/// Returns the label of the button
pub fn label(&self) -> &SharedString {
match self {
PromptButton::Ok(label) => label,
PromptButton::Cancel(label) => label,
PromptButton::Other(label) => label,
}
}
}
impl From<&str> for PromptButton {
fn from(value: &str) -> Self {
match value.to_lowercase().as_str() {
"ok" => PromptButton::Ok("OK".into()),
"cancel" => PromptButton::Cancel("Cancel".into()),
_ => PromptButton::Other(SharedString::from(value.to_owned())),
}
}
}