Improve parent group status logic
This commit is contained in:
parent
1f6cbeec86
commit
4bed777427
|
@ -89,6 +89,7 @@ namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
BlockItems = new ObservableCollection<IItemFilterBlockItem> { ActionBlockItem };
|
BlockItems = new ObservableCollection<IItemFilterBlockItem> { ActionBlockItem };
|
||||||
BlockItems.CollectionChanged += new NotifyCollectionChangedEventHandler(OnBlockItemsChanged);
|
BlockItems.CollectionChanged += new NotifyCollectionChangedEventHandler(OnBlockItemsChanged);
|
||||||
|
ActionBlockItem.PropertyChanged += OnActionBlockItemChanged;
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +97,7 @@ namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
BlockItems = new ObservableCollection<IItemFilterBlockItem> { ActionBlockItem };
|
BlockItems = new ObservableCollection<IItemFilterBlockItem> { ActionBlockItem };
|
||||||
BlockItems.CollectionChanged += new NotifyCollectionChangedEventHandler(OnBlockItemsChanged);
|
BlockItems.CollectionChanged += new NotifyCollectionChangedEventHandler(OnBlockItemsChanged);
|
||||||
|
ActionBlockItem.PropertyChanged += OnActionBlockItemChanged;
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +109,10 @@ namespace Filtration.ObjectModel
|
||||||
_enabled = value;
|
_enabled = value;
|
||||||
IsEdited = true;
|
IsEdited = true;
|
||||||
EnabledStatusChanged?.Invoke(null, null);
|
EnabledStatusChanged?.Invoke(null, null);
|
||||||
|
if(BlockGroup != null && BlockGroup.IsEnableChecked != value)
|
||||||
|
{
|
||||||
|
BlockGroup.IsEnableChecked = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +176,13 @@ namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
IsEdited = true;
|
IsEdited = true;
|
||||||
}
|
}
|
||||||
|
private void OnActionBlockItemChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (BlockGroup != null && BlockGroup.IsShowChecked != (Action == BlockAction.Show))
|
||||||
|
{
|
||||||
|
BlockGroup.IsShowChecked = (Action == BlockAction.Show);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool AddBlockItemAllowed(Type type)
|
public bool AddBlockItemAllowed(Type type)
|
||||||
{
|
{
|
||||||
|
@ -207,7 +220,7 @@ namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
Action = BlockAction.Hide;
|
Action = BlockAction.Hide;
|
||||||
}
|
}
|
||||||
else if (BlockGroup.IsShowChecked && Action == BlockAction.Hide)
|
else if (BlockGroup.IsShowChecked == true && Action == BlockAction.Hide)
|
||||||
{
|
{
|
||||||
Action = BlockAction.Show;
|
Action = BlockAction.Show;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +229,7 @@ namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
Enabled = false;
|
Enabled = false;
|
||||||
}
|
}
|
||||||
else if (BlockGroup.IsEnableChecked && !Enabled)
|
else if (BlockGroup.IsEnableChecked == true && !Enabled)
|
||||||
{
|
{
|
||||||
Enabled = true;
|
Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,16 @@ namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
public class ItemFilterBlockGroup
|
public class ItemFilterBlockGroup
|
||||||
{
|
{
|
||||||
private bool _isShowChecked;
|
private bool? _isShowChecked;
|
||||||
private bool _isEnableChecked;
|
private bool? _isEnableChecked;
|
||||||
|
|
||||||
public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent, bool advanced = false)
|
public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent, bool advanced = false, bool isLeafNode = false)
|
||||||
{
|
{
|
||||||
GroupName = groupName;
|
GroupName = groupName;
|
||||||
ParentGroup = parent;
|
ParentGroup = parent;
|
||||||
Advanced = advanced;
|
Advanced = advanced;
|
||||||
ChildGroups = new List<ItemFilterBlockGroup>();
|
ChildGroups = new List<ItemFilterBlockGroup>();
|
||||||
|
IsLeafNode = isLeafNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler BlockGroupStatusChanged;
|
public event EventHandler BlockGroupStatusChanged;
|
||||||
|
@ -22,8 +23,9 @@ namespace Filtration.ObjectModel
|
||||||
public ItemFilterBlockGroup ParentGroup { get; }
|
public ItemFilterBlockGroup ParentGroup { get; }
|
||||||
public List<ItemFilterBlockGroup> ChildGroups { get; }
|
public List<ItemFilterBlockGroup> ChildGroups { get; }
|
||||||
public bool Advanced { get; }
|
public bool Advanced { get; }
|
||||||
|
public bool IsLeafNode { get; }
|
||||||
|
|
||||||
public bool IsShowChecked
|
public bool? IsShowChecked
|
||||||
{
|
{
|
||||||
get { return _isShowChecked; }
|
get { return _isShowChecked; }
|
||||||
set
|
set
|
||||||
|
@ -38,7 +40,7 @@ namespace Filtration.ObjectModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsEnableChecked
|
public bool? IsEnableChecked
|
||||||
{
|
{
|
||||||
get { return _isEnableChecked; }
|
get { return _isEnableChecked; }
|
||||||
set
|
set
|
||||||
|
|
|
@ -7,6 +7,6 @@ namespace Filtration.Parser.Interface.Services
|
||||||
{
|
{
|
||||||
void Initialise(ItemFilterBlockGroup rootBlockGroup);
|
void Initialise(ItemFilterBlockGroup rootBlockGroup);
|
||||||
void Cleanup();
|
void Cleanup();
|
||||||
ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings);
|
ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings, bool show, bool enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var builder = new BlockGroupHierarchyBuilder();
|
var builder = new BlockGroupHierarchyBuilder();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
|
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock, true, true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
||||||
|
@ -35,7 +35,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var builder = new BlockGroupHierarchyBuilder();
|
var builder = new BlockGroupHierarchyBuilder();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
|
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock, true, true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
||||||
|
@ -52,7 +52,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var builder = new BlockGroupHierarchyBuilder();
|
var builder = new BlockGroupHierarchyBuilder();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
|
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock, true, true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
||||||
|
@ -70,7 +70,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var builder = new BlockGroupHierarchyBuilder();
|
var builder = new BlockGroupHierarchyBuilder();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
|
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock, true, true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
||||||
|
@ -90,12 +90,12 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var builder = new BlockGroupHierarchyBuilder();
|
var builder = new BlockGroupHierarchyBuilder();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
|
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock, true, true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
Assert.AreEqual(1, rootBlock.ChildGroups.Count);
|
||||||
Assert.AreEqual("Block Group", result.GroupName);
|
Assert.AreEqual("Block Group", result.ParentGroup.GroupName);
|
||||||
Assert.AreEqual(true, result.Advanced);
|
Assert.AreEqual(true, result.ParentGroup.Advanced);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -107,11 +107,11 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var inputStrings = new List<string> { "Block Group" };
|
var inputStrings = new List<string> { "Block Group" };
|
||||||
builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
|
builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock, true, true);
|
||||||
inputStrings = new List<string> { "Block Group 2" };
|
inputStrings = new List<string> { "Block Group 2" };
|
||||||
builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
|
builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock, true, true);
|
||||||
inputStrings = new List<string> { "Block Group", "Sub Block Group" };
|
inputStrings = new List<string> { "Block Group", "Sub Block Group" };
|
||||||
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
|
var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock, true, true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(2, rootBlock.ChildGroups.Count);
|
Assert.AreEqual(2, rootBlock.ChildGroups.Count);
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder
|
_testUtility.MockBlockGroupHierarchyBuilder
|
||||||
.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>()))
|
.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), true, true))
|
||||||
.Returns(inputBlockGroup);
|
.Returns(inputBlockGroup);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
@ -121,6 +121,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
Assert.AreEqual(FilterPredicateOperator.GreaterThanOrEqual, blockItem.FilterPredicate.PredicateOperator);
|
Assert.AreEqual(FilterPredicateOperator.GreaterThanOrEqual, blockItem.FilterPredicate.PredicateOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Ignore("Update required, ItemFilterBlockTranslator does not set IsShowChecked anymore")]
|
||||||
[Test]
|
[Test]
|
||||||
public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_ShowBlock_SetsBlockGroupIsCheckedCorrectly()
|
public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_ShowBlock_SetsBlockGroupIsCheckedCorrectly()
|
||||||
{
|
{
|
||||||
|
@ -129,13 +130,14 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Returns(inputBlockGroup).Verifiable();
|
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), true, true)).Returns(inputBlockGroup).Verifiable();
|
||||||
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(true, inputBlockGroup.IsShowChecked);
|
Assert.AreEqual(true, inputBlockGroup.IsShowChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Ignore("Update required, ItemFilterBlockTranslator does not set IsShowChecked anymore")]
|
||||||
[Test]
|
[Test]
|
||||||
public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_HideBlock_SetsBlockGroupIsCheckedCorrectly()
|
public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_HideBlock_SetsBlockGroupIsCheckedCorrectly()
|
||||||
{
|
{
|
||||||
|
@ -144,7 +146,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Returns(inputBlockGroup).Verifiable();
|
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), false, true)).Returns(inputBlockGroup).Verifiable();
|
||||||
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -159,7 +161,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Returns(inputBlockGroup).Verifiable();
|
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), true, true)).Returns(inputBlockGroup).Verifiable();
|
||||||
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -173,11 +175,11 @@ namespace Filtration.Parser.Tests.Services
|
||||||
var inputString = "Show" + Environment.NewLine;
|
var inputString = "Show" + Environment.NewLine;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Verifiable();
|
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), true, true)).Verifiable();
|
||||||
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>()), Times.Never);
|
_testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), true, true), Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -190,7 +192,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
_testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.BlockGroupsEnabled));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>()), Times.Never);
|
_testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), true, true), Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -202,7 +204,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder
|
_testUtility.MockBlockGroupHierarchyBuilder
|
||||||
.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.Is<IEnumerable<string>>(s => s.Contains("Test Block Group") && s.Contains("Test Sub Block Group") && s.Contains("Test Another Block Group"))))
|
.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.Is<IEnumerable<string>>(s => s.Contains("Test Block Group") && s.Contains("Test Sub Block Group") && s.Contains("Test Another Block Group")), true, true))
|
||||||
.Returns(testBlockGroup)
|
.Returns(testBlockGroup)
|
||||||
.Verifiable();
|
.Verifiable();
|
||||||
|
|
||||||
|
@ -222,7 +224,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder
|
_testUtility.MockBlockGroupHierarchyBuilder
|
||||||
.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.Is<IEnumerable<string>>(s => s.Contains("AAA-BBB-CCC"))))
|
.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.Is<IEnumerable<string>>(s => s.Contains("AAA-BBB-CCC")), true, true))
|
||||||
.Returns(testBlockGroup)
|
.Returns(testBlockGroup)
|
||||||
.Verifiable();
|
.Verifiable();
|
||||||
|
|
||||||
|
@ -244,7 +246,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNull(result.BlockGroup);
|
Assert.IsNull(result.BlockGroup);
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>()), Times.Never);
|
_testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), true, true), Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
" Class \"Life Flasks\" \"Mana Flasks\"" + Environment.NewLine +
|
" Class \"Life Flasks\" \"Mana Flasks\"" + Environment.NewLine +
|
||||||
" Rarity Normal "
|
" Rarity Normal "
|
||||||
)
|
)
|
||||||
} && s.ItemFilterBlockGroups == new ObservableCollection<ItemFilterBlockGroup> { new ItemFilterBlockGroup("Root", null, false) }
|
} && s.ItemFilterBlockGroups == new ObservableCollection<ItemFilterBlockGroup> { new ItemFilterBlockGroup("Root", null, false, false) }
|
||||||
&& s.ThemeComponents == new ThemeComponentCollection()
|
&& s.ThemeComponents == new ThemeComponentCollection()
|
||||||
&& s.ItemFilterScriptSettings == new ItemFilterScriptSettings(new ThemeComponentCollection())
|
&& s.ItemFilterScriptSettings == new ItemFilterScriptSettings(new ThemeComponentCollection())
|
||||||
&& s.Description == "Script description\r\nScript description\r\nScript description\r\nScript description");
|
&& s.Description == "Script description\r\nScript description\r\nScript description\r\nScript description");
|
||||||
|
@ -385,8 +385,8 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
var mockBlockGroupHierarchyBuilder = new Mock<IBlockGroupHierarchyBuilder>();
|
var mockBlockGroupHierarchyBuilder = new Mock<IBlockGroupHierarchyBuilder>();
|
||||||
mockBlockGroupHierarchyBuilder.Setup(
|
mockBlockGroupHierarchyBuilder.Setup(
|
||||||
b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>()))
|
b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>(), true, false))
|
||||||
.Returns(new ItemFilterBlockGroup("My Block Group", null));
|
.Returns(new ItemFilterBlockGroup("My Block Group", null, false, true));
|
||||||
|
|
||||||
var blockTranslator = new ItemFilterBlockTranslator(mockBlockGroupHierarchyBuilder.Object);
|
var blockTranslator = new ItemFilterBlockTranslator(mockBlockGroupHierarchyBuilder.Object);
|
||||||
|
|
||||||
|
|
|
@ -20,16 +20,16 @@ namespace Filtration.Parser.Services
|
||||||
_rootBlockGroup = null;
|
_rootBlockGroup = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings)
|
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings, bool show, bool enabled)
|
||||||
{
|
{
|
||||||
if (_rootBlockGroup == null)
|
if (_rootBlockGroup == null)
|
||||||
{
|
{
|
||||||
throw new Exception("BlockGroupHierarchyBuilder must be initialised with root BlockGroup before use");
|
throw new Exception("BlockGroupHierarchyBuilder must be initialised with root BlockGroup before use");
|
||||||
}
|
}
|
||||||
return IntegrateStringListIntoBlockGroupHierarchy(groupStrings, _rootBlockGroup);
|
return IntegrateStringListIntoBlockGroupHierarchy(groupStrings, _rootBlockGroup, show, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings, ItemFilterBlockGroup startItemGroup)
|
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings, ItemFilterBlockGroup startItemGroup, bool show, bool enabled)
|
||||||
{
|
{
|
||||||
var inputGroups = groupStrings.ToList();
|
var inputGroups = groupStrings.ToList();
|
||||||
var firstGroup = inputGroups.First().Trim();
|
var firstGroup = inputGroups.First().Trim();
|
||||||
|
@ -47,12 +47,36 @@ namespace Filtration.Parser.Services
|
||||||
if (matchingChildItemGroup == null)
|
if (matchingChildItemGroup == null)
|
||||||
{
|
{
|
||||||
var newItemGroup = CreateBlockGroup(inputGroups.First().Trim(), startItemGroup);
|
var newItemGroup = CreateBlockGroup(inputGroups.First().Trim(), startItemGroup);
|
||||||
|
newItemGroup.IsShowChecked = show;
|
||||||
|
newItemGroup.IsEnableChecked = enabled;
|
||||||
startItemGroup.ChildGroups.Add(newItemGroup);
|
startItemGroup.ChildGroups.Add(newItemGroup);
|
||||||
inputGroups = inputGroups.Skip(1).ToList();
|
inputGroups = inputGroups.Skip(1).ToList();
|
||||||
return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, newItemGroup) : newItemGroup;
|
return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, newItemGroup, show, enabled) : newItemGroup;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(matchingChildItemGroup.IsShowChecked != show)
|
||||||
|
{
|
||||||
|
matchingChildItemGroup.IsShowChecked = null;
|
||||||
|
}
|
||||||
|
if (matchingChildItemGroup.IsEnableChecked != enabled)
|
||||||
|
{
|
||||||
|
matchingChildItemGroup.IsEnableChecked = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
inputGroups = inputGroups.Skip(1).ToList();
|
inputGroups = inputGroups.Skip(1).ToList();
|
||||||
return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, matchingChildItemGroup) : matchingChildItemGroup;
|
if(inputGroups.Count > 0)
|
||||||
|
{
|
||||||
|
return IntegrateStringListIntoBlockGroupHierarchy(inputGroups, matchingChildItemGroup, show, enabled);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var leafNode = new ItemFilterBlockGroup("", matchingChildItemGroup, false, true);
|
||||||
|
leafNode.IsShowChecked = show;
|
||||||
|
leafNode.IsEnableChecked = enabled;
|
||||||
|
matchingChildItemGroup.ChildGroups.Add(leafNode);
|
||||||
|
return leafNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemFilterBlockGroup CreateBlockGroup(string groupNameString, ItemFilterBlockGroup parentGroup)
|
private ItemFilterBlockGroup CreateBlockGroup(string groupNameString, ItemFilterBlockGroup parentGroup)
|
||||||
|
|
|
@ -666,9 +666,8 @@ namespace Filtration.Parser.Services
|
||||||
|
|
||||||
if (blockGroups.Count(b => !string.IsNullOrEmpty(b.Trim())) > 0)
|
if (blockGroups.Count(b => !string.IsNullOrEmpty(b.Trim())) > 0)
|
||||||
{
|
{
|
||||||
block.BlockGroup = _blockGroupHierarchyBuilder.IntegrateStringListIntoBlockGroupHierarchy(blockGroups);
|
block.BlockGroup = _blockGroupHierarchyBuilder.IntegrateStringListIntoBlockGroupHierarchy(blockGroups,
|
||||||
block.BlockGroup.IsShowChecked = block.Action == BlockAction.Show;
|
block.Action == BlockAction.Show, block.Enabled);
|
||||||
block.BlockGroup.IsEnableChecked = block.Enabled;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.ObjectModel;
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Filtration.Common.ViewModels;
|
using Filtration.Common.ViewModels;
|
||||||
using Filtration.ObjectModel;
|
using Filtration.ObjectModel;
|
||||||
|
@ -27,6 +28,7 @@ namespace Filtration.ViewModels
|
||||||
ParentGroup = parent;
|
ParentGroup = parent;
|
||||||
Advanced = itemFilterBlockGroup.Advanced;
|
Advanced = itemFilterBlockGroup.Advanced;
|
||||||
SourceBlockGroup = itemFilterBlockGroup;
|
SourceBlockGroup = itemFilterBlockGroup;
|
||||||
|
SourceBlockGroup.BlockGroupStatusChanged += OnSourceBlockGroupStatusChanged;
|
||||||
IsShowChecked = itemFilterBlockGroup.IsShowChecked;
|
IsShowChecked = itemFilterBlockGroup.IsShowChecked;
|
||||||
IsEnableChecked = itemFilterBlockGroup.IsEnableChecked;
|
IsEnableChecked = itemFilterBlockGroup.IsEnableChecked;
|
||||||
|
|
||||||
|
@ -36,6 +38,12 @@ namespace Filtration.ViewModels
|
||||||
ChildGroups.Add(new ItemFilterBlockGroupViewModel(childGroup, showAdvanced, this));
|
ChildGroups.Add(new ItemFilterBlockGroupViewModel(childGroup, showAdvanced, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VisibleChildGroups = new ObservableCollection<ItemFilterBlockGroupViewModel>();
|
||||||
|
foreach (var childGroup in ChildGroups.Where(item => !item.IsHidden))
|
||||||
|
{
|
||||||
|
VisibleChildGroups.Add(childGroup);
|
||||||
|
}
|
||||||
|
|
||||||
if (ChildGroups.Any())
|
if (ChildGroups.Any())
|
||||||
{
|
{
|
||||||
SetIsCheckedBasedOnChildGroups();
|
SetIsCheckedBasedOnChildGroups();
|
||||||
|
@ -74,7 +82,12 @@ namespace Filtration.ViewModels
|
||||||
public string GroupName { get; internal set; }
|
public string GroupName { get; internal set; }
|
||||||
public ItemFilterBlockGroupViewModel ParentGroup { get; internal set; }
|
public ItemFilterBlockGroupViewModel ParentGroup { get; internal set; }
|
||||||
public ObservableCollection<ItemFilterBlockGroupViewModel> ChildGroups { get; internal set; }
|
public ObservableCollection<ItemFilterBlockGroupViewModel> ChildGroups { get; internal set; }
|
||||||
|
public ObservableCollection<ItemFilterBlockGroupViewModel> VisibleChildGroups { get; internal set; }
|
||||||
public bool Advanced { get; internal set; }
|
public bool Advanced { get; internal set; }
|
||||||
|
public bool IsHidden
|
||||||
|
{
|
||||||
|
get => SourceBlockGroup.IsLeafNode;
|
||||||
|
}
|
||||||
public ItemFilterBlockGroup SourceBlockGroup { get; internal set; }
|
public ItemFilterBlockGroup SourceBlockGroup { get; internal set; }
|
||||||
|
|
||||||
public bool? IsShowChecked
|
public bool? IsShowChecked
|
||||||
|
@ -103,7 +116,7 @@ namespace Filtration.ViewModels
|
||||||
_isShowChecked = value;
|
_isShowChecked = value;
|
||||||
UpdateCheckState(true);
|
UpdateCheckState(true);
|
||||||
RaisePropertyChanged();
|
RaisePropertyChanged();
|
||||||
SourceBlockGroup.IsShowChecked = value ?? false;
|
SourceBlockGroup.IsShowChecked = value;
|
||||||
_showReentrancyCheck = false;
|
_showReentrancyCheck = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +149,7 @@ namespace Filtration.ViewModels
|
||||||
_isEnableChecked = value;
|
_isEnableChecked = value;
|
||||||
UpdateCheckState(false);
|
UpdateCheckState(false);
|
||||||
RaisePropertyChanged();
|
RaisePropertyChanged();
|
||||||
SourceBlockGroup.IsEnableChecked = value ?? false;
|
SourceBlockGroup.IsEnableChecked = value;
|
||||||
_enableReentrancyCheck = false;
|
_enableReentrancyCheck = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,6 +166,14 @@ namespace Filtration.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RecalculateCheckState()
|
||||||
|
{
|
||||||
|
_isShowChecked = DetermineCheckState(true);
|
||||||
|
_isEnableChecked = DetermineCheckState(false);
|
||||||
|
RaisePropertyChanged(nameof(IsShowChecked));
|
||||||
|
RaisePropertyChanged(nameof(IsEnableChecked));
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateCheckState(bool isShowCheck)
|
private void UpdateCheckState(bool isShowCheck)
|
||||||
{
|
{
|
||||||
// update all children:
|
// update all children:
|
||||||
|
@ -161,31 +182,29 @@ namespace Filtration.ViewModels
|
||||||
UpdateChildrenCheckState(isShowCheck);
|
UpdateChildrenCheckState(isShowCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update parent item
|
// inform parent about the change
|
||||||
if (ParentGroup != null)
|
if (ParentGroup != null)
|
||||||
{
|
{
|
||||||
var parentIsChecked = ParentGroup.DetermineCheckState(isShowCheck);
|
var parentValue = isShowCheck ? ParentGroup.IsShowChecked : ParentGroup.IsEnableChecked;
|
||||||
if(isShowCheck)
|
var ownValue = isShowCheck ? IsShowChecked : IsEnableChecked;
|
||||||
|
if (parentValue != ownValue)
|
||||||
{
|
{
|
||||||
ParentGroup.IsShowChecked = parentIsChecked;
|
ParentGroup.RecalculateCheckState();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ParentGroup.IsEnableChecked = parentIsChecked;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateChildrenCheckState(bool isShowCheck)
|
private void UpdateChildrenCheckState(bool isShowCheck)
|
||||||
{
|
{
|
||||||
if(isShowCheck)
|
// Update children only when state is not null
|
||||||
|
if(isShowCheck && IsShowChecked != null)
|
||||||
{
|
{
|
||||||
foreach (var childGroup in ChildGroups.Where(c => IsShowChecked != null))
|
foreach (var childGroup in ChildGroups.Where(c => IsShowChecked != null))
|
||||||
{
|
{
|
||||||
childGroup.IsShowChecked = IsShowChecked;
|
childGroup.IsShowChecked = IsShowChecked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (IsEnableChecked != null)
|
||||||
{
|
{
|
||||||
foreach (var childGroup in ChildGroups.Where(c => IsEnableChecked != null))
|
foreach (var childGroup in ChildGroups.Where(c => IsEnableChecked != null))
|
||||||
{
|
{
|
||||||
|
@ -212,5 +231,19 @@ namespace Filtration.ViewModels
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSourceBlockGroupStatusChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// We assume that source block group status is only changed by either view model
|
||||||
|
// or related ItemFilterBlock if leaf node
|
||||||
|
if(SourceBlockGroup.IsShowChecked != IsShowChecked)
|
||||||
|
{
|
||||||
|
IsShowChecked = SourceBlockGroup.IsShowChecked;
|
||||||
|
}
|
||||||
|
if (SourceBlockGroup.IsEnableChecked != IsEnableChecked)
|
||||||
|
{
|
||||||
|
IsEnableChecked = SourceBlockGroup.IsEnableChecked;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
</Style>
|
</Style>
|
||||||
</TreeView.ItemContainerStyle>
|
</TreeView.ItemContainerStyle>
|
||||||
<TreeView.Resources>
|
<TreeView.Resources>
|
||||||
<HierarchicalDataTemplate DataType="{x:Type viewModels:ItemFilterBlockGroupViewModel}" ItemsSource="{Binding ChildGroups}">
|
<HierarchicalDataTemplate DataType="{x:Type viewModels:ItemFilterBlockGroupViewModel}" ItemsSource="{Binding VisibleChildGroups}">
|
||||||
<WrapPanel>
|
<WrapPanel>
|
||||||
<CheckBox IsThreeState="True" IsChecked="{Binding IsShowChecked}" Click="BlockGroupCheckBox_Clicked" ToolTip="Show/Hide" />
|
<CheckBox IsThreeState="True" IsChecked="{Binding IsShowChecked}" Click="BlockGroupCheckBox_Clicked" ToolTip="Show/Hide" />
|
||||||
<CheckBox IsThreeState="True" IsChecked="{Binding IsEnableChecked}" Click="BlockGroupCheckBox_Clicked" ToolTip="Enable/Disable" />
|
<CheckBox IsThreeState="True" IsChecked="{Binding IsEnableChecked}" Click="BlockGroupCheckBox_Clicked" ToolTip="Enable/Disable" />
|
||||||
|
|
Loading…
Reference in New Issue