Skip to content

Commit e044c03

Browse files
committed
Close #1334
1 parent 2b8c71a commit e044c03

File tree

4 files changed

+73
-18
lines changed

4 files changed

+73
-18
lines changed

RetailCoder.VBE/UI/Command/FindAllImplementationsCommand.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Rubberduck.Parsing.Grammar;
99
using Rubberduck.Parsing.Symbols;
1010
using Rubberduck.Parsing.VBA;
11+
using Rubberduck.UI.Command.MenuItems;
1112
using Rubberduck.UI.Controls;
1213

1314
namespace Rubberduck.UI.Command
@@ -39,19 +40,49 @@ public FindAllImplementationsCommand(INavigateCommand navigateCommand, IMessageB
3940
_state.StateChanged += _state_StateChanged;
4041
}
4142

43+
private Declaration FindNewDeclaration(Declaration declaration)
44+
{
45+
return _state.AllUserDeclarations.SingleOrDefault(item =>
46+
item.ProjectId == declaration.ProjectId &&
47+
item.ComponentName == declaration.ComponentName &&
48+
item.ParentScope == declaration.ParentScope &&
49+
item.IdentifierName == declaration.IdentifierName &&
50+
item.DeclarationType == declaration.DeclarationType);
51+
}
52+
4253
private void _state_StateChanged(object sender, ParserStateEventArgs e)
4354
{
4455
if (e.State != ParserState.Ready) { return; }
4556

4657
if (_viewModel == null) { return; }
4758

59+
UiDispatcher.InvokeAsync(UpdateTab);
60+
}
61+
62+
private void UpdateTab()
63+
{
4864
var findImplementationsTabs = _viewModel.Tabs.Where(
4965
t => t.Header.StartsWith(RubberduckUI.AllImplementations_Caption.Replace("'{0}'", ""))).ToList();
5066

5167
foreach (var tab in findImplementationsTabs)
5268
{
53-
Execute(tab.Target);
54-
tab.CloseCommand.Execute(null);
69+
var newTarget = FindNewDeclaration(tab.Target);
70+
if (newTarget == null)
71+
{
72+
tab.CloseCommand.Execute(null);
73+
return;
74+
}
75+
76+
var vm = CreateViewModel(newTarget);
77+
if (vm.SearchResults.Any())
78+
{
79+
tab.SearchResults = vm.SearchResults;
80+
tab.Target = vm.Target;
81+
}
82+
else
83+
{
84+
tab.CloseCommand.Execute(null);
85+
}
5586
}
5687
}
5788

RetailCoder.VBE/UI/Command/FindAllReferencesCommand.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Vbe.Interop;
66
using Rubberduck.Parsing.Symbols;
77
using Rubberduck.Parsing.VBA;
8+
using Rubberduck.UI.Command.MenuItems;
89
using Rubberduck.UI.Controls;
910

1011
namespace Rubberduck.UI.Command
@@ -36,21 +37,44 @@ public FindAllReferencesCommand(INavigateCommand navigateCommand, IMessageBox me
3637
_state.StateChanged += _state_StateChanged;
3738
}
3839

40+
private Declaration FindNewDeclaration(Declaration declaration)
41+
{
42+
return _state.AllUserDeclarations.SingleOrDefault(item =>
43+
item.ProjectId == declaration.ProjectId &&
44+
item.ComponentName == declaration.ComponentName &&
45+
item.ParentScope == declaration.ParentScope &&
46+
item.IdentifierName == declaration.IdentifierName &&
47+
item.DeclarationType == declaration.DeclarationType);
48+
}
49+
3950
private void _state_StateChanged(object sender, ParserStateEventArgs e)
4051
{
4152
if (e.State != ParserState.Ready) { return; }
4253

4354
if (_viewModel == null) { return; }
4455

56+
UiDispatcher.InvokeAsync(UpdateTab);
57+
}
58+
59+
private void UpdateTab()
60+
{
4561
var findReferenceTabs = _viewModel.Tabs.Where(
4662
t => t.Header.StartsWith(RubberduckUI.AllReferences_Caption.Replace("'{0}'", ""))).ToList();
4763

4864
foreach (var tab in findReferenceTabs)
4965
{
50-
var vm = CreateViewModel(tab.Target);
66+
var newTarget = FindNewDeclaration(tab.Target);
67+
if (newTarget == null)
68+
{
69+
tab.CloseCommand.Execute(null);
70+
return;
71+
}
72+
73+
var vm = CreateViewModel(newTarget);
5174
if (vm.SearchResults.Any())
5275
{
5376
tab.SearchResults = vm.SearchResults;
77+
tab.Target = vm.Target;
5478
}
5579
else
5680
{

RetailCoder.VBE/UI/Command/ShowParserErrorsCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ private void UpdateTab()
5151
var vm = CreateViewModel();
5252

5353
var tab = _viewModel.Tabs.FirstOrDefault(t => t.Header == RubberduckUI.Parser_ParserError);
54-
if (tab == null)
55-
{
56-
_viewModel.AddTab(vm);
57-
_viewModel.SelectedTab = vm;
58-
}
59-
else
54+
if (tab != null)
6055
{
6156
if (_state.Status != ParserState.Error)
6257
{
@@ -67,6 +62,11 @@ private void UpdateTab()
6762
tab.SearchResults = vm.SearchResults;
6863
}
6964
}
65+
else if (_state.Status == ParserState.Error)
66+
{
67+
_viewModel.AddTab(vm);
68+
_viewModel.SelectedTab = vm;
69+
}
7070
}
7171

7272
public override void Execute(object parameter)

RetailCoder.VBE/UI/Controls/SearchResultsViewModel.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ public class SearchResultsViewModel : ViewModelBase, INavigateSelection
1313
{
1414
private readonly INavigateCommand _navigateCommand;
1515
private readonly string _header;
16-
private readonly Declaration _target;
1716

1817
public SearchResultsViewModel(INavigateCommand navigateCommand, string header, Declaration target, IEnumerable<SearchResultItem> searchResults)
1918
{
2019
_navigateCommand = navigateCommand;
2120
_header = header;
22-
_target = target;
23-
_searchResults = new ObservableCollection<SearchResultItem>(searchResults);
21+
Target = target;
22+
SearchResultsSource = new CollectionViewSource();
23+
SearchResultsSource.GroupDescriptions.Add(new PropertyGroupDescription("ParentScope.QualifiedName.QualifiedModuleName.Name"));
24+
SearchResultsSource.SortDescriptions.Add(new SortDescription("ParentScope.QualifiedName.QualifiedModuleName.Name", ListSortDirection.Ascending));
25+
SearchResultsSource.SortDescriptions.Add(new SortDescription("Selection.StartLine", ListSortDirection.Ascending));
26+
SearchResultsSource.SortDescriptions.Add(new SortDescription("Selection.StartColumn", ListSortDirection.Ascending));
27+
28+
SearchResults = new ObservableCollection<SearchResultItem>(searchResults);
2429

2530
_closeCommand = new DelegateCommand(ExecuteCloseCommand);
2631
}
@@ -33,12 +38,7 @@ public ObservableCollection<SearchResultItem> SearchResults
3338
{
3439
_searchResults = value;
3540

36-
SearchResultsSource = new CollectionViewSource();
3741
SearchResultsSource.Source = _searchResults;
38-
SearchResultsSource.GroupDescriptions.Add(new PropertyGroupDescription("ParentScope.QualifiedName.QualifiedModuleName.Name"));
39-
SearchResultsSource.SortDescriptions.Add(new SortDescription("ParentScope.QualifiedName.QualifiedModuleName.Name", ListSortDirection.Ascending));
40-
SearchResultsSource.SortDescriptions.Add(new SortDescription("Selection.StartLine", ListSortDirection.Ascending));
41-
SearchResultsSource.SortDescriptions.Add(new SortDescription("Selection.StartColumn", ListSortDirection.Ascending));
4242

4343
OnPropertyChanged();
4444
OnPropertyChanged("SearchResultsSource");
@@ -52,7 +52,7 @@ public ObservableCollection<SearchResultItem> SearchResults
5252
private readonly ICommand _closeCommand;
5353
public ICommand CloseCommand { get { return _closeCommand; } }
5454

55-
public Declaration Target { get {return _target; } }
55+
public Declaration Target { get; set; }
5656

5757
private SearchResultItem _selectedItem;
5858
public SearchResultItem SelectedItem

0 commit comments

Comments
 (0)