Allow ability to enable/disable blocks with groups
https://github.com/ben-wallis/Filtration/issues/40 For any given block that uses block groups, those blocks will be enabled/disabled rather than toggled between show/hide if the following syntax is used: [show|hide] #! [group_spec] Notice the additional "!" immediately after the "#" and before the first group name. It is possible to have some blocks which toggle Enable/Disable and some which toggle Show/Hide for a given group.
This commit is contained in:
parent
11d85fdd1b
commit
8e5cd0045f
|
@ -1,17 +1,23 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Media;
|
||||
using Filtration.ObjectModel.Annotations;
|
||||
using Filtration.ObjectModel.BlockItemBaseTypes;
|
||||
using Filtration.ObjectModel.BlockItemTypes;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.Extensions;
|
||||
|
||||
|
||||
namespace Filtration.ObjectModel
|
||||
{
|
||||
public interface IItemFilterBlock
|
||||
{
|
||||
bool Enabled { get; set; }
|
||||
// Rather than toggling between Hide/Show when a group is toggled, Disable/Enable
|
||||
bool DisableWithGroup { get; set; }
|
||||
string Description { get; set; }
|
||||
ItemFilterBlockGroup BlockGroup { get; set; }
|
||||
BlockAction Action { get; set; }
|
||||
|
@ -26,18 +32,43 @@ namespace Filtration.ObjectModel
|
|||
bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup);
|
||||
}
|
||||
|
||||
public class ItemFilterBlock : IItemFilterBlock
|
||||
public class ItemFilterBlock : IItemFilterBlock, INotifyPropertyChanged
|
||||
{
|
||||
protected bool _Enabled;
|
||||
|
||||
private ItemFilterBlockGroup _blockGroup;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
var handler = PropertyChanged;
|
||||
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public ItemFilterBlock()
|
||||
{
|
||||
BlockItems = new ObservableCollection<IItemFilterBlockItem> {new ActionBlockItem(BlockAction.Show)};
|
||||
Enabled = true;
|
||||
DisableWithGroup = false;
|
||||
_Enabled = true;
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public bool Enabled
|
||||
{
|
||||
get { return _Enabled; }
|
||||
set
|
||||
{
|
||||
if (_Enabled != value)
|
||||
{
|
||||
_Enabled = value;
|
||||
OnPropertyChanged(nameof(Enabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Description { get; set; }
|
||||
public bool DisableWithGroup { get; set; }
|
||||
|
||||
public ItemFilterBlockGroup BlockGroup
|
||||
{
|
||||
|
@ -113,13 +144,28 @@ namespace Filtration.ObjectModel
|
|||
|
||||
private void OnBlockGroupStatusChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (BlockGroup.IsChecked == false && Action == BlockAction.Show)
|
||||
if (DisableWithGroup)
|
||||
{
|
||||
Action = BlockAction.Hide;
|
||||
if (BlockGroup.IsChecked != Enabled)
|
||||
{
|
||||
Enabled = BlockGroup.IsChecked;
|
||||
// DFRICE
|
||||
Console.WriteLine("TOGGLE! ENABLED=" + (Enabled ? "YES" : "NO"));
|
||||
// This is a bit hacky. Enabled/Disabled isn't part of BlockItems,
|
||||
// but we want to piggy back on the Observerable aspect of it.
|
||||
// Just generate a change event for the Action (Show/Hide) block.
|
||||
}
|
||||
}
|
||||
else if (BlockGroup.IsChecked && Action == BlockAction.Hide)
|
||||
else
|
||||
{
|
||||
Action = BlockAction.Show;
|
||||
if (BlockGroup.IsChecked == false && Action == BlockAction.Show)
|
||||
{
|
||||
Action = BlockAction.Hide;
|
||||
}
|
||||
else if (BlockGroup.IsChecked && Action == BlockAction.Hide)
|
||||
{
|
||||
Action = BlockAction.Show;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -394,12 +394,27 @@ namespace Filtration.Parser.Services
|
|||
var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal);
|
||||
if (blockGroupStart <= 0) return;
|
||||
|
||||
var blockGroupText = inputString.Substring(blockGroupStart + 1);
|
||||
var blockGroupText = inputString.Substring(blockGroupStart + 1).TrimStart();
|
||||
|
||||
if (blockGroupText.StartsWith("!"))
|
||||
{
|
||||
block.DisableWithGroup = true;
|
||||
blockGroupText = blockGroupText.Substring(1);
|
||||
//block.Description = block.Description + "--DR--";
|
||||
}
|
||||
|
||||
var blockGroups = blockGroupText.Split('-').ToList();
|
||||
if (blockGroups.Count(b => !string.IsNullOrEmpty(b.Trim())) > 0)
|
||||
{
|
||||
block.BlockGroup = _blockGroupHierarchyBuilder.IntegrateStringListIntoBlockGroupHierarchy(blockGroups);
|
||||
block.BlockGroup.IsChecked = block.Action == BlockAction.Show;
|
||||
if (block.DisableWithGroup)
|
||||
{
|
||||
block.BlockGroup.IsChecked = block.Enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
block.BlockGroup.IsChecked = block.Action == BlockAction.Show;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,7 +469,7 @@ namespace Filtration.Parser.Services
|
|||
|
||||
if (block.BlockGroup != null)
|
||||
{
|
||||
outputString += " # " + block.BlockGroup;
|
||||
outputString += (block.DisableWithGroup ? " #! " : " # ") + block.BlockGroup;
|
||||
}
|
||||
|
||||
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||
|
|
|
@ -82,6 +82,12 @@ namespace Filtration.ViewModels
|
|||
{
|
||||
blockItem.PropertyChanged += OnBlockItemChanged;
|
||||
}
|
||||
|
||||
// ItemFilterBlocks have innate properties themselves to listen to (such as enabled/disabled)
|
||||
if (itemFilterBlock is ItemFilterBlock)
|
||||
{
|
||||
((ItemFilterBlock)itemFilterBlock).PropertyChanged += OnBlockChanged;
|
||||
}
|
||||
}
|
||||
|
||||
public RelayCommand CopyBlockCommand { get; private set; }
|
||||
|
@ -204,15 +210,7 @@ namespace Filtration.ViewModels
|
|||
public bool BlockEnabled
|
||||
{
|
||||
get { return Block.Enabled; }
|
||||
set
|
||||
{
|
||||
if (Block.Enabled != value)
|
||||
{
|
||||
Block.Enabled = value;
|
||||
IsDirty = true;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
set { Block.Enabled = value;}
|
||||
}
|
||||
|
||||
public string BlockDescription
|
||||
|
@ -368,6 +366,13 @@ namespace Filtration.ViewModels
|
|||
//}
|
||||
}
|
||||
|
||||
private void OnBlockChanged(object sender, EventArgs e)
|
||||
{
|
||||
IsDirty = true;
|
||||
RaisePropertyChanged(nameof(BlockEnabled));
|
||||
Console.WriteLine("OnBlockChanged");
|
||||
}
|
||||
|
||||
public void RefreshBlockPreview()
|
||||
{
|
||||
RaisePropertyChanged(nameof(DisplayTextColor));
|
||||
|
|
Loading…
Reference in New Issue