Refactored ThemeComponentBuilder into ThemeComponentCollection
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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