Skip to content

Commit ea6c2e8

Browse files
committed
Simplify grouping and sorting, only reparse on UI thread - closes #4637
1 parent e2816a5 commit ea6c2e8

File tree

4 files changed

+276
-129
lines changed

4 files changed

+276
-129
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using Rubberduck.Parsing.Inspections.Abstract;
2+
using System.Collections.Generic;
3+
4+
namespace Rubberduck.UI.Inspections
5+
{
6+
public static class InspectionResultComparer
7+
{
8+
public static Comparer<IInspectionResult> InspectionType { get; } = new CompareByInspectionType();
9+
10+
public static Comparer<IInspectionResult> Name { get; } = new CompareByInspectionName();
11+
12+
public static Comparer<IInspectionResult> Location { get; } = new CompareByLocation();
13+
14+
public static Comparer<IInspectionResult> Severity { get; } = new CompareBySeverity();
15+
}
16+
17+
public class CompareByInspectionType : Comparer<IInspectionResult>
18+
{
19+
public override int Compare(IInspectionResult x, IInspectionResult y)
20+
{
21+
if (x == y)
22+
{
23+
return 0;
24+
}
25+
26+
if (x?.Inspection?.InspectionType is null)
27+
{
28+
return -1;
29+
}
30+
31+
return x.Inspection.InspectionType.CompareTo(y?.Inspection?.InspectionType);
32+
}
33+
}
34+
35+
public class CompareByInspectionName : Comparer<IInspectionResult>
36+
{
37+
public override int Compare(IInspectionResult x, IInspectionResult y)
38+
{
39+
if (x == y)
40+
{
41+
return 0;
42+
}
43+
44+
if (x?.Inspection?.Name is null)
45+
{
46+
return -1;
47+
}
48+
49+
return x.Inspection.Name.CompareTo(y?.Inspection?.Name);
50+
}
51+
}
52+
53+
public class CompareByLocation : Comparer<IInspectionResult>
54+
{
55+
public override int Compare(IInspectionResult x, IInspectionResult y)
56+
{
57+
if (x == y)
58+
{
59+
return 0;
60+
}
61+
62+
var first = x?.QualifiedSelection.QualifiedName;
63+
64+
if (first is null)
65+
{
66+
return -1;
67+
}
68+
69+
var second = y?.QualifiedSelection.QualifiedName;
70+
71+
if (second is null)
72+
{
73+
return 1;
74+
}
75+
76+
var nameComparison = first.Value.Name.CompareTo(second.Value.Name);
77+
if (nameComparison != 0)
78+
{
79+
return nameComparison;
80+
}
81+
82+
return x.QualifiedSelection.CompareTo(y.QualifiedSelection);
83+
}
84+
}
85+
86+
public class CompareBySeverity : Comparer<IInspectionResult>
87+
{
88+
public override int Compare(IInspectionResult x, IInspectionResult y)
89+
{
90+
if (x == y)
91+
{
92+
return 0;
93+
}
94+
95+
if (y?.Inspection is null)
96+
{
97+
return 1;
98+
}
99+
100+
// The CodeInspectionSeverity enum is ordered least severe to most. We want the opposite.
101+
return y.Inspection.Severity.CompareTo(x?.Inspection?.Severity);
102+
}
103+
}
104+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
5+
namespace Rubberduck.UI.Inspections
6+
{
7+
/// <summary>
8+
/// Provides a mutally exclusive binding between an InspectionResultGrouping and a boolean.
9+
/// Note: This is a stateful converter, so each bound control requires its own converter instance.
10+
/// </summary>
11+
public class InspectionResultGroupingToBooleanConverter : IValueConverter
12+
{
13+
private InspectionResultGrouping _state;
14+
15+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
16+
{
17+
if (!(parameter is InspectionResultGrouping governing) ||
18+
!(value is InspectionResultGrouping bound))
19+
{
20+
return false;
21+
}
22+
23+
_state = bound;
24+
return _state == governing;
25+
}
26+
27+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
28+
{
29+
if (!(parameter is InspectionResultGrouping governing) ||
30+
!(value is bool isSet))
31+
{
32+
return _state;
33+
}
34+
35+
_state = isSet ? governing : _state;
36+
return _state;
37+
}
38+
}
39+
}

Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
<codeInspections:InspectionFilterToBooleanConverter x:Key="WarningFlagConverter" />
7171
<codeInspections:InspectionFilterToBooleanConverter x:Key="SuggestionFlagConverter" />
7272
<codeInspections:InspectionFilterToBooleanConverter x:Key="HintFlagConverter" />
73+
<codeInspections:InspectionResultGroupingToBooleanConverter x:Key="GroupByTypeConverter" />
74+
<codeInspections:InspectionResultGroupingToBooleanConverter x:Key="GroupByNameConverter" />
75+
<codeInspections:InspectionResultGroupingToBooleanConverter x:Key="GroupByLocationConverter" />
76+
<codeInspections:InspectionResultGroupingToBooleanConverter x:Key="GroupBySeverityConverter" />
7377
<Style x:Key="ToolBarToggleStyle" TargetType="ToggleButton">
7478
<Setter Property="Margin" Value="2" />
7579
<Setter Property="BorderBrush" Value="{x:Static SystemColors.ActiveBorderBrush}" />
@@ -105,25 +109,25 @@
105109

106110
<ToggleButton Style="{StaticResource ToolBarToggleStyle}"
107111
ToolTip="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GroupingStyle_ByInspectionType}"
108-
IsChecked="{Binding GroupByInspectionType, Mode=TwoWay}">
112+
IsChecked="{Binding Path=Grouping, Converter={StaticResource GroupByTypeConverter}, ConverterParameter={x:Static codeInspections:InspectionResultGrouping.Type}}">
109113
<Image Source="{StaticResource GroupByInspectionTypeImage}" />
110114
</ToggleButton>
111115

112116
<ToggleButton Style="{StaticResource ToolBarToggleStyle}"
113117
ToolTip="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GroupingStyle_ByName}"
114-
IsChecked="{Binding GroupByName, Mode=TwoWay}">
118+
IsChecked="{Binding Path=Grouping, Converter={StaticResource GroupByNameConverter}, ConverterParameter={x:Static codeInspections:InspectionResultGrouping.Name}}">
115119
<Image Source="{StaticResource GroupByInspectionImage}" />
116120
</ToggleButton>
117121

118122
<ToggleButton Style="{StaticResource ToolBarToggleStyle}"
119123
ToolTip="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GroupingStyle_ByLocation}"
120-
IsChecked="{Binding GroupByLocation, Mode=TwoWay}">
124+
IsChecked="{Binding Path=Grouping, Converter={StaticResource GroupByLocationConverter}, ConverterParameter={x:Static codeInspections:InspectionResultGrouping.Location}}">
121125
<Image Source="{StaticResource GroupByLocationImage}" />
122126
</ToggleButton>
123127

124128
<ToggleButton Style="{StaticResource ToolBarToggleStyle}"
125129
ToolTip="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GroupingStyle_BySeverity}"
126-
IsChecked="{Binding GroupBySeverity, Mode=TwoWay}" >
130+
IsChecked="{Binding Path=Grouping, Converter={StaticResource GroupBySeverityConverter}, ConverterParameter={x:Static codeInspections:InspectionResultGrouping.Severity}}">
127131
<Image Source="{StaticResource GroupBySeverityImage}" />
128132
</ToggleButton>
129133

@@ -191,7 +195,8 @@
191195
</DataGrid.Columns>
192196
</controls:GroupingGrid>
193197

194-
<controls:EmptyUIRefresh Grid.Row="1" Visibility="{Binding EmptyUIRefreshVisibility}"/>
198+
<controls:EmptyUIRefresh Grid.Row="1" Visibility="{Binding Unparsed, Converter={StaticResource BoolToVisibility}}" />
199+
195200

196201
<controls:BusyIndicator Grid.Row="1" Width="120" Height="120" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibility}}" />
197202

0 commit comments

Comments
 (0)