|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Globalization;
|
4 | 4 | using System.Linq;
|
| 5 | +using System.Runtime.InteropServices; |
5 | 6 | using Rubberduck.Resources;
|
6 | 7 | using Rubberduck.Parsing;
|
7 | 8 | using Rubberduck.Parsing.Symbols;
|
@@ -99,30 +100,49 @@ public void SetStatusLabelCaption(ParserState state, int? errorCount = null)
|
99 | 100 |
|
100 | 101 | private void SetStatusLabelCaption(string caption, int? errorCount = null)
|
101 | 102 | {
|
102 |
| - var reparseCommandButton = FindChildByTag(typeof(ReparseCommandMenuItem).FullName) as ReparseCommandMenuItem; |
103 |
| - if (reparseCommandButton == null) { return; } |
104 |
| - |
105 |
| - var showErrorsCommandButton = FindChildByTag(typeof(ShowParserErrorsCommandMenuItem).FullName) as ShowParserErrorsCommandMenuItem; |
106 |
| - if (showErrorsCommandButton == null) { return; } |
107 |
| - |
108 |
| - _uiDispatcher.Invoke(() => |
| 103 | + //This try-catch block guarantees that problems with the COM registration of the command bar classes |
| 104 | + //only affect the status label text instead of aborting the status change or even crashing the host. |
| 105 | + //See issue #5349 at https://github.com/rubberduck-vba/Rubberduck/issues/5349 |
| 106 | + try |
109 | 107 | {
|
110 |
| - try |
| 108 | + var reparseCommandButton = |
| 109 | + FindChildByTag(typeof(ReparseCommandMenuItem).FullName) as ReparseCommandMenuItem; |
| 110 | + if (reparseCommandButton == null) |
111 | 111 | {
|
112 |
| - reparseCommandButton.SetCaption(caption); |
113 |
| - reparseCommandButton.SetToolTip(string.Format(RubberduckUI.ReparseToolTipText, caption)); |
114 |
| - if (errorCount.HasValue && errorCount.Value > 0) |
115 |
| - { |
116 |
| - showErrorsCommandButton.SetToolTip( |
117 |
| - string.Format(RubberduckUI.ParserErrorToolTipText, errorCount.Value)); |
118 |
| - } |
| 112 | + return; |
119 | 113 | }
|
120 |
| - catch (Exception exception) |
| 114 | + |
| 115 | + var showErrorsCommandButton = |
| 116 | + FindChildByTag(typeof(ShowParserErrorsCommandMenuItem).FullName) as ShowParserErrorsCommandMenuItem; |
| 117 | + if (showErrorsCommandButton == null) |
121 | 118 | {
|
122 |
| - Logger.Error(exception, "Exception thrown trying to set the status label caption on the UI thread."); |
| 119 | + return; |
123 | 120 | }
|
124 |
| - }); |
125 |
| - Localize(); |
| 121 | + |
| 122 | + _uiDispatcher.Invoke(() => |
| 123 | + { |
| 124 | + try |
| 125 | + { |
| 126 | + reparseCommandButton.SetCaption(caption); |
| 127 | + reparseCommandButton.SetToolTip(string.Format(RubberduckUI.ReparseToolTipText, caption)); |
| 128 | + if (errorCount.HasValue && errorCount.Value > 0) |
| 129 | + { |
| 130 | + showErrorsCommandButton.SetToolTip( |
| 131 | + string.Format(RubberduckUI.ParserErrorToolTipText, errorCount.Value)); |
| 132 | + } |
| 133 | + } |
| 134 | + catch (Exception exception) |
| 135 | + { |
| 136 | + Logger.Error(exception, |
| 137 | + "Exception thrown trying to set the status label caption on the UI thread."); |
| 138 | + } |
| 139 | + }); |
| 140 | + Localize(); |
| 141 | + } |
| 142 | + catch (COMException exception) |
| 143 | + { |
| 144 | + Logger.Error(exception, "COMException thrown trying to set the status label caption."); |
| 145 | + } |
126 | 146 | }
|
127 | 147 |
|
128 | 148 | private void SetContextSelectionCaption(string caption, int contextReferenceCount, string description)
|
|
0 commit comments