Skip to content

Commit b8c6933

Browse files
committed
fix namespaces from merge.
1 parent 071a91f commit b8c6933

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Input;
7+
using System.Windows.Interactivity;
8+
using GongSolutions.Wpf.DragDrop.Utilities;
9+
10+
namespace Rubberduck.UI.Inspections
11+
{
12+
public class InspectionContextMenuBehavior : Behavior<DataGrid>
13+
{
14+
protected override void OnAttached()
15+
{
16+
base.OnAttached();
17+
18+
var element = AssociatedObject;
19+
if (element == null)
20+
{
21+
return;
22+
}
23+
24+
AddHandler(element);
25+
}
26+
27+
private void AddHandler(FrameworkElement element)
28+
{
29+
element.PreviewMouseRightButtonDown += OnClickStarting;
30+
element.MouseMove += OnMouseMoved;
31+
element.ContextMenuOpening += OnContextMenuOpened;
32+
element.ContextMenuClosing += OnContextMenuClosed;
33+
}
34+
35+
private void RemoveHandler(FrameworkElement element)
36+
{
37+
element.PreviewMouseRightButtonDown -= OnClickStarting;
38+
element.MouseMove -= OnMouseMoved;
39+
element.ContextMenuOpening -= OnContextMenuOpened;
40+
element.ContextMenuClosing -= OnContextMenuClosed;
41+
}
42+
43+
private void OnClickStarting(object sender, MouseButtonEventArgs e)
44+
{
45+
var element = AssociatedObject;
46+
var listItem = element?.GetVisualAncestor<ListViewItem>();
47+
48+
if (listItem == null)
49+
{
50+
e.Handled = true;
51+
return;
52+
}
53+
54+
listItem.IsSelected = true;
55+
}
56+
57+
private void OnMouseMoved(object sender, MouseEventArgs e)
58+
{
59+
if (!(sender is DataGrid grid) || _contextMenuOpen || grid.ContextMenu is null)
60+
{
61+
return;
62+
}
63+
64+
grid.ContextMenu.Visibility = GetDataGridRows(grid).Any(row => row.IsMouseOver) ? Visibility.Visible : Visibility.Collapsed;
65+
}
66+
67+
private static IEnumerable<DataGridRow> GetDataGridRows(ItemsControl grid)
68+
{
69+
var source = grid.ItemsSource;
70+
if (source is null)
71+
{
72+
yield break;
73+
}
74+
75+
foreach (var item in source)
76+
{
77+
if (grid.ItemContainerGenerator.ContainerFromItem(item) is DataGridRow row)
78+
{
79+
yield return row;
80+
}
81+
}
82+
}
83+
84+
private bool _contextMenuOpen;
85+
86+
private void OnContextMenuOpened(object sender, EventArgs e)
87+
{
88+
_contextMenuOpen = true;
89+
}
90+
91+
private void OnContextMenuClosed(object sender, EventArgs e)
92+
{
93+
_contextMenuOpen = false;
94+
}
95+
96+
protected override void OnDetaching()
97+
{
98+
var listView = AssociatedObject;
99+
if (listView != null)
100+
{
101+
RemoveHandler(listView);
102+
}
103+
104+
base.OnDetaching();
105+
}
106+
}
107+
}

Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=CodeInspectionResults_Location}" Binding="{Binding QualifiedSelection.QualifiedName, Mode=OneTime}" />
218218
</DataGrid.Columns>
219219
<DataGrid.ContextMenu>
220-
<ContextMenu ItemsSource="{Binding PlacementTarget.DataContext.QuickFixes, RelativeSource={RelativeSource Self}}">
220+
<ContextMenu ItemsSource="{Binding PlacementTarget.DataContext.QuickFixes, RelativeSource={RelativeSource Self}}" Visibility="Collapsed">
221221
<ContextMenu.Resources>
222222
<Style TargetType="{x:Type MenuItem}">
223223
<Setter Property="Icon">
@@ -235,6 +235,7 @@
235235
</DataGrid.ContextMenu>
236236
<i:Interaction.Behaviors>
237237
<controls:GroupItemExpandedBehavior ExpandedState="{Binding ExpandedState, Mode=TwoWay}" />
238+
<codeInspections:InspectionContextMenuBehavior />
238239
</i:Interaction.Behaviors>
239240
</controls:GroupingGrid>
240241

Rubberduck.Main/Root/RubberduckIoCInstaller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private void RegisterConfiguration(IWindsorContainer container, Assembly[] assem
241241
.ImplementedBy<IndenterConfigProvider>()
242242
.LifestyleSingleton());
243243

244-
container.Register(Component.For<IConfigProvider<UnitTestSettings>>()
244+
container.Register(Component.For<IConfigProvider<UnitTesting.Settings.UnitTestSettings>>()
245245
.ImplementedBy<UnitTestConfigProvider>()
246246
.LifestyleSingleton());
247247
}

0 commit comments

Comments
 (0)