|
| 1 | +using System; |
1 | 2 | using System.Collections.Generic;
|
2 | 3 | using Rubberduck.Navigation.CodeExplorer;
|
3 | 4 | using Rubberduck.Templates;
|
@@ -28,24 +29,49 @@ public bool CanExecuteForNode(ICodeExplorerNode model)
|
28 | 29 |
|
29 | 30 | protected override bool EvaluateCanExecute(object parameter)
|
30 | 31 | {
|
31 |
| - // TODO this cast needs to be safer. |
32 |
| - var data = ((string templateName, ICodeExplorerNode model)) parameter; |
| 32 | + if (parameter is null) |
| 33 | + { |
| 34 | + return false; |
| 35 | + } |
| 36 | + |
| 37 | + try |
| 38 | + { |
| 39 | + // TODO this cast needs to be safer. |
| 40 | + var data = ((string templateName, ICodeExplorerNode model))parameter; |
33 | 41 |
|
34 |
| - return base.EvaluateCanExecute(data.model); |
| 42 | + return base.EvaluateCanExecute(data.model); |
| 43 | + } |
| 44 | + catch (Exception ex) |
| 45 | + { |
| 46 | + Logger.Trace(ex); |
| 47 | + return false; |
| 48 | + } |
35 | 49 | }
|
36 | 50 |
|
37 | 51 | protected override void OnExecute(object parameter)
|
38 | 52 | {
|
39 |
| - // TODO this cast needs to be safer. |
40 |
| - var data = ((string templateName, ICodeExplorerNode node)) parameter; |
41 |
| - |
42 |
| - if (string.IsNullOrWhiteSpace(data.templateName) || !(data.node is CodeExplorerItemViewModel model)) |
| 53 | + if (parameter is null) |
43 | 54 | {
|
44 | 55 | return;
|
45 | 56 | }
|
46 | 57 |
|
47 |
| - var moduleText = GetTemplate(data.templateName); |
48 |
| - AddComponent(model, moduleText); |
| 58 | + try |
| 59 | + { |
| 60 | + // TODO this cast needs to be safer. |
| 61 | + var data = ((string templateName, ICodeExplorerNode node))parameter; |
| 62 | + |
| 63 | + if (string.IsNullOrWhiteSpace(data.templateName) || !(data.node is CodeExplorerItemViewModel model)) |
| 64 | + { |
| 65 | + return; |
| 66 | + } |
| 67 | + |
| 68 | + var moduleText = GetTemplate(data.templateName); |
| 69 | + AddComponent(model, moduleText); |
| 70 | + } |
| 71 | + catch (Exception ex) |
| 72 | + { |
| 73 | + Logger.Trace(ex); |
| 74 | + } |
49 | 75 | }
|
50 | 76 |
|
51 | 77 | private string GetTemplate(string name)
|
|
0 commit comments