Skip to content

Commit bcd87f2

Browse files
authored
Merge pull request #4044 from Vogel612/windows-forms-purge
Follow Up to 4006
2 parents 38be737 + 114589e commit bcd87f2

File tree

8 files changed

+79
-35
lines changed

8 files changed

+79
-35
lines changed

Rubberduck.Core/App.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void ApplyCultureConfig()
153153
{
154154
Logger.Error(exception, "Error Setting Culture for Rubberduck");
155155
// not accessing resources here, because setting resource culture literally just failed.
156-
_messageBox.NotifyError(exception.Message, "Rubberduck");
156+
_messageBox.NotifyWarn(exception.Message, "Rubberduck");
157157
_config.UserSettings.GeneralSettings.Language.Code = currentCulture.Name;
158158
_configService.SaveConfiguration(_config);
159159
}

Rubberduck.Core/UI/CodeExplorer/Commands/RemoveCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ protected override bool EvaluateCanExecute(object parameter)
5757
protected override void OnExecute(object parameter)
5858
{
5959
var message = string.Format(CodeExplorerUI.ExportBeforeRemove_Prompt, ((CodeExplorerComponentViewModel)parameter).Name);
60-
var result = _messageBox.Confirm(message, CodeExplorerUI.ExportBeforeRemove_Caption, true);
60+
var result = _messageBox.Confirm(message, CodeExplorerUI.ExportBeforeRemove_Caption, ConfirmationOutcome.Yes);
6161

62-
if (!result.HasValue)
62+
if (result == ConfirmationOutcome.Cancel)
6363
{
6464
return;
6565
}
6666

67-
if (result.Value && !ExportFile((CodeExplorerComponentViewModel)parameter))
67+
if (result == ConfirmationOutcome.Yes && !ExportFile((CodeExplorerComponentViewModel)parameter))
6868
{
6969
return;
7070
}

Rubberduck.Interaction/IMessageBox.cs

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,49 @@ namespace Rubberduck.Interaction
55
{
66
public interface IMessageBox
77
{
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>
812
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>
1018
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>
1126
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
1551
}
1652

1753
public class MessageBox : IMessageBox
@@ -21,11 +57,6 @@ public void Message(string text)
2157
Forms.MessageBox.Show(text);
2258
}
2359

24-
public void NotifyError(string text, string caption)
25-
{
26-
Forms.MessageBox.Show(text, caption, Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Error);
27-
}
28-
2960
public void NotifyWarn(string text, string caption)
3061
{
3162
Forms.MessageBox.Show(text, caption, Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Exclamation);
@@ -46,22 +77,35 @@ public bool ConfirmYesNo(string text, string caption, bool suggestion)
4677
return Forms.MessageBox.Show(text, caption, Forms.MessageBoxButtons.YesNo, Forms.MessageBoxIcon.Exclamation, suggestion ? Forms.MessageBoxDefaultButton.Button1 : Forms.MessageBoxDefaultButton.Button2) == Forms.DialogResult.Yes;
4778
}
4879

49-
public bool? Confirm(string text, string caption, bool? suggestion)
80+
public ConfirmationOutcome Confirm(string text, string caption, ConfirmationOutcome suggestion = ConfirmationOutcome.Yes)
5081
{
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+
}
5297
var result = Forms.MessageBox.Show(text, caption, Forms.MessageBoxButtons.YesNoCancel, Forms.MessageBoxIcon.Exclamation, suggestionButton);
5398

5499
switch (result)
55100
{
56101
case Forms.DialogResult.Cancel:
57-
return null;
102+
return ConfirmationOutcome.Cancel;
58103
case Forms.DialogResult.Yes:
59-
return true;
104+
return ConfirmationOutcome.Yes;
60105
case Forms.DialogResult.No:
61-
return false;
106+
return ConfirmationOutcome.No;
62107
default:
63108
return suggestion;
64-
65109
}
66110
}
67111
}

RubberduckTests/CodeExplorer/CodeExplorerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public void RemoveCommand_RemovesModuleWhenPromptOk()
773773
saveFileDialog.Setup(o => o.ShowDialog()).Returns(DialogResult.OK);
774774

775775
var messageBox = new Mock<IMessageBox>();
776-
messageBox.Setup(m => m.Confirm(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool?>())).Returns(true);
776+
messageBox.Setup(m => m.Confirm(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ConfirmationOutcome>())).Returns(ConfirmationOutcome.Yes);
777777

778778
var projectRepository = new ProjectsRepository(vbe.Object);
779779
using (var state = new RubberduckParserState(vbe.Object, projectRepository, new DeclarationFinderFactory(), vbeEvents.Object))
@@ -859,7 +859,7 @@ public void RemoveCommand_GivenMsgBoxNO_RemovesModuleNoExport()
859859
saveFileDialog.Setup(o => o.ShowDialog()).Returns(DialogResult.OK);
860860

861861
var messageBox = new Mock<IMessageBox>();
862-
messageBox.Setup(m => m.Confirm(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool?>())).Returns(false);
862+
messageBox.Setup(m => m.Confirm(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ConfirmationOutcome>())).Returns(ConfirmationOutcome.No);
863863

864864
var projectRepository = new ProjectsRepository(vbe.Object);
865865
using (var state = new RubberduckParserState(vbe.Object, projectRepository, new DeclarationFinderFactory(), vbeEvents.Object))
@@ -902,7 +902,7 @@ public void RemoveModule_Cancel()
902902
saveFileDialog.Setup(o => o.OverwritePrompt);
903903

904904
var messageBox = new Mock<IMessageBox>();
905-
messageBox.Setup(m => m.Confirm(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns((bool?)null);
905+
messageBox.Setup(m => m.Confirm(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ConfirmationOutcome>())).Returns(ConfirmationOutcome.Cancel);
906906

907907
var projectRepository = new ProjectsRepository(vbe.Object);
908908
using (var state = new RubberduckParserState(vbe.Object, projectRepository, new DeclarationFinderFactory(), vbeEvents.Object))

RubberduckTests/Refactoring/IntroduceParameterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ Dim fizz As Date
630630
{
631631

632632
var messageBox = new Mock<IMessageBox>();
633-
messageBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>())).Returns(false);
633+
messageBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(false);
634634

635635
var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object);
636636

RubberduckTests/Refactoring/RemoveParametersTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ Private Sub IClass1_DoSomething(ByVal a As Integer)
18641864
var module2 = project.Object.VBComponents[1].CodeModule;
18651865

18661866
var messageBox = new Mock<IMessageBox>();
1867-
messageBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
1867+
messageBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(true);
18681868

18691869
//Specify Params to remove
18701870
var model = new RemoveParametersModel(state, qualifiedSelection, messageBox.Object);
@@ -1910,7 +1910,7 @@ Private Sub IClass1_DoSomething(ByVal a As Integer, ByVal b As String)
19101910
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(project.Object.VBComponents[0]), selection);
19111911

19121912
var messageBox = new Mock<IMessageBox>();
1913-
messageBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>())).Returns(false);
1913+
messageBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(false);
19141914

19151915
//Specify Params to remove
19161916
var model = new RemoveParametersModel(state, qualifiedSelection, messageBox.Object);

RubberduckTests/Refactoring/RenameTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ End Sub"
12321232
};
12331233
PerformExpectedVersusActualRenameTests(tdo, inputOutput1, inputOutputWithSelection, inputOutput3);
12341234

1235-
tdo.MsgBox.Verify(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
1235+
tdo.MsgBox.Verify(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()), Times.Once);
12361236
}
12371237

12381238
[Test]
@@ -1310,7 +1310,7 @@ End Sub"
13101310
};
13111311
PerformExpectedVersusActualRenameTests(tdo, inputOutput1, inputOutputWithSelection, inputOutput3);
13121312

1313-
tdo.MsgBox.Verify(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
1313+
tdo.MsgBox.Verify(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()), Times.Once);
13141314
}
13151315

13161316
[Test]
@@ -1494,7 +1494,7 @@ End Sub"
14941494
};
14951495
PerformExpectedVersusActualRenameTests(tdo, inputOutput1, inputOutput2);
14961496

1497-
tdo.MsgBox.Verify(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
1497+
tdo.MsgBox.Verify(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()), Times.Once);
14981498
}
14991499

15001500
[Test]
@@ -1524,7 +1524,7 @@ End Sub"
15241524
tdo.MsgBoxReturn = DialogResult.No;
15251525
PerformExpectedVersusActualRenameTests(tdo, inputOutput1, inputOutput2);
15261526

1527-
tdo.MsgBox.Verify(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
1527+
tdo.MsgBox.Verify(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()), Times.Once);
15281528
}
15291529

15301530
#endregion
@@ -1634,7 +1634,7 @@ public void RenameRefactoring_RenameCodeModule()
16341634
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);
16351635

16361636
var msgbox = new Mock<IMessageBox>();
1637-
msgbox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
1637+
msgbox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(true);
16381638

16391639
var vbeWrapper = vbe.Object;
16401640
var model = new RenameModel(vbeWrapper, state, qualifiedSelection) { NewName = newName };
@@ -1671,7 +1671,7 @@ public void RenameRefactoring_RenameProject()
16711671
{
16721672

16731673
var msgbox = new Mock<IMessageBox>();
1674-
msgbox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
1674+
msgbox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(true);
16751675

16761676
var vbeWrapper = vbe.Object;
16771677
var model = new RenameModel(vbeWrapper, state, default(QualifiedSelection)) { NewName = newName };
@@ -2280,7 +2280,7 @@ public void RenameRefactoring_RenameClassModule_DoesNotChangeMeReferences()
22802280
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);
22812281

22822282
var msgbox = new Mock<IMessageBox>();
2283-
msgbox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
2283+
msgbox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(true);
22842284

22852285
var vbeWrapper = vbe.Object;
22862286
var model = new RenameModel(vbeWrapper, state, qualifiedSelection) { NewName = newName };
@@ -2363,7 +2363,7 @@ private static void InitializeTestDataObject(RenameTestsDataObject tdo
23632363

23642364
tdo.MsgBox = new Mock<IMessageBox>();
23652365
// FIXME this might be a bit broken now
2366-
tdo.MsgBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>())).Returns(tdo.MsgBoxReturn == DialogResult.Yes);
2366+
tdo.MsgBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(tdo.MsgBoxReturn == DialogResult.Yes);
23672367

23682368
tdo.VBE = tdo.VBE ?? BuildProject(tdo.ProjectName, tdo.ModuleTestSetupDefs);
23692369
tdo.ParserState = MockParser.CreateAndParse(tdo.VBE, testLibraries: testLibraries);

RubberduckTests/Refactoring/ReorderParametersTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ Private Sub IClass1_DoSomething(ByVal b As String, ByVal a As Integer)
13911391
var module2 = project.Object.VBComponents[1].CodeModule;
13921392

13931393
var messageBox = new Mock<IMessageBox>();
1394-
messageBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
1394+
messageBox.Setup(m => m.ConfirmYesNo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(true);
13951395

13961396
//Specify Params to remove
13971397
var model = new ReorderParametersModel(state, qualifiedSelection, messageBox.Object);
@@ -1438,7 +1438,7 @@ Private Sub IClass1_DoSomething(ByVal a As Integer, ByVal b As String)
14381438
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(project.Object.VBComponents[0]), selection);
14391439

14401440
var messageBox = new Mock<IMessageBox>();
1441-
messageBox.Setup(m => m.Confirm(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool?>())).Returns(false);
1441+
messageBox.Setup(m => m.Confirm(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ConfirmationOutcome>())).Returns(ConfirmationOutcome.No);
14421442

14431443
//Specify Params to remove
14441444
var model = new ReorderParametersModel(state, qualifiedSelection, messageBox.Object);

0 commit comments

Comments
 (0)