Refactored ThemeComponentBuilder into ThemeComponentCollection
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Filtration.Converters
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var themeComponentsList = values[0] as List<ThemeComponent>;
|
||||
var themeComponentsList = values[0] as ThemeComponentCollection;
|
||||
if (themeComponentsList == null || themeComponentsList.Count == 0) return null;
|
||||
|
||||
var blockItem = values[1] as ColorBlockItem;
|
||||
|
||||
@@ -159,7 +159,6 @@
|
||||
<Compile Include="Translators\BlockGroupHierarchyBuilder.cs" />
|
||||
<Compile Include="Translators\ItemFilterBlockTranslator.cs" />
|
||||
<Compile Include="Translators\ItemFilterScriptTranslator.cs" />
|
||||
<Compile Include="Translators\ThemeComponentListBuilder.cs" />
|
||||
<Compile Include="UserControls\AutoScrollingListBox.cs" />
|
||||
<Compile Include="UserControls\BlockItemControl.xaml.cs">
|
||||
<DependentUpon>BlockItemControl.xaml</DependentUpon>
|
||||
|
||||
@@ -10,14 +10,15 @@ using Filtration.ObjectModel.BlockItemBaseTypes;
|
||||
using Filtration.ObjectModel.BlockItemTypes;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.Extensions;
|
||||
using Filtration.ObjectModel.ThemeEditor;
|
||||
using Filtration.Utilities;
|
||||
|
||||
namespace Filtration.Translators
|
||||
{
|
||||
internal interface IItemFilterBlockTranslator
|
||||
{
|
||||
void InitialiseForExistingScript(ItemFilterScript script);
|
||||
ItemFilterBlock TranslateStringToItemFilterBlock(string inputString);
|
||||
ItemFilterBlock TranslateStringToItemFilterBlock(string inputString,
|
||||
ThemeComponentCollection masterComponentCollection);
|
||||
string TranslateItemFilterBlockToString(ItemFilterBlock block);
|
||||
void ReplaceColorBlockItemsFromString(ObservableCollection<IItemFilterBlockItem> blockItems, string inputString);
|
||||
}
|
||||
@@ -25,26 +26,20 @@ namespace Filtration.Translators
|
||||
internal class ItemFilterBlockTranslator : IItemFilterBlockTranslator
|
||||
{
|
||||
private readonly IBlockGroupHierarchyBuilder _blockGroupHierarchyBuilder;
|
||||
private readonly IThemeComponentListBuilder _themeComponentListBuilder;
|
||||
private const string Indent = " ";
|
||||
private readonly string _newLine = Environment.NewLine + Indent;
|
||||
private ThemeComponentCollection _masterComponentCollection;
|
||||
|
||||
public ItemFilterBlockTranslator(IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder, IThemeComponentListBuilder themeComponentListBuilder)
|
||||
public ItemFilterBlockTranslator(IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder)
|
||||
{
|
||||
_blockGroupHierarchyBuilder = blockGroupHierarchyBuilder;
|
||||
_themeComponentListBuilder = themeComponentListBuilder;
|
||||
}
|
||||
|
||||
public void InitialiseForExistingScript(ItemFilterScript script)
|
||||
{
|
||||
_themeComponentListBuilder.Initialise(script.ThemeComponents);
|
||||
_blockGroupHierarchyBuilder.Initialise(script.ItemFilterBlockGroups.First());
|
||||
}
|
||||
|
||||
// This method converts a string into a ItemFilterBlock. This is used for pasting ItemFilterBlocks
|
||||
// and reading ItemFilterScripts from a file.
|
||||
public ItemFilterBlock TranslateStringToItemFilterBlock(string inputString)
|
||||
public ItemFilterBlock TranslateStringToItemFilterBlock(string inputString, ThemeComponentCollection masterComponentCollection)
|
||||
{
|
||||
_masterComponentCollection = masterComponentCollection;
|
||||
var block = new ItemFilterBlock();
|
||||
var showHideFound = false;
|
||||
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
||||
@@ -300,9 +295,9 @@ namespace Filtration.Translators
|
||||
{
|
||||
throw new Exception("Parsing error - unknown theme component type");
|
||||
}
|
||||
if (_themeComponentListBuilder.IsInitialised)
|
||||
if (_masterComponentCollection != null)
|
||||
{
|
||||
blockItem.ThemeComponent = _themeComponentListBuilder.AddComponent(componentType, componentName,
|
||||
blockItem.ThemeComponent = _masterComponentCollection.AddComponent(componentType, componentName,
|
||||
blockItem.Color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,12 @@ namespace Filtration.Translators
|
||||
{
|
||||
private readonly IItemFilterBlockTranslator _blockTranslator;
|
||||
private readonly IBlockGroupHierarchyBuilder _blockGroupHierarchyBuilder;
|
||||
private readonly IThemeComponentListBuilder _themeComponentListBuilder;
|
||||
|
||||
public ItemFilterScriptTranslator(IItemFilterBlockTranslator blockTranslator,
|
||||
IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder,
|
||||
IThemeComponentListBuilder themeComponentListBuilder)
|
||||
IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder)
|
||||
{
|
||||
_blockTranslator = blockTranslator;
|
||||
_blockGroupHierarchyBuilder = blockGroupHierarchyBuilder;
|
||||
_themeComponentListBuilder = themeComponentListBuilder;
|
||||
}
|
||||
|
||||
public ItemFilterScript TranslateStringToItemFilterScript(string inputString)
|
||||
@@ -55,8 +52,6 @@ namespace Filtration.Translators
|
||||
script.Description = script.Description.TrimEnd('\n').TrimEnd('\r');
|
||||
}
|
||||
|
||||
_themeComponentListBuilder.Initialise();
|
||||
|
||||
// Extract each block from between boundaries and translate it into a ItemFilterBlock object
|
||||
// and add that object to the ItemFilterBlocks list
|
||||
for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next)
|
||||
@@ -66,12 +61,10 @@ namespace Filtration.Translators
|
||||
var block = new string[end - begin];
|
||||
Array.Copy(lines, begin, block, 0, end - begin);
|
||||
var blockString = string.Join("\r\n", block);
|
||||
script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString));
|
||||
script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script.ThemeComponents));
|
||||
}
|
||||
|
||||
script.ThemeComponents = _themeComponentListBuilder.GetComponents();
|
||||
_blockGroupHierarchyBuilder.Cleanup();
|
||||
_themeComponentListBuilder.Cleanup();
|
||||
return script;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.ThemeEditor;
|
||||
|
||||
namespace Filtration.Translators
|
||||
{
|
||||
internal interface IThemeComponentListBuilder
|
||||
{
|
||||
void Initialise();
|
||||
void Initialise(List<ThemeComponent> themeComponents);
|
||||
bool IsInitialised { get; }
|
||||
ThemeComponent AddComponent(ThemeComponentType componentType, string componentName, Color componentColor);
|
||||
List<ThemeComponent> GetComponents();
|
||||
void Cleanup();
|
||||
}
|
||||
|
||||
internal class ThemeComponentListBuilder : IThemeComponentListBuilder
|
||||
{
|
||||
private List<ThemeComponent> _themeComponents;
|
||||
|
||||
public ThemeComponentListBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsInitialised
|
||||
{
|
||||
get
|
||||
{
|
||||
return _themeComponents != null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialise()
|
||||
{
|
||||
_themeComponents = new List<ThemeComponent>();
|
||||
}
|
||||
|
||||
public void Initialise(List<ThemeComponent> themeComponents)
|
||||
{
|
||||
_themeComponents = themeComponents;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
_themeComponents = null;
|
||||
}
|
||||
|
||||
public ThemeComponent AddComponent(ThemeComponentType componentType, string componentName, Color componentColor)
|
||||
{
|
||||
if (ComponentExists(componentType, componentName))
|
||||
{
|
||||
return _themeComponents.FirstOrDefault(t => t.ComponentName == componentName && t.ComponentType == componentType);
|
||||
}
|
||||
|
||||
var component = new ThemeComponent(componentType, componentName, componentColor);
|
||||
_themeComponents.Add(component);
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
public List<ThemeComponent> GetComponents()
|
||||
{
|
||||
return _themeComponents;
|
||||
}
|
||||
|
||||
private bool ComponentExists(ThemeComponentType componentType, string componentName)
|
||||
{
|
||||
return _themeComponents.Exists(c => c.ComponentName == componentName && c.ComponentType == componentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -543,8 +543,7 @@ namespace Filtration.ViewModels
|
||||
var clipboardText = Clipboard.GetText();
|
||||
if (clipboardText.IsNullOrEmpty()) return;
|
||||
|
||||
_blockTranslator.InitialiseForExistingScript(Script);
|
||||
var translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(clipboardText);
|
||||
var translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(clipboardText, Script.ThemeComponents);
|
||||
if (translatedBlock == null) return;
|
||||
|
||||
var vm = _itemFilterBlockViewModelFactory.Create();
|
||||
|
||||
@@ -23,11 +23,6 @@ namespace Filtration.WindsorInstallers
|
||||
Component.For<IBlockGroupHierarchyBuilder>()
|
||||
.ImplementedBy<BlockGroupHierarchyBuilder>()
|
||||
.LifeStyle.Singleton);
|
||||
|
||||
container.Register(
|
||||
Component.For<IThemeComponentListBuilder>()
|
||||
.ImplementedBy<ThemeComponentListBuilder>()
|
||||
.LifeStyle.Singleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user