7
7
using Rubberduck . Settings ;
8
8
using Rubberduck . SettingsProvider ;
9
9
using Rubberduck . UI . Command ;
10
+ using Rubberduck . Resources . Inspections ;
11
+ using System . Globalization ;
12
+ using System ;
10
13
using Rubberduck . Resources ;
11
14
12
15
namespace Rubberduck . UI . Settings
@@ -29,6 +32,10 @@ public InspectionSettingsViewModel(Configuration config)
29
32
InspectionSettings . GroupDescriptions ? . Add ( new PropertyGroupDescription ( "TypeLabel" ) ) ;
30
33
ExportButtonCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , _ => ExportSettings ( ) ) ;
31
34
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 ) ) ) ) ;
32
39
}
33
40
34
41
public void UpdateCollection ( CodeInspectionSeverity severity )
@@ -43,7 +50,7 @@ public void UpdateCollection(CodeInspectionSeverity severity)
43
50
InspectionSettings . CommitEdit ( ) ;
44
51
}
45
52
46
- private string _inspectionSettingsDescriptionFilter ;
53
+ private string _inspectionSettingsDescriptionFilter = string . Empty ;
47
54
public string InspectionSettingsDescriptionFilter
48
55
{
49
56
get => _inspectionSettingsDescriptionFilter ;
@@ -52,54 +59,39 @@ public string InspectionSettingsDescriptionFilter
52
59
if ( _inspectionSettingsDescriptionFilter != value )
53
60
{
54
61
_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 ) ;
67
63
}
68
64
}
69
65
}
70
66
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
73
72
{
74
- get => _areInspectionsFilteredBySeverity ;
73
+ get => _selectedSeverityFilter ;
75
74
set
76
75
{
77
- if ( _areInspectionsFilteredBySeverity != value )
76
+ if ( ! _selectedSeverityFilter . Equals ( value ) )
78
77
{
79
- _areInspectionsFilteredBySeverity = value ;
78
+ _selectedSeverityFilter = value . Replace ( " " , string . Empty ) ;
80
79
OnPropertyChanged ( ) ;
80
+ InspectionSettings . Filter = item => FilterResults ( item ) ;
81
81
}
82
82
}
83
- }
83
+ }
84
84
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 )
88
86
{
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 ;
98
89
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
+ }
103
95
104
96
private ListCollectionView _inspectionSettings ;
105
97
public ListCollectionView InspectionSettings
0 commit comments