Skip to content

Commit 06a36d7

Browse files
committed
Themes initialization simplified; main menu items reordered
1 parent 73456df commit 06a36d7

2 files changed

Lines changed: 21 additions & 81 deletions

File tree

OpenHardwareMonitor/UI/MainForm.Designer.cs

Lines changed: 4 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OpenHardwareMonitor/UI/MainForm.cs

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Drawing;
55
using System.IO;
66
using System.Linq;
7-
using System.Runtime.InteropServices;
87
using System.Windows.Forms;
98
using Aga.Controls.Tree;
109
using Aga.Controls.Tree.NodeControls;
@@ -17,7 +16,6 @@ namespace OpenHardwareMonitor.UI;
1716

1817
public sealed partial class MainForm : Form
1918
{
20-
private ToolStripMenuItem _autoThemeMenuItem;
2119
private readonly UserOption _autoStart;
2220
private readonly Computer _computer;
2321
private readonly SensorGadget _gadget;
@@ -543,63 +541,21 @@ private void InitializeTheme()
543541
ThemedHScrollIndicator.AddToControl(treeView);
544542
TreeViewAdvThemeExtender.SubscribeToThemes();
545543

546-
if (Theme.SupportsAutoThemeSwitching())
547-
{
548-
_autoThemeMenuItem = new ToolStripRadioButtonMenuItem("Auto");
549-
_autoThemeMenuItem.Click += (o, e) =>
550-
{
551-
_autoThemeMenuItem.Checked = true;
552-
Theme.SetAutoTheme();
553-
_settings.SetValue("theme", "auto");
554-
};
555-
themeMenuItem.DropDownItems.Add(_autoThemeMenuItem);
556-
}
557-
558-
var settingsTheme = _settings.GetValue("theme", "auto");
559-
var allThemes = CustomTheme.GetAllThemes("themes", "OpenHardwareMonitor.Resources.themes").OrderBy(x => x.DisplayName).ToList();
560-
var setTheme = allThemes.FirstOrDefault(theme => settingsTheme == theme.Id);
561-
if (setTheme != null)
562-
{
563-
Theme.Current = setTheme;
564-
}
565-
566-
AddThemeMenuItems(allThemes.Where(t => t is not CustomTheme));
567-
var customThemes = allThemes.Where(t => t is CustomTheme).ToList();
568-
if (customThemes.Count > 0)
569-
{
570-
themeMenuItem.DropDownItems.Add("-");
571-
AddThemeMenuItems(customThemes);
572-
}
573-
574-
if (setTheme == null && themeMenuItem.DropDownItems.Count > 0)
575-
themeMenuItem.DropDownItems[0].PerformClick();
576-
577-
Theme.Current.Apply(this);
578-
}
579-
580-
private void AddThemeMenuItems(IEnumerable<Theme> themes)
581-
{
582-
foreach (Theme theme in themes)
583-
{
584-
var item = new ToolStripRadioButtonMenuItem(theme.DisplayName);
585-
item.Tag = theme;
586-
item.Click += OnThemeMenuItemClick;
587-
themeMenuItem.DropDownItems.Add(item);
588-
589-
if (Theme.Current != null && Theme.Current.Id == theme.Id)
544+
//themeMenuItem.MenuItems.Clear();
545+
var currentItem = CustomTheme.FillThemesMenu((title, theme, onClick) => {
546+
if (theme == null && onClick == null)
590547
{
591-
item.Checked = true;
548+
themeMenuItem.DropDownItems.Add(title);
549+
return null;
592550
}
593-
}
594-
}
595-
596-
private void OnThemeMenuItemClick(object sender, EventArgs e)
597-
{
598-
if (sender is not ToolStripRadioButtonMenuItem item || item.Tag is not Theme theme)
599-
return;
600-
item.Checked = true;
601-
Theme.Current = theme;
602-
_settings.SetValue("theme", theme.Id);
551+
var item = new ToolStripRadioButtonMenuItem(title, null, onClick);
552+
themeMenuItem.DropDownItems.Add(item);
553+
return item;
554+
}, () => {
555+
_settings.SetValue("theme", Theme.IsAutoThemeEnabled ? "auto" : Theme.Current.Id);
556+
}, _settings.GetValue("theme", "auto"), "OpenHardwareMonitor.Resources.themes");
557+
currentItem?.PerformClick();
558+
Theme.Current.Apply(this);
603559
}
604560

605561
private void InsertSorted(IList<Node> nodes, HardwareNode node)
@@ -970,10 +926,10 @@ protected override void WndProc(ref Message m)
970926
{
971927
SysTrayHideShow();
972928
}
973-
else if (m.Msg == WinApiHelper.WM_WININICHANGE && Marshal.PtrToStringUni(m.LParam) == "ImmersiveColorSet" && _autoThemeMenuItem?.Checked == true)
974-
{
975-
Theme.SetAutoTheme();
976-
}
929+
//else if (m.Msg == WinApiHelper.WM_WININICHANGE && Marshal.PtrToStringUni(m.LParam) == "ImmersiveColorSet" && Theme.IsAutoThemeEnabled)
930+
//{
931+
// Theme.SetAutoTheme();
932+
//}
977933
else if (_minimizeOnClose.Value && m.Msg == WinApiHelper.WM_SYS_COMMAND && m.WParam.ToInt64() == WinApiHelper.SC_CLOSE)
978934
{
979935
//Apparently the user wants to minimize rather than close

0 commit comments

Comments
 (0)