2015-06-04 13:15:54 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2015-06-06 15:44:38 -04:00
|
|
|
|
using System.Linq;
|
2015-06-24 14:57:16 -04:00
|
|
|
|
using Filtration.ObjectModel.BlockItemTypes;
|
2015-06-26 12:42:20 -04:00
|
|
|
|
using Filtration.ObjectModel.ThemeEditor;
|
2015-06-04 13:15:54 -04:00
|
|
|
|
|
2015-06-24 14:57:16 -04:00
|
|
|
|
namespace Filtration.ObjectModel
|
2015-06-04 13:15:54 -04:00
|
|
|
|
{
|
2015-12-19 18:02:32 -05:00
|
|
|
|
public interface IItemFilterScript
|
|
|
|
|
{
|
2015-12-28 12:30:34 -05:00
|
|
|
|
ObservableCollection<IItemFilterBlock> ItemFilterBlocks { get; }
|
2015-12-19 18:02:32 -05:00
|
|
|
|
ObservableCollection<ItemFilterBlockGroup> ItemFilterBlockGroups { get; }
|
|
|
|
|
ThemeComponentCollection ThemeComponents { get; set; }
|
|
|
|
|
string FilePath { get; set; }
|
|
|
|
|
string Description { get; set; }
|
|
|
|
|
DateTime DateModified { get; set; }
|
|
|
|
|
List<string> Validate();
|
|
|
|
|
void ReplaceColors(ReplaceColorsParameterSet replaceColorsParameterSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ItemFilterScript : IItemFilterScript
|
2015-06-04 13:15:54 -04:00
|
|
|
|
{
|
2015-06-08 15:17:34 -04:00
|
|
|
|
public ItemFilterScript()
|
2015-06-04 13:15:54 -04:00
|
|
|
|
{
|
2015-12-28 12:30:34 -05:00
|
|
|
|
ItemFilterBlocks = new ObservableCollection<IItemFilterBlock>();
|
2015-06-08 17:29:39 -04:00
|
|
|
|
ItemFilterBlockGroups = new ObservableCollection<ItemFilterBlockGroup>
|
|
|
|
|
{
|
|
|
|
|
new ItemFilterBlockGroup("Root", null)
|
|
|
|
|
};
|
2015-07-05 11:54:09 -04:00
|
|
|
|
ThemeComponents = new ThemeComponentCollection { IsMasterCollection = true};
|
2015-06-04 13:15:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-28 12:30:34 -05:00
|
|
|
|
public ObservableCollection<IItemFilterBlock> ItemFilterBlocks { get; }
|
2015-12-13 15:17:15 -05:00
|
|
|
|
public ObservableCollection<ItemFilterBlockGroup> ItemFilterBlockGroups { get; }
|
2015-06-25 18:05:24 -04:00
|
|
|
|
|
2015-07-05 11:54:09 -04:00
|
|
|
|
public ThemeComponentCollection ThemeComponents { get; set; }
|
2015-06-08 17:29:39 -04:00
|
|
|
|
|
2015-06-04 13:15:54 -04:00
|
|
|
|
public string FilePath { get; set; }
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
public DateTime DateModified { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<string> Validate()
|
|
|
|
|
{
|
|
|
|
|
var validationErrors = new List<string>();
|
|
|
|
|
|
2015-06-08 15:17:34 -04:00
|
|
|
|
if (ItemFilterBlocks.Count == 0)
|
2015-06-04 13:15:54 -04:00
|
|
|
|
{
|
|
|
|
|
validationErrors.Add("A script must have at least one block");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return validationErrors;
|
|
|
|
|
}
|
2016-08-21 08:33:14 -04:00
|
|
|
|
|
2015-06-06 15:44:38 -04:00
|
|
|
|
public void ReplaceColors(ReplaceColorsParameterSet replaceColorsParameterSet)
|
|
|
|
|
{
|
|
|
|
|
foreach (
|
|
|
|
|
var block in
|
2015-06-08 15:17:34 -04:00
|
|
|
|
ItemFilterBlocks.Where(b => BlockIsColorReplacementCandidate(replaceColorsParameterSet, b)))
|
2015-06-06 15:44:38 -04:00
|
|
|
|
{
|
|
|
|
|
if (replaceColorsParameterSet.ReplaceTextColor)
|
|
|
|
|
{
|
|
|
|
|
var textColorBlockItem = block.BlockItems.OfType<TextColorBlockItem>().First();
|
|
|
|
|
textColorBlockItem.Color = replaceColorsParameterSet.NewTextColor;
|
|
|
|
|
}
|
|
|
|
|
if (replaceColorsParameterSet.ReplaceBackgroundColor)
|
|
|
|
|
{
|
|
|
|
|
var backgroundColorBlockItem = block.BlockItems.OfType<BackgroundColorBlockItem>().First();
|
|
|
|
|
backgroundColorBlockItem.Color = replaceColorsParameterSet.NewBackgroundColor;
|
|
|
|
|
}
|
|
|
|
|
if (replaceColorsParameterSet.ReplaceBorderColor)
|
|
|
|
|
{
|
|
|
|
|
var borderColorBlockItem = block.BlockItems.OfType<BorderColorBlockItem>().First();
|
|
|
|
|
borderColorBlockItem.Color = replaceColorsParameterSet.NewBorderColor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-28 12:30:34 -05:00
|
|
|
|
private bool BlockIsColorReplacementCandidate(ReplaceColorsParameterSet replaceColorsParameterSet, IItemFilterBlock block)
|
2015-06-06 15:44:38 -04:00
|
|
|
|
{
|
|
|
|
|
var textColorItem = block.HasBlockItemOfType<TextColorBlockItem>()
|
|
|
|
|
? block.BlockItems.OfType<TextColorBlockItem>().First()
|
|
|
|
|
: null;
|
|
|
|
|
var backgroundColorItem = block.HasBlockItemOfType<BackgroundColorBlockItem>()
|
|
|
|
|
? block.BlockItems.OfType<BackgroundColorBlockItem>().First()
|
|
|
|
|
: null;
|
|
|
|
|
var borderColorItem = block.HasBlockItemOfType<BorderColorBlockItem>()
|
|
|
|
|
? block.BlockItems.OfType<BorderColorBlockItem>().First()
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
// If we don't have all of the things we want to replace, then we aren't a candidate for replacing those things.
|
|
|
|
|
if ((textColorItem == null && replaceColorsParameterSet.ReplaceTextColor) ||
|
|
|
|
|
(backgroundColorItem == null && replaceColorsParameterSet.ReplaceBackgroundColor) ||
|
|
|
|
|
(borderColorItem == null && replaceColorsParameterSet.ReplaceBorderColor))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((replaceColorsParameterSet.ReplaceTextColor &&
|
|
|
|
|
textColorItem.Color != replaceColorsParameterSet.OldTextColor) ||
|
|
|
|
|
(replaceColorsParameterSet.ReplaceBackgroundColor &&
|
|
|
|
|
backgroundColorItem.Color != replaceColorsParameterSet.OldBackgroundColor) ||
|
|
|
|
|
(replaceColorsParameterSet.ReplaceBorderColor &&
|
|
|
|
|
borderColorItem.Color != replaceColorsParameterSet.OldBorderColor))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 13:15:54 -04:00
|
|
|
|
}
|
|
|
|
|
}
|