Skip to content

Commit 629836c

Browse files
committed
Only display messagebox for error from a given source once.
1 parent b923664 commit 629836c

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

RetailCoder.VBE/UI/Command/CommandBase.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
24
using System.Runtime.InteropServices;
35
using System.Windows.Forms;
46
using System.Windows.Input;
@@ -10,6 +12,8 @@ namespace Rubberduck.UI.Command
1012
[ComVisible(false)]
1113
public abstract class CommandBase : ICommand
1214
{
15+
private static readonly List<MethodBase> ExceptionTargetSites = new List<MethodBase>();
16+
1317
protected CommandBase(ILogger logger)
1418
{
1519
_logger = logger;
@@ -33,12 +37,17 @@ public bool CanExecute(object parameter)
3337
}
3438
catch (Exception exception)
3539
{
36-
_logger.Fatal(exception);
40+
Logger.Fatal(exception);
41+
42+
if (!ExceptionTargetSites.Contains(exception.TargetSite))
43+
{
44+
ExceptionTargetSites.Add(exception.TargetSite);
3745

38-
var messageBox = new MessageBox();
39-
messageBox.Show(
40-
RubberduckUI.RubberduckFatalError, RubberduckUI.Rubberduck,
41-
MessageBoxButtons.OK, MessageBoxIcon.Error);
46+
var messageBox = new MessageBox();
47+
messageBox.Show(
48+
RubberduckUI.RubberduckFatalError, RubberduckUI.Rubberduck,
49+
MessageBoxButtons.OK, MessageBoxIcon.Error);
50+
}
4251

4352
return false;
4453
}
@@ -52,12 +61,17 @@ public void Execute(object parameter)
5261
}
5362
catch (Exception exception)
5463
{
55-
_logger.Fatal(exception);
64+
Logger.Fatal(exception);
65+
66+
if (!ExceptionTargetSites.Contains(exception.TargetSite))
67+
{
68+
ExceptionTargetSites.Add(exception.TargetSite);
5669

57-
var messageBox = new MessageBox();
58-
messageBox.Show(
59-
RubberduckUI.RubberduckFatalError, RubberduckUI.Rubberduck,
60-
MessageBoxButtons.OK, MessageBoxIcon.Error);
70+
var messageBox = new MessageBox();
71+
messageBox.Show(
72+
RubberduckUI.RubberduckFatalError, RubberduckUI.Rubberduck,
73+
MessageBoxButtons.OK, MessageBoxIcon.Error);
74+
}
6175
}
6276
}
6377

0 commit comments

Comments
 (0)