diff --git a/AboutPage/AboutWidget.cs b/AboutPage/AboutWidget.cs index 1dd1b64b7..3b5ecf993 100644 --- a/AboutPage/AboutWidget.cs +++ b/AboutPage/AboutWidget.cs @@ -28,23 +28,14 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.Agg; -using MatterHackers.Agg.Font; -using MatterHackers.Agg.Image; using MatterHackers.Agg.PlatformAbstract; using MatterHackers.Agg.UI; -using MatterHackers.Localizations; -using MatterHackers.MatterControl.ContactForm; -using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.DataStorage; -using MatterHackers.MatterControl.HtmlParsing; -using MatterHackers.MatterControl.PrintLibrary; using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.MatterControl.PrintQueue; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Net; namespace MatterHackers.MatterControl { @@ -73,7 +64,7 @@ namespace MatterHackers.MatterControl customInfoTopToBottom.AddChild(new GuiWidget(1, 10)); string aboutHtmlFile = Path.Combine("OEMSettings", "AboutPage.html"); - string htmlContent = StaticData.Instance.ReadAllText(aboutHtmlFile); + string htmlContent = StaticData.Instance.ReadAllText(aboutHtmlFile); #if false // test { @@ -102,7 +93,7 @@ namespace MatterHackers.MatterControl public static void DeleteCacheData(int daysOldToDelete) { - if(LibraryProviderSQLite.PreloadingCalibrationFiles) + if (LibraryProviderSQLite.PreloadingCalibrationFiles) { return; } @@ -188,7 +179,7 @@ namespace MatterHackers.MatterControl return VersionInfo.Instance.ReleaseVersion; } - static HashSet folderNamesToPreserve = new HashSet() + private static HashSet folderNamesToPreserve = new HashSet() { "profiles", }; diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 78f9e2dd4..350183aad 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -206,15 +206,22 @@ namespace MatterHackers.MatterControl if (applicationInstanceCount == 0) { Assembly mcAssembly = Assembly.GetEntryAssembly(); - if(mcAssembly != null) + if (mcAssembly != null) { string applicationName = Path.GetFileNameWithoutExtension(mcAssembly.Location).ToUpper(); Process[] p1 = Process.GetProcesses(); 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++; } } } diff --git a/CustomWidgets/ThemeColorSelectorWidget.cs b/CustomWidgets/ThemeColorSelectorWidget.cs index e0babd06c..5b7beadc8 100644 --- a/CustomWidgets/ThemeColorSelectorWidget.cs +++ b/CustomWidgets/ThemeColorSelectorWidget.cs @@ -54,10 +54,10 @@ namespace MatterHackers.MatterControl { Width = containerHeight }; - columnContainer.AddChild(CreateThemeButton(allThemes[index], index)); + columnContainer.AddChild(CreateThemeButton(allThemes[index])); int secondRowIndex = index + themeCount / 2; - columnContainer.AddChild(CreateThemeButton(allThemes[secondRowIndex], secondRowIndex)); + columnContainer.AddChild(CreateThemeButton(allThemes[secondRowIndex])); this.AddChild(columnContainer); @@ -67,7 +67,7 @@ namespace MatterHackers.MatterControl this.Width = containerHeight * (themeCount / 2); } - public Button CreateThemeButton(IThemeColors theme, int index) + public Button CreateThemeButton(IThemeColors theme) { var normal = new GuiWidget(colorSelectSize, colorSelectSize); normal.BackgroundColor = theme.PrimaryAccentColor; @@ -82,18 +82,16 @@ namespace MatterHackers.MatterControl var colorButton = new Button(0, 0, new ButtonViewStates(normal, hover, pressed, disabled)) { - Name = index.ToString() + Name = theme.Name, }; colorButton.Click += (s, e) => { - string themeIndexText = ((GuiWidget)s).Name; - int themeIndex; + string themeName = ((GuiWidget)s).Name; - if (int.TryParse(themeIndexText, out themeIndex) && themeIndex < ActiveTheme.AvailableThemes.Count) - { - ActiveSliceSettings.Instance.SetValue(SettingsKey.active_theme_index, themeIndex.ToString()); - ActiveTheme.Instance = ActiveTheme.AvailableThemes[themeIndex]; - } + // save it for this printer + ActiveSliceSettings.Instance.SetValue(SettingsKey.active_theme_name, themeName); + + ActiveTheme.Instance = ActiveTheme.GetThemeColors(themeName); }; colorButton.MouseEnterBounds += (s, e) => diff --git a/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs b/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs index 3fe6fbe30..710bcff85 100644 --- a/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs +++ b/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs @@ -105,7 +105,7 @@ namespace MatterHackers.MatterControl.DataStorage.ClassicDB 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 var allMacros = Datastore.Instance.dbSQLite.Query("SELECT * FROM CustomCommands WHERE PrinterId = " + printer.Id); diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index e10f2f420..30bcc38b7 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -418,32 +418,14 @@ public static bool CameraPreviewActive = false; public static void LoadUITheme() { - //Load the default theme by index - if (string.IsNullOrEmpty(UserSettings.Instance.get(UserSettingsKey.ActiveThemeIndex))) + if (string.IsNullOrEmpty(UserSettings.Instance.get(UserSettingsKey.ActiveThemeName))) { - for (int i = 0; i < ActiveTheme.AvailableThemes.Count; i++) - { - IThemeColors current = ActiveTheme.AvailableThemes[i]; - if (current.Name == OemSettings.Instance.ThemeColor) - { - UserSettings.Instance.set(UserSettingsKey.ActiveThemeIndex, i.ToString()); - break; - } - } + ActiveTheme.Instance = ActiveTheme.GetThemeColors("Blue - Light"); } - - int themeIndex; - if (int.TryParse(UserSettings.Instance.get(UserSettingsKey.ActiveThemeIndex), out themeIndex) - && themeIndex < ActiveTheme.AvailableThemes.Count) + else { - try - { - ActiveTheme.Instance = ActiveTheme.AvailableThemes[themeIndex]; - } - catch - { - GuiWidget.BreakInDebugger(); - } + string name = UserSettings.Instance.get(UserSettingsKey.ActiveThemeName); + ActiveTheme.Instance = ActiveTheme.GetThemeColors(name); } } diff --git a/SettingsManagement/UserSettings.cs b/SettingsManagement/UserSettings.cs index eb218b148..fdfbdf040 100644 --- a/SettingsManagement/UserSettings.cs +++ b/SettingsManagement/UserSettings.cs @@ -11,7 +11,7 @@ namespace MatterHackers.MatterControl public const string UpdateFeedType = nameof(UpdateFeedType); public const string ApplicationDisplayMode = nameof(ApplicationDisplayMode); public const string defaultRenderSetting = nameof(defaultRenderSetting); - public const string ActiveThemeIndex = nameof(ActiveThemeIndex); + public const string ActiveThemeName = nameof(ActiveThemeName); } public class UserSettings diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index 9e725de84..fdbc2e2d8 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -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 /// 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(); } } diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index eb953a6af..d9d4a8a6e 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -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) diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index c69b6596e..34f75cf2c 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -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 ThemeIndexNameMapping = new Dictionary() + { + { 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 LoadHttpOemProfile(string make, string model) { string deviceToken = OemSettings.Instance.OemProfiles[make][model]; diff --git a/SlicerConfiguration/Settings/ProfileMigrations.cs b/SlicerConfiguration/Settings/ProfileMigrations.cs index bb67b0c23..4d9292e4b 100644 --- a/SlicerConfiguration/Settings/ProfileMigrations.cs +++ b/SlicerConfiguration/Settings/ProfileMigrations.cs @@ -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": diff --git a/SlicerConfiguration/Settings/SettingsHelpers.cs b/SlicerConfiguration/Settings/SettingsHelpers.cs index aec0c7804..334455c5e 100644 --- a/SlicerConfiguration/Settings/SettingsHelpers.cs +++ b/SlicerConfiguration/Settings/SettingsHelpers.cs @@ -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); diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 6ad32abd5..adbbcb5ba 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 6ad32abd5e9e5649706b84af8407d21199a4c421 +Subproject commit adbbcb5ba8b62dff74c777013ead4784b74f4efd