Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
304 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Rubberduck.Core/UI/AddRemoveReferences/BindableListItemDrillThroughBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
using System.Windows.Interactivity; | ||
using GongSolutions.Wpf.DragDrop.Utilities; | ||
|
||
namespace Rubberduck.UI.Controls | ||
{ | ||
public class BindableListItemDrillThroughBehavior : Behavior<FrameworkElement> | ||
{ | ||
protected override void OnAttached() | ||
{ | ||
base.OnAttached(); | ||
|
||
var element = AssociatedObject; | ||
if (element == null) | ||
{ | ||
return; | ||
} | ||
|
||
AddHandler(element); | ||
} | ||
|
||
private void AddHandler(IInputElement element) | ||
{ | ||
element.PreviewMouseLeftButtonDown += OnClickStarting; | ||
} | ||
|
||
private void RemoveHandler(IInputElement element) | ||
{ | ||
element.PreviewMouseLeftButtonDown -= OnClickStarting; | ||
} | ||
|
||
private void OnClickStarting(object sender, MouseButtonEventArgs e) | ||
{ | ||
var element = AssociatedObject; | ||
var listItem = element?.GetVisualAncestor<ListViewItem>(); | ||
|
||
if (listItem == null) | ||
{ | ||
return; | ||
} | ||
|
||
listItem.IsSelected = true; | ||
} | ||
|
||
protected override void OnDetaching() | ||
{ | ||
var listView = AssociatedObject; | ||
if (listView != null) | ||
{ | ||
RemoveHandler(listView); | ||
} | ||
|
||
base.OnDetaching(); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
Rubberduck.Core/UI/AddRemoveReferences/BindableListViewResizeBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Interactivity; | ||
using GongSolutions.Wpf.DragDrop.Utilities; | ||
|
||
namespace Rubberduck.UI.AddRemoveReferences | ||
{ | ||
public class BindableListViewResizeBehavior : Behavior<ListView> | ||
{ | ||
protected override void OnAttached() | ||
{ | ||
base.OnAttached(); | ||
|
||
var listView = AssociatedObject; | ||
if (listView == null) | ||
{ | ||
return; | ||
} | ||
|
||
AddHandler(listView); | ||
} | ||
|
||
private void AddHandler(FrameworkElement listView) | ||
{ | ||
listView.SizeChanged += OnSizeChanged; | ||
} | ||
|
||
private void RemoveHandler(FrameworkElement listView) | ||
{ | ||
listView.SizeChanged -= OnSizeChanged; | ||
} | ||
|
||
private void OnSizeChanged(object sender, SizeChangedEventArgs e) | ||
{ | ||
if (!e.WidthChanged) | ||
{ | ||
return; | ||
} | ||
|
||
var listView = AssociatedObject; | ||
|
||
var textBlock = listView?.GetVisualDescendent<TextBlock>(); | ||
// ListView uses a grid internally, so we need to overshoot and come back. WPWTF. | ||
var grid = textBlock?.GetVisualAncestor<Grid>(); | ||
var target = grid?.ColumnDefinitions.FirstOrDefault(column => column.Width.IsStar); | ||
|
||
if (target == null) | ||
{ | ||
return; | ||
} | ||
|
||
var scroll = listView.GetVisualDescendents<ScrollViewer>() | ||
.FirstOrDefault(element => element.ComputedVerticalScrollBarVisibility == Visibility.Visible); | ||
|
||
var scrollWidth = scroll != null && scroll.IsVisible ? scroll.ActualWidth - scroll.ViewportWidth : 0; | ||
var calculated = listView.ActualWidth - grid.ColumnDefinitions | ||
.Where(column => !ReferenceEquals(target, column)) | ||
.Sum(column => column.Width.Value) - scrollWidth; | ||
|
||
target.Width = new GridLength(calculated); | ||
} | ||
|
||
protected override void OnDetaching() | ||
{ | ||
var listView = AssociatedObject; | ||
if (listView != null) | ||
{ | ||
RemoveHandler(listView); | ||
} | ||
|
||
base.OnDetaching(); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Rubberduck.Core/UI/AddRemoveReferences/SearchImageSourceConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows.Media; | ||
using ImageSourceConverter = Rubberduck.UI.Converters.ImageSourceConverter; | ||
|
||
namespace Rubberduck.UI.AddRemoveReferences | ||
{ | ||
public class SearchImageSourceConverter : ImageSourceConverter | ||
{ | ||
private readonly ImageSource _search = ToImageSource(Resources.RubberduckUI.magnifier_medium); | ||
private readonly ImageSource _clear = ToImageSource(Resources.RubberduckUI.cross_script); | ||
|
||
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return string.IsNullOrEmpty(value?.ToString()) ? _search : _clear; | ||
} | ||
} | ||
} |
Oops, something went wrong.