@@ -5,13 +5,49 @@ namespace Rubberduck.Interaction
5
5
{
6
6
public interface IMessageBox
7
7
{
8
+ /// <summary>
9
+ /// Show a message to the user. Will only return after the user has acknowledged the message.
10
+ /// </summary>
11
+ /// <param name="text">The message to show to the user</param>
8
12
void Message ( string text ) ;
9
- void NotifyError ( string text , string caption ) ;
13
+ /// <summary>
14
+ /// Notify the user of a warning. Will only return after the user has acknowledged the warning.
15
+ /// </summary>
16
+ /// <param name="text">The Warning text to show the user</param>
17
+ /// <param name="caption">The caption of the dialog window</param>
10
18
void NotifyWarn ( string text , string caption ) ;
19
+ /// <summary>
20
+ /// Ask the user a question. Neither user selection must have any non-reversible consequences.
21
+ /// Will only return on user-input.
22
+ /// </summary>
23
+ /// <param name="text">The Question to ask the user</param>
24
+ /// <param name="caption">The caption of the dialog window</param>
25
+ /// <returns>true, if the user selects "Yes", false if the user selects "No"</returns>
11
26
bool Question ( string text , string caption ) ;
12
- bool ConfirmYesNo ( string text , string caption ) ;
13
- bool ConfirmYesNo ( string text , string caption , bool suggestion ) ;
14
- bool ? Confirm ( string text , string caption , bool ? suggestion ) ;
27
+ /// <summary>
28
+ /// Ask the user for a simple confirmation. If the user selects an option, non-reversible consequences are acceptable.
29
+ /// Will only return on user-input.
30
+ /// </summary>
31
+ /// <param name="text">The question to ask the user</param>
32
+ /// <param name="caption">The caption of the dialog window</param>
33
+ /// <param name="suggestion">The pre-selected result for the user, defaults to <b>Yes</b></param>
34
+ /// <returns>true, if the user selects "Yes", false if the user selects "No"</returns>
35
+ bool ConfirmYesNo ( string text , string caption , bool suggestion = true ) ;
36
+ /// <summary>
37
+ /// Ask the user for a confirmation. If the user selects an option that is not "Cancel",
38
+ /// non-reversible consequences are acceptable.
39
+ /// Will only return on user-input.
40
+ /// </summary>
41
+ /// <param name="text">The question to ask the user</param>
42
+ /// <param name="caption">The caption of the dialog window</param>
43
+ /// <param name="suggestion">The pre-selected result for the user, defaults to <b>Cancel</b></param>
44
+ /// <returns>Yes, No or Cancel respectively, according to the user's input</returns>
45
+ ConfirmationOutcome Confirm ( string text , string caption , ConfirmationOutcome suggestion = ConfirmationOutcome . Cancel ) ;
46
+ }
47
+
48
+ public enum ConfirmationOutcome
49
+ {
50
+ Yes , No , Cancel
15
51
}
16
52
17
53
public class MessageBox : IMessageBox
@@ -21,11 +57,6 @@ public void Message(string text)
21
57
Forms . MessageBox . Show ( text ) ;
22
58
}
23
59
24
- public void NotifyError ( string text , string caption )
25
- {
26
- Forms . MessageBox . Show ( text , caption , Forms . MessageBoxButtons . OK , Forms . MessageBoxIcon . Error ) ;
27
- }
28
-
29
60
public void NotifyWarn ( string text , string caption )
30
61
{
31
62
Forms . MessageBox . Show ( text , caption , Forms . MessageBoxButtons . OK , Forms . MessageBoxIcon . Exclamation ) ;
@@ -46,22 +77,35 @@ public bool ConfirmYesNo(string text, string caption, bool suggestion)
46
77
return Forms . MessageBox . Show ( text , caption , Forms . MessageBoxButtons . YesNo , Forms . MessageBoxIcon . Exclamation , suggestion ? Forms . MessageBoxDefaultButton . Button1 : Forms . MessageBoxDefaultButton . Button2 ) == Forms . DialogResult . Yes ;
47
78
}
48
79
49
- public bool ? Confirm ( string text , string caption , bool ? suggestion )
80
+ public ConfirmationOutcome Confirm ( string text , string caption , ConfirmationOutcome suggestion = ConfirmationOutcome . Yes )
50
81
{
51
- var suggestionButton = suggestion . HasValue ? ( suggestion . Value ? Forms . MessageBoxDefaultButton . Button1 : Forms . MessageBoxDefaultButton . Button2 ) : Forms . MessageBoxDefaultButton . Button3 ;
82
+ Forms . MessageBoxDefaultButton suggestionButton ;
83
+ switch ( suggestion )
84
+ {
85
+ // default required to shut the compiler up about "unassigned variable"
86
+ default :
87
+ case ConfirmationOutcome . Yes :
88
+ suggestionButton = Forms . MessageBoxDefaultButton . Button1 ;
89
+ break ;
90
+ case ConfirmationOutcome . No :
91
+ suggestionButton = Forms . MessageBoxDefaultButton . Button2 ;
92
+ break ;
93
+ case ConfirmationOutcome . Cancel :
94
+ suggestionButton = Forms . MessageBoxDefaultButton . Button3 ;
95
+ break ;
96
+ }
52
97
var result = Forms . MessageBox . Show ( text , caption , Forms . MessageBoxButtons . YesNoCancel , Forms . MessageBoxIcon . Exclamation , suggestionButton ) ;
53
98
54
99
switch ( result )
55
100
{
56
101
case Forms . DialogResult . Cancel :
57
- return null ;
102
+ return ConfirmationOutcome . Cancel ;
58
103
case Forms . DialogResult . Yes :
59
- return true ;
104
+ return ConfirmationOutcome . Yes ;
60
105
case Forms . DialogResult . No :
61
- return false ;
106
+ return ConfirmationOutcome . No ;
62
107
default :
63
108
return suggestion ;
64
-
65
109
}
66
110
}
67
111
}
0 commit comments