44using System . Drawing ;
55using System . IO ;
66using System . Linq ;
7- using System . Runtime . InteropServices ;
87using System . Windows . Forms ;
98using Aga . Controls . Tree ;
109using Aga . Controls . Tree . NodeControls ;
@@ -17,7 +16,6 @@ namespace OpenHardwareMonitor.UI;
1716
1817public 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