forked from bytecode77/bytecode-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageBoxes.cs
More file actions
141 lines (137 loc) · 7.69 KB
/
MessageBoxes.cs
File metadata and controls
141 lines (137 loc) · 7.69 KB
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
using System.Windows;
namespace BytecodeApi.UI.Dialogs
{
/// <summary>
/// Helper class for dialogs using the <see cref="MessageBox" /> class.
/// </summary>
public static class MessageBoxes
{
/// <summary>
/// Gets or sets the <see cref="Window" /> object that is used as the owner parameter for calls to the <see cref="MessageBox" /> class. If <see cref="Window" /> is <see langword="null" />, no owner is specified.
/// </summary>
public static Window Window { get; set; }
/// <summary>
/// Gets or sets the caption for message boxes shown by the <see cref="Information" /> method. The initial value is "Information".
/// </summary>
public static string CaptionForInformation { get; set; }
/// <summary>
/// Gets or sets the caption for message boxes shown by the <see cref="Confirmation(string)" /> method. The initial value is "Confirmation".
/// </summary>
public static string CaptionForConfirmation { get; set; }
/// <summary>
/// Gets or sets the caption for message boxes shown by the <see cref="Warning" /> method. The initial value is "Warning".
/// </summary>
public static string CaptionForWarning { get; set; }
/// <summary>
/// Gets or sets the caption for message boxes shown by the <see cref="Error" /> method. The initial value is "Error".
/// </summary>
public static string CaptionForError { get; set; }
static MessageBoxes()
{
CaptionForInformation = "Information";
CaptionForConfirmation = "Confirmation";
CaptionForWarning = "Warning";
CaptionForError = "Error";
}
/// <summary>
/// Shows a <see cref="MessageBox" /> dialog with the specified message, using <see cref="CaptionForInformation" /> as title and an "OK" button. The title is a static <see cref="string" /> value, set to "Information" by default.
/// </summary>
/// <param name="message">A <see cref="string" /> specifying the message to be displayed.</param>
public static void Information(string message)
{
ShowMessageBox(message, CaptionForInformation, MessageBoxButton.OK, MessageBoxImage.Information);
}
/// <summary>
/// Shows a <see cref="MessageBox" /> dialog with the specified message, using <see cref="CaptionForConfirmation" /> as title and "Yes" and "No" buttons. The title is a static <see cref="string" /> value, set to "Confirmation" by default.
/// </summary>
/// <param name="message">A <see cref="string" /> specifying the message to be displayed.</param>
/// <returns>
/// <see langword="true" />, if "Yes" has been selected;
/// otherwise, <see langword="false" />.
/// </returns>
public static bool Confirmation(string message)
{
return Confirmation(message, false);
}
/// <summary>
/// Shows a <see cref="MessageBox" /> dialog with the specified message, using <see cref="CaptionForConfirmation" /> as title and "Yes" and "No" buttons. The title is a static <see cref="string" /> value, set to "Confirmation" by default.
/// </summary>
/// <param name="message">A <see cref="string" /> specifying the message to be displayed.</param>
/// <param name="isWarning"><see langword="true" /> to use the warning icon; <see langword="false" /> to use the information icon.</param>
/// <returns>
/// <see langword="true" />, if "Yes" has been selected;
/// otherwise, <see langword="false" />.
/// </returns>
public static bool Confirmation(string message, bool isWarning)
{
return Confirmation(message, isWarning, false);
}
/// <summary>
/// Shows a <see cref="MessageBox" /> dialog with the specified message, using <see cref="CaptionForConfirmation" /> as title and "Yes" and "No" buttons. The title is a static <see cref="string" /> value, set to "Confirmation" by default.
/// </summary>
/// <param name="message">A <see cref="string" /> specifying the message to be displayed.</param>
/// <param name="isWarning"><see langword="true" /> to use the warning icon; <see langword="false" /> to use the information icon.</param>
/// <param name="useOkCancel"><see langword="true" /> to use "Yes" and "No"; <see langword="false" /> to use "OK" and "Cancel" buttons.</param>
/// <returns>
/// <see langword="true" />, if "Yes" or "OK" has been selected;
/// otherwise, <see langword="false" />.
/// </returns>
public static bool Confirmation(string message, bool isWarning, bool useOkCancel)
{
return ShowMessageBox(message, CaptionForConfirmation, useOkCancel ? MessageBoxButton.OKCancel : MessageBoxButton.YesNo, isWarning ? MessageBoxImage.Warning : MessageBoxImage.Question) == (useOkCancel ? MessageBoxResult.OK : MessageBoxResult.Yes);
}
/// <summary>
/// Shows a <see cref="MessageBox" /> dialog with the specified message, using <see cref="CaptionForConfirmation" /> as title and "Yes", "No" and "Cancel" buttons. The title is a static <see cref="string" /> value, set to "Confirmation" by default.
/// </summary>
/// <param name="message">A <see cref="string" /> specifying the message to be displayed.</param>
/// <returns>
/// <see langword="true" />, if "Yes" has been selected;
/// <see langword="false" />, if "No" has been selected;
/// <see langword="null" />, if "Cancel" has been selected.
/// </returns>
public static bool? ConfirmationWithCancel(string message)
{
return ConfirmationWithCancel(message, false);
}
/// <summary>
/// Shows a <see cref="MessageBox" /> dialog with the specified message, using <see cref="CaptionForConfirmation" /> as title and "Yes", "No" and "Cancel" buttons. The title is a static <see cref="string" /> value, set to "Confirmation" by default.
/// </summary>
/// <param name="message">A <see cref="string" /> specifying the message to be displayed.</param>
/// <param name="isWarning"><see langword="true" /> to use the warning icon; <see langword="false" /> to use the information icon.</param>
/// <returns>
/// <see langword="true" />, if "Yes" has been selected;
/// <see langword="false" />, if "No" has been selected;
/// <see langword="null" />, if "Cancel" has been selected.
/// </returns>
public static bool? ConfirmationWithCancel(string message, bool isWarning)
{
switch (ShowMessageBox(message, CaptionForConfirmation, MessageBoxButton.YesNoCancel, isWarning ? MessageBoxImage.Warning : MessageBoxImage.Question))
{
case MessageBoxResult.Yes: return true;
case MessageBoxResult.No: return false;
default: return null;
}
}
/// <summary>
/// Shows a <see cref="MessageBox" /> dialog with the specified message, using <see cref="CaptionForWarning" /> as title and an "OK" button. The title is a static <see cref="string" /> value, set to "Warning" by default.
/// </summary>
/// <param name="message">A <see cref="string" /> specifying the message to be displayed.</param>
public static void Warning(string message)
{
ShowMessageBox(message, CaptionForWarning, MessageBoxButton.OK, MessageBoxImage.Warning);
}
/// <summary>
/// Shows a <see cref="MessageBox" /> dialog with the specified message, using <see cref="CaptionForError" /> as title and an "OK" button. The title is a static <see cref="string" /> value, set to "Error" by default.
/// </summary>
/// <param name="message">A <see cref="string" /> specifying the message to be displayed.</param>
public static void Error(string message)
{
ShowMessageBox(message, CaptionForError, MessageBoxButton.OK, MessageBoxImage.Error);
}
private static MessageBoxResult ShowMessageBox(string message, string caption, MessageBoxButton button, MessageBoxImage image)
{
if (Window == null) return MessageBox.Show(message ?? "", caption ?? "", button, image);
else return MessageBox.Show(Window, message ?? "", caption ?? "", button, image);
}
}
}