Refactored ThemeComponentBuilder into ThemeComponentCollection

This commit is contained in:
Ben
2015-07-05 16:54:09 +01:00
parent 3ea0530c01
commit 511f503e88
16 changed files with 118 additions and 279 deletions

View File

@@ -83,6 +83,7 @@
<Compile Include="ReplaceColorsParameterSet.cs" />
<Compile Include="ThemeEditor\Theme.cs" />
<Compile Include="ThemeEditor\ThemeComponent.cs" />
<Compile Include="ThemeEditor\ThemeComponentCollection.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -16,13 +16,13 @@ namespace Filtration.ObjectModel
{
new ItemFilterBlockGroup("Root", null)
};
ThemeComponents = new List<ThemeComponent>();
ThemeComponents = new ThemeComponentCollection { IsMasterCollection = true};
}
public ObservableCollection<ItemFilterBlock> ItemFilterBlocks { get; private set; }
public ObservableCollection<ItemFilterBlockGroup> ItemFilterBlockGroups { get; private set; }
public List<ThemeComponent> ThemeComponents { get; set; }
public ThemeComponentCollection ThemeComponents { get; set; }
public string FilePath { get; set; }
public string Description { get; set; }

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
using Filtration.ObjectModel.Enums;
@@ -8,24 +9,26 @@ namespace Filtration.ObjectModel.ThemeEditor
[Serializable]
public class Theme
{
private readonly List<ThemeComponent> _components;
private readonly ThemeComponentCollection _components;
public Theme()
{
_components = new List<ThemeComponent>();
_components = new ThemeComponentCollection { IsMasterCollection = false};
}
public string Name { get; set; }
public string FilePath { get; set; }
public List<ThemeComponent> Components
public ThemeComponentCollection Components
{
get { return _components; }
}
public bool ComponentExists(ThemeComponentType componentType, string componentName)
{
return _components.Exists(c => c.ComponentName == componentName && c.ComponentType == componentType);
var componentCount =
_components.Count(c => c.ComponentName == componentName && c.ComponentType == componentType);
return componentCount > 0;
}
public void AddComponent(ThemeComponentType componentType, string componentName, Color componentColor)

View File

@@ -0,0 +1,32 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Media;
using Filtration.ObjectModel.Enums;
namespace Filtration.ObjectModel.ThemeEditor
{
public class ThemeComponentCollection : Collection<ThemeComponent>
{
public bool IsMasterCollection { get; set; }
public ThemeComponent AddComponent(ThemeComponentType componentType, string componentName, Color componentColor)
{
if (ComponentExists(componentType, componentName))
{
return Items.FirstOrDefault(t => t.ComponentName == componentName && t.ComponentType == componentType);
}
var component = new ThemeComponent(componentType, componentName, componentColor);
Items.Add(component);
return component;
}
private bool ComponentExists(ThemeComponentType componentType, string componentName)
{
var componentCount =
Items.Count(c => c.ComponentName == componentName && c.ComponentType == componentType);
return componentCount > 0;
}
}
}