|
| 1 | +using System; |
1 | 2 | using System.Collections.Generic;
|
2 | 3 | using System.Linq;
|
3 | 4 | using System.Runtime.InteropServices;
|
@@ -38,14 +39,22 @@ public void Localize()
|
38 | 39 | return;
|
39 | 40 | }
|
40 | 41 |
|
41 |
| - foreach (var kvp in _items) |
| 42 | + foreach (var kvp in _items.Where(kv => kv.Key != null && kv.Value != null)) |
42 | 43 | {
|
43 |
| - var item = kvp; |
44 |
| - UiDispatcher.Invoke(() => |
| 44 | + try |
45 | 45 | {
|
46 |
| - item.Value.Caption = item.Key.Caption.Invoke(); |
47 |
| - item.Value.TooltipText = item.Key.ToolTipText.Invoke(); |
48 |
| - }); |
| 46 | + var item = kvp; |
| 47 | + UiDispatcher.Invoke(() => |
| 48 | + { |
| 49 | + item.Value.Caption = item.Key.Caption.Invoke(); |
| 50 | + item.Value.TooltipText = item.Key.ToolTipText.Invoke(); |
| 51 | + }); |
| 52 | + |
| 53 | + } |
| 54 | + catch (Exception e) |
| 55 | + { |
| 56 | + Logger.Error(e, $"Assignment of {kvp.Value.GetType().Name}.Caption or .TooltipText for {kvp.Key.GetType().Name} threw an exception."); |
| 57 | + } |
49 | 58 | }
|
50 | 59 | }
|
51 | 60 |
|
@@ -92,17 +101,23 @@ private ICommandBarControl InitializeChildControl(ICommandMenuItem item)
|
92 | 101 |
|
93 | 102 | public void EvaluateCanExecute(RubberduckParserState state)
|
94 | 103 | {
|
95 |
| - foreach (var kvp in _items) |
| 104 | + foreach (var kvp in _items.Where(kv => kv.Key != null && kv.Value != null)) |
96 | 105 | {
|
97 | 106 | var commandItem = kvp.Key;
|
98 |
| - if (commandItem != null && kvp.Value != null) |
| 107 | + var canExecute = false; |
| 108 | + try |
99 | 109 | {
|
100 |
| - var canExecute = commandItem.EvaluateCanExecute(state); |
101 |
| - kvp.Value.IsEnabled = canExecute; |
102 |
| - if (commandItem.HiddenWhenDisabled) |
103 |
| - { |
104 |
| - kvp.Value.IsVisible = canExecute; |
105 |
| - } |
| 110 | + canExecute = commandItem.EvaluateCanExecute(state); |
| 111 | + |
| 112 | + } |
| 113 | + catch (Exception e) |
| 114 | + { |
| 115 | + Logger.Error(e, $"{commandItem?.GetType().Name ?? nameof(ICommandMenuItem)}.EvaluateCanExecute(RubberduckParserState) threw an exception."); |
| 116 | + } |
| 117 | + kvp.Value.IsEnabled = canExecute; |
| 118 | + if (commandItem?.HiddenWhenDisabled ?? false) |
| 119 | + { |
| 120 | + kvp.Value.IsVisible = canExecute; |
106 | 121 | }
|
107 | 122 | }
|
108 | 123 | }
|
|
0 commit comments