Skip to content

Commit c596563

Browse files
committed
implemented groupings in CodeInspections, ToDoItems and UnitTests (each needed their own MenuItemGroup.GroupName); simplified ToDoItems VM code and tweaked UI layout to work with collapsing/hidden controls.
1 parent 2578d55 commit c596563

File tree

8 files changed

+119
-118
lines changed

8 files changed

+119
-118
lines changed

RetailCoder.VBE/ToDoItems/ToDoItem.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,16 @@ public class ToDoItem : INavigateSource
1515
private readonly string _description;
1616
public string Description { get { return _description; } }
1717

18-
private readonly string _projectName;
19-
public string ProjectName { get { return _projectName; } }
20-
21-
private readonly string _moduleName;
22-
public string ModuleName { get { return _moduleName; } }
23-
24-
private readonly int _lineNumber;
25-
public int LineNumber { get { return _lineNumber; } }
26-
2718
private readonly string _type;
2819
public string Type { get { return _type; } }
2920

3021
private readonly QualifiedSelection _selection;
31-
public QualifiedSelection GetSelection() { return _selection; }
22+
public QualifiedSelection Selection { get { return _selection; } }
3223

3324
public ToDoItem(string markerText, CommentNode comment)
34-
: this(markerText, comment.CommentText, comment.QualifiedSelection)
35-
{
36-
}
37-
38-
public ToDoItem(string markerText, string description, QualifiedSelection qualifiedSelection)
3925
{
40-
_description = description;
41-
_selection = qualifiedSelection;
42-
_projectName = qualifiedSelection.QualifiedName.ProjectName;
43-
_moduleName = qualifiedSelection.QualifiedName.ComponentName;
44-
_lineNumber = qualifiedSelection.Selection.StartLine;
26+
_description = comment.CommentText;
27+
_selection = comment.QualifiedSelection;
4528
_type = markerText;
4629
}
4730

RetailCoder.VBE/UI/CodeInspections/InspectionResultsControl.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304

305305
<CollectionViewSource x:Key="ResultsByModule" Source="{Binding Results}">
306306
<CollectionViewSource.SortDescriptions>
307-
<componentModel:SortDescription PropertyName="QualifiedSelection.QualifiedName.ComponentName"/>
307+
<componentModel:SortDescription PropertyName="QualifiedSelection.QualifiedName.Name"/>
308308
</CollectionViewSource.SortDescriptions>
309309
<CollectionViewSource.GroupDescriptions>
310310
<PropertyGroupDescription PropertyName="QualifiedSelection.QualifiedName" />
@@ -355,10 +355,10 @@
355355

356356
<MenuItem x:Name="GroupByInspectionType" Style="{DynamicResource MenuItemStyle}" VerticalAlignment="Center"
357357
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GroupingStyle_ByInspectionType}" IsChecked="True"
358-
IsCheckable="True" controls:MenuItemGroup.GroupName="GroupingStyle" />
358+
IsCheckable="True" controls:MenuItemGroup.GroupName="InspectionsResults_GroupingStyle" />
359359
<MenuItem x:Name="GroupByModule" Style="{DynamicResource MenuItemStyle}" VerticalAlignment="Center"
360360
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GroupingStyle_ByLocation}"
361-
IsCheckable="True" controls:MenuItemGroup.GroupName="GroupingStyle" />
361+
IsCheckable="True" controls:MenuItemGroup.GroupName="InspectionsResults_GroupingStyle" />
362362
</MenuItem>
363363
</Menu>
364364

RetailCoder.VBE/UI/CodeInspections/InspectionResultsControl.xaml.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System.Windows;
22
using System.Windows.Controls;
3-
using System.Windows.Data;
4-
using System.Windows.Input;
5-
using Rubberduck.Inspections;
63

74
namespace Rubberduck.UI.CodeInspections
85
{
@@ -21,7 +18,7 @@ public InspectionResultsControl()
2118

2219
private void InspectionResultsControl_Loaded(object sender, RoutedEventArgs e)
2320
{
24-
if (ViewModel.CanRefresh)
21+
if (ViewModel != null && ViewModel.CanRefresh)
2522
{
2623
ViewModel.RefreshCommand.Execute(null);
2724
}

RetailCoder.VBE/UI/CodeInspections/InspectionResultsViewModel.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ public InspectionResultsViewModel(RubberduckParserState state, IInspector inspec
4242
_quickFixInModuleCommand = new DelegateCommand(ExecuteQuickFixInModuleCommand);
4343
_quickFixInProjectCommand = new DelegateCommand(ExecuteQuickFixInProjectCommand);
4444
_copyResultsCommand = new DelegateCommand(ExecuteCopyResultsCommand, CanExecuteCopyResultsCommand);
45-
46-
_inspectionResults = new ListCollectionView(_results);
47-
if (_inspectionResults.GroupDescriptions != null)
48-
{
49-
_inspectionResults.GroupDescriptions.Add(new PropertyGroupDescription("Inspection", new InspectionTypeConverter()));
50-
}
51-
}
52-
53-
private readonly ListCollectionView _inspectionResults;
54-
55-
public ListCollectionView InspectionResults
56-
{
57-
get { return _inspectionResults; }
5845
}
5946

6047
private readonly ObservableCollection<ICodeInspectionResult> _results = new ObservableCollection<ICodeInspectionResult>();
@@ -80,29 +67,13 @@ public INavigateSource SelectedItem
8067
CanExecuteQuickFixInProject = false;
8168

8269
var inspectionResult = _selectedItem as InspectionResultBase;
83-
8470
if (inspectionResult != null)
8571
{
8672
SelectedInspection = inspectionResult.Inspection;
8773
CanQuickFix = inspectionResult.HasQuickFixes;
8874
_defaultFix = inspectionResult.DefaultQuickFix;
8975
CanExecuteQuickFixInModule = _defaultFix != null && _defaultFix.CanFixInModule;
9076
}
91-
else
92-
{
93-
var viewGroup = _selectedItem as CollectionViewGroup;
94-
if (viewGroup != null)
95-
{
96-
var grouping = viewGroup;
97-
var inspection = grouping.Name as IInspection;
98-
if (inspection != null)
99-
{
100-
SelectedInspection = inspection;
101-
var result = _results.FirstOrDefault(item => item.Inspection == inspection);
102-
_defaultFix = result == null ? null : result.DefaultQuickFix;
103-
}
104-
}
105-
}
10677

10778
CanDisableInspection = SelectedInspection != null;
10879
CanExecuteQuickFixInProject = _defaultFix != null && _defaultFix.CanFixInProject;

RetailCoder.VBE/UI/ToDoItems/ToDoExplorerControl.xaml

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:toDoItems="clr-namespace:Rubberduck.UI.ToDoItems"
77
xmlns:themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
88
xmlns:controls="clr-namespace:Rubberduck.UI.Controls"
9+
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
910
x:Class="Rubberduck.UI.ToDoItems.ToDoExplorerControl"
1011
Language="{UICulture}"
1112
mc:Ignorable="d"
@@ -210,9 +211,35 @@
210211
</DataTrigger>
211212
</Style.Triggers>
212213
</Style>
214+
215+
<CollectionViewSource x:Key="ItemsByMarker" Source="{Binding Items}">
216+
<CollectionViewSource.SortDescriptions>
217+
<componentModel:SortDescription PropertyName="Type" />
218+
</CollectionViewSource.SortDescriptions>
219+
<CollectionViewSource.GroupDescriptions>
220+
<PropertyGroupDescription PropertyName="Type" />
221+
</CollectionViewSource.GroupDescriptions>
222+
</CollectionViewSource>
223+
224+
<CollectionViewSource x:Key="ItemsByLocation" Source="{Binding Items}">
225+
<CollectionViewSource.SortDescriptions>
226+
<componentModel:SortDescription PropertyName="Selection.QualifiedName.Name" />
227+
</CollectionViewSource.SortDescriptions>
228+
<CollectionViewSource.GroupDescriptions>
229+
<PropertyGroupDescription PropertyName="Selection.QualifiedName" />
230+
</CollectionViewSource.GroupDescriptions>
231+
</CollectionViewSource>
232+
213233
</UserControl.Resources>
214-
<DockPanel LastChildFill="True">
215-
<ToolBarTray DockPanel.Dock="Top" IsLocked="True">
234+
235+
<Grid>
236+
237+
<Grid.RowDefinitions>
238+
<RowDefinition Height="30"/>
239+
<RowDefinition Height="*" />
240+
</Grid.RowDefinitions>
241+
242+
<ToolBarTray Grid.Row="0" IsLocked="True">
216243
<ToolBar Style="{DynamicResource ToolBarWithOverflowOnlyShowingWhenNeededStyle}">
217244
<Button ToolTip="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Refresh}" Command="{Binding RefreshCommand, Mode=OneWay}" BorderThickness="0" Background="Transparent">
218245
<Image Source="{StaticResource RefreshImage}" />
@@ -221,16 +248,45 @@
221248
<Button ToolTip="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Remove}" Command="{Binding Remove}" BorderThickness="0" Background="Transparent">
222249
<Image Source="{StaticResource DeleteImage}" />
223250
</Button>
251+
<Menu>
252+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GroupingGrid_GroupingStyle}">
253+
<MenuItem.Icon>
254+
<Image Height="16" Source="../../Resources/Microsoft/PNG/GroupBy_284_32.png" />
255+
</MenuItem.Icon>
256+
257+
<MenuItem x:Name="GroupByMarker" Style="{DynamicResource MenuItemStyle}" VerticalAlignment="Center"
258+
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GroupingStyle_ByMarker}" IsChecked="True"
259+
IsCheckable="True" controls:MenuItemGroup.GroupName="ToDoExplorer_GroupingStyle" />
260+
<MenuItem x:Name="GroupByLocation" Style="{DynamicResource MenuItemStyle}" VerticalAlignment="Center"
261+
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GroupingStyle_ByLocation}"
262+
IsCheckable="True" controls:MenuItemGroup.GroupName="ToDoExplorer_GroupingStyle" />
263+
</MenuItem>
264+
</Menu>
224265
</ToolBar>
225266
</ToolBarTray>
226-
<controls:GroupingGrid ItemsSource="{Binding ToDos}"
227-
SelectedItem="{Binding SelectedToDo}">
267+
268+
<controls:GroupingGrid Grid.Row="1" ShowGroupingItemCount="True"
269+
ItemsSource="{Binding Source={StaticResource ItemsByMarker}}"
270+
SelectedItem="{Binding SelectedItem}"
271+
Visibility="{Binding Path=IsChecked, ElementName=GroupByMarker, Converter={StaticResource BoolToVisibility}}">
272+
<controls:GroupingGrid.Columns>
273+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TodoExplorer_Description}" Binding="{Binding Description}" Width="*"/>
274+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ProjectName}" Binding="{Binding Selection.QualifiedName.ProjectName}" />
275+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ModuleName}" Binding="{Binding Selection.QualifiedName.ComponentName}" />
276+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TodoExplorer_LineNumber}" Binding="{Binding Selection.Selection.StartLine}" />
277+
</controls:GroupingGrid.Columns>
278+
</controls:GroupingGrid>
279+
280+
<controls:GroupingGrid Grid.Row="1" ShowGroupingItemCount="True"
281+
ItemsSource="{Binding Source={StaticResource ItemsByLocation}}"
282+
SelectedItem="{Binding SelectedItem}"
283+
Visibility="{Binding Path=IsChecked, ElementName=GroupByLocation, Converter={StaticResource BoolToVisibility}}">
228284
<controls:GroupingGrid.Columns>
229285
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TodoExplorer_Description}" Binding="{Binding Description}" Width="*"/>
230-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ProjectName}" Binding="{Binding ProjectName}" />
231-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ModuleName}" Binding="{Binding ModuleName}" />
232-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TodoExplorer_LineNumber}" Binding="{Binding LineNumber}" />
286+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ProjectName}" Binding="{Binding Selection.QualifiedName.ProjectName}" />
287+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ModuleName}" Binding="{Binding Selection.QualifiedName.ComponentName}" />
288+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TodoExplorer_LineNumber}" Binding="{Binding Selection.Selection.StartLine}" />
233289
</controls:GroupingGrid.Columns>
234290
</controls:GroupingGrid>
235-
</DockPanel>
291+
</Grid>
236292
</UserControl>
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
using System.Windows.Input;
2-
1+

32
namespace Rubberduck.UI.ToDoItems
43
{
54
/// <summary>
65
/// Interaction logic for ToDoExplorerControl.xaml
76
/// </summary>
87
public partial class ToDoExplorerControl
98
{
9+
private ToDoExplorerViewModel ViewModel { get { return DataContext as ToDoExplorerViewModel; } }
10+
1011
public ToDoExplorerControl()
1112
{
1213
InitializeComponent();
14+
Loaded += ToDoExplorerControl_Loaded;
15+
}
16+
17+
void ToDoExplorerControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
18+
{
19+
if (ViewModel != null && ViewModel.RefreshCommand.CanExecute(null))
20+
{
21+
ViewModel.RefreshCommand.Execute(null);
22+
}
1323
}
1424
}
1525
}
Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
23
using System.Linq;
3-
using System.Threading.Tasks;
4-
using System.Windows.Data;
54
using System.Windows.Input;
65
using System.Windows.Threading;
76
using Rubberduck.Parsing.Nodes;
@@ -15,28 +14,19 @@ namespace Rubberduck.UI.ToDoItems
1514
{
1615
public class ToDoExplorerViewModel : ViewModelBase, INavigateSelection
1716
{
17+
private readonly Dispatcher _dispatcher;
1818
private readonly RubberduckParserState _state;
19-
private readonly IEnumerable<ToDoMarker> _markers;
20-
private ListCollectionView _toDos;
19+
private readonly IGeneralConfigService _configService;
20+
2121
public ToDoExplorerViewModel(RubberduckParserState state, IGeneralConfigService configService)
2222
{
23+
_dispatcher = Dispatcher.CurrentDispatcher;
2324
_state = state;
24-
_markers = configService.LoadConfiguration().UserSettings.ToDoListSettings.ToDoMarkers;
25-
26-
_uiDispatcher = Dispatcher.CurrentDispatcher;
25+
_configService = configService;
2726
}
2827

29-
public ListCollectionView ToDos {
30-
get
31-
{
32-
return _toDos;
33-
}
34-
set
35-
{
36-
_toDos = value;
37-
OnPropertyChanged();
38-
}
39-
}
28+
private readonly ObservableCollection<ToDoItem> _items = new ObservableCollection<ToDoItem>();
29+
public ObservableCollection<ToDoItem> Items { get { return _items; } }
4030

4131
private ICommand _refreshCommand;
4232
public ICommand RefreshCommand
@@ -61,20 +51,27 @@ private async void _state_StateChanged(object sender, ParserStateEventArgs e)
6151
{
6252
return;
6353
}
64-
var results = await GetItems();
65-
66-
_uiDispatcher.Invoke(() =>
54+
_dispatcher.Invoke(() =>
6755
{
68-
ToDos = new ListCollectionView(results.ToList());
69-
if (ToDos.GroupDescriptions != null)
56+
Items.Clear();
57+
foreach (var item in GetItems())
7058
{
71-
ToDos.GroupDescriptions.Add(new PropertyGroupDescription("Type"));
59+
Items.Add(item);
7260
}
7361
});
7462
}
7563

76-
public INavigateSource SelectedItem { get { return SelectedToDo; } set { SelectedToDo = value as ToDoItem; } }
77-
public ToDoItem SelectedToDo { get; set; }
64+
private ToDoItem _selectedItem;
65+
66+
public INavigateSource SelectedItem
67+
{
68+
get { return _selectedItem; }
69+
set
70+
{
71+
_selectedItem = value as ToDoItem;
72+
OnPropertyChanged();
73+
}
74+
}
7875

7976
private ICommand _clear;
8077
public ICommand Remove
@@ -87,25 +84,23 @@ public ICommand Remove
8784
}
8885
return _clear = new DelegateCommand(_ =>
8986
{
90-
if (SelectedToDo == null)
87+
if (_selectedItem == null)
9188
{
9289
return;
9390
}
94-
var module = SelectedToDo.GetSelection().QualifiedName.Component.CodeModule;
91+
var module = _selectedItem.Selection.QualifiedName.Component.CodeModule;
9592

96-
var oldContent = module.Lines[SelectedToDo.LineNumber, 1];
97-
var newContent =
98-
oldContent.Remove(SelectedToDo.GetSelection().Selection.StartColumn - 1);
93+
var oldContent = module.Lines[_selectedItem.Selection.Selection.StartLine, 1];
94+
var newContent = oldContent.Remove(_selectedItem.Selection.Selection.StartColumn - 1);
9995

100-
module.ReplaceLine(SelectedToDo.LineNumber, newContent);
96+
module.ReplaceLine(_selectedItem.Selection.Selection.StartLine, newContent);
10197

10298
RefreshCommand.Execute(null);
10399
});
104100
}
105101
}
106102

107103
private NavigateCommand _navigateCommand;
108-
private readonly Dispatcher _uiDispatcher;
109104

110105
public INavigateCommand NavigateCommand
111106
{
@@ -121,26 +116,15 @@ public INavigateCommand NavigateCommand
121116

122117
private IEnumerable<ToDoItem> GetToDoMarkers(CommentNode comment)
123118
{
124-
var c = _markers.Where(marker => !string.IsNullOrEmpty(marker.Text));
125-
var t = _markers.Select(marker => marker.Text.ToLowerInvariant());
126-
var v = comment.Comment.ToLowerInvariant();
127-
var y = _markers.Where(marker => comment.Comment.ToLowerInvariant().Contains(marker.Text.ToLowerInvariant()));
128-
var z = _markers.Select(marker => new ToDoItem(marker.Text, comment)).ToList();
129-
130-
return _markers.Where(marker => !string.IsNullOrEmpty(marker.Text)
131-
&& comment.Comment.ToLowerInvariant().Contains(marker.Text.ToLowerInvariant()))
132-
.Select(marker => new ToDoItem(marker.Text, comment)).ToList();
119+
var markers = _configService.LoadConfiguration().UserSettings.ToDoListSettings.ToDoMarkers;
120+
return markers.Where(marker => !string.IsNullOrEmpty(marker.Text)
121+
&& comment.Comment.ToLowerInvariant().Contains(marker.Text.ToLowerInvariant()))
122+
.Select(marker => new ToDoItem(marker.Text, comment));
133123
}
134124

135-
private async Task<IOrderedEnumerable<ToDoItem>> GetItems()
125+
private IEnumerable<ToDoItem> GetItems()
136126
{
137-
var markers = _state.AllComments.SelectMany(GetToDoMarkers).ToList();
138-
var sortedItems = markers.OrderByDescending(item => item.Type)
139-
.ThenBy(item => item.ProjectName)
140-
.ThenBy(item => item.ModuleName)
141-
.ThenBy(item => item.LineNumber);
142-
143-
return sortedItems;
127+
return _state.AllComments.SelectMany(GetToDoMarkers);
144128
}
145129
}
146130
}

0 commit comments

Comments
 (0)