Skip to content

Commit ed54aa6

Browse files
committed
finalized FindAllReferences logic (message when no references found, navigate directly when only one reference is found)
1 parent 9de0c55 commit ed54aa6

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed

RetailCoder.VBE/UI/Command/FindAllReferencesCommand.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Runtime.InteropServices;
4+
using System.Windows.Forms;
45
using Microsoft.Vbe.Interop;
56
using Rubberduck.Navigation;
67
using Rubberduck.Parsing.Symbols;
@@ -17,14 +18,16 @@ namespace Rubberduck.UI.Command
1718
public class FindAllReferencesCommand : CommandBase
1819
{
1920
private readonly INavigateCommand _navigateCommand;
21+
private readonly IMessageBox _messageBox;
2022
private readonly RubberduckParserState _state;
2123
private readonly IActiveCodePaneEditor _editor;
2224
private readonly ISearchResultsWindowViewModel _viewModel;
2325
private readonly SearchResultPresenterInstanceManager _presenterService;
2426

25-
public FindAllReferencesCommand(INavigateCommand navigateCommand, RubberduckParserState state, IActiveCodePaneEditor editor, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService)
27+
public FindAllReferencesCommand(INavigateCommand navigateCommand, IMessageBox messageBox, RubberduckParserState state, IActiveCodePaneEditor editor, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService)
2628
{
2729
_navigateCommand = navigateCommand;
30+
_messageBox = messageBox;
2831
_state = state;
2932
_editor = editor;
3033
_viewModel = viewModel;
@@ -45,6 +48,18 @@ public override void Execute(object parameter)
4548
}
4649

4750
var viewModel = CreateViewModel(declaration);
51+
if (!viewModel.SearchResults.Any())
52+
{
53+
_messageBox.Show(string.Format(RubberduckUI.AllReferences_NoneFound, declaration.IdentifierName), RubberduckUI.Rubberduck, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
54+
return;
55+
}
56+
57+
if (viewModel.SearchResults.Count == 1)
58+
{
59+
_navigateCommand.Execute(viewModel.SearchResults[0].GetNavigationArgs());
60+
return;
61+
}
62+
4863
_viewModel.AddTab(viewModel);
4964
_viewModel.SelectedTab = viewModel;
5065

@@ -65,7 +80,7 @@ private SearchResultsViewModel CreateViewModel(Declaration declaration)
6580
new SearchResultItem(
6681
reference.QualifiedModuleName.QualifyMemberName(reference.ParentScope.Split('.').Last()),
6782
reference.Selection,
68-
reference.Context.GetText()));
83+
_editor.GetLines(reference.Selection)));
6984

7085
var viewModel = new SearchResultsViewModel(_navigateCommand,
7186
string.Format(RubberduckUI.SearchResults_AllReferencesTabFormat, declaration.IdentifierName), results);

RetailCoder.VBE/UI/Controls/SearchResultsViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public SearchResultItem SelectedItem
5050
}
5151
}
5252

53-
public INavigateCommand NavigateCommand { get {return _navigateCommand; } }
54-
5553
private void ExecuteCloseCommand(object parameter)
5654
{
5755
OnClose();
@@ -67,6 +65,7 @@ private void OnClose()
6765
}
6866
}
6967

68+
public INavigateCommand NavigateCommand { get { return _navigateCommand; } }
7069
INavigateSource INavigateSelection.SelectedItem { get { return SelectedItem; } }
7170
}
7271
}

RetailCoder.VBE/UI/Controls/SearchView.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
ItemsSource="{Binding SearchResultsSource.View}"
4242
SelectedItem="{Binding SelectedItem}">
4343
<DataGrid.Columns>
44-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SearchResults_ModuleName}" Binding="{Binding QualifiedMemberName.QualifiedModuleName}" />
4544
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SearchResults_MemberName}" Binding="{Binding QualifiedMemberName.MemberName}" />
46-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SearchResults_Location}" Binding="{Binding Selection}" Width="*" />
45+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SearchResults_Line}" Binding="{Binding Selection.StartLine}" />
46+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SearchResults_Context}" Binding="{Binding ResultText}" Width="*" />
4747
</DataGrid.Columns>
4848
</controls:GroupingGrid>
4949
</DataTemplate>

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 21 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,9 +1317,8 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
13171317
<data name="SearchResults_Caption" xml:space="preserve">
13181318
<value>Search Results</value>
13191319
</data>
1320-
<data name="SearchResults_Location" xml:space="preserve">
1321-
<value>Location</value>
1322-
<comment>The line and column in the code module, in L1C1 notation</comment>
1320+
<data name="SearchResults_Line" xml:space="preserve">
1321+
<value>Line</value>
13231322
</data>
13241323
<data name="SearchResults_MemberName" xml:space="preserve">
13251324
<value>Member</value>
@@ -1329,8 +1328,8 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
13291328
<value>Module</value>
13301329
<comment>The qualified module name, e.g. "Project1.Module1"</comment>
13311330
</data>
1332-
<data name="SearchResults_Result" xml:space="preserve">
1333-
<value>Result</value>
1331+
<data name="SearchResults_Context" xml:space="preserve">
1332+
<value>Context</value>
13341333
<comment>A column to display the search result itself</comment>
13351334
</data>
13361335
<data name="SearchResults_AllImplementationsTabFormat" xml:space="preserve">
@@ -1341,4 +1340,7 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
13411340
<value>All references: '{0}'</value>
13421341
<comment>0: declaration.identifiername</comment>
13431342
</data>
1343+
<data name="Rubberduck" xml:space="preserve">
1344+
<value>Rubberduck</value>
1345+
</data>
13441346
</root>

0 commit comments

Comments
 (0)