Populate themes to its own helper method

This commit is contained in:
Matt Nadareski
2021-06-29 22:54:50 -07:00
parent cd6414c032
commit 55fc8d5e40

View File

@@ -44,30 +44,42 @@ namespace RedBookPlayer.GUI
void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
_themeList = this.FindControl<ListBox>("ThemeList");
_themeList.SelectionChanged += ThemeList_SelectionChanged;
List<string> items = new List<string>();
items.Add("default");
if(Directory.Exists("themes/"))
{
foreach(string dir in Directory.EnumerateDirectories("themes/"))
{
string themeName = dir.Split('/')[1];
if (!File.Exists($"themes/{themeName}/view.xaml"))
continue;
items.Add(themeName);
}
}
_themeList.Items = items;
PopulateThemes();
this.FindControl<Button>("ApplyButton").Click += ApplySettings;
this.FindControl<Slider>("VolumeSlider").PropertyChanged += (s, e) => UpdateView();
}
/// <summary>
/// Populate the list of themes
/// </summary>
private void PopulateThemes()
{
// Get a reference to the theme list
_themeList = this.FindControl<ListBox>("ThemeList");
_themeList.SelectionChanged += ThemeList_SelectionChanged;
// Create a list of all found themes
List<string> items = new List<string>();
items.Add("default");
// Ensure the theme directory exists
if(!Directory.Exists("themes/"))
Directory.CreateDirectory("themes/");
// Add all theme directories if they're valid
foreach(string dir in Directory.EnumerateDirectories("themes/"))
{
string themeName = dir.Split('/')[1];
if(!File.Exists($"themes/{themeName}/view.xaml"))
continue;
items.Add(themeName);
}
_themeList.Items = items;
}
}
}