Add font size theme support & improve theme system

This commit is contained in:
azakhi
2018-08-25 15:52:16 +03:00
parent 8ba3433dcf
commit bc5a005ee7
26 changed files with 247 additions and 70 deletions

View File

@@ -47,6 +47,7 @@ namespace Filtration
cfg.CreateMap<Theme, IThemeEditorViewModel>().ConstructUsingServiceLocator();
cfg.CreateMap<ThemeComponent, ThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<ColorThemeComponent, ColorThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<IntegerThemeComponent, IntegerThemeComponentViewModel>().ReverseMap();
cfg.CreateMap<IThemeEditorViewModel, Theme>();
});

View File

@@ -16,7 +16,7 @@ namespace Filtration.Converters
var themeComponentsList = values[0] as ThemeComponentCollection;
if (themeComponentsList == null || themeComponentsList.Count == 0) return null;
var blockItem = values[1] as ColorBlockItem;
var blockItem = values[1] as BlockItemBase;
if (blockItem == null) return null;
ThemeComponentType themeComponentType;
@@ -33,6 +33,10 @@ namespace Filtration.Converters
{
themeComponentType = ThemeComponentType.BorderColor;
}
else if (blockItem.GetType() == typeof(FontSizeBlockItem))
{
themeComponentType = ThemeComponentType.FontSize;
}
else
{
return null;

View File

@@ -116,9 +116,21 @@
<!-- Font Size Template -->
<DataTemplate DataType="{x:Type blockItemTypes:FontSizeBlockItem}">
<WrapPanel HorizontalAlignment="Left">
<xctk:ShortUpDown Value="{Binding Value}" Minimum="{Binding Minimum}" Maximum="{Binding Maximum}" Width="50" />
</WrapPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<xctk:ShortUpDown Grid.Column="0" Value="{Binding Value}" Minimum="{Binding Minimum}" Maximum="{Binding Maximum}" Margin="0,0,10,0" />
<userControls:ThemeComponentSelectionControl Grid.Column="1" ThemeComponent="{Binding ThemeComponent}">
<userControls:ThemeComponentSelectionControl.AvailableThemeComponents>
<MultiBinding Converter="{StaticResource AvailableThemeComponentsConverter}">
<Binding Path="DataContext.Script.ThemeComponents" RelativeSource="{RelativeSource AncestorType={x:Type views:ItemFilterScriptView}}"/>
<Binding Path="." />
</MultiBinding>
</userControls:ThemeComponentSelectionControl.AvailableThemeComponents>
</userControls:ThemeComponentSelectionControl>
</Grid>
</DataTemplate>
<!-- Sound Template -->

View File

@@ -6,6 +6,7 @@ using System.Windows;
using Filtration.Annotations;
using Filtration.ObjectModel;
using Filtration.ObjectModel.BlockItemBaseTypes;
using Filtration.ObjectModel.Enums;
using Filtration.ObjectModel.ThemeEditor;
using Filtration.Views;
using GalaSoft.MvvmLight.CommandWpf;
@@ -21,10 +22,10 @@ namespace Filtration.UserControls
// ReSharper disable once PossibleNullReferenceException
(Content as FrameworkElement).DataContext = this;
SetBlockColorCommand = new RelayCommand(OnSetBlockColorCommmand);
SetBlockValueCommand = new RelayCommand(OnSetBlockValueCommmand);
}
public RelayCommand SetBlockColorCommand { get; private set; }
public RelayCommand SetBlockValueCommand { get; private set; }
public static readonly DependencyProperty BlockItemProperty = DependencyProperty.Register(
"BlockItem",
@@ -93,12 +94,25 @@ namespace Filtration.UserControls
"Icon1", "Icon2", "Icon3", "Icon4", "Icon5", "Icon6"
};
private void OnSetBlockColorCommmand()
{
var blockItem = BlockItem as ColorBlockItem;
if (blockItem?.ThemeComponent == null) return;
private void OnSetBlockValueCommmand()
{
var blockItemWithTheme = BlockItem as IBlockItemWithTheme;
if (blockItemWithTheme?.ThemeComponent == null) return;
blockItem.Color = ((ColorThemeComponent)blockItem.ThemeComponent).Color;
var componentType = ((IBlockItemWithTheme)BlockItem).ThemeComponent.ComponentType;
switch(componentType)
{
case ThemeComponentType.BackgroundColor:
case ThemeComponentType.BorderColor:
case ThemeComponentType.TextColor:
var colorBlockItem = BlockItem as ColorBlockItem;
colorBlockItem.Color = ((ColorThemeComponent)colorBlockItem.ThemeComponent).Color;
break;
case ThemeComponentType.FontSize:
var integerBlockItem = BlockItem as IntegerBlockItem;
integerBlockItem.Value = ((IntegerThemeComponent)integerBlockItem.ThemeComponent).Value;
break;
}
}
public event PropertyChangedEventHandler PropertyChanged;

View File

@@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:userControls="clr-namespace:Filtration.UserControls"
xmlns:themeEditor="clr-namespace:Filtration.ObjectModel.ThemeEditor;assembly=Filtration.ObjectModel"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=userControls:ThemeComponentSelectionControl}"
@@ -21,7 +22,7 @@
<Setter Property="MinHeight" Value="0" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
@@ -32,44 +33,42 @@
Visibility="{Binding ShowThemeComponentComboBox, Converter={StaticResource BooleanToVisibilityConverter}}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SetBlockColorCommand, RelativeSource={RelativeSource AncestorType=userControls:BlockItemControl}}" />
<i:InvokeCommandAction Command="{Binding SetBlockValueCommand, RelativeSource={RelativeSource AncestorType=userControls:BlockItemControl}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBox.ItemTemplate>
<DataTemplate >
<ContentControl Content="{Binding}">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="ComponentNameColumn" Width="Auto" />
<ColumnDefinition SharedSizeGroup="ComponentColorColumn" Width="20" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding ComponentName}" Margin="0,0,2,0" />
<Border Grid.Column="1" Background="{Binding Color, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="{x:Null}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding ComponentName}" />
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemTemplate>
<DataTemplate >
<ContentControl Content="{Binding}">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="ComponentNameColumn" Width="Auto" />
<ColumnDefinition SharedSizeGroup="ComponentValueColumn" Width="20" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding ComponentName}" Margin="0,0,2,0" />
<ContentControl Content="{Binding Mode=OneWay}" Grid.Column="1">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type themeEditor:ColorThemeComponent}">
<Border Background="{Binding Color, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
</DataTemplate>
<DataTemplate DataType="{x:Type themeEditor:IntegerThemeComponent}">
<TextBlock Text="{Binding Value}" FontWeight="Bold" />
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ContentControl.Style>
</ContentControl>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<userControls:CrossButton Grid.Column="1" Height="12" Command="{Binding RemoveThemeComponentCommand}" VerticalAlignment="Top" Visibility="{Binding ShowThemeComponentComboBox, Converter={StaticResource BooleanToVisibilityConverter}}" />
<TextBlock Grid.Column="0" Grid.ColumnSpan="2" Visibility="{Binding ShowThemeComponentComboBox, Converter={StaticResource InverseBooleanVisibilityConverter}}" VerticalAlignment="Center">

View File

@@ -563,7 +563,7 @@ namespace Filtration.ViewModels
Script.ThemeComponents.Where(
t =>
Script.ItemFilterBlocks.OfType<ItemFilterBlock>().Count(
b => b.BlockItems.OfType<ColorBlockItem>().Count(i => i.ThemeComponent == t) > 0) == 0).ToList();
b => b.BlockItems.OfType<IBlockItemWithTheme>().Count(i => i.ThemeComponent == t) > 0) == 0).ToList();
if (unusedThemeComponents.Count <= 0) return true;

View File

@@ -114,6 +114,7 @@ namespace Filtration.ViewModels
AddTextColorThemeComponentCommand = new RelayCommand(OnAddTextColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBackgroundColorThemeComponentCommand = new RelayCommand(OnAddBackgroundColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBorderColorThemeComponentCommand = new RelayCommand(OnAddBorderColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddFontSizeThemeComponentCommand = new RelayCommand(OnAddFontSizeThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
DeleteThemeComponentCommand = new RelayCommand(OnDeleteThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable && _avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent != null);
ExpandAllBlocksCommand = new RelayCommand(OnExpandAllBlocksCommand, () => ActiveDocumentIsScript);
@@ -213,6 +214,7 @@ namespace Filtration.ViewModels
public RelayCommand AddTextColorThemeComponentCommand { get; }
public RelayCommand AddBackgroundColorThemeComponentCommand { get; }
public RelayCommand AddBorderColorThemeComponentCommand { get; }
public RelayCommand AddFontSizeThemeComponentCommand { get; }
public RelayCommand DeleteThemeComponentCommand { get; }
public RelayCommand AddBlockCommand { get; }
@@ -677,6 +679,11 @@ namespace Filtration.ViewModels
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.AddThemeComponentCommand.Execute(ThemeComponentType.BorderColor);
}
private void OnAddFontSizeThemeComponentCommand()
{
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.AddThemeComponentCommand.Execute(ThemeComponentType.FontSize);
}
private void OnDeleteThemeComponentCommand()
{
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.DeleteThemeComponentCommand.Execute(

View File

@@ -129,6 +129,7 @@
<fluent:Button SizeDefinition="Middle" Header="Add Text Color" Icon="{StaticResource AddIcon}" Command="{Binding AddTextColorThemeComponentCommand}" />
<fluent:Button SizeDefinition="Middle" Header="Add Background Color" Icon="{StaticResource AddIcon}" Command="{Binding AddBackgroundColorThemeComponentCommand}" />
<fluent:Button SizeDefinition="Middle" Header="Add Border Color" Icon="{StaticResource AddIcon}" Command="{Binding AddBorderColorThemeComponentCommand}" />
<fluent:Button SizeDefinition="Middle" Header="Add Font Size" Icon="{StaticResource AddIcon}" Command="{Binding AddFontSizeThemeComponentCommand}" />
</fluent:RibbonGroupBox>
<fluent:RibbonGroupBox Header="Delete">
<fluent:Button Header="Delete Theme Component" Icon="{StaticResource ThemeComponentDeleteIcon}" LargeIcon="{StaticResource ThemeComponentDeleteIcon}" Command="{Binding DeleteThemeComponentCommand}" />