2021-03-19 17:07:27 -03:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
|
|
|
2021-06-29 14:23:33 -07:00
|
|
|
namespace RedBookPlayer.GUI
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-03-23 19:58:25 -03:00
|
|
|
public class SettingsWindow : Window
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-06 21:34:33 -07:00
|
|
|
private readonly Settings _settings;
|
|
|
|
|
private string _selectedTheme;
|
|
|
|
|
private ListBox _themeList;
|
2021-03-19 17:07:27 -03:00
|
|
|
|
2021-06-06 20:28:36 +01:00
|
|
|
public SettingsWindow() {}
|
2021-03-24 17:34:04 -03:00
|
|
|
|
|
|
|
|
public SettingsWindow(Settings settings)
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-06 21:34:33 -07:00
|
|
|
DataContext = _settings = settings;
|
2021-03-19 17:07:27 -03:00
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ThemeList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
2021-06-06 21:34:33 -07:00
|
|
|
if (e.AddedItems.Count == 0)
|
2021-03-19 17:07:27 -03:00
|
|
|
return;
|
|
|
|
|
|
2021-06-06 21:34:33 -07:00
|
|
|
_selectedTheme = (string)e.AddedItems[0];
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
2021-03-24 17:34:04 -03:00
|
|
|
public void ApplySettings(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2021-06-06 21:34:33 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(_selectedTheme))
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-06 21:34:33 -07:00
|
|
|
_settings.SelectedTheme = _selectedTheme;
|
|
|
|
|
MainWindow.ApplyTheme(_selectedTheme);
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:34:33 -07:00
|
|
|
_settings.Save();
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:34:33 -07:00
|
|
|
public void UpdateView() => this.FindControl<TextBlock>("VolumeLabel").Text = _settings.Volume.ToString();
|
2021-03-29 19:40:22 -03:00
|
|
|
|
2021-06-06 20:28:36 +01:00
|
|
|
void InitializeComponent()
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
|
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
|
|
|
|
2021-06-06 21:34:33 -07:00
|
|
|
_themeList = this.FindControl<ListBox>("ThemeList");
|
|
|
|
|
_themeList.SelectionChanged += ThemeList_SelectionChanged;
|
2021-03-19 17:07:27 -03:00
|
|
|
|
2021-06-06 20:28:36 +01:00
|
|
|
List<string> items = new List<string>();
|
2021-03-19 17:07:27 -03:00
|
|
|
items.Add("default");
|
|
|
|
|
|
2021-06-06 20:28:36 +01:00
|
|
|
if(Directory.Exists("themes/"))
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-06 20:28:36 +01:00
|
|
|
foreach(string dir in Directory.EnumerateDirectories("themes/"))
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
|
|
|
|
string themeName = dir.Split('/')[1];
|
|
|
|
|
|
2021-06-06 21:34:33 -07:00
|
|
|
if (!File.Exists($"themes/{themeName}/view.xaml"))
|
2021-03-19 17:07:27 -03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
items.Add(themeName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:34:33 -07:00
|
|
|
_themeList.Items = items;
|
2021-03-19 17:07:27 -03:00
|
|
|
|
2021-06-06 20:28:36 +01:00
|
|
|
this.FindControl<Button>("ApplyButton").Click += ApplySettings;
|
2021-03-29 19:40:22 -03:00
|
|
|
this.FindControl<Slider>("VolumeSlider").PropertyChanged += (s, e) => UpdateView();
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|