Refactor theme code to support different types

This commit is contained in:
azakhi
2018-08-24 22:07:24 +03:00
parent d0bc0b6864
commit 8ba3433dcf
17 changed files with 122 additions and 64 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using Filtration.ObjectModel.Annotations;
using Filtration.ObjectModel.Enums;
namespace Filtration.ObjectModel.ThemeEditor
{
[Serializable]
public class ColorThemeComponent : ThemeComponent
{
private Color _color;
private readonly object _eventLock = new object();
public ColorThemeComponent(ThemeComponentType componentType, string componentName, Color componentColor)
{
if (componentName == null || componentColor == null)
{
throw new ArgumentException("Null parameters not allowed in ColorThemeComponent constructor");
}
ComponentType = componentType;
Color = componentColor;
ComponentName = componentName;
}
public Color Color
{
get { return _color; }
set
{
_color = value;
OnPropertyChanged();
_themeComponentUpdatedEventHandler?.Invoke(this, EventArgs.Empty);
}
}
}
}

View File

@@ -32,7 +32,7 @@ namespace Filtration.ObjectModel.ThemeEditor
public void AddComponent(ThemeComponentType componentType, string componentName, Color componentColor)
{
_components.Add(new ThemeComponent(componentType, componentName, componentColor));
_components.Add(new ColorThemeComponent(componentType, componentName, componentColor));
}
}
}

View File

@@ -10,8 +10,7 @@ namespace Filtration.ObjectModel.ThemeEditor
[Serializable]
public class ThemeComponent : INotifyPropertyChanged
{
private Color _color;
private EventHandler _themeComponentUpdatedEventHandler;
protected EventHandler _themeComponentUpdatedEventHandler;
private readonly object _eventLock = new object();
public ThemeComponent()
@@ -19,18 +18,6 @@ namespace Filtration.ObjectModel.ThemeEditor
}
public ThemeComponent(ThemeComponentType componentType, string componentName, Color componentColor)
{
if (componentName == null || componentColor == null)
{
throw new ArgumentException("Null parameters not allowed in ThemeComponent constructor");
}
ComponentType = componentType;
Color = componentColor;
ComponentName = componentName;
}
// By implementing a custom event accessor here we can keep the UsageCount up to date.
public event EventHandler ThemeComponentUpdated
{
@@ -58,17 +45,6 @@ namespace Filtration.ObjectModel.ThemeEditor
public string ComponentName { get; set; }
public ThemeComponentType ComponentType{ get; set; }
public Color Color
{
get { return _color; }
set
{
_color = value;
OnPropertyChanged();
_themeComponentUpdatedEventHandler?.Invoke(this, EventArgs.Empty);
}
}
public int UsageCount
{
get

View File

@@ -16,7 +16,15 @@ namespace Filtration.ObjectModel.ThemeEditor
return Items.FirstOrDefault(t => t.ComponentName == componentName && t.ComponentType == componentType);
}
var component = new ThemeComponent(componentType, componentName, componentColor);
ThemeComponent component = null;
switch(componentType)
{
case ThemeComponentType.BackgroundColor:
case ThemeComponentType.BorderColor:
case ThemeComponentType.TextColor:
component = new ColorThemeComponent(componentType, componentName, componentColor);
break;
}
Items.Add(component);
return component;