Skip to content

Commit a39cda5

Browse files
committed
Merge pull request #1099 from retailcoder/CodeExplorer
Code Inspections UI update
2 parents 012ddf1 + 515efda commit a39cda5

13 files changed

+456
-249
lines changed

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@
301301
<Compile Include="Common\WinAPI\WM.cs" />
302302
<Compile Include="Inspections\MakeSingleLineParameterQuickFix.cs" />
303303
<Compile Include="Inspections\RemoveExplicitCallStatemntQuickFix.cs" />
304+
<Compile Include="UI\Controls\MenuItemGroup.cs" />
304305
<Compile Include="UI\Controls\GroupingGrid.xaml.cs">
305306
<DependentUpon>GroupingGrid.xaml</DependentUpon>
306307
</Compile>
@@ -424,7 +425,7 @@
424425
<Compile Include="Inspections\IdentifierNotUsedInspectionResult.cs" />
425426
<Compile Include="Inspections\VariableNotAssignedInspection.cs" />
426427
<Compile Include="Inspections\IdentifierNotAssignedInspectionResult.cs" />
427-
<Compile Include="UI\BusyIndicator.xaml.cs">
428+
<Compile Include="UI\Controls\BusyIndicator.xaml.cs">
428429
<DependentUpon>BusyIndicator.xaml</DependentUpon>
429430
</Compile>
430431
<Compile Include="Navigation\CodeExplorer\CodeExplorerComponentViewModel.cs" />
@@ -805,7 +806,7 @@
805806
<Compile Include="UI\ToDoItems\ToDoExplorerDockablePresenter.cs" />
806807
<Compile Include="UI\ToDoItems\ToDoExplorerViewModel.cs" />
807808
<Compile Include="UI\ToDoItems\ToDoItemClickEventArgs.cs" />
808-
<Compile Include="UI\BindableSelectedItemBehavior.cs" />
809+
<Compile Include="UI\Controls\BindableSelectedItemBehavior.cs" />
809810
<Compile Include="UI\UnitTesting\StandardModuleTestExplorerModel.cs" />
810811
<Compile Include="UI\UnitTesting\TestExplorerControl.xaml.cs">
811812
<DependentUpon>TestExplorerControl.xaml</DependentUpon>
@@ -1374,7 +1375,7 @@
13741375
<SubType>Designer</SubType>
13751376
<Generator>MSBuild:Compile</Generator>
13761377
</Page>
1377-
<Page Include="UI\BusyIndicator.xaml">
1378+
<Page Include="UI\Controls\BusyIndicator.xaml">
13781379
<SubType>Designer</SubType>
13791380
<Generator>MSBuild:Compile</Generator>
13801381
</Page>

RetailCoder.VBE/UI/BusyIndicator.xaml.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:resx="clr-namespace:Rubberduck.UI"
76
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
87
xmlns:codeExplorer="clr-namespace:Rubberduck.Navigation.CodeExplorer"
8+
xmlns:controls="clr-namespace:Rubberduck.UI.Controls"
99
ResxExtension.DefaultResxName="Rubberduck.UI.RubberduckUI"
1010
Language="{UICulture}"
1111
mc:Ignorable="d"
@@ -187,11 +187,11 @@
187187
MouseDoubleClick="TreeView_OnMouseDoubleClick"
188188
Style="{StaticResource CodeExplorerTreeViewStyle}">
189189
<i:Interaction.Behaviors>
190-
<resx:BindableSelectedItemBehavior SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
190+
<controls:BindableSelectedItemBehavior SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
191191
</i:Interaction.Behaviors>
192192
</TreeView>
193193

194-
<resx:BusyIndicator Grid.Row="1" Width="36" Height="36" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibility}}" />
194+
<controls:BusyIndicator Grid.Row="1" Width="36" Height="36" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibility}}" />
195195

196196
<GridSplitter Grid.Row="2" Height="5" ShowsPreview="True" Cursor="SizeNS" HorizontalAlignment="Stretch"/>
197197

RetailCoder.VBE/UI/CodeInspections/InspectionResultsControl.xaml

Lines changed: 290 additions & 149 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,11 @@ namespace Rubberduck.UI.CodeInspections
1111
/// </summary>
1212
public partial class InspectionResultsControl : UserControl
1313
{
14-
private readonly CollectionViewSource _inspectionTypeGroupsViewSource;
15-
private readonly DataTemplate _inspectionTypeGroupsTemplate;
16-
17-
private readonly CollectionViewSource _moduleGroupsViewSource;
18-
private readonly DataTemplate _moduleGroupsTemplate;
19-
2014
private InspectionResultsViewModel ViewModel { get { return DataContext as InspectionResultsViewModel; } }
2115

2216
public InspectionResultsControl()
2317
{
2418
InitializeComponent();
25-
26-
_inspectionTypeGroupsViewSource = (CollectionViewSource)FindResource("InspectionTypeGroupViewSource");
27-
_inspectionTypeGroupsTemplate = (DataTemplate)FindResource("InspectionTypeGroupsTemplate");
28-
29-
_moduleGroupsViewSource = (CollectionViewSource)FindResource("CodeModuleGroupViewSource");
30-
_moduleGroupsTemplate = (DataTemplate)FindResource("CodeModuleGroupsTemplate");
31-
3219
Loaded += InspectionResultsControl_Loaded;
3320
}
3421

@@ -39,35 +26,5 @@ private void InspectionResultsControl_Loaded(object sender, RoutedEventArgs e)
3926
ViewModel.RefreshCommand.Execute(null);
4027
}
4128
}
42-
43-
private bool _isModuleTemplate;
44-
private void ToggleButton_Click(object sender, RoutedEventArgs e)
45-
{
46-
_isModuleTemplate = TreeViewStyleToggle.IsChecked.HasValue && TreeViewStyleToggle.IsChecked.Value;
47-
//InspectionResultsTreeView.ItemTemplate = _isModuleTemplate
48-
// ? _moduleGroupsTemplate
49-
// : _inspectionTypeGroupsTemplate;
50-
51-
//InspectionResultsTreeView.ItemsSource = _isModuleTemplate
52-
// ? _moduleGroupsViewSource.View.Groups
53-
// : _inspectionTypeGroupsViewSource.View.Groups;
54-
}
55-
56-
private void InspectionResultsTreeView_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
57-
{
58-
if (ViewModel == null || ViewModel.SelectedItem == null)
59-
{
60-
return;
61-
}
62-
63-
var selectedResult = ViewModel.SelectedItem as InspectionResultBase;
64-
if (selectedResult == null)
65-
{
66-
return;
67-
}
68-
69-
var arg = selectedResult.QualifiedSelection.GetNavitationArgs();
70-
ViewModel.NavigateCommand.Execute(arg);
71-
}
7229
}
7330
}

RetailCoder.VBE/UI/BindableSelectedItemBehavior.cs renamed to RetailCoder.VBE/UI/Controls/BindableSelectedItemBehavior.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Windows.Controls;
33
using System.Windows.Interactivity;
44

5-
namespace Rubberduck.UI
5+
namespace Rubberduck.UI.Controls
66
{
77
/// <summary>
88
/// http://stackoverflow.com/a/5118406/1188513

RetailCoder.VBE/UI/BusyIndicator.xaml renamed to RetailCoder.VBE/UI/Controls/BusyIndicator.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="Rubberduck.UI.BusyIndicator"
1+
<UserControl x:Class="Rubberduck.UI.Controls.BusyIndicator"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Windows.Controls;
2+
3+
namespace Rubberduck.UI.Controls
4+
{
5+
/// <summary>
6+
/// Interaction logic for BusyIndicator.xaml
7+
/// </summary>
8+
public partial class BusyIndicator : UserControl
9+
{
10+
public BusyIndicator()
11+
{
12+
InitializeComponent();
13+
}
14+
}
15+
}

RetailCoder.VBE/UI/Controls/GroupingGrid.xaml.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
11
using System.Windows;
2-
using System.Windows.Data;
32
using System.Windows.Input;
43

54
namespace Rubberduck.UI.Controls
65
{
76
public partial class GroupingGrid
87
{
9-
public static readonly DependencyProperty IsExpandedProperty =
10-
DependencyProperty.Register("IsExpanded", typeof (bool), typeof (GroupingGrid));
11-
128
public static readonly DependencyProperty ShowGroupingItemCountProperty =
139
DependencyProperty.Register("ShowGroupingItemCount", typeof (bool), typeof (GroupingGrid));
1410

15-
public bool IsExpanded
16-
{
17-
get { return (bool)GetValue(IsExpandedProperty); }
18-
set { SetValue(IsExpandedProperty, value); }
19-
}
20-
2111
public bool ShowGroupingItemCount
2212
{
2313
get { return (bool) GetValue(ShowGroupingItemCountProperty); }
2414
set { SetValue(ShowGroupingItemCountProperty, value); }
2515
}
2616

27-
public static readonly DependencyProperty GroupedItemSourceProperty =
28-
DependencyProperty.Register("GroupedItemSource", typeof (CollectionViewSource), typeof (GroupingGrid));
29-
30-
public CollectionViewSource GroupedItemSource
31-
{
32-
get { return (CollectionViewSource) GetValue(GroupedItemSourceProperty); }
33-
set { SetValue(GroupedItemSourceProperty, value); }
34-
}
35-
3617
public GroupingGrid()
3718
{
3819
InitializeComponent();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
6+
namespace Rubberduck.UI.Controls
7+
{
8+
/// <summary>
9+
/// Thanks to @Patrick at http://stackoverflow.com/a/3652980/1188513
10+
/// </summary>
11+
public class MenuItemGroup : DependencyObject
12+
{
13+
private static readonly Dictionary<MenuItem, string> ElementToGroupNames = new Dictionary<MenuItem, string>();
14+
15+
public static readonly DependencyProperty GroupNameProperty =
16+
DependencyProperty.RegisterAttached("GroupName",
17+
typeof(string),
18+
typeof(MenuItemGroup),
19+
new PropertyMetadata(string.Empty, OnGroupNameChanged));
20+
21+
public static void SetGroupName(MenuItem element, string value)
22+
{
23+
element.SetValue(GroupNameProperty, value);
24+
}
25+
26+
public static string GetGroupName(MenuItem element)
27+
{
28+
return element.GetValue(GroupNameProperty).ToString();
29+
}
30+
31+
private static void OnGroupNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
32+
{
33+
//Add an entry to the group name collection
34+
var menuItem = d as MenuItem;
35+
36+
if (menuItem != null)
37+
{
38+
var newGroupName = e.NewValue.ToString();
39+
var oldGroupName = e.OldValue.ToString();
40+
if (string.IsNullOrEmpty(newGroupName))
41+
{
42+
//Removing the toggle button from grouping
43+
RemoveCheckboxFromGrouping(menuItem);
44+
}
45+
else
46+
{
47+
//Switching to a new group
48+
if (newGroupName != oldGroupName)
49+
{
50+
if (!string.IsNullOrEmpty(oldGroupName))
51+
{
52+
//Remove the old group mapping
53+
RemoveCheckboxFromGrouping(menuItem);
54+
}
55+
ElementToGroupNames.Add(menuItem, e.NewValue.ToString());
56+
menuItem.Checked += MenuItemChecked;
57+
}
58+
}
59+
}
60+
}
61+
62+
private static void RemoveCheckboxFromGrouping(MenuItem checkBox)
63+
{
64+
ElementToGroupNames.Remove(checkBox);
65+
checkBox.Checked -= MenuItemChecked;
66+
}
67+
68+
69+
static void MenuItemChecked(object sender, RoutedEventArgs e)
70+
{
71+
var menuItem = e.OriginalSource as MenuItem;
72+
foreach (var item in ElementToGroupNames)
73+
{
74+
if (item.Key != menuItem && item.Value == GetGroupName(menuItem))
75+
{
76+
item.Key.IsChecked = false;
77+
}
78+
}
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)