Add SchemaVersion to reset themes to default on change
- Extract embedded ThemeSet type to new file - Eliminate redundant SerializedTheme type - Issue MatterHackers/MCCentral#4353 Toggle buttons missing dots
This commit is contained in:
parent
2ee7848093
commit
e2c5ae4bfd
8 changed files with 93 additions and 65 deletions
|
|
@ -152,6 +152,12 @@ namespace MatterHackers.MatterControl
|
|||
if (File.Exists(ProfileManager.Instance.ProfileThemeSetPath))
|
||||
{
|
||||
themeset = JsonConvert.DeserializeObject<ThemeSet>(File.ReadAllText(ProfileManager.Instance.ProfileThemeSetPath));
|
||||
|
||||
// If the serialized format is older than the current format, null and fall back to latest default below
|
||||
if (themeset.SchemeVersion != ThemeSet.LatestSchemeVersion)
|
||||
{
|
||||
themeset = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
|
@ -159,7 +165,7 @@ namespace MatterHackers.MatterControl
|
|||
if (themeset == null)
|
||||
{
|
||||
var themeProvider = ThemeProviders.Values.First();
|
||||
themeset = themeProvider.GetTheme(themeProvider.ThemeNames.First(), themeProvider.DefaultColor);
|
||||
themeset = themeProvider.GetTheme(themeProvider.ThemeNames.First());
|
||||
}
|
||||
|
||||
DefaultThumbView.ThumbColor = new Color(themeset.Theme.Colors.PrimaryTextColor, 30);
|
||||
|
|
@ -199,28 +205,6 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
public class ThemeSet
|
||||
{
|
||||
public string ThemeID { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public ThemeConfig Theme { get; set; }
|
||||
|
||||
public ThemeConfig MenuTheme { get; set; }
|
||||
|
||||
public List<Color> AccentColors { get; set; } = new List<Color>();
|
||||
|
||||
public void SetAccentColor(Color accentColor)
|
||||
{
|
||||
this.Theme.PrimaryAccentColor = accentColor;
|
||||
this.Theme.AccentMimimalOverlay = accentColor.WithAlpha(90);
|
||||
|
||||
this.MenuTheme.PrimaryAccentColor = accentColor;
|
||||
this.MenuTheme.AccentMimimalOverlay = accentColor.WithAlpha(90);
|
||||
}
|
||||
}
|
||||
|
||||
public class ApplicationController
|
||||
{
|
||||
public HelpArticle HelpArticles { get; set; }
|
||||
|
|
|
|||
|
|
@ -37,50 +37,45 @@ namespace MatterHackers.MatterControl
|
|||
using MatterHackers.Agg.Platform;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class SerializedTheme : IColorTheme
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public Color DefaultColor { get; set; }
|
||||
|
||||
public IEnumerable<string> ThemeNames { get; set; }
|
||||
|
||||
public ThemeSet GetTheme(string mode, Color accentColor)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class DirectoryTheme : IColorTheme
|
||||
{
|
||||
private string path;
|
||||
|
||||
public DirectoryTheme()
|
||||
{
|
||||
}
|
||||
|
||||
public DirectoryTheme(string directory)
|
||||
{
|
||||
var themeSetData = JsonConvert.DeserializeObject<SerializedTheme>(
|
||||
AggContext.StaticData.ReadAllText(Path.Combine(directory, "theme.json")));
|
||||
|
||||
path = directory;
|
||||
|
||||
this.Name = Path.GetFileName(directory);
|
||||
this.ThemeNames = AggContext.StaticData.GetFiles(directory).Where(p => Path.GetFileName(p) != "theme.json").Select(p => Path.GetFileNameWithoutExtension(p)).ToArray();
|
||||
|
||||
this.DefaultColor = themeSetData.DefaultColor;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public Color DefaultColor { get; }
|
||||
|
||||
public IEnumerable<string> ThemeNames { get; }
|
||||
|
||||
public ThemeSet GetTheme(string themeName, Color accentColor)
|
||||
{
|
||||
ThemeSet themeset = null;
|
||||
var themeset = this.LoadTheme(themeName);
|
||||
themeset.SetAccentColor(accentColor);
|
||||
|
||||
return themeset;
|
||||
}
|
||||
|
||||
public ThemeSet GetTheme(string themeName)
|
||||
{
|
||||
var themeset = this.LoadTheme(themeName);
|
||||
themeset.SetAccentColor(themeset.AccentColors.First());
|
||||
|
||||
return themeset;
|
||||
}
|
||||
|
||||
private ThemeSet LoadTheme(string themeName)
|
||||
{
|
||||
ThemeSet themeset;
|
||||
try
|
||||
{
|
||||
themeset = JsonConvert.DeserializeObject<ThemeSet>(
|
||||
|
|
@ -92,8 +87,9 @@ namespace MatterHackers.MatterControl
|
|||
AggContext.StaticData.ReadAllText(Path.Combine(path, this.ThemeNames.First() + ".json")));
|
||||
}
|
||||
|
||||
// Set SchemaVersion at construction time
|
||||
themeset.SchemeVersion = ThemeSet.LatestSchemeVersion;
|
||||
themeset.ThemeID = themeName;
|
||||
themeset.SetAccentColor(accentColor);
|
||||
|
||||
return themeset;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,11 @@ namespace MatterHackers.MatterControl
|
|||
public interface IColorTheme
|
||||
{
|
||||
string Name { get; }
|
||||
Color DefaultColor { get; }
|
||||
|
||||
ThemeSet GetTheme(string mode);
|
||||
|
||||
ThemeSet GetTheme(string mode, Color accentColor);
|
||||
|
||||
IEnumerable<string> ThemeNames { get; }
|
||||
}
|
||||
}
|
||||
63
MatterControlLib/ApplicationView/Themes/ThemeSet.cs
Normal file
63
MatterControlLib/ApplicationView/Themes/ThemeSet.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
Copyright (c) 2018, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using MatterHackers.Agg;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class ThemeSet
|
||||
{
|
||||
public static int LatestSchemeVersion { get; } = 20181023;
|
||||
|
||||
public string ThemeID { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public ThemeConfig Theme { get; set; }
|
||||
|
||||
public ThemeConfig MenuTheme { get; set; }
|
||||
|
||||
public List<Color> AccentColors { get; set; } = new List<Color>();
|
||||
|
||||
public void SetAccentColor(Color accentColor)
|
||||
{
|
||||
this.Theme.PrimaryAccentColor = accentColor;
|
||||
this.Theme.AccentMimimalOverlay = accentColor.WithAlpha(90);
|
||||
|
||||
this.MenuTheme.PrimaryAccentColor = accentColor;
|
||||
this.MenuTheme.AccentMimimalOverlay = accentColor.WithAlpha(90);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The latest version of the theme file format. When changed, the clients state becomes invalid and will require a reset to the new theme format
|
||||
/// </summary>
|
||||
public int SchemeVersion { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -95,8 +95,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage
|
|||
colorSelector.RebuildColorButtons();
|
||||
|
||||
this.CreateThemeModeButtons();
|
||||
|
||||
this.PreviewTheme(_themeProvider.DefaultColor);
|
||||
}
|
||||
}
|
||||
private void CreateThemeModeButtons()
|
||||
|
|
@ -138,7 +136,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
|
|||
}
|
||||
else
|
||||
{
|
||||
themeset = provider.GetTheme(themeName, provider.DefaultColor);
|
||||
themeset = provider.GetTheme(themeName);
|
||||
}
|
||||
|
||||
previewContainer.AddChild(new ThemePreviewButton(themeset, this)
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"DefaultMode": "Dark",
|
||||
"DefaultColor": "#cb4b16",
|
||||
"Colors": ["#b58900", "#cb4b16", "#dc322f", "#d33682", "#6c71c4", "#268bd2", "#2aa198", "#859900"]
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"DefaultMode": "Dark",
|
||||
"DefaultColor": "#ac193dff",
|
||||
"Colors": ["#ac193dff", "#dc4fadff", "#ff8119ff", "#008a17ff", "#004b8bff", "#008299ff", "#5db2ffff", "#4617b4ff", "#8c0095ff", "#585858ff"]
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"DefaultMode": "Dark",
|
||||
"DefaultColor": "#b58900",
|
||||
"Colors": ["#b58900", "#cb4b16", "#dc322f", "#d33682", "#6c71c4", "#268bd2", "#2aa198", "#859900"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue