Skip to content

Commit

Permalink
Refresh TODO explorer to match other UI elements, refactor grouping t…
Browse files Browse the repository at this point in the history
…o get rid of duplicated grid control.
  • Loading branch information
comintern committed Feb 26, 2019
1 parent 7acfedb commit 0f527e5
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 364 deletions.
42 changes: 42 additions & 0 deletions Rubberduck.Core/UI/Converters/GroupingToBooleanConverter.cs
@@ -0,0 +1,42 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Rubberduck.UI.ToDoItems;

namespace Rubberduck.UI.Converters
{
public class ToDoItemGroupingToBooleanConverter : GroupingToBooleanConverter<ToDoItemGrouping> { }

/// <summary>
/// Provides a mutually exclusive binding between an ToDoItemGrouping and a boolean.
/// Note: This is a stateful converter, so each bound control requires its own converter instance.
/// </summary>
public class GroupingToBooleanConverter<T> : IValueConverter where T : IConvertible, IComparable
{
private T _state;

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(parameter is T governing) ||
!(value is T bound))
{
return false;
}

_state = bound;
return _state.Equals(governing);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(parameter is T governing) ||
!(value is bool isSet))
{
return _state;
}

_state = isSet ? governing : _state;
return _state;
}
}
}

0 comments on commit 0f527e5

Please sign in to comment.