Add support for custom themes in chardonnay

This commit is contained in:
Michael Bucari-Tovo 2025-03-11 17:31:15 -06:00
parent a37eb383cd
commit b34970bd47
26 changed files with 719 additions and 280 deletions

View file

@ -28,7 +28,7 @@
<TextBlock
Name="PART_Label"
Padding="4,0"
Background="{DynamicResource SystemAltHighColor}"
Background="{DynamicResource SystemRegionColor}"
Text="{TemplateBinding Label}"
/>
</Grid>

View file

@ -158,15 +158,24 @@
<TextBlock
Grid.Column="0"
FontSize="16"
Margin="0,0,15,0"
VerticalAlignment="Center"
Text="Theme: "/>
Text="Theme:"/>
<controls:WheelComboBox
Name="ThemeComboBox"
Grid.Column="1"
MinWidth="80"
SelectedItem="{CompiledBinding ThemeVariant, Mode=TwoWay}"
ItemsSource="{CompiledBinding Themes}"/>
<Button
Grid.Column="2"
HorizontalAlignment="Right"
Padding="20,0"
VerticalAlignment="Stretch"
Content="Edit Theme Colors"
Click="EditThemeColors_Click"/>
</Grid>
</Grid>
</UserControl>

View file

@ -1,13 +1,18 @@
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Dinah.Core;
using FileManager;
using LibationAvalonia.Dialogs;
using LibationAvalonia.ViewModels.Settings;
using LibationFileManager;
using System.Linq;
#nullable enable
namespace LibationAvalonia.Controls.Settings
{
public partial class Important : UserControl
{
private ImportantSettingsVM? ViewModel => DataContext as ImportantSettingsVM;
public Important()
{
InitializeComponent();
@ -16,6 +21,42 @@ namespace LibationAvalonia.Controls.Settings
_ = Configuration.Instance.LibationFiles;
DataContext = new ImportantSettingsVM(Configuration.Instance);
}
ThemeComboBox.SelectionChanged += ThemeComboBox_SelectionChanged;
}
private void EditThemeColors_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (App.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
{
//Only allow a single instance of the theme picker
//Show it as a window, not a dialog, so users can preview
//their changes throughout the entire app.
if (lifetime.Windows.OfType<ThemePickerDialog>().FirstOrDefault() is ThemePickerDialog dialog)
{
dialog.BringIntoView();
}
else
{
var themePicker = new ThemePickerDialog();
themePicker.Show();
}
}
}
private void ThemeComboBox_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
//Remove the combo box before changing the theme, then re-add it.
//This is a workaround to a crash that will happen if the theme
//is changed while the combo box is open
ThemeComboBox.SelectionChanged -= ThemeComboBox_SelectionChanged;
var parent = ThemeComboBox.Parent as Panel;
if (parent?.Children.Remove(ThemeComboBox) ?? false)
{
Configuration.Instance.SetString(ViewModel?.ThemeVariant, nameof(ViewModel.ThemeVariant));
parent.Children.Add(ThemeComboBox);
}
ThemeComboBox.SelectionChanged += ThemeComboBox_SelectionChanged;
}
public void OpenLogFolderButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)