Merge 07fc5588a75fd465b2168556dc37ee21e51b9e24 into 7b8ff1e3cbe13f52844619c58ee289b97fa5e92f

This commit is contained in:
Derrick Rice 2017-05-14 18:16:20 +00:00 committed by GitHub
commit 02a52c81cf
3 changed files with 92 additions and 20 deletions

View File

@ -1,17 +1,23 @@
using System; using System;
using System.ComponentModel;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Media; using System.Windows.Media;
using Filtration.ObjectModel.Annotations;
using Filtration.ObjectModel.BlockItemBaseTypes; using Filtration.ObjectModel.BlockItemBaseTypes;
using Filtration.ObjectModel.BlockItemTypes; using Filtration.ObjectModel.BlockItemTypes;
using Filtration.ObjectModel.Enums; using Filtration.ObjectModel.Enums;
using Filtration.ObjectModel.Extensions; using Filtration.ObjectModel.Extensions;
namespace Filtration.ObjectModel namespace Filtration.ObjectModel
{ {
public interface IItemFilterBlock public interface IItemFilterBlock
{ {
bool Enabled { get; set; } 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; } string Description { get; set; }
ItemFilterBlockGroup BlockGroup { get; set; } ItemFilterBlockGroup BlockGroup { get; set; }
BlockAction Action { get; set; } BlockAction Action { get; set; }
@ -26,18 +32,43 @@ namespace Filtration.ObjectModel
bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup); bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup);
} }
public class ItemFilterBlock : IItemFilterBlock public class ItemFilterBlock : IItemFilterBlock, INotifyPropertyChanged
{ {
protected bool _Enabled;
private ItemFilterBlockGroup _blockGroup; 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() public ItemFilterBlock()
{ {
BlockItems = new ObservableCollection<IItemFilterBlockItem> {new ActionBlockItem(BlockAction.Show)}; 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 string Description { get; set; }
public bool DisableWithGroup { get; set; }
public ItemFilterBlockGroup BlockGroup public ItemFilterBlockGroup BlockGroup
{ {
@ -113,13 +144,23 @@ namespace Filtration.ObjectModel
private void OnBlockGroupStatusChanged(object sender, EventArgs e) 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;
}
} }
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;
}
} }
} }

View File

@ -394,12 +394,36 @@ namespace Filtration.Parser.Services
var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal); var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal);
if (blockGroupStart <= 0) return; if (blockGroupStart <= 0) return;
var blockGroupText = inputString.Substring(blockGroupStart + 1); var blockGroupText = inputString.Substring(blockGroupStart + 1).TrimStart();
var blockGroupModeStart = blockGroupText.IndexOf("|", StringComparison.Ordinal);
if (blockGroupModeStart >= 0)
{
var blockGroupMode = blockGroupText.Substring(blockGroupModeStart + 1).Trim();
blockGroupText = blockGroupText.Substring(0, blockGroupModeStart);
// Compatible with http://filterblast.oversoul.xyz/item-filter-syntax.html#smartblocks
// Except that REMOVE is just like COMMENT and DISABLE.
if (blockGroupMode.Equals("Comment", StringComparison.OrdinalIgnoreCase) ||
blockGroupMode.Equals("Remove", StringComparison.OrdinalIgnoreCase) ||
blockGroupMode.Equals("Disable", StringComparison.OrdinalIgnoreCase))
{
block.DisableWithGroup = true;
}
}
var blockGroups = blockGroupText.Split('-').ToList(); var blockGroups = blockGroupText.Split('-').ToList();
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.IsChecked = block.Action == BlockAction.Show; if (block.DisableWithGroup)
{
block.BlockGroup.IsChecked = block.Enabled;
}
else
{
block.BlockGroup.IsChecked = block.Action == BlockAction.Show;
}
} }
} }
@ -455,6 +479,10 @@ namespace Filtration.Parser.Services
if (block.BlockGroup != null) if (block.BlockGroup != null)
{ {
outputString += " # " + block.BlockGroup; outputString += " # " + block.BlockGroup;
if (block.DisableWithGroup)
{
outputString += " | Disable";
}
} }
// ReSharper disable once LoopCanBeConvertedToQuery // ReSharper disable once LoopCanBeConvertedToQuery

View File

@ -4,7 +4,6 @@ using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Windows.Media; using System.Windows.Media;
using Filtration.Common.ViewModels;
using Filtration.ObjectModel; using Filtration.ObjectModel;
using Filtration.ObjectModel.BlockItemBaseTypes; using Filtration.ObjectModel.BlockItemBaseTypes;
using Filtration.ObjectModel.BlockItemTypes; using Filtration.ObjectModel.BlockItemTypes;
@ -13,7 +12,7 @@ using Filtration.Views;
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
using Xceed.Wpf.Toolkit; using Xceed.Wpf.Toolkit;
namespace Filtration.ViewModels namespace Filtration.ViewModels
{ {
internal interface IItemFilterBlockViewModel internal interface IItemFilterBlockViewModel
@ -82,6 +81,12 @@ namespace Filtration.ViewModels
{ {
blockItem.PropertyChanged += OnBlockItemChanged; 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; } public RelayCommand CopyBlockCommand { get; private set; }
@ -204,15 +209,7 @@ namespace Filtration.ViewModels
public bool BlockEnabled public bool BlockEnabled
{ {
get { return Block.Enabled; } get { return Block.Enabled; }
set set { Block.Enabled = value;}
{
if (Block.Enabled != value)
{
Block.Enabled = value;
IsDirty = true;
RaisePropertyChanged();
}
}
} }
public string BlockDescription public string BlockDescription
@ -368,6 +365,12 @@ namespace Filtration.ViewModels
//} //}
} }
private void OnBlockChanged(object sender, EventArgs e)
{
IsDirty = true;
RaisePropertyChanged(nameof(BlockEnabled));
}
public void RefreshBlockPreview() public void RefreshBlockPreview()
{ {
RaisePropertyChanged(nameof(DisplayTextColor)); RaisePropertyChanged(nameof(DisplayTextColor));