Skip to content

Commit

Permalink
#596 first version of rewritting theming
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Aug 2, 2018
1 parent 902d12a commit f39d4aa
Show file tree
Hide file tree
Showing 34 changed files with 762 additions and 1,397 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Expand Up @@ -40,7 +40,7 @@ tools/

# Generated files
Fluent.Ribbon/Themes/**/Styles.xaml
Fluent.Ribbon/Themes/Accents/*.xaml
Fluent.Ribbon/Themes/Themes/*.xaml
packages/
.tmp

Expand All @@ -52,4 +52,5 @@ TestResult.xml
*.local

# Allowed files
!Fluent.Ribbon/Themes/XamlCombine.exe
!Fluent.Ribbon/Themes/XamlCombine.exe
!Fluent.Ribbon/Themes/Theme.Template.exe
19 changes: 13 additions & 6 deletions Changelog.md
Expand Up @@ -19,8 +19,8 @@
- `GlassFrameThickness` was removed in favor of the new `GlowWindowBehavior`. Thus you can now use `GlowBrush` and `NonActiveGlowBrush` on `RibbonWindow`. The resize border now also works "outside" of the window.
This fixes [#307](../../issues/307), [#319](../../issues/319) and [#556](../../issues/556).
- The default value for `TabItemSelectedForeground` on `RibbonContextualTabGroup` is now bound to `Fluent.Ribbon.Brushes.RibbonContextualTabGroup.TabItemSelectedForeground`. Previously this was bound to `Foreground` of `RibbonContextualTabGroup`.
- The default value for `TabItemMouseOverForeground` on `RibbonContextualTabGroup` is now bound to `Fluent.Ribbon.Brushes.RibbonContextualTabGroup.TabItemMouseOverForeground.Light` or `Fluent.Ribbon.Brushes.RibbonContextualTabGroup.TabItemMouseOverForeground.Dark` depending on the used app theme. Previously this was bound to `Fluent.Ribbon.Brushes.HighlightBrush` or `BlackBrush`.
- The default value for `Fluent:RibbonProperties.MouseOverForeground` on `RibbonTabItem` is now bound to `Fluent.Ribbon.Brushes.RibbonTabItem.MouseOver.Foreground.Light` or `Fluent.Ribbon.Brushes.RibbonTabItem.MouseOver.Foreground.Dark` depending on the used app theme. Previously this was bound to `Fluent.Ribbon.Brushes.HighlightBrush` or `BlackBrush`.
- The default value for `TabItemMouseOverForeground` on `RibbonContextualTabGroup` is now bound to `Fluent.Ribbon.Brushes.RibbonContextualTabGroup.TabItemMouseOverForeground`. Previously this was bound to `Fluent.Ribbon.Brushes.HighlightBrush` or `BlackBrush`.
- The default value for `Fluent:RibbonProperties.MouseOverForeground` on `RibbonTabItem` is now bound to `Fluent.Ribbon.Brushes.RibbonTabItem.MouseOver.Foreground`. Previously this was bound to `Fluent.Ribbon.Brushes.HighlightBrush` or `BlackBrush`.

**The following resources were added, renamed or removed ("---" indicates added when in column "Old" and removed when in column "New"):**

Expand Down Expand Up @@ -49,10 +49,17 @@
| OnIsOpenFalseStoryboard | Fluent.Ribbon.Storyboards.Backstage.IsOpenFalseStoryboard |
| --- | Fluent.Ribbon.Brushes.RibbonWindow.TitleBackground |
| --- | Fluent.Ribbon.Brushes.RibbonContextualTabGroup.TabItemSelectedForeground |
| --- | Fluent.Ribbon.Brushes.RibbonContextualTabGroup.TabItemMouseOverForeground.Light |
| --- | Fluent.Ribbon.Brushes.RibbonContextualTabGroup.TabItemMouseOverForeground.Dark |
| --- | Fluent.Ribbon.Brushes.RibbonTabItem.MouseOver.Foreground.Dark |
| --- | Fluent.Ribbon.Brushes.RibbonTabItem.MouseOver.Foreground.Light |
| --- | Fluent.Ribbon.Brushes.RibbonContextualTabGroup.TabItemMouseOverForeground |
| --- | Fluent.Ribbon.Brushes.RibbonTabItem.MouseOver.Foreground |
| --- | Fluent.Ribbon.Brushes.Backstage.Background |
| --- | Fluent.Ribbon.Brushes.Backstage.Foreground |
| --- | Fluent.Ribbon.Brushes.BackstageTabControl.Button.Background |
| --- | Fluent.Ribbon.Brushes.BackstageTabItem.Header.Foreground |
| --- | Fluent.Ribbon.Brushes.BackstageTabItem.MouseOver.Background |
| --- | Fluent.Ribbon.Brushes.BackstageTabItem.Selected.Background |
| --- | Fluent.Ribbon.Brushes.Backstage.BackButton.Background |
| --- | Fluent.Ribbon.Brushes.Backstage.BackButton.Foreground |
| --- | Fluent.Ribbon.Brushes.BackstageTabControl.ItemsPanelBackground |
</p></details>

- ### Bug fixes
Expand Down
4 changes: 0 additions & 4 deletions Directory.build.props
Expand Up @@ -12,10 +12,6 @@
<OutputPath>$(MSBuildThisFileDirectory)\bin\$(MSBuildProjectName)\$(Configuration)\</OutputPath>
<RestoreSources Condition="Exists('C:\DEV\OSS_Own\ControlzEx\Publish')">C:\DEV\OSS_Own\ControlzEx\Publish</RestoreSources>
</PropertyGroup>
<PropertyGroup>
<_SdkLanguageName>CSharp</_SdkLanguageName>
<_SdkLanguageExtension>.cs</_SdkLanguageExtension>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<DefineConstants>NET45</DefineConstants>
</PropertyGroup>
Expand Down
6 changes: 2 additions & 4 deletions Fluent.Ribbon.Showcase/App.xaml
Expand Up @@ -8,11 +8,9 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Generic.xaml" />

<!--<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Colors/BaseLight.xaml" />
<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Accents/Green.xaml" />-->
<!--<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Themes/Light.Green.xaml" />-->

<!--<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Colors/BaseDark.xaml" />
<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Accents/Green.xaml" />-->
<!--<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Themes/Dark.Green.xaml" />-->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
2 changes: 1 addition & 1 deletion Fluent.Ribbon.Showcase/App.xaml.cs
Expand Up @@ -38,7 +38,7 @@ public App()
protected override void OnStartup(StartupEventArgs e)
{
ThemeManager.IsAutomaticWindowsAppModeSettingSyncEnabled = true;
ThemeManager.SyncAppThemeWithWindowsAppModeSetting();
ThemeManager.SyncThemeWithWindowsAppModeSetting();

base.OnStartup(e);
}
Expand Down
2 changes: 2 additions & 0 deletions Fluent.Ribbon.Showcase/Fluent.Ribbon.Showcase.csproj
Expand Up @@ -20,6 +20,8 @@
<ProjectReference Include="..\Fluent.Ribbon\Fluent.Ribbon.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
Expand Down
120 changes: 120 additions & 0 deletions Fluent.Ribbon.Showcase/Helpers/ColorSchemeGenerator.cs
@@ -0,0 +1,120 @@
namespace XamlColorSchemeGenerator
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Web.Script.Serialization;

internal class ColorSchemeGenerator
{
public void GenerateColorSchemeFiles(string inputFile)
{
var parameters = new JavaScriptSerializer().Deserialize<GeneratorParameters>(File.ReadAllText(inputFile, Encoding.UTF8));

var templateDirectory = Path.GetDirectoryName(Path.GetFullPath(inputFile));
var templateFile = Path.Combine(templateDirectory, parameters.TemplateFile);
var templateContent = File.ReadAllText(templateFile, Encoding.UTF8);

foreach (var variant in parameters.BaseColorSchemes)
{
foreach (var colorScheme in parameters.ColorSchemes)
{
this.GenerateColorSchemeFile(parameters, templateDirectory, templateContent, variant, colorScheme);
}
}
}

public void GenerateColorSchemeFile(GeneratorParameters parameters, string templateDirectory, string templateContent, BaseColorScheme baseColorScheme, ColorScheme colorScheme)
{
var themeName = $"{baseColorScheme.Name}.{colorScheme.Name}";
var themeDisplayName = $"{colorScheme.Name} ({baseColorScheme.Name})";
var themeFilename = $"{themeName}.xaml";
var themeTempFileName = $"{themeFilename}_{Guid.NewGuid()}.xaml";

var themeFile = Path.Combine(templateDirectory, themeFilename);
var themeTempFile = Path.Combine(Path.GetTempPath(), themeTempFileName);

try
{
var fileContent = this.GenerateColorSchemeFileContent(parameters, baseColorScheme, colorScheme, templateContent, themeName, themeDisplayName);

File.WriteAllText(themeTempFile, fileContent, Encoding.UTF8);

Trace.WriteLine($"Comparing temp file \"{themeTempFile}\" to \"{themeFile}\"");

if (File.Exists(themeFile) == false
|| File.ReadAllText(themeFile) != File.ReadAllText(themeTempFile))
{
File.Copy(themeTempFile, themeFile, true);

Trace.WriteLine($"Resource Dictionary saved to \"{themeFile}\".");
}
else
{
Trace.WriteLine("New Resource Dictionary did not differ from existing file. No new file written.");
}
}
finally
{
if (File.Exists(themeTempFile))
{
File.Delete(themeTempFile);
}
}
}

public string GenerateColorSchemeFileContent(GeneratorParameters parameters, BaseColorScheme baseColorScheme, ColorScheme colorScheme, string templateContent, string themeName, string themeDisplayName)
{
templateContent = templateContent.Replace("{{ThemeName}}", themeName);
templateContent = templateContent.Replace("{{ThemeDisplayName}}", themeDisplayName);
templateContent = templateContent.Replace("{{BaseColorScheme}}", baseColorScheme.Name);
templateContent = templateContent.Replace("{{ColorScheme}}", colorScheme.Name);

foreach (var value in colorScheme.Values)
{
templateContent = templateContent.Replace($"{{{{{value.Key}}}}}", value.Value);
}

foreach (var value in baseColorScheme.Values)
{
templateContent = templateContent.Replace($"{{{{{value.Key}}}}}", value.Value);
}

foreach (var value in parameters.DefaultValues)
{
templateContent = templateContent.Replace($"{{{{{value.Key}}}}}", value.Value);
}

return templateContent;
}
}

internal class GeneratorParameters
{
public string TemplateFile { get; set; }

public Dictionary<string, string> DefaultValues { get; set; } = new Dictionary<string, string>();

public BaseColorScheme[] BaseColorSchemes { get; set; }

public ColorScheme[] ColorSchemes { get; set; }
}

[DebuggerDisplay("{" + nameof(Name) + "}")]
internal class BaseColorScheme
{
public string Name { get; set; }

public Dictionary<string, string> Values { get; set; }
}

[DebuggerDisplay("{" + nameof(Name) + "}")]
internal class ColorScheme
{
public string Name { get; set; }

public Dictionary<string, string> Values { get; set; } = new Dictionary<string, string>();
}
}

0 comments on commit f39d4aa

Please sign in to comment.