44/* information. */
55/******************************************************************************/
66using System ;
7+ using System . Collections . Generic ;
8+ using System . Linq ;
79using Polycode . NostalgicPlayer . Controls . Events ;
810using Polycode . NostalgicPlayer . Controls . Theme . Interfaces ;
11+ using Polycode . NostalgicPlayer . Controls . Theme . Purple ;
912using Polycode . NostalgicPlayer . Controls . Theme . Standard ;
1013
1114namespace Polycode . NostalgicPlayer . Controls . Theme
@@ -17,7 +20,13 @@ namespace Polycode.NostalgicPlayer.Controls.Theme
1720 /// </summary>
1821 internal class ThemeManager : IThemeManager , IDisposable
1922 {
20- private ITheme theme ;
23+ private readonly ITheme [ ] embeddedThemes =
24+ [
25+ new StandardTheme ( ) ,
26+ new PurpleTheme ( )
27+ ] ;
28+
29+ private ITheme currentTheme ;
2130
2231 /********************************************************************/
2332 /// <summary>
@@ -26,7 +35,7 @@ internal class ThemeManager : IThemeManager, IDisposable
2635 /********************************************************************/
2736 public ThemeManager ( )
2837 {
29- theme = new StandardTheme ( ) ;
38+ currentTheme = embeddedThemes [ 0 ] ;
3039 }
3140
3241
@@ -38,10 +47,13 @@ public ThemeManager()
3847 /********************************************************************/
3948 public void Dispose ( )
4049 {
41- if ( theme is IDisposable disposable )
42- disposable . Dispose ( ) ;
50+ foreach ( ITheme theme in embeddedThemes )
51+ {
52+ if ( theme is IDisposable disposable )
53+ disposable . Dispose ( ) ;
54+ }
4355
44- theme = null ;
56+ currentTheme = null ;
4557 }
4658
4759
@@ -55,12 +67,24 @@ public void Dispose()
5567
5668
5769
70+ /********************************************************************/
71+ /// <summary>
72+ /// Return all available themes that can be used
73+ /// </summary>
74+ /********************************************************************/
75+ public Guid [ ] GetAvailableThemes ( )
76+ {
77+ return GetThemes ( ) . Select ( x => x . Id ) . ToArray ( ) ;
78+ }
79+
80+
81+
5882 /********************************************************************/
5983 /// <summary>
6084 /// Return the current theme
6185 /// </summary>
6286 /********************************************************************/
63- public ITheme CurrentTheme => theme ;
87+ public ITheme CurrentTheme => currentTheme ;
6488
6589
6690
@@ -69,12 +93,11 @@ public void Dispose()
6993 /// Switch to the new theme given
7094 /// </summary>
7195 /********************************************************************/
72- public void SwitchTheme ( ITheme newTheme )
96+ public void SwitchTheme ( Guid themeId )
7397 {
74- if ( theme is IDisposable disposable )
75- disposable . Dispose ( ) ;
76-
77- theme = newTheme ;
98+ currentTheme = GetThemes ( ) . FirstOrDefault ( x => x . Id == themeId ) ;
99+ if ( currentTheme == null )
100+ currentTheme = embeddedThemes [ 0 ] ;
78101
79102 RefreshControls ( ) ;
80103 }
@@ -89,7 +112,20 @@ public void SwitchTheme(ITheme newTheme)
89112 public void RefreshControls ( )
90113 {
91114 if ( ThemeChanged != null )
92- ThemeChanged ( this , new ThemeChangedEventArgs ( theme ) ) ;
115+ ThemeChanged ( this , new ThemeChangedEventArgs ( currentTheme ) ) ;
116+ }
117+
118+ #region Private methods
119+ /********************************************************************/
120+ /// <summary>
121+ /// Return all available themes that can be used
122+ /// </summary>
123+ /********************************************************************/
124+ private IEnumerable < ITheme > GetThemes ( )
125+ {
126+ foreach ( ITheme theme in embeddedThemes )
127+ yield return theme ;
93128 }
129+ #endregion
94130 }
95131}
0 commit comments