|
6 | 6 | using Microsoft.Vbe.Interop; |
7 | 7 | using Rubberduck.Parsing.Symbols; |
8 | 8 | using Rubberduck.Parsing.VBA; |
| 9 | +using Rubberduck.UI.Command.MenuItems; |
9 | 10 | using Rubberduck.UI.Controls; |
10 | 11 | using Rubberduck.VBEditor; |
11 | 12 |
|
12 | 13 | namespace Rubberduck.UI.Command |
13 | 14 | { |
14 | | - public interface IShowParserErrorsCommand : ICommand { } |
| 15 | + public interface IShowParserErrorsCommand : ICommand, IDisposable { } |
15 | 16 |
|
16 | 17 | [ComVisible(false)] |
17 | 18 | public class ShowParserErrorsCommand : CommandBase, IShowParserErrorsCommand |
18 | 19 | { |
| 20 | + private readonly VBE _vbe; |
19 | 21 | private readonly INavigateCommand _navigateCommand; |
20 | 22 | private readonly RubberduckParserState _state; |
21 | 23 | private readonly ISearchResultsWindowViewModel _viewModel; |
22 | 24 | private readonly SearchResultPresenterInstanceManager _presenterService; |
23 | 25 |
|
24 | | - public ShowParserErrorsCommand(INavigateCommand navigateCommand, RubberduckParserState state, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService) |
| 26 | + public ShowParserErrorsCommand(VBE vbe, INavigateCommand navigateCommand, RubberduckParserState state, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService) |
25 | 27 | { |
| 28 | + _vbe = vbe; |
26 | 29 | _navigateCommand = navigateCommand; |
27 | 30 | _state = state; |
28 | 31 | _viewModel = viewModel; |
29 | 32 | _presenterService = presenterService; |
| 33 | + |
| 34 | + _state.StateChanged += _state_StateChanged; |
30 | 35 | } |
31 | 36 |
|
32 | | - public override void Execute(object parameter) |
| 37 | + private void _state_StateChanged(object sender, ParserStateEventArgs e) |
33 | 38 | { |
34 | | - if (_state.Status != ParserState.Error) |
35 | | - { |
36 | | - return; |
37 | | - } |
| 39 | + if (_viewModel == null) { return; } |
38 | 40 |
|
39 | | - var viewModel = CreateViewModel(); |
| 41 | + if (_state.Status != ParserState.Error && _state.Status != ParserState.Parsed) { return; } |
| 42 | + |
| 43 | + UiDispatcher.InvokeAsync(UpdateTab); |
| 44 | + } |
| 45 | + |
| 46 | + private void UpdateTab() |
| 47 | + { |
40 | 48 | if (_viewModel == null) |
41 | 49 | { |
42 | 50 | return; |
43 | 51 | } |
44 | 52 |
|
45 | 53 | var oldTab = _viewModel.Tabs.FirstOrDefault(tab => tab.Header == RubberduckUI.Parser_ParserError); |
46 | | - |
47 | | - _viewModel.AddTab(viewModel); |
48 | | - _viewModel.SelectedTab = viewModel; |
| 54 | + if (_state.Status == ParserState.Error) |
| 55 | + { |
| 56 | + var viewModel = CreateViewModel(); |
| 57 | + _viewModel.AddTab(viewModel); |
| 58 | + _viewModel.SelectedTab = viewModel; |
| 59 | + } |
49 | 60 |
|
50 | 61 | if (oldTab != null) |
51 | 62 | { |
52 | 63 | oldTab.CloseCommand.Execute(null); |
53 | 64 | } |
| 65 | + } |
| 66 | + |
| 67 | + public override void Execute(object parameter) |
| 68 | + { |
| 69 | + if (_viewModel == null) |
| 70 | + { |
| 71 | + return; |
| 72 | + } |
54 | 73 |
|
55 | 74 | try |
56 | 75 | { |
@@ -90,5 +109,13 @@ private Declaration FindModuleDeclaration(VBComponent component) |
90 | 109 | var declaration = new Declaration(new QualifiedMemberName(new QualifiedModuleName(component), component.Name), project, project == null ? null : project.Scope, component.Name, null, false, false, Accessibility.Global, DeclarationType.ProceduralModule, false, null, false); |
91 | 110 | return result ?? declaration; // module isn't in parser state - give it a dummy declaration, just so the ViewModel has something to chew on |
92 | 111 | } |
| 112 | + |
| 113 | + public void Dispose() |
| 114 | + { |
| 115 | + if (_state != null) |
| 116 | + { |
| 117 | + _state.StateChanged += _state_StateChanged; |
| 118 | + } |
| 119 | + } |
93 | 120 | } |
94 | 121 | } |
0 commit comments