Skip to content

Commit ef55bc8

Browse files
committed
Add filtering for inspection severities
1 parent 2d43684 commit ef55bc8

File tree

5 files changed

+63
-56
lines changed

5 files changed

+63
-56
lines changed

Rubberduck.Core/UI/Settings/GeneralSettings.xaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@
113113
</Label>
114114
<Label Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GeneralSettings_LanguageLabel}" FontWeight="SemiBold" />
115115
<ComboBox Width="210"
116-
HorizontalAlignment="Left"
117-
Margin="5"
118-
SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}"
119-
ItemsSource="{Binding Languages, UpdateSourceTrigger=PropertyChanged}"
120-
DisplayMemberPath="Name" />
116+
HorizontalAlignment="Left"
117+
Margin="5"
118+
SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}"
119+
ItemsSource="{Binding Languages, UpdateSourceTrigger=PropertyChanged}"
120+
DisplayMemberPath="Name" />
121121

122122
<CheckBox Margin="5,0,0,5" Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GeneralSettings_ShowSplash}"
123123
IsChecked="{Binding ShowSplashAtStartup}" />
@@ -131,11 +131,11 @@
131131
<Label Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GeneralSettings_MinimumLogLevelLabel}" FontWeight="SemiBold" />
132132
<StackPanel Orientation="Horizontal">
133133
<ComboBox Width="210"
134-
HorizontalAlignment="Left"
135-
Margin="5"
136-
SelectedItem="{Binding SelectedLogLevel, Mode=TwoWay}"
137-
ItemsSource="{Binding LogLevels, UpdateSourceTrigger=PropertyChanged}"
138-
DisplayMemberPath="Name"/>
134+
HorizontalAlignment="Left"
135+
Margin="5"
136+
SelectedItem="{Binding SelectedLogLevel, Mode=TwoWay}"
137+
ItemsSource="{Binding LogLevels, UpdateSourceTrigger=PropertyChanged}"
138+
DisplayMemberPath="Name"/>
139139
<Button
140140
Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GeneralSettings_ShowLogFolder}"
141141
Padding="5"

Rubberduck.Core/UI/Settings/InspectionSettings.xaml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@
276276
<DockPanel FlowDirection="LeftToRight">
277277
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
278278
<Label Style="{StaticResource HeaderText}"
279-
Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=CodeInspectionSettings_InspectionSeveritySettingsLabel}">
280-
</Label>
279+
Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=CodeInspectionSettings_InspectionSeveritySettingsLabel}" />
281280
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
282281
<Label Content="-"/>
283282
<Label Style="{StaticResource HeaderText}"
@@ -287,15 +286,10 @@
287286
HorizontalAlignment="Stretch" />
288287
<Border Width="10" />
289288
<Label Style="{StaticResource HeaderText}"
290-
Content="Severity:" />
291-
<CheckBox IsChecked="{Binding AreInspectionsFilteredBySeverity, UpdateSourceTrigger=PropertyChanged}" />
292-
<StackPanel Orientation="Horizontal">
293-
<ComboBox Width="100"
294-
IsEnabled="{Binding AreInspectionsFilteredBySeverity}"
295-
ItemsSource="{Binding InspectionSettingsSeverityFilter}">
296-
<!--, UpdateSourceTrigger=PropertyChanged-->
297-
</ComboBox>
298-
</StackPanel>
289+
Content="Severity:" />
290+
<ComboBox Width="100"
291+
ItemsSource="{Binding SeverityFilters, UpdateSourceTrigger=PropertyChanged}"
292+
SelectedItem="{Binding SelectedSeverityFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
299293
</StackPanel>
300294
</StackPanel>
301295
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Left"

Rubberduck.Core/UI/Settings/InspectionSettingsViewModel.cs

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
using Rubberduck.Settings;
88
using Rubberduck.SettingsProvider;
99
using Rubberduck.UI.Command;
10+
using Rubberduck.Resources.Inspections;
11+
using System.Globalization;
12+
using System;
1013
using Rubberduck.Resources;
1114

1215
namespace Rubberduck.UI.Settings
@@ -29,6 +32,10 @@ public InspectionSettingsViewModel(Configuration config)
2932
InspectionSettings.GroupDescriptions?.Add(new PropertyGroupDescription("TypeLabel"));
3033
ExportButtonCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ => ExportSettings());
3134
ImportButtonCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ => ImportSettings());
35+
36+
SeverityFilters = new ObservableCollection<string>(
37+
new[] { InspectionsUI.ResourceManager.GetString("CodeInspectionSeverity_All", CultureInfo.CurrentUICulture) }
38+
.Concat(Enum.GetNames(typeof(CodeInspectionSeverity)).Select(s => InspectionsUI.ResourceManager.GetString("CodeInspectionSeverity_" + s, CultureInfo.CurrentUICulture))));
3239
}
3340

3441
public void UpdateCollection(CodeInspectionSeverity severity)
@@ -43,7 +50,7 @@ public void UpdateCollection(CodeInspectionSeverity severity)
4350
InspectionSettings.CommitEdit();
4451
}
4552

46-
private string _inspectionSettingsDescriptionFilter;
53+
private string _inspectionSettingsDescriptionFilter = string.Empty;
4754
public string InspectionSettingsDescriptionFilter
4855
{
4956
get => _inspectionSettingsDescriptionFilter;
@@ -52,54 +59,39 @@ public string InspectionSettingsDescriptionFilter
5259
if (_inspectionSettingsDescriptionFilter != value)
5360
{
5461
_inspectionSettingsDescriptionFilter = value;
55-
OnPropertyChanged(nameof(InspectionSettings));
56-
57-
if (string.IsNullOrEmpty(value))
58-
{
59-
InspectionSettings.Filter = null;
60-
}
61-
else
62-
{
63-
InspectionSettings.Filter = item => (item as CodeInspectionSetting)?
64-
.Description.ToUpper()
65-
.Contains(value.ToUpper()) ?? true;
66-
}
62+
InspectionSettings.Filter = item => FilterResults(item);
6763
}
6864
}
6965
}
7066

71-
private bool _areInspectionsFilteredBySeverity;
72-
public bool AreInspectionsFilteredBySeverity
67+
public ObservableCollection<string> SeverityFilters { get; }
68+
69+
static private readonly string _allResultsFilter = InspectionsUI.ResourceManager.GetString("CodeInspectionSeverity_All", CultureInfo.CurrentUICulture);
70+
private string _selectedSeverityFilter = _allResultsFilter;
71+
public string SelectedSeverityFilter
7372
{
74-
get => _areInspectionsFilteredBySeverity;
73+
get => _selectedSeverityFilter;
7574
set
7675
{
77-
if (_areInspectionsFilteredBySeverity != value)
76+
if (!_selectedSeverityFilter.Equals(value))
7877
{
79-
_areInspectionsFilteredBySeverity = value;
78+
_selectedSeverityFilter = value.Replace(" ", string.Empty);
8079
OnPropertyChanged();
80+
InspectionSettings.Filter = item => FilterResults(item);
8181
}
8282
}
83-
}
83+
}
8484

85-
private CodeInspectionSeverity _appliedSeverityFilter;
86-
private List<CodeInspectionSeverity> _inspectionSettingsSeverityFilters = new List<CodeInspectionSeverity> { CodeInspectionSeverity.DoNotShow, CodeInspectionSeverity.Error, CodeInspectionSeverity.Warning, CodeInspectionSeverity.Suggestion, CodeInspectionSeverity.Hint };
87-
public List<CodeInspectionSeverity> InspectionSettingsSeverityFilters
85+
private bool FilterResults(object setting)
8886
{
89-
get => _inspectionSettingsSeverityFilters;
90-
set
91-
{
92-
93-
if (_inspectionSettingsSeverityFilters.Contains(value))
94-
{
95-
_inspectionSettingsSeverityFilters = value;
96-
97-
AreInspectionsFilteredBySeverity = true;
87+
OnPropertyChanged(nameof(InspectionSettings));
88+
var cis = setting as CodeInspectionSetting;
9889

99-
OnPropertyChanged(nameof(InspectionSettings));
100-
}
101-
}
102-
}
90+
return cis.Description.ToUpper().Contains(_inspectionSettingsDescriptionFilter.ToUpper())
91+
&& _selectedSeverityFilter == _allResultsFilter
92+
? true
93+
: cis.Severity.ToString() == _selectedSeverityFilter;
94+
}
10395

10496
private ListCollectionView _inspectionSettings;
10597
public ListCollectionView InspectionSettings

Rubberduck.Resources/Inspections/InspectionsUI.Designer.cs

Lines changed: 18 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
@@ -187,4 +187,7 @@
187187
<data name="information_white" type="System.Resources.ResXFileRef, System.Windows.Forms">
188188
<value>..\icons\fugue\information-white.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
189189
</data>
190+
<data name="CodeInspectionSeverity_All" xml:space="preserve">
191+
<value>All</value>
192+
</data>
190193
</root>

0 commit comments

Comments
 (0)