diff --git a/Filtration.ObjectModel/BlockItemBaseTypes/ColorBlockItem.cs b/Filtration.ObjectModel/BlockItemBaseTypes/ColorBlockItem.cs
index f955782..7f6efc9 100644
--- a/Filtration.ObjectModel/BlockItemBaseTypes/ColorBlockItem.cs
+++ b/Filtration.ObjectModel/BlockItemBaseTypes/ColorBlockItem.cs
@@ -63,7 +63,7 @@ namespace Filtration.ObjectModel.BlockItemBaseTypes
private void OnThemeComponentUpdated(object sender, EventArgs e)
{
- Color = ((ThemeComponent) sender).Color;
+ Color = ((ColorThemeComponent) sender).Color;
}
private void OnThemeComponentDeleted(object sender, EventArgs e)
diff --git a/Filtration.ObjectModel/Filtration.ObjectModel.csproj b/Filtration.ObjectModel/Filtration.ObjectModel.csproj
index 4213fe3..89582ac 100644
--- a/Filtration.ObjectModel/Filtration.ObjectModel.csproj
+++ b/Filtration.ObjectModel/Filtration.ObjectModel.csproj
@@ -131,6 +131,7 @@
+
diff --git a/Filtration.ObjectModel/ThemeEditor/ColorThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/ColorThemeComponent.cs
new file mode 100644
index 0000000..de1ae3d
--- /dev/null
+++ b/Filtration.ObjectModel/ThemeEditor/ColorThemeComponent.cs
@@ -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);
+ }
+ }
+ }
+}
diff --git a/Filtration.ObjectModel/ThemeEditor/Theme.cs b/Filtration.ObjectModel/ThemeEditor/Theme.cs
index d21f2b4..34b8cbc 100644
--- a/Filtration.ObjectModel/ThemeEditor/Theme.cs
+++ b/Filtration.ObjectModel/ThemeEditor/Theme.cs
@@ -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));
}
}
}
diff --git a/Filtration.ObjectModel/ThemeEditor/ThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/ThemeComponent.cs
index 635dbb7..07169bd 100644
--- a/Filtration.ObjectModel/ThemeEditor/ThemeComponent.cs
+++ b/Filtration.ObjectModel/ThemeEditor/ThemeComponent.cs
@@ -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
diff --git a/Filtration.ObjectModel/ThemeEditor/ThemeComponentCollection.cs b/Filtration.ObjectModel/ThemeEditor/ThemeComponentCollection.cs
index 12eaf7e..d2d88fe 100644
--- a/Filtration.ObjectModel/ThemeEditor/ThemeComponentCollection.cs
+++ b/Filtration.ObjectModel/ThemeEditor/ThemeComponentCollection.cs
@@ -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;
diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs
index 0c3a281..cd3a9ae 100644
--- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs
+++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs
@@ -773,7 +773,7 @@ namespace Filtration.Parser.Tests.Services
// Arrange
var inputString = "Show" + Environment.NewLine +
" SetTextColor 255 20 100 # Rare Item Text";
- var testComponent = new ThemeComponent(ThemeComponentType.TextColor, "Rare Item Text", new Color { R = 255, G = 20, B = 100});
+ var testComponent = new ColorThemeComponent(ThemeComponentType.TextColor, "Rare Item Text", new Color { R = 255, G = 20, B = 100});
var testInputThemeComponentCollection = new ThemeComponentCollection { testComponent };
// Act
@@ -1751,7 +1751,7 @@ namespace Filtration.Parser.Tests.Services
var blockItem = new TextColorBlockItem(new Color {A = 255, R = 54, G = 102, B = 255})
{
- ThemeComponent = new ThemeComponent(ThemeComponentType.TextColor, "Test Theme Component", new Color())
+ ThemeComponent = new ColorThemeComponent(ThemeComponentType.TextColor, "Test Theme Component", new Color())
};
_testUtility.TestBlock.BlockItems.Add(blockItem);
diff --git a/Filtration.ThemeEditor.Tests/Services/TestThemeService.cs b/Filtration.ThemeEditor.Tests/Services/TestThemeService.cs
index 086f4f1..f3d9c43 100644
--- a/Filtration.ThemeEditor.Tests/Services/TestThemeService.cs
+++ b/Filtration.ThemeEditor.Tests/Services/TestThemeService.cs
@@ -26,7 +26,7 @@ namespace Filtration.ThemeEditor.Tests.Services
var testInputTheme = new Theme();
var testInputThemeComponentColor = new Color{ R = 255, G = 0, B = 1 };
- var testInputThemeComponent = new ThemeComponent(ThemeComponentType.TextColor, "Test Component 1", testInputThemeComponentColor);
+ var testInputThemeComponent = new ColorThemeComponent(ThemeComponentType.TextColor, "Test Component 1", testInputThemeComponentColor);
testInputTheme.Components.Add(testInputThemeComponent);
testInputBlockItem.ThemeComponent = testInputThemeComponent;
var mockMessageBoxService = new Mock();
@@ -53,8 +53,8 @@ namespace Filtration.ThemeEditor.Tests.Services
var testInputTheme = new Theme();
var testInputThemeComponentColor = new Color { R = 255, G = 0, B = 1 };
- var testInputThemeComponent = new ThemeComponent(ThemeComponentType.TextColor, "Test Component 1", testInputThemeComponentColor);
- var testInputBlockItemThemeComponent = new ThemeComponent(ThemeComponentType.TextColor, "Different Component", testInputThemeComponentColor);
+ var testInputThemeComponent = new ColorThemeComponent(ThemeComponentType.TextColor, "Test Component 1", testInputThemeComponentColor);
+ var testInputBlockItemThemeComponent = new ColorThemeComponent(ThemeComponentType.TextColor, "Different Component", testInputThemeComponentColor);
testInputTheme.Components.Add(testInputThemeComponent);
testInputBlockItem.ThemeComponent = testInputBlockItemThemeComponent;
diff --git a/Filtration.ThemeEditor/Filtration.ThemeEditor.csproj b/Filtration.ThemeEditor/Filtration.ThemeEditor.csproj
index 0cc1a04..4a5d93d 100644
--- a/Filtration.ThemeEditor/Filtration.ThemeEditor.csproj
+++ b/Filtration.ThemeEditor/Filtration.ThemeEditor.csproj
@@ -108,6 +108,7 @@
+
diff --git a/Filtration.ThemeEditor/Providers/ThemeProvider.cs b/Filtration.ThemeEditor/Providers/ThemeProvider.cs
index 238c392..18fb0ed 100644
--- a/Filtration.ThemeEditor/Providers/ThemeProvider.cs
+++ b/Filtration.ThemeEditor/Providers/ThemeProvider.cs
@@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Filtration.ObjectModel;
+using Filtration.ObjectModel.Enums;
using Filtration.ObjectModel.ThemeEditor;
using Filtration.ThemeEditor.Services;
using Filtration.ThemeEditor.ViewModels;
@@ -34,7 +35,14 @@ namespace Filtration.ThemeEditor.Providers
var themeComponentCollection = script.ThemeComponents.Aggregate(new ThemeComponentCollection(),
(c, component) =>
{
- c.Add(new ThemeComponent(component.ComponentType, component.ComponentName, component.Color));
+ switch(component.ComponentType)
+ {
+ case ThemeComponentType.BackgroundColor:
+ case ThemeComponentType.BorderColor:
+ case ThemeComponentType.TextColor:
+ c.Add(new ColorThemeComponent(component.ComponentType, component.ComponentName, ((ColorThemeComponent)component).Color));
+ break;
+ }
return c;
});
diff --git a/Filtration.ThemeEditor/Services/ThemeService.cs b/Filtration.ThemeEditor/Services/ThemeService.cs
index 6ebaa94..4e3e23d 100644
--- a/Filtration.ThemeEditor/Services/ThemeService.cs
+++ b/Filtration.ThemeEditor/Services/ThemeService.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Filtration.Common.Services;
@@ -29,39 +30,19 @@ namespace Filtration.ThemeEditor.Services
var mismatchedComponents = false;
foreach (var component in theme.Components)
{
- var componentMatched = false;
- Type targetType = null;
+ var blocks = script.ItemFilterBlocks.OfType();
switch (component.ComponentType)
{
case ThemeComponentType.BackgroundColor:
- targetType = typeof (BackgroundColorBlockItem);
+ mismatchedComponents = ApplyColorTheme(blocks, typeof(BackgroundColorBlockItem), component);
break;
case ThemeComponentType.TextColor:
- targetType = typeof (TextColorBlockItem);
+ mismatchedComponents = ApplyColorTheme(blocks, typeof(TextColorBlockItem), component);
break;
case ThemeComponentType.BorderColor:
- targetType = typeof (BorderColorBlockItem);
+ mismatchedComponents = ApplyColorTheme(blocks, typeof(BorderColorBlockItem), component);
break;
}
-
- foreach (var block in script.ItemFilterBlocks.OfType())
- {
- foreach (var blockItem in block.BlockItems.Where(i => i.GetType() == targetType))
- {
- var colorBlockItem = (ColorBlockItem) blockItem;
- if (colorBlockItem.ThemeComponent != null &&
- colorBlockItem.ThemeComponent.ComponentName == component.ComponentName)
- {
- colorBlockItem.Color = component.Color;
- componentMatched = true;
- }
- }
- }
-
- if (!componentMatched)
- {
- mismatchedComponents = true;
- }
}
if (mismatchedComponents)
@@ -71,5 +52,25 @@ namespace Filtration.ThemeEditor.Services
MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}
+
+ private bool ApplyColorTheme(IEnumerable blocks, Type type, ThemeComponent component)
+ {
+ var componentMatched = false;
+ foreach (var block in blocks)
+ {
+ foreach (var blockItem in block.BlockItems.Where(i => i.GetType() == type))
+ {
+ var colorBlockItem = (ColorBlockItem)blockItem;
+ if (colorBlockItem.ThemeComponent != null &&
+ colorBlockItem.ThemeComponent.ComponentName == component.ComponentName)
+ {
+ colorBlockItem.Color = ((ColorThemeComponent)component).Color;
+ componentMatched = true;
+ }
+ }
+ }
+
+ return !componentMatched;
+ }
}
}
diff --git a/Filtration.ThemeEditor/ViewModels/ColorThemeComponentViewModel.cs b/Filtration.ThemeEditor/ViewModels/ColorThemeComponentViewModel.cs
new file mode 100644
index 0000000..81c196b
--- /dev/null
+++ b/Filtration.ThemeEditor/ViewModels/ColorThemeComponentViewModel.cs
@@ -0,0 +1,10 @@
+using System.Windows.Media;
+using Filtration.ObjectModel.Enums;
+
+namespace Filtration.ThemeEditor.ViewModels
+{
+ public class ColorThemeComponentViewModel : ThemeComponentViewModel
+ {
+ public Color Color { get; set; }
+ }
+}
diff --git a/Filtration.ThemeEditor/ViewModels/ThemeComponentViewModel.cs b/Filtration.ThemeEditor/ViewModels/ThemeComponentViewModel.cs
index 76f2836..28e363a 100644
--- a/Filtration.ThemeEditor/ViewModels/ThemeComponentViewModel.cs
+++ b/Filtration.ThemeEditor/ViewModels/ThemeComponentViewModel.cs
@@ -7,13 +7,11 @@ namespace Filtration.ThemeEditor.ViewModels
{
string ComponentName { get; set; }
ThemeComponentType ComponentType { get; set; }
- Color Color { get; set; }
}
public class ThemeComponentViewModel : IThemeComponentViewModel
{
public string ComponentName { get; set; }
public ThemeComponentType ComponentType { get; set; }
- public Color Color { get; set; }
}
}
diff --git a/Filtration.ThemeEditor/ViewModels/ThemeEditorViewModel.cs b/Filtration.ThemeEditor/ViewModels/ThemeEditorViewModel.cs
index ab9f796..9552e32 100644
--- a/Filtration.ThemeEditor/ViewModels/ThemeEditorViewModel.cs
+++ b/Filtration.ThemeEditor/ViewModels/ThemeEditorViewModel.cs
@@ -194,8 +194,15 @@ namespace Filtration.ThemeEditor.ViewModels
private void OnAddThemeComponentCommand(ThemeComponentType themeComponentType)
{
- Components.Add(new ThemeComponent(themeComponentType, "Untitled Component",
- new Color {A = 255, R = 255, G = 255, B = 255}));
+ switch (themeComponentType)
+ {
+ case ThemeComponentType.BackgroundColor:
+ case ThemeComponentType.BorderColor:
+ case ThemeComponentType.TextColor:
+ Components.Add(new ColorThemeComponent(themeComponentType, "Untitled Component",
+ new Color { A = 255, R = 255, G = 255, B = 255 }));
+ break;
+ }
}
private void OnDeleteThemeComponentCommand(ThemeComponent themeComponent)
diff --git a/Filtration.ThemeEditor/Views/ThemeComponentControl.xaml b/Filtration.ThemeEditor/Views/ThemeComponentControl.xaml
index ea830e2..bcd5453 100644
--- a/Filtration.ThemeEditor/Views/ThemeComponentControl.xaml
+++ b/Filtration.ThemeEditor/Views/ThemeComponentControl.xaml
@@ -58,6 +58,13 @@
-
+
+
+
+
+
+
+
+
diff --git a/Filtration/App.xaml.cs b/Filtration/App.xaml.cs
index 6690e58..61ab85d 100644
--- a/Filtration/App.xaml.cs
+++ b/Filtration/App.xaml.cs
@@ -46,6 +46,7 @@ namespace Filtration
cfg.ConstructServicesUsing(_container.Resolve);
cfg.CreateMap().ConstructUsingServiceLocator();
cfg.CreateMap().ReverseMap();
+ cfg.CreateMap().ReverseMap();
cfg.CreateMap();
});
diff --git a/Filtration/UserControls/BlockItemControl.xaml.cs b/Filtration/UserControls/BlockItemControl.xaml.cs
index 70d9d0d..43a9ca7 100644
--- a/Filtration/UserControls/BlockItemControl.xaml.cs
+++ b/Filtration/UserControls/BlockItemControl.xaml.cs
@@ -6,6 +6,7 @@ using System.Windows;
using Filtration.Annotations;
using Filtration.ObjectModel;
using Filtration.ObjectModel.BlockItemBaseTypes;
+using Filtration.ObjectModel.ThemeEditor;
using Filtration.Views;
using GalaSoft.MvvmLight.CommandWpf;
using Xceed.Wpf.Toolkit;
@@ -97,7 +98,7 @@ namespace Filtration.UserControls
var blockItem = BlockItem as ColorBlockItem;
if (blockItem?.ThemeComponent == null) return;
- blockItem.Color = blockItem.ThemeComponent.Color;
+ blockItem.Color = ((ColorThemeComponent)blockItem.ThemeComponent).Color;
}
public event PropertyChangedEventHandler PropertyChanged;