Skip to content

Commit 8242ad4

Browse files
Hosch250retailcoder
authored andcommitted
Refresh parser error state when parser refreshes. (#1678)
* Refresh parser errors view on state changed. * Tweak the implementation
1 parent 142de1a commit 8242ad4

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

RetailCoder.VBE/UI/Command/ShowParserErrorsCommand.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,70 @@
66
using Microsoft.Vbe.Interop;
77
using Rubberduck.Parsing.Symbols;
88
using Rubberduck.Parsing.VBA;
9+
using Rubberduck.UI.Command.MenuItems;
910
using Rubberduck.UI.Controls;
1011
using Rubberduck.VBEditor;
1112

1213
namespace Rubberduck.UI.Command
1314
{
14-
public interface IShowParserErrorsCommand : ICommand { }
15+
public interface IShowParserErrorsCommand : ICommand, IDisposable { }
1516

1617
[ComVisible(false)]
1718
public class ShowParserErrorsCommand : CommandBase, IShowParserErrorsCommand
1819
{
20+
private readonly VBE _vbe;
1921
private readonly INavigateCommand _navigateCommand;
2022
private readonly RubberduckParserState _state;
2123
private readonly ISearchResultsWindowViewModel _viewModel;
2224
private readonly SearchResultPresenterInstanceManager _presenterService;
2325

24-
public ShowParserErrorsCommand(INavigateCommand navigateCommand, RubberduckParserState state, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService)
26+
public ShowParserErrorsCommand(VBE vbe, INavigateCommand navigateCommand, RubberduckParserState state, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService)
2527
{
28+
_vbe = vbe;
2629
_navigateCommand = navigateCommand;
2730
_state = state;
2831
_viewModel = viewModel;
2932
_presenterService = presenterService;
33+
34+
_state.StateChanged += _state_StateChanged;
3035
}
3136

32-
public override void Execute(object parameter)
37+
private void _state_StateChanged(object sender, ParserStateEventArgs e)
3338
{
34-
if (_state.Status != ParserState.Error)
35-
{
36-
return;
37-
}
39+
if (_viewModel == null) { return; }
3840

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+
{
4048
if (_viewModel == null)
4149
{
4250
return;
4351
}
4452

4553
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+
}
4960

5061
if (oldTab != null)
5162
{
5263
oldTab.CloseCommand.Execute(null);
5364
}
65+
}
66+
67+
public override void Execute(object parameter)
68+
{
69+
if (_viewModel == null)
70+
{
71+
return;
72+
}
5473

5574
try
5675
{
@@ -90,5 +109,13 @@ private Declaration FindModuleDeclaration(VBComponent component)
90109
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);
91110
return result ?? declaration; // module isn't in parser state - give it a dummy declaration, just so the ViewModel has something to chew on
92111
}
112+
113+
public void Dispose()
114+
{
115+
if (_state != null)
116+
{
117+
_state.StateChanged += _state_StateChanged;
118+
}
119+
}
93120
}
94121
}

0 commit comments

Comments
 (0)