Skip to content

Commit dcbb979

Browse files
committed
Sort inspections by localized name in AnnotateDeclaration UI
The way it is set up, the ordering will not react to a change in UI culture, but that is OK since the dialog is modal; no possibility to get to the settings dialog during its lifetime.
1 parent 5237703 commit dcbb979

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

Rubberduck.Core/UI/Refactorings/AnnotateDeclaration/AnnotateDeclarationView.xaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@
7575
<converters:SpecificValueToVisibilityConverter SpecialValue="{x:Static annotations:AnnotationArgumentType.Inspection}" CollapseSpecialValue="False" x:Key="InspectionArgumentVisibilityConverter"/>
7676
<DataTemplate DataType="{x:Type local:IAnnotationArgumentViewModel}" x:Key="ArgumentValueTemplate">
7777
<DataTemplate.Resources>
78-
<CollectionViewSource Source="{Binding InspectionNames}" x:Key="InspectionNamesView">
79-
<CollectionViewSource.SortDescriptions>
80-
<scm:SortDescription PropertyName="." />
81-
<!-- This is not really the sort we want. We want a converter here, which is impossible. -->
82-
</CollectionViewSource.SortDescriptions>
83-
</CollectionViewSource>
78+
<CollectionViewSource Source="{Binding InspectionNames}" x:Key="InspectionNamesView" />
8479
</DataTemplate.Resources>
8580
<StackPanel>
8681
<TextBox Text="{Binding ArgumentValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"

Rubberduck.Core/UI/Refactorings/AnnotateDeclaration/AnnotationArgumentViewModel.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4+
using System.Globalization;
45
using System.Linq;
6+
using System.Windows.Controls;
7+
using System.Windows.Data;
58
using Rubberduck.Parsing.Annotations;
69
using Rubberduck.Refactorings.AnnotateDeclaration;
710
using Rubberduck.Resources;
11+
using Rubberduck.UI.Converters;
812

913
namespace Rubberduck.UI.Refactorings.AnnotateDeclaration
1014
{
@@ -24,13 +28,16 @@ internal class AnnotationArgumentViewModel : ViewModelBase, IAnnotationArgumentV
2428
private const int MaxAllowedCharacters = 511;
2529

2630
private TypedAnnotationArgument _model;
31+
private readonly IReadOnlyList<string> _inspectionNames;
32+
private readonly IValueConverter _inspectionNameConverter;
2733

28-
public AnnotationArgumentViewModel(TypedAnnotationArgument model, IReadOnlyList<string> inspectionNames)
34+
public AnnotationArgumentViewModel(TypedAnnotationArgument model, IReadOnlyList<string> inspectionNames, InspectionToLocalizedNameConverter inspectionNameConverter)
2935
{
3036
_model = model;
37+
_inspectionNameConverter = inspectionNameConverter;
38+
_inspectionNames = inspectionNames;
3139

3240
ApplicableArgumentTypes = ApplicableTypes(_model.ArgumentType);
33-
InspectionNames = inspectionNames;
3441
BooleanValues = new List<string> { "True", "False" };
3542

3643
_model.ArgumentType = ApplicableArgumentTypes.FirstOrDefault();
@@ -53,9 +60,12 @@ private IReadOnlyList<AnnotationArgumentType> ApplicableTypes(AnnotationArgument
5360
public IReadOnlyList<AnnotationArgumentType> ApplicableArgumentTypes { get; }
5461

5562
public bool CanEditArgumentType => ApplicableArgumentTypes.Count > 1;
56-
public IReadOnlyList<string> InspectionNames { get; }
5763
public IReadOnlyList<string> BooleanValues { get; }
5864

65+
public IReadOnlyList<string> InspectionNames => _inspectionNames
66+
.OrderBy(inspectionName => _inspectionNameConverter.Convert(inspectionName, typeof(TextBlock), null, CultureInfo.CurrentUICulture))
67+
.ToList();
68+
5969
public AnnotationArgumentType ArgumentType
6070
{
6171
get => _model.ArgumentType;
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using System.Windows.Data;
34
using Rubberduck.CodeAnalysis.Inspections;
45
using Rubberduck.Parsing.Annotations;
56
using Rubberduck.Refactorings.AnnotateDeclaration;
7+
using Rubberduck.UI.Converters;
68

79
namespace Rubberduck.UI.Refactorings.AnnotateDeclaration
810
{
911
internal class AnnotationArgumentViewModelFactory : IAnnotationArgumentViewModelFactory
1012
{
11-
private readonly IReadOnlyList<string> InspectionNames;
13+
private readonly IReadOnlyList<string> _inspectionNames;
14+
private readonly InspectionToLocalizedNameConverter _inspectionNameConverter;
1215

13-
public AnnotationArgumentViewModelFactory(IEnumerable<IInspection> inspections)
16+
public AnnotationArgumentViewModelFactory(IEnumerable<IInspection> inspections, InspectionToLocalizedNameConverter inspectionNameConverter)
1417
{
15-
InspectionNames = inspections
18+
_inspectionNames = inspections
1619
.Select(inspection => inspection.AnnotationName)
1720
.ToList();
21+
_inspectionNameConverter = inspectionNameConverter;
1822
}
1923

2024
public IAnnotationArgumentViewModel Create(AnnotationArgumentType argumentType, string argument = null)
2125
{
2226
var model = new TypedAnnotationArgument(argumentType, argument ?? string.Empty);
23-
return new AnnotationArgumentViewModel(model, InspectionNames);
27+
return new AnnotationArgumentViewModel(model, _inspectionNames, _inspectionNameConverter);
2428
}
2529
}
2630
}

RubberduckTests/Refactoring/AnnotateDeclaration/AnnotationArgumentViewModelTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NUnit.Framework;
55
using Rubberduck.Parsing.Annotations;
66
using Rubberduck.Refactorings.AnnotateDeclaration;
7+
using Rubberduck.UI.Converters;
78
using Rubberduck.UI.Refactorings.AnnotateDeclaration;
89

910
namespace RubberduckTests.Refactoring.AnnotateDeclaration
@@ -217,7 +218,8 @@ private AnnotationArgumentViewModel TestViewModel(
217218
IReadOnlyList<string> inspectionNames = null)
218219
{
219220
var model = new TypedAnnotationArgument(argumentType, initialArgument ?? string.Empty);
220-
return new AnnotationArgumentViewModel(model, inspectionNames ?? new List<string>());
221+
var inspectionNameConverter = new InspectionToLocalizedNameConverter();
222+
return new AnnotationArgumentViewModel(model, inspectionNames ?? new List<string>(), inspectionNameConverter);
221223
}
222224
}
223225
}

0 commit comments

Comments
 (0)