Changed the theme colors to save by name

fixed linux run bug MatterHackers/MCCentral#344

ActiveTheme does not recreate its data all the time
This commit is contained in:
Lars Brubaker 2016-08-31 11:42:02 -07:00
parent 698426858e
commit 22bca53d69
12 changed files with 89 additions and 69 deletions

View file

@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public static void RefreshActiveInstance(PrinterSettings updatedProfile)
{
bool themeChanged = activeInstance.GetValue(SettingsKey.active_theme_index) != updatedProfile.GetValue(SettingsKey.active_theme_index);
bool themeChanged = activeInstance.GetValue(SettingsKey.active_theme_name) != updatedProfile.GetValue(SettingsKey.active_theme_name);
activeInstance = updatedProfile;
@ -119,23 +119,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
/// </summary>
public static void SwitchToPrinterTheme(bool doReloadEvent)
{
int defaultThemeIndex = ActiveTheme.GetThemeIndex("Blue - Light");
int themeIndex;
if (ActiveSliceSettings.Instance != null)
{
string activeThemeIndex = ActiveSliceSettings.Instance.GetValue(SettingsKey.active_theme_index);
if (string.IsNullOrEmpty(activeThemeIndex) || !int.TryParse(activeThemeIndex, out themeIndex))
if (ActiveSliceSettings.Instance.PrinterSelected)
{
themeIndex = defaultThemeIndex;
string activeThemeName = ActiveSliceSettings.Instance.GetValue(SettingsKey.active_theme_name);
if (string.IsNullOrEmpty(activeThemeName))
{
activeThemeName = "Blue - Light";
}
if (!doReloadEvent)
{
ActiveTheme.SuspendEvents();
}
ActiveTheme.Instance = ActiveTheme.GetThemeColors(activeThemeName);
ActiveTheme.ResumeEvents();
}
if (!doReloadEvent)
{
ActiveTheme.SuspendEvents();
}
ActiveTheme.Instance = ActiveTheme.AvailableThemes[themeIndex];
ActiveTheme.ResumeEvents();
}
}

View file

@ -864,6 +864,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
var persistenceLayer = layer ?? UserLayer;
if(settingsKey == SettingsKey.active_theme_name)
{
// also save it to the user settings so we can load it first thing on startup before a profile is loaded.
UserSettings.Instance.set(UserSettingsKey.ActiveThemeName, settingsValue);
}
// If the setting exists and is set the requested value, exit without setting or saving
string existingValue;
if (persistenceLayer.TryGetValue(settingsKey, out existingValue) && existingValue == settingsValue)

View file

@ -427,7 +427,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
// Set initial theme to current theme
newProfile.SetValue(SettingsKey.active_theme_index, ActiveSliceSettings.Instance.GetValue(SettingsKey.active_theme_index));
try
{
string name = ThemeIndexNameMapping[int.Parse(ActiveSliceSettings.Instance.GetValue("active_theme_index"))];
newProfile.SetValue(SettingsKey.active_theme_name, name);
}
catch
{
}
Instance.Profiles.Add(new PrinterInfo
{
@ -445,6 +453,32 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
ActiveSliceSettings.Instance = newProfile;
}
public static Dictionary<int, string> ThemeIndexNameMapping = new Dictionary<int, string>()
{
{ 0,"Blue - Dark"},
{ 1,"Teal - Dark"},
{ 2,"Green - Dark"},
{ 3,"Light Blue - Dark"},
{ 4,"Orange - Dark"},
{ 5,"Purple - Dark"},
{ 6,"Red - Dark"},
{ 7,"Pink - Dark"},
{ 8,"Grey - Dark"},
{ 9,"Pink - Dark"},
//Light themes
{ 10,"Blue - Light"},
{ 11,"Teal - Light"},
{ 12,"Green - Light"},
{ 13,"Light Blue - Light"},
{ 14,"Orange - Light"},
{ 15,"Purple - Light"},
{ 16,"Red - Light"},
{ 17,"Pink - Light"},
{ 18,"Grey - Light"},
{ 19,"Pink - Light"},
};
private async static Task<PrinterSettings> LoadHttpOemProfile(string make, string model)
{
string deviceToken = OemSettings.Instance.OemProfiles[make][model];

View file

@ -187,7 +187,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
break;
case "MatterControl.ActiveThemeIndex":
layer.Add(SettingsKey.active_theme_index, item.Value);
{
string themeName = ProfileManager.ThemeIndexNameMapping[int.Parse(ActiveSliceSettings.Instance.GetValue("active_theme_index"))];
layer.Add(SettingsKey.active_theme_name, themeName);
}
break;
case "MatterControl.PublishBedImage":

View file

@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
public static class SettingsKey
{
public const string active_theme_index = nameof(active_theme_index);
public const string active_theme_name = nameof(active_theme_name);
public const string auto_connect = nameof(auto_connect);
public const string baud_rate = nameof(baud_rate);
public const string bed_remove_part_temperature = nameof(bed_remove_part_temperature);