Add add/delete block group support to blocks

This commit is contained in:
azakhi
2018-09-07 15:26:12 +03:00
parent d23741555a
commit bfd722d362
6 changed files with 230 additions and 10 deletions

View File

@@ -17,14 +17,14 @@ namespace Filtration.ObjectModel
IsLeafNode = isLeafNode;
}
public event EventHandler BlockGroupStatusChanged;
public string GroupName { get; }
public ItemFilterBlockGroup ParentGroup { get; }
public ItemFilterBlockGroup ParentGroup { get; set; }
public List<ItemFilterBlockGroup> ChildGroups { get; }
public bool Advanced { get; }
public bool IsLeafNode { get; }
public event EventHandler BlockGroupStatusChanged;
public bool? IsShowChecked
{
get { return _isShowChecked; }
@@ -55,6 +55,57 @@ namespace Filtration.ObjectModel
}
}
public void ClearStatusChangeSubscribers()
{
BlockGroupStatusChanged = null;
}
public void AddOrJoinBlockGroup(ItemFilterBlockGroup blockGroup)
{
var childIndex = ChildGroups.FindIndex(item => item.GroupName.Equals(blockGroup.GroupName));
if (!blockGroup.IsLeafNode && childIndex >= 0)
{
while(blockGroup.ChildGroups.Count > 0)
{
ChildGroups[childIndex].AddOrJoinBlockGroup(blockGroup.ChildGroups[0]);
}
}
else
{
if(blockGroup.ParentGroup != null)
{
blockGroup.ParentGroup.ChildGroups.Remove(blockGroup);
}
blockGroup.ParentGroup = this;
ChildGroups.Add(blockGroup);
}
}
public void DetachSelf(bool keepChildren)
{
if(ParentGroup == null)
return;
if(IsLeafNode && ParentGroup.ParentGroup != null && ParentGroup.ChildGroups.Count < 2)
{
ParentGroup.DetachSelf(false);
}
else
{
ParentGroup.ChildGroups.Remove(this);
if (keepChildren)
{
foreach(var child in ChildGroups)
{
ParentGroup.AddOrJoinBlockGroup(child);
}
}
ParentGroup = null;
}
}
public override string ToString()
{
if(ParentGroup == null)