Skip to content

Commit 71b9554

Browse files
authored
Merge pull request #5095 from IvenBach/Issue5080_Text_filter_for_Code_Inspections
Add description filter for Code Inspections
2 parents ed5bf5a + ecb9299 commit 71b9554

File tree

11 files changed

+78
-44
lines changed

11 files changed

+78
-44
lines changed

Rubberduck.Core/Common/ExportFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static string Csv(object[][] data, string title, ColumnInfo[] columnInfos
7575

7676
private static string CsvEncode(object value)
7777
{
78-
var s = "";
78+
var s = string.Empty;
7979
if (value is string)
8080
{
8181
s = value.ToString();
@@ -121,7 +121,7 @@ public static string HtmlClipboardFragment(object[][] data, string title, Column
121121
"</body>\r\n" +
122122
"</html>";
123123

124-
var html = ExportFormatter.HtmlTable(data, title, columnInfos);
124+
var html = HtmlTable(data, title, columnInfos);
125125

126126
var CFHeaderLength = string.Format(CFHeaderTemplate, OffsetFormat, OffsetFormat, OffsetFormat, OffsetFormat).Length;
127127
var startFragment = CFHeaderLength + HtmlHeader.Length;
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Diagnostics.CodeAnalysis;
1+
using System.Diagnostics.CodeAnalysis;
32
using System.Windows.Forms;
43
using Rubberduck.Navigation.CodeExplorer;
54
using Rubberduck.Resources.CodeExplorer;
@@ -10,8 +9,8 @@ namespace Rubberduck.UI.CodeExplorer
109
public sealed partial class CodeExplorerWindow : UserControl, IDockableUserControl
1110
{
1211
private const string ClassId = "C5318B59-172F-417C-88E3-B377CDA2D809";
13-
string IDockableUserControl.ClassId { get { return ClassId; } }
14-
string IDockableUserControl.Caption { get { return CodeExplorerUI.CodeExplorerDockablePresenter_Caption; } }
12+
string IDockableUserControl.ClassId => ClassId;
13+
string IDockableUserControl.Caption => CodeExplorerUI.CodeExplorerDockablePresenter_Caption;
1514

1615
private CodeExplorerWindow()
1716
{
@@ -20,14 +19,9 @@ private CodeExplorerWindow()
2019

2120
public CodeExplorerWindow(CodeExplorerViewModel viewModel) : this()
2221
{
23-
_viewModel = viewModel;
24-
codeExplorerControl1.DataContext = _viewModel;
25-
}
26-
27-
private readonly CodeExplorerViewModel _viewModel;
28-
public CodeExplorerViewModel ViewModel
29-
{
30-
get { return _viewModel; }
22+
ViewModel = viewModel;
23+
codeExplorerControl1.DataContext = viewModel;
3124
}
25+
public CodeExplorerViewModel ViewModel { get; }
3226
}
3327
}

Rubberduck.Core/UI/Controls/SearchBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<Button Name="SearchButton" Grid.Column="1" Command="{Binding ClearSearchCommand}"
4949
BorderBrush="{x:Static SystemColors.ControlLightBrush}"
5050
Background="Transparent"
51-
Width="20" Height="20" Padding="0" Margin="0,1"
51+
Width="20" Height="20" Padding="0"
5252
xmlns:sys="clr-namespace:System;assembly=mscorlib">
5353
<Button.Resources>
5454
<converters:SearchImageSourceConverter x:Key="SearchToIcon" />

Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@
136136

137137
<Label Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GroupingGrid_Filter}" VerticalContentAlignment="Center" />
138138

139+
<controls:SearchBox Width="100"
140+
Text="{Binding InspectionDescriptionFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
141+
142+
<Label Content="{Resx ResxName=Rubberduck.Resources.Inspections.InspectionsUI ,Key=CodeInspection_SeverityFilter}" />
143+
139144
<ToggleButton Style="{StaticResource ToolBarToggleStyle}"
140145
ToolTip="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=InspectionResults_FilterByError}"
141146
IsChecked="{Binding Path=SelectedFilters, Converter={StaticResource InspectionTypeToBooleanConverter}, ConverterParameter={x:Static codeInspections:InspectionResultsFilter.Error}}">

Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using System.Windows.Input;
1414
using NLog;
1515
using Rubberduck.Common;
16+
using Rubberduck.Inspections.Abstract;
17+
using Rubberduck.Inspections.Results;
1618
using Rubberduck.Interaction.Navigation;
1719
using Rubberduck.Parsing.Inspections;
1820
using Rubberduck.Parsing.Inspections.Abstract;
@@ -260,6 +262,29 @@ public InspectionResultsFilter SelectedFilters
260262
}
261263
}
262264

265+
private string _inspectionDescriptionFilter = string.Empty;
266+
public string InspectionDescriptionFilter
267+
{
268+
get => _inspectionDescriptionFilter;
269+
set
270+
{
271+
if (_inspectionDescriptionFilter != value)
272+
{
273+
_inspectionDescriptionFilter = value;
274+
OnPropertyChanged();
275+
Results.Filter = FilterResults;
276+
OnPropertyChanged(nameof(Results));
277+
}
278+
}
279+
}
280+
281+
private bool FilterResults(object inspectionResult)
282+
{
283+
var inspectionResultBase = inspectionResult as InspectionResultBase;
284+
285+
return inspectionResultBase.Description.ToUpper().Contains(InspectionDescriptionFilter.ToUpper()); ;
286+
}
287+
263288
private bool InspectionFilter(IInspectionResult result)
264289
{
265290
switch (result.Inspection.Severity)
@@ -625,20 +650,20 @@ private void ExecuteQuickFixInAllProjectsCommand(object parameter)
625650
private void ExecuteCopyResultsCommand(object parameter)
626651
{
627652
const string xmlSpreadsheetDataFormat = "XML Spreadsheet";
628-
if (_results == null)
653+
if (Results == null)
629654
{
630655
return;
631656
}
632657

633-
var resultArray = _results.OfType<IExportable>().Select(result => result.ToArray()).ToArray();
658+
var resultArray = Results.OfType<IExportable>().Select(result => result.ToArray()).ToArray();
634659

635-
var resource = _results.Count == 1
660+
var resource = resultArray.Count() == 1
636661
? Resources.RubberduckUI.CodeInspections_NumberOfIssuesFound_Singular
637662
: Resources.RubberduckUI.CodeInspections_NumberOfIssuesFound_Plural;
638663

639-
var title = string.Format(resource, DateTime.Now.ToString(CultureInfo.InvariantCulture), _results.Count);
664+
var title = string.Format(resource, DateTime.Now.ToString(CultureInfo.InvariantCulture), resultArray.Count());
640665

641-
var textResults = title + Environment.NewLine + string.Join("", _results.OfType<IExportable>().Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
666+
var textResults = title + Environment.NewLine + string.Join(string.Empty, Results.OfType<IExportable>().Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
642667
var csvResults = ExportFormatter.Csv(resultArray, title, ColumnInformation);
643668
var htmlResults = ExportFormatter.HtmlClipboardFragment(resultArray, title, ColumnInformation);
644669
var rtfResults = ExportFormatter.RTF(resultArray, title);

Rubberduck.Core/UI/Settings/InspectionSettings.xaml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@
256256
</DataTrigger>
257257
</Style.Triggers>
258258
</Style>
259-
<Style x:Key="HeaderBackground" TargetType="Label">
260-
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
261-
<Setter Property="Background" Value="DarkGray"/>
262-
</Style>
263259
<Style x:Key="HeaderText" TargetType="Label">
264260
<Setter Property="Foreground" Value="White"/>
265261
<Setter Property="FontWeight" Value="SemiBold"/>
@@ -283,20 +279,23 @@
283279
<DockPanel FlowDirection="LeftToRight">
284280
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
285281
<Label Style="{StaticResource HeaderText}"
286-
Content="{Resx Key=CodeInspectionSettings_InspectionSeveritySettingsLabel, ResxName=Rubberduck.Resources.RubberduckUI}" Margin="5,5,0,5" Width="123" />
282+
Content="{Resx Key=CodeInspectionSettings_InspectionSeveritySettingsLabel, ResxName=Rubberduck.Resources.RubberduckUI}" Margin="5,5,0,5" Width="127" />
287283
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
288-
<Label Content="-" Margin="0,5"/>
289-
<Image Source="{StaticResource FilterImage}" Margin="0,5" Width="19" RenderTransformOrigin="0.564,1.859" />
290-
<Label Style="{StaticResource HeaderText}"
291-
Content="{Resx Key=InspectionSettings_FilterByDescription, ResxName=Rubberduck.Resources.RubberduckUI}" Margin="0,5" />
292-
<TextBox MinWidth="125"
293-
Text="{Binding InspectionSettingsDescriptionFilter, UpdateSourceTrigger=PropertyChanged}" Margin="0,5" Height="26" />
284+
<StackPanel.Resources>
285+
<Style BasedOn="{StaticResource HeaderText}" TargetType="Label">
286+
<Setter Property="Margin" Value="0,5" />
287+
</Style>
288+
</StackPanel.Resources>
289+
<Label Content="-" />
290+
<Image Source="{StaticResource FilterImage}" Width="19" />
291+
<Label Content="{Resx Key=InspectionSettings_FilterByDescription, ResxName=Rubberduck.Resources.RubberduckUI}" />
292+
<controls:SearchBox Width="100"
293+
Text="{Binding InspectionSettingsDescriptionFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="26" />
294294
<Border Width="10" />
295-
<Label Style="{StaticResource HeaderText}"
296-
Content="{Resx Key=InspectionSettings_FilterBySeverity, ResxName=Rubberduck.Resources.RubberduckUI}" Margin="0,5" />
295+
<Label Content="{Resx Key=InspectionSettings_FilterBySeverity, ResxName=Rubberduck.Resources.RubberduckUI}" />
297296
<ComboBox Width="100"
298297
ItemsSource="{Binding SeverityFilters, UpdateSourceTrigger=PropertyChanged}"
299-
SelectedItem="{Binding SelectedSeverityFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,5" />
298+
SelectedItem="{Binding SelectedSeverityFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
300299
</StackPanel>
301300
</StackPanel>
302301
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Left"

Rubberduck.Core/UI/Settings/InspectionSettingsViewModel.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public string InspectionSettingsDescriptionFilter
6969
if (_inspectionSettingsDescriptionFilter != value)
7070
{
7171
_inspectionSettingsDescriptionFilter = value;
72-
InspectionSettings.Filter = item => FilterResults(item);
72+
OnPropertyChanged();
73+
InspectionSettings.Filter = FilterResults;
74+
OnPropertyChanged(nameof(InspectionSettings));
7375
}
7476
}
7577
}
@@ -87,14 +89,14 @@ public string SelectedSeverityFilter
8789
{
8890
_selectedSeverityFilter = value.Replace(" ", string.Empty);
8991
OnPropertyChanged();
90-
InspectionSettings.Filter = item => FilterResults(item);
92+
InspectionSettings.Filter = FilterResults;
93+
OnPropertyChanged(nameof(InspectionSettings));
9194
}
9295
}
9396
}
9497

9598
private bool FilterResults(object setting)
9699
{
97-
OnPropertyChanged(nameof(InspectionSettings));
98100
var cis = setting as CodeInspectionSetting;
99101

100102
return cis.Description.ToUpper().Contains(_inspectionSettingsDescriptionFilter.ToUpper())
@@ -104,10 +106,7 @@ private bool FilterResults(object setting)
104106
private ListCollectionView _inspectionSettings;
105107
public ListCollectionView InspectionSettings
106108
{
107-
get
108-
{
109-
return _inspectionSettings;
110-
}
109+
get => _inspectionSettings;
111110

112111
set
113112
{

Rubberduck.Resources/Inspections/InspectionsUI.Designer.cs

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

Rubberduck.Resources/Inspections/InspectionsUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,7 @@
226226
<data name="ExportColumnHeader_Type" xml:space="preserve">
227227
<value>Type</value>
228228
</data>
229+
<data name="CodeInspection_SeverityFilter" xml:space="preserve">
230+
<value>Severity</value>
231+
</data>
229232
</root>

Rubberduck.Resources/RubberduckUI.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)