feat(desktop): add theme chooser

This commit is contained in:
Anna 2020-11-15 12:57:33 -05:00
parent 40d249f60a
commit 03697c336b
5 changed files with 46 additions and 3 deletions

View File

@ -4,6 +4,11 @@ using System.Globalization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Markup;
using ModernWpf;
// TODO: Up/down to cycle through input history
// TODO: key word notification, notifications on message type, targeted message (like emote targeting you)
// TODO: right click message to send tell to sender?
namespace XIVChat_Desktop {
/// <summary>
@ -27,7 +32,6 @@ namespace XIVChat_Desktop {
}
public bool Connected => this.Connection != null;
public bool Disconnected => this.Connection == null;
public event PropertyChangedEventHandler? PropertyChanged;
@ -55,6 +59,16 @@ namespace XIVChat_Desktop {
MessageBox.Show($"Could not save configuration file. {ex.Message}");
}
this.Config.PropertyChanged += (o, args) => {
if (args.PropertyName != nameof(Configuration.Theme)) {
return;
}
this.UpdateTheme();
};
this.UpdateTheme();
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(
@ -86,9 +100,17 @@ namespace XIVChat_Desktop {
_ = new ConfigWindow(wnd, this.Config);
}
private void UpdateTheme() {
ThemeManager.Current.ApplicationTheme = this.Config.Theme switch {
Theme.System => null,
Theme.Dark => ApplicationTheme.Dark,
Theme.Light => ApplicationTheme.Light,
_ => null,
};
}
private void ConnectionStatusChanged() {
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Connected)));
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Disconnected)));
}
public void Connect(string host, ushort port) {

View File

@ -36,6 +36,9 @@
Unchecked="AlwaysOnTop_Unchecked" />
<CheckBox Content="Compact mode"
IsChecked="{Binding Config.CompactMode}" />
<ComboBox x:Name="ThemeChooser"
ui:ControlHelper.Header="Theme"
SelectedItem="{Binding Config.Theme}" />
<Slider ui:ControlHelper.Header="Opacity"
Value="{Binding Config.Opacity}"
Minimum=".3"

View File

@ -16,6 +16,8 @@ namespace XIVChat_Desktop {
this.InitializeComponent();
this.DataContext = this;
this.ThemeChooser.ItemsSource = (Theme[])Enum.GetValues(typeof(Theme));
}
private void AlwaysOnTop_Checked(object? sender, RoutedEventArgs e) {

View File

@ -62,6 +62,16 @@ namespace XIVChat_Desktop {
}
}
private Theme theme = Theme.System;
public Theme Theme {
get => this.theme;
set {
this.theme = value;
this.OnPropertyChanged(nameof(this.Theme));
}
}
private void OnPropertyChanged(string propName) {
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
@ -170,6 +180,12 @@ namespace XIVChat_Desktop {
}
}
public enum Theme {
System,
Light,
Dark,
}
[JsonObject]
public class TrustedKey {
public string Name { get; set; }

View File

@ -179,7 +179,7 @@ namespace XIVChat_Desktop {
public event PropertyChangedEventHandler? PropertyChanged;
internal virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) {
internal void OnPropertyChanged([CallerMemberName] string? propertyName = null) {
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}