Refactored ThemeComponentBuilder into ThemeComponentCollection
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user