Add enable/disable checkbox to group browser
This commit is contained in:
parent
ae38197052
commit
1f6cbeec86
|
@ -14,6 +14,7 @@ namespace Filtration.ObjectModel
|
|||
public interface IItemFilterBlock : IItemFilterBlockBase
|
||||
{
|
||||
bool Enabled { get; set; }
|
||||
event EventHandler EnabledStatusChanged;
|
||||
string Description { get; set; }
|
||||
ItemFilterBlockGroup BlockGroup { get; set; }
|
||||
BlockAction Action { get; set; }
|
||||
|
@ -105,8 +106,12 @@ namespace Filtration.ObjectModel
|
|||
{
|
||||
_enabled = value;
|
||||
IsEdited = true;
|
||||
EnabledStatusChanged?.Invoke(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler EnabledStatusChanged;
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return _description; }
|
||||
|
@ -198,14 +203,23 @@ namespace Filtration.ObjectModel
|
|||
|
||||
private void OnBlockGroupStatusChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (BlockGroup.IsChecked == false && Action == BlockAction.Show)
|
||||
if (BlockGroup.IsShowChecked == false && Action == BlockAction.Show)
|
||||
{
|
||||
Action = BlockAction.Hide;
|
||||
}
|
||||
else if (BlockGroup.IsChecked && Action == BlockAction.Hide)
|
||||
else if (BlockGroup.IsShowChecked && Action == BlockAction.Hide)
|
||||
{
|
||||
Action = BlockAction.Show;
|
||||
}
|
||||
|
||||
if (BlockGroup.IsEnableChecked == false && Enabled)
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
else if (BlockGroup.IsEnableChecked && !Enabled)
|
||||
{
|
||||
Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Color DisplayTextColor
|
||||
|
|
|
@ -5,7 +5,8 @@ namespace Filtration.ObjectModel
|
|||
{
|
||||
public class ItemFilterBlockGroup
|
||||
{
|
||||
private bool _isChecked;
|
||||
private bool _isShowChecked;
|
||||
private bool _isEnableChecked;
|
||||
|
||||
public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent, bool advanced = false)
|
||||
{
|
||||
|
@ -22,14 +23,14 @@ namespace Filtration.ObjectModel
|
|||
public List<ItemFilterBlockGroup> ChildGroups { get; }
|
||||
public bool Advanced { get; }
|
||||
|
||||
public bool IsChecked
|
||||
public bool IsShowChecked
|
||||
{
|
||||
get { return _isChecked; }
|
||||
get { return _isShowChecked; }
|
||||
set
|
||||
{
|
||||
if (value != _isChecked)
|
||||
if (value != _isShowChecked)
|
||||
{
|
||||
_isChecked = value;
|
||||
_isShowChecked = value;
|
||||
// Raise an event to let blocks that have this block group assigned that
|
||||
// they might need to change their Action due to the block group status changing.
|
||||
BlockGroupStatusChanged?.Invoke(null, null);
|
||||
|
@ -37,6 +38,21 @@ namespace Filtration.ObjectModel
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsEnableChecked
|
||||
{
|
||||
get { return _isEnableChecked; }
|
||||
set
|
||||
{
|
||||
if (value != _isEnableChecked)
|
||||
{
|
||||
_isEnableChecked = value;
|
||||
// Raise an event to let blocks that have this block group assigned that
|
||||
// they might need to change their Enabled due to the block group status changing.
|
||||
BlockGroupStatusChanged?.Invoke(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var currentBlockGroup = this;
|
||||
|
|
|
@ -133,7 +133,7 @@ namespace Filtration.Parser.Tests.Services
|
|||
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(true, inputBlockGroup.IsChecked);
|
||||
Assert.AreEqual(true, inputBlockGroup.IsShowChecked);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -148,7 +148,7 @@ namespace Filtration.Parser.Tests.Services
|
|||
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(false, inputBlockGroup.IsChecked);
|
||||
Assert.AreEqual(false, inputBlockGroup.IsShowChecked);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -667,7 +667,8 @@ namespace Filtration.Parser.Services
|
|||
if (blockGroups.Count(b => !string.IsNullOrEmpty(b.Trim())) > 0)
|
||||
{
|
||||
block.BlockGroup = _blockGroupHierarchyBuilder.IntegrateStringListIntoBlockGroupHierarchy(blockGroups);
|
||||
block.BlockGroup.IsChecked = block.Action == BlockAction.Show;
|
||||
block.BlockGroup.IsShowChecked = block.Action == BlockAction.Show;
|
||||
block.BlockGroup.IsEnableChecked = block.Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,12 @@ namespace Filtration.ViewModels
|
|||
{
|
||||
internal class ItemFilterBlockGroupViewModel : ViewModelBase
|
||||
{
|
||||
private bool? _isChecked;
|
||||
private bool _reentrancyCheck;
|
||||
private bool _postMapComplete;
|
||||
private bool? _isShowChecked;
|
||||
private bool? _isEnableChecked;
|
||||
private bool _showReentrancyCheck;
|
||||
private bool _enableReentrancyCheck;
|
||||
private bool _showPostMapComplete;
|
||||
private bool _enablePostMapComplete;
|
||||
private bool _isExpanded;
|
||||
|
||||
public ItemFilterBlockGroupViewModel()
|
||||
|
@ -24,7 +27,8 @@ namespace Filtration.ViewModels
|
|||
ParentGroup = parent;
|
||||
Advanced = itemFilterBlockGroup.Advanced;
|
||||
SourceBlockGroup = itemFilterBlockGroup;
|
||||
IsChecked = itemFilterBlockGroup.IsChecked;
|
||||
IsShowChecked = itemFilterBlockGroup.IsShowChecked;
|
||||
IsEnableChecked = itemFilterBlockGroup.IsEnableChecked;
|
||||
|
||||
ChildGroups = new ObservableCollection<ItemFilterBlockGroupViewModel>();
|
||||
foreach (var childGroup in itemFilterBlockGroup.ChildGroups.Where(c => showAdvanced || !c.Advanced))
|
||||
|
@ -40,17 +44,30 @@ namespace Filtration.ViewModels
|
|||
|
||||
private void SetIsCheckedBasedOnChildGroups()
|
||||
{
|
||||
if (ChildGroups.All(g => g.IsChecked == true))
|
||||
if (ChildGroups.All(g => g.IsShowChecked == true))
|
||||
{
|
||||
IsChecked = true;
|
||||
IsShowChecked = true;
|
||||
}
|
||||
else if (ChildGroups.Any(g => g.IsChecked == true || g.IsChecked == null))
|
||||
else if (ChildGroups.Any(g => g.IsShowChecked == true || g.IsShowChecked == null))
|
||||
{
|
||||
IsChecked = null;
|
||||
IsShowChecked = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
IsChecked = false;
|
||||
IsShowChecked = false;
|
||||
}
|
||||
|
||||
if (ChildGroups.All(g => g.IsEnableChecked == true))
|
||||
{
|
||||
IsEnableChecked = true;
|
||||
}
|
||||
else if (ChildGroups.Any(g => g.IsEnableChecked == true || g.IsEnableChecked == null))
|
||||
{
|
||||
IsEnableChecked = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
IsEnableChecked = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,34 +77,67 @@ namespace Filtration.ViewModels
|
|||
public bool Advanced { get; internal set; }
|
||||
public ItemFilterBlockGroup SourceBlockGroup { get; internal set; }
|
||||
|
||||
public bool? IsChecked
|
||||
public bool? IsShowChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isChecked;
|
||||
return _isShowChecked;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!_postMapComplete)
|
||||
if (!_showPostMapComplete)
|
||||
{
|
||||
_isChecked = value;
|
||||
_postMapComplete = true;
|
||||
_isShowChecked = value;
|
||||
_showPostMapComplete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isChecked != value)
|
||||
if (_isShowChecked != value)
|
||||
{
|
||||
|
||||
if (_reentrancyCheck)
|
||||
if (_showReentrancyCheck)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_reentrancyCheck = true;
|
||||
_isChecked = value;
|
||||
UpdateCheckState();
|
||||
_showReentrancyCheck = true;
|
||||
_isShowChecked = value;
|
||||
UpdateCheckState(true);
|
||||
RaisePropertyChanged();
|
||||
SourceBlockGroup.IsChecked = value ?? false;
|
||||
_reentrancyCheck = false;
|
||||
SourceBlockGroup.IsShowChecked = value ?? false;
|
||||
_showReentrancyCheck = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool? IsEnableChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnableChecked;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!_enablePostMapComplete)
|
||||
{
|
||||
_isEnableChecked = value;
|
||||
_enablePostMapComplete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isEnableChecked != value)
|
||||
{
|
||||
|
||||
if (_enableReentrancyCheck)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_enableReentrancyCheck = true;
|
||||
_isEnableChecked = value;
|
||||
UpdateCheckState(false);
|
||||
RaisePropertyChanged();
|
||||
SourceBlockGroup.IsEnableChecked = value ?? false;
|
||||
_enableReentrancyCheck = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,39 +153,58 @@ namespace Filtration.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdateCheckState()
|
||||
private void UpdateCheckState(bool isShowCheck)
|
||||
{
|
||||
// update all children:
|
||||
if (ChildGroups.Count != 0)
|
||||
{
|
||||
UpdateChildrenCheckState();
|
||||
UpdateChildrenCheckState(isShowCheck);
|
||||
}
|
||||
|
||||
// update parent item
|
||||
if (ParentGroup != null)
|
||||
{
|
||||
var parentIsChecked = ParentGroup.DetermineCheckState();
|
||||
ParentGroup.IsChecked = parentIsChecked;
|
||||
var parentIsChecked = ParentGroup.DetermineCheckState(isShowCheck);
|
||||
if(isShowCheck)
|
||||
{
|
||||
ParentGroup.IsShowChecked = parentIsChecked;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParentGroup.IsEnableChecked = parentIsChecked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateChildrenCheckState()
|
||||
private void UpdateChildrenCheckState(bool isShowCheck)
|
||||
{
|
||||
foreach (var childGroup in ChildGroups.Where(c => IsChecked != null))
|
||||
if(isShowCheck)
|
||||
{
|
||||
childGroup.IsChecked = IsChecked;
|
||||
foreach (var childGroup in ChildGroups.Where(c => IsShowChecked != null))
|
||||
{
|
||||
childGroup.IsShowChecked = IsShowChecked;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var childGroup in ChildGroups.Where(c => IsEnableChecked != null))
|
||||
{
|
||||
childGroup.IsEnableChecked = IsEnableChecked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool? DetermineCheckState()
|
||||
private bool? DetermineCheckState(bool isShowCheck)
|
||||
{
|
||||
var allChildrenChecked = ChildGroups.Count(x => x.IsChecked == true) == ChildGroups.Count;
|
||||
var allChildrenChecked = (isShowCheck ? ChildGroups.Count(x => x.IsShowChecked == true) :
|
||||
ChildGroups.Count(x => x.IsEnableChecked == true)) == ChildGroups.Count;
|
||||
if (allChildrenChecked)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var allChildrenUnchecked = ChildGroups.Count(x => x.IsChecked == false) == ChildGroups.Count;
|
||||
var allChildrenUnchecked = (isShowCheck ? ChildGroups.Count(x => x.IsShowChecked == false) :
|
||||
ChildGroups.Count(x => x.IsEnableChecked == false)) == ChildGroups.Count;
|
||||
if (allChildrenUnchecked)
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -65,6 +65,7 @@ namespace Filtration.ViewModels
|
|||
_parentScriptViewModel = parentScriptViewModel;
|
||||
|
||||
Block = itemFilterBlock;
|
||||
Block.EnabledStatusChanged += OnBlockEnabledStatusChanged;
|
||||
|
||||
itemFilterBlock.BlockItems.CollectionChanged += OnBlockItemsCollectionChanged;
|
||||
|
||||
|
@ -438,6 +439,11 @@ namespace Filtration.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
private void OnBlockEnabledStatusChanged(object sender, EventArgs e)
|
||||
{
|
||||
RaisePropertyChanged(nameof(BlockEnabled));
|
||||
}
|
||||
|
||||
private void OnBlockItemChanged(object sender, EventArgs e)
|
||||
{
|
||||
var itemFilterBlockItem = sender as IItemFilterBlockItem;
|
||||
|
|
|
@ -38,8 +38,9 @@
|
|||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type viewModels:ItemFilterBlockGroupViewModel}" ItemsSource="{Binding ChildGroups}">
|
||||
<WrapPanel>
|
||||
<CheckBox IsThreeState="True" IsChecked="{Binding IsChecked}" Click="BlockGroupCheckBox_Clicked" />
|
||||
<TextBlock Text="{Binding GroupName}" VerticalAlignment="Center" Foreground="{Binding Advanced, Converter={StaticResource BlockGroupAdvancedColorConverter}}" />
|
||||
<CheckBox IsThreeState="True" IsChecked="{Binding IsShowChecked}" Click="BlockGroupCheckBox_Clicked" ToolTip="Show/Hide" />
|
||||
<CheckBox IsThreeState="True" IsChecked="{Binding IsEnableChecked}" Click="BlockGroupCheckBox_Clicked" ToolTip="Enable/Disable" />
|
||||
<TextBlock Text="{Binding GroupName}" VerticalAlignment="Center" Foreground="{Binding Advanced, Converter={StaticResource BlockGroupAdvancedColorConverter}}" />
|
||||
</WrapPanel>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
|
|
Loading…
Reference in New Issue