-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathThemeControl.xaml.cs
More file actions
107 lines (89 loc) · 3.74 KB
/
ThemeControl.xaml.cs
File metadata and controls
107 lines (89 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using System.Windows.Navigation;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Threading;
using Torch.API.Managers;
using Torch.API.Plugins;
using Torch.Server.Annotations;
using Torch.Server.Managers;
using Torch.Server.ViewModels;
namespace Torch.Server.Views
{
/// <summary>
/// Interaction logic for ThemeControl.xaml
/// </summary>
public partial class ThemeControl : UserControl, INotifyPropertyChanged
{
/// <summary>
/// Action other views can subscribe to to update their views if they dont inherit the style from the window for some reason.
/// </summary>
public static Action<ResourceDictionary> UpdateDynamicControls;
/// <summary>
/// Current theme other views can set their theme to when they first spawn
/// </summary>
public static ResourceDictionary currentTheme = new ResourceDictionary() { Source = new Uri(@"/Views/Resources.xaml", UriKind.Relative) };
/// <summary>
/// The current torch window and config.
/// </summary>
public TorchUI uiSource;
private TorchConfig _torchConfig;
/// <summary>
/// List of available themes
/// </summary>
public List<string> Themes
{
get => _themes.Keys.ToList();
}
private Dictionary<string, ResourceDictionary> _themes = new Dictionary<string, ResourceDictionary>();
private HashSet<ITorchPlugin> plugins;
public event PropertyChangedEventHandler PropertyChanged;
public ThemeControl()
{
InitializeComponent();
this.DataContext = this;
_themes["Dark theme"] = new ResourceDictionary() { Source = new Uri(@"/Themes/Dark Theme.xaml", UriKind.Relative) };
_themes["Animated Dark theme"] = new ResourceDictionary() { Source = new Uri(@"/Themes/Dark Theme Animated.xaml", UriKind.Relative) };
_themes["Light theme"] = new ResourceDictionary() { Source = new Uri(@"/Themes/Light Theme.xaml", UriKind.Relative) };
_themes["Light theme animated"] = new ResourceDictionary() { Source = new Uri(@"/Themes/Light Theme Animated.xaml", UriKind.Relative) };
_themes["Torch Theme"] = new ResourceDictionary() { Source = new Uri(@"/Views/Resources.xaml", UriKind.Relative) };
}
public void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox box = (ComboBox)sender;
var boxText = box.SelectedItem.ToString();
ChangeTheme(_themes[boxText].Source);
if (_torchConfig != null)
{
_torchConfig.LastUsedTheme = boxText;
_torchConfig.Save();
}
}
public void ChangeTheme(Uri uri)
{
uiSource.Resources.MergedDictionaries.Clear();
var resource = new ResourceDictionary() { Source = uri };
uiSource.Resources.MergedDictionaries.Add(resource);
UpdateDynamicControls?.Invoke(resource);
currentTheme = resource;
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
public void SetConfig(TorchConfig config)
{
_torchConfig = config;
if (_themes.ContainsKey(config.LastUsedTheme))
ChangeTheme(_themes[config.LastUsedTheme].Source);
}
}
}