forked from NickeManarin/ScreenToGif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialog.xaml.cs
182 lines (149 loc) · 5.19 KB
/
Dialog.xaml.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System;
using System.Windows;
using System.Windows.Controls;
namespace Translator;
/// <summary>
/// Interaction logic for Dialog.xaml
/// </summary>
public partial class Dialog : Window
{
/// <summary>
/// Default constructor.
/// </summary>
public Dialog()
{
InitializeComponent();
}
#region Methods
private Canvas GetIcon(Icons icon)
{
switch (icon)
{
case Icons.Error:
return (Canvas)FindResource("Vector.Error");
case Icons.Info:
return (Canvas)FindResource("Vector.Info");
case Icons.Success:
return (Canvas)FindResource("Vector.Success");
case Icons.Warning:
return (Canvas)FindResource("Vector.Warning");
case Icons.Question:
return (Canvas)FindResource("Vector.Question");
default:
return (Canvas)FindResource("Vector.Info");
}
}
private void PrepareOk(string title, string instruction, string observation, Icons icon)
{
CancelButton.Visibility = Visibility.Collapsed;
YesButton.Visibility = Visibility.Collapsed;
NoButton.Visibility = Visibility.Collapsed;
OkButton.Focus();
IconViewbox.Child = GetIcon(icon);
InstructionLabel.Content = instruction;
ObservationTextBlock.Text = observation;
Title = title;
}
private void PrepareOkCancel(string title, string instruction, string observation, Icons icon)
{
YesButton.Visibility = Visibility.Collapsed;
NoButton.Visibility = Visibility.Collapsed;
CancelButton.Focus();
IconViewbox.Child = GetIcon(icon);
InstructionLabel.Content = instruction;
ObservationTextBlock.Text = observation;
Title = title;
}
private void PrepareAsk(string title, string instruction, string observation, Icons icon)
{
CancelButton.Visibility = Visibility.Collapsed;
OkButton.Visibility = Visibility.Collapsed;
NoButton.Focus();
IconViewbox.Child = GetIcon(icon);
InstructionLabel.Content = instruction;
ObservationTextBlock.Text = observation;
Title = title;
}
/// <summary>
/// Shows a Ok dialog.
/// </summary>
/// <param name="title">The title of the window.</param>
/// <param name="instruction">The main instruction.</param>
/// <param name="observation">A complementar observation.</param>
/// <param name="icon">The image of the dialog.</param>
/// <returns>True if Ok</returns>
public static bool Ok(string title, string instruction, string observation, Icons icon = Icons.Error)
{
var dialog = new Dialog();
dialog.PrepareOk(title, instruction, observation.Replace(@"\n", Environment.NewLine).Replace(@"\r", ""), icon);
var result = dialog.ShowDialog();
return result.HasValue && result.Value;
}
/// <summary>
/// Shows a Ok/Cancel dialog.
/// </summary>
/// <param name="title">The title of the window.</param>
/// <param name="instruction">The main instruction.</param>
/// <param name="observation">A complementar observation.</param>
/// <param name="icon">The image of the dialog.</param>
/// <returns>True if Ok</returns>
public static bool OkCancel(string title, string instruction, string observation, Icons icon = Icons.Error)
{
var dialog = new Dialog();
dialog.PrepareOkCancel(title, instruction, observation.Replace(@"\n", Environment.NewLine).Replace(@"\r", ""), icon);
var result = dialog.ShowDialog();
return result.HasValue && result.Value;
}
/// <summary>
/// Shows a Yes/No dialog.
/// </summary>
/// <param name="title">The title of the window.</param>
/// <param name="instruction">The main instruction.</param>
/// <param name="observation">A complementar observation.</param>
/// <param name="icon">The image of the dialog.</param>
/// <returns>True if Yes</returns>
public static bool Ask(string title, string instruction, string observation, Icons icon = Icons.Question)
{
var dialog = new Dialog();
dialog.PrepareAsk(title, instruction, observation.Replace(@"\n", Environment.NewLine).Replace(@"\r", ""), icon);
var result = dialog.ShowDialog();
return result.HasValue && result.Value;
}
#endregion
#region Events
private void FalseActionButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void TrueActionButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
#endregion
/// <summary>
/// Dialog Icons.
/// </summary>
public enum Icons
{
/// <summary>
/// Information. Blue.
/// </summary>
Info,
/// <summary>
/// Warning, yellow.
/// </summary>
Warning,
/// <summary>
/// Error, red.
/// </summary>
Error,
/// <summary>
/// Success, green.
/// </summary>
Success,
/// <summary>
/// A question mark, blue.
/// </summary>
Question,
}
}