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:
parent
698426858e
commit
22bca53d69
12 changed files with 89 additions and 69 deletions
|
|
@ -28,23 +28,14 @@ either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using MatterHackers.Agg;
|
using MatterHackers.Agg;
|
||||||
using MatterHackers.Agg.Font;
|
|
||||||
using MatterHackers.Agg.Image;
|
|
||||||
using MatterHackers.Agg.PlatformAbstract;
|
using MatterHackers.Agg.PlatformAbstract;
|
||||||
using MatterHackers.Agg.UI;
|
using MatterHackers.Agg.UI;
|
||||||
using MatterHackers.Localizations;
|
|
||||||
using MatterHackers.MatterControl.ContactForm;
|
|
||||||
using MatterHackers.MatterControl.CustomWidgets;
|
|
||||||
using MatterHackers.MatterControl.DataStorage;
|
using MatterHackers.MatterControl.DataStorage;
|
||||||
using MatterHackers.MatterControl.HtmlParsing;
|
|
||||||
using MatterHackers.MatterControl.PrintLibrary;
|
|
||||||
using MatterHackers.MatterControl.PrintLibrary.Provider;
|
using MatterHackers.MatterControl.PrintLibrary.Provider;
|
||||||
using MatterHackers.MatterControl.PrintQueue;
|
using MatterHackers.MatterControl.PrintQueue;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
namespace MatterHackers.MatterControl
|
namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
|
|
@ -73,7 +64,7 @@ namespace MatterHackers.MatterControl
|
||||||
customInfoTopToBottom.AddChild(new GuiWidget(1, 10));
|
customInfoTopToBottom.AddChild(new GuiWidget(1, 10));
|
||||||
|
|
||||||
string aboutHtmlFile = Path.Combine("OEMSettings", "AboutPage.html");
|
string aboutHtmlFile = Path.Combine("OEMSettings", "AboutPage.html");
|
||||||
string htmlContent = StaticData.Instance.ReadAllText(aboutHtmlFile);
|
string htmlContent = StaticData.Instance.ReadAllText(aboutHtmlFile);
|
||||||
|
|
||||||
#if false // test
|
#if false // test
|
||||||
{
|
{
|
||||||
|
|
@ -102,7 +93,7 @@ namespace MatterHackers.MatterControl
|
||||||
|
|
||||||
public static void DeleteCacheData(int daysOldToDelete)
|
public static void DeleteCacheData(int daysOldToDelete)
|
||||||
{
|
{
|
||||||
if(LibraryProviderSQLite.PreloadingCalibrationFiles)
|
if (LibraryProviderSQLite.PreloadingCalibrationFiles)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +179,7 @@ namespace MatterHackers.MatterControl
|
||||||
return VersionInfo.Instance.ReleaseVersion;
|
return VersionInfo.Instance.ReleaseVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HashSet<string> folderNamesToPreserve = new HashSet<string>()
|
private static HashSet<string> folderNamesToPreserve = new HashSet<string>()
|
||||||
{
|
{
|
||||||
"profiles",
|
"profiles",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -206,15 +206,22 @@ namespace MatterHackers.MatterControl
|
||||||
if (applicationInstanceCount == 0)
|
if (applicationInstanceCount == 0)
|
||||||
{
|
{
|
||||||
Assembly mcAssembly = Assembly.GetEntryAssembly();
|
Assembly mcAssembly = Assembly.GetEntryAssembly();
|
||||||
if(mcAssembly != null)
|
if (mcAssembly != null)
|
||||||
{
|
{
|
||||||
string applicationName = Path.GetFileNameWithoutExtension(mcAssembly.Location).ToUpper();
|
string applicationName = Path.GetFileNameWithoutExtension(mcAssembly.Location).ToUpper();
|
||||||
Process[] p1 = Process.GetProcesses();
|
Process[] p1 = Process.GetProcesses();
|
||||||
foreach (System.Diagnostics.Process pro in p1)
|
foreach (System.Diagnostics.Process pro in p1)
|
||||||
{
|
{
|
||||||
if (pro.ProcessName.ToUpper().Contains(applicationName))
|
try
|
||||||
|
{
|
||||||
|
if (pro?.ProcessName != null
|
||||||
|
&& pro.ProcessName.ToUpper().Contains(applicationName))
|
||||||
|
{
|
||||||
|
applicationInstanceCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
{
|
{
|
||||||
applicationInstanceCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,10 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
Width = containerHeight
|
Width = containerHeight
|
||||||
};
|
};
|
||||||
columnContainer.AddChild(CreateThemeButton(allThemes[index], index));
|
columnContainer.AddChild(CreateThemeButton(allThemes[index]));
|
||||||
|
|
||||||
int secondRowIndex = index + themeCount / 2;
|
int secondRowIndex = index + themeCount / 2;
|
||||||
columnContainer.AddChild(CreateThemeButton(allThemes[secondRowIndex], secondRowIndex));
|
columnContainer.AddChild(CreateThemeButton(allThemes[secondRowIndex]));
|
||||||
|
|
||||||
this.AddChild(columnContainer);
|
this.AddChild(columnContainer);
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ namespace MatterHackers.MatterControl
|
||||||
this.Width = containerHeight * (themeCount / 2);
|
this.Width = containerHeight * (themeCount / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Button CreateThemeButton(IThemeColors theme, int index)
|
public Button CreateThemeButton(IThemeColors theme)
|
||||||
{
|
{
|
||||||
var normal = new GuiWidget(colorSelectSize, colorSelectSize);
|
var normal = new GuiWidget(colorSelectSize, colorSelectSize);
|
||||||
normal.BackgroundColor = theme.PrimaryAccentColor;
|
normal.BackgroundColor = theme.PrimaryAccentColor;
|
||||||
|
|
@ -82,18 +82,16 @@ namespace MatterHackers.MatterControl
|
||||||
|
|
||||||
var colorButton = new Button(0, 0, new ButtonViewStates(normal, hover, pressed, disabled))
|
var colorButton = new Button(0, 0, new ButtonViewStates(normal, hover, pressed, disabled))
|
||||||
{
|
{
|
||||||
Name = index.ToString()
|
Name = theme.Name,
|
||||||
};
|
};
|
||||||
colorButton.Click += (s, e) =>
|
colorButton.Click += (s, e) =>
|
||||||
{
|
{
|
||||||
string themeIndexText = ((GuiWidget)s).Name;
|
string themeName = ((GuiWidget)s).Name;
|
||||||
int themeIndex;
|
|
||||||
|
|
||||||
if (int.TryParse(themeIndexText, out themeIndex) && themeIndex < ActiveTheme.AvailableThemes.Count)
|
// save it for this printer
|
||||||
{
|
ActiveSliceSettings.Instance.SetValue(SettingsKey.active_theme_name, themeName);
|
||||||
ActiveSliceSettings.Instance.SetValue(SettingsKey.active_theme_index, themeIndex.ToString());
|
|
||||||
ActiveTheme.Instance = ActiveTheme.AvailableThemes[themeIndex];
|
ActiveTheme.Instance = ActiveTheme.GetThemeColors(themeName);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
colorButton.MouseEnterBounds += (s, e) =>
|
colorButton.MouseEnterBounds += (s, e) =>
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ namespace MatterHackers.MatterControl.DataStorage.ClassicDB
|
||||||
ProfileManager.Instance.SetLastProfile(printer.Id.ToString());
|
ProfileManager.Instance.SetLastProfile(printer.Id.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
layeredProfile.UserLayer[SettingsKey.active_theme_index] = UserSettings.Instance.get(UserSettingsKey.ActiveThemeIndex);
|
layeredProfile.UserLayer[SettingsKey.active_theme_name] = UserSettings.Instance.get(UserSettingsKey.ActiveThemeName);
|
||||||
|
|
||||||
// Import macros from the database
|
// Import macros from the database
|
||||||
var allMacros = Datastore.Instance.dbSQLite.Query<CustomCommands>("SELECT * FROM CustomCommands WHERE PrinterId = " + printer.Id);
|
var allMacros = Datastore.Instance.dbSQLite.Query<CustomCommands>("SELECT * FROM CustomCommands WHERE PrinterId = " + printer.Id);
|
||||||
|
|
|
||||||
|
|
@ -418,32 +418,14 @@ public static bool CameraPreviewActive = false;
|
||||||
|
|
||||||
public static void LoadUITheme()
|
public static void LoadUITheme()
|
||||||
{
|
{
|
||||||
//Load the default theme by index
|
if (string.IsNullOrEmpty(UserSettings.Instance.get(UserSettingsKey.ActiveThemeName)))
|
||||||
if (string.IsNullOrEmpty(UserSettings.Instance.get(UserSettingsKey.ActiveThemeIndex)))
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ActiveTheme.AvailableThemes.Count; i++)
|
ActiveTheme.Instance = ActiveTheme.GetThemeColors("Blue - Light");
|
||||||
{
|
|
||||||
IThemeColors current = ActiveTheme.AvailableThemes[i];
|
|
||||||
if (current.Name == OemSettings.Instance.ThemeColor)
|
|
||||||
{
|
|
||||||
UserSettings.Instance.set(UserSettingsKey.ActiveThemeIndex, i.ToString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
int themeIndex;
|
|
||||||
if (int.TryParse(UserSettings.Instance.get(UserSettingsKey.ActiveThemeIndex), out themeIndex)
|
|
||||||
&& themeIndex < ActiveTheme.AvailableThemes.Count)
|
|
||||||
{
|
{
|
||||||
try
|
string name = UserSettings.Instance.get(UserSettingsKey.ActiveThemeName);
|
||||||
{
|
ActiveTheme.Instance = ActiveTheme.GetThemeColors(name);
|
||||||
ActiveTheme.Instance = ActiveTheme.AvailableThemes[themeIndex];
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
GuiWidget.BreakInDebugger();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ namespace MatterHackers.MatterControl
|
||||||
public const string UpdateFeedType = nameof(UpdateFeedType);
|
public const string UpdateFeedType = nameof(UpdateFeedType);
|
||||||
public const string ApplicationDisplayMode = nameof(ApplicationDisplayMode);
|
public const string ApplicationDisplayMode = nameof(ApplicationDisplayMode);
|
||||||
public const string defaultRenderSetting = nameof(defaultRenderSetting);
|
public const string defaultRenderSetting = nameof(defaultRenderSetting);
|
||||||
public const string ActiveThemeIndex = nameof(ActiveThemeIndex);
|
public const string ActiveThemeName = nameof(ActiveThemeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserSettings
|
public class UserSettings
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
|
|
||||||
public static void RefreshActiveInstance(PrinterSettings updatedProfile)
|
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;
|
activeInstance = updatedProfile;
|
||||||
|
|
||||||
|
|
@ -119,23 +119,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SwitchToPrinterTheme(bool doReloadEvent)
|
public static void SwitchToPrinterTheme(bool doReloadEvent)
|
||||||
{
|
{
|
||||||
int defaultThemeIndex = ActiveTheme.GetThemeIndex("Blue - Light");
|
|
||||||
|
|
||||||
int themeIndex;
|
|
||||||
if (ActiveSliceSettings.Instance != null)
|
if (ActiveSliceSettings.Instance != null)
|
||||||
{
|
{
|
||||||
string activeThemeIndex = ActiveSliceSettings.Instance.GetValue(SettingsKey.active_theme_index);
|
if (ActiveSliceSettings.Instance.PrinterSelected)
|
||||||
if (string.IsNullOrEmpty(activeThemeIndex) || !int.TryParse(activeThemeIndex, out themeIndex))
|
|
||||||
{
|
{
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -864,6 +864,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
{
|
{
|
||||||
var persistenceLayer = layer ?? UserLayer;
|
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
|
// If the setting exists and is set the requested value, exit without setting or saving
|
||||||
string existingValue;
|
string existingValue;
|
||||||
if (persistenceLayer.TryGetValue(settingsKey, out existingValue) && existingValue == settingsValue)
|
if (persistenceLayer.TryGetValue(settingsKey, out existingValue) && existingValue == settingsValue)
|
||||||
|
|
|
||||||
|
|
@ -427,7 +427,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set initial theme to current theme
|
// 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
|
Instance.Profiles.Add(new PrinterInfo
|
||||||
{
|
{
|
||||||
|
|
@ -445,6 +453,32 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
ActiveSliceSettings.Instance = newProfile;
|
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)
|
private async static Task<PrinterSettings> LoadHttpOemProfile(string make, string model)
|
||||||
{
|
{
|
||||||
string deviceToken = OemSettings.Instance.OemProfiles[make][model];
|
string deviceToken = OemSettings.Instance.OemProfiles[make][model];
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "MatterControl.ActiveThemeIndex":
|
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;
|
break;
|
||||||
|
|
||||||
case "MatterControl.PublishBedImage":
|
case "MatterControl.PublishBedImage":
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
{
|
{
|
||||||
public static class SettingsKey
|
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 auto_connect = nameof(auto_connect);
|
||||||
public const string baud_rate = nameof(baud_rate);
|
public const string baud_rate = nameof(baud_rate);
|
||||||
public const string bed_remove_part_temperature = nameof(bed_remove_part_temperature);
|
public const string bed_remove_part_temperature = nameof(bed_remove_part_temperature);
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6ad32abd5e9e5649706b84af8407d21199a4c421
|
Subproject commit adbbcb5ba8b62dff74c777013ead4784b74f4efd
|
||||||
Loading…
Add table
Add a link
Reference in a new issue