From 1f6cbeec86a594eae4929547b90957dce5f1385b Mon Sep 17 00:00:00 2001 From: azakhi Date: Thu, 6 Sep 2018 09:59:09 +0300 Subject: [PATCH] Add enable/disable checkbox to group browser --- Filtration.ObjectModel/ItemFilterBlock.cs | 18 ++- .../ItemFilterBlockGroup.cs | 26 +++- .../Services/TestItemFilterBlockTranslator.cs | 4 +- .../Services/ItemFilterBlockTranslator.cs | 3 +- .../ItemFilterBlockGroupViewModel.cs | 131 +++++++++++++----- .../ViewModels/ItemFilterBlockViewModel.cs | 6 + .../ToolPanes/BlockGroupBrowserView.xaml | 5 +- 7 files changed, 150 insertions(+), 43 deletions(-) diff --git a/Filtration.ObjectModel/ItemFilterBlock.cs b/Filtration.ObjectModel/ItemFilterBlock.cs index 9062c76..37d8f53 100644 --- a/Filtration.ObjectModel/ItemFilterBlock.cs +++ b/Filtration.ObjectModel/ItemFilterBlock.cs @@ -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 diff --git a/Filtration.ObjectModel/ItemFilterBlockGroup.cs b/Filtration.ObjectModel/ItemFilterBlockGroup.cs index 594069f..cd21964 100644 --- a/Filtration.ObjectModel/ItemFilterBlockGroup.cs +++ b/Filtration.ObjectModel/ItemFilterBlockGroup.cs @@ -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 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; diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index 311bebf..400fc38 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -133,7 +133,7 @@ namespace Filtration.Parser.Tests.Services _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(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(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); // Assert - Assert.AreEqual(false, inputBlockGroup.IsChecked); + Assert.AreEqual(false, inputBlockGroup.IsShowChecked); } [Test] diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index fed51c4..1960096 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -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; } } diff --git a/Filtration/ViewModels/ItemFilterBlockGroupViewModel.cs b/Filtration/ViewModels/ItemFilterBlockGroupViewModel.cs index 54b7243..f8dc29e 100644 --- a/Filtration/ViewModels/ItemFilterBlockGroupViewModel.cs +++ b/Filtration/ViewModels/ItemFilterBlockGroupViewModel.cs @@ -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(); 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; diff --git a/Filtration/ViewModels/ItemFilterBlockViewModel.cs b/Filtration/ViewModels/ItemFilterBlockViewModel.cs index 4fa9893..5bf50e3 100644 --- a/Filtration/ViewModels/ItemFilterBlockViewModel.cs +++ b/Filtration/ViewModels/ItemFilterBlockViewModel.cs @@ -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; diff --git a/Filtration/Views/ToolPanes/BlockGroupBrowserView.xaml b/Filtration/Views/ToolPanes/BlockGroupBrowserView.xaml index 1e2dbd1..bcc0b1e 100644 --- a/Filtration/Views/ToolPanes/BlockGroupBrowserView.xaml +++ b/Filtration/Views/ToolPanes/BlockGroupBrowserView.xaml @@ -38,8 +38,9 @@ - - + + +