This repository has been archived by the owner on Jul 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.xaml.cs
118 lines (104 loc) · 4.13 KB
/
Settings.xaml.cs
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
108
109
110
111
112
113
114
115
116
117
118
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Index
{
public partial class Settings : Page
{
public Settings()
{
InitializeComponent();
this.Dispatcher.Invoke(() =>
{
if (Properties.Settings.Default.Theme == "Dark")
{
this.Dark.IsSelected = true;
this.Light.IsSelected = false;
Wpf.Ui.Appearance.Accent.Apply(SystemParameters.WindowGlassColor, Wpf.Ui.Appearance.ThemeType.Dark, true);
}
if (Properties.Settings.Default.Theme == "Light")
{
this.Light.IsSelected = true;
this.Dark.IsSelected = false;
Wpf.Ui.Appearance.Accent.Apply(SystemParameters.WindowGlassColor, Wpf.Ui.Appearance.ThemeType.Light, true);
}
if (string.IsNullOrWhiteSpace(Properties.Settings.Default.Directory))
{
DirectoryText.Content = "Not set";
}
else
{
DirectoryText.Content = Properties.Settings.Default.Directory;
}
if (string.IsNullOrWhiteSpace(Properties.Settings.Default.Throttle.ToString()) == false && Properties.Settings.Default.Throttle != 0)
{
throttletoggle.IsEnabled = true;
throttletoggle.IsChecked = true;
throttlebox.Text = Properties.Settings.Default.Throttle.ToString();
}
});
}
private void SetFolder(object sender, MouseButtonEventArgs e)
{
Dispatcher.Invoke(() =>
{
using var fbd = new System.Windows.Forms.FolderBrowserDialog();
var result = fbd.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
DirectoryText.Content = fbd.SelectedPath;
Properties.Settings.Default.Directory = fbd.SelectedPath;
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
}
});
}
private void ThemeChanged(object sender, SelectionChangedEventArgs e)
{
if (Theme.SelectedIndex != -1)
{
if (Theme.SelectedIndex == 0)
{
Properties.Settings.Default.Theme = "Dark";
Wpf.Ui.Appearance.Accent.Apply(SystemParameters.WindowGlassColor, Wpf.Ui.Appearance.ThemeType.Dark, true);
}
if (Theme.SelectedIndex == 1)
{
Properties.Settings.Default.Theme = "Light";
Wpf.Ui.Appearance.Accent.Apply(SystemParameters.WindowGlassColor, Wpf.Ui.Appearance.ThemeType.Light, true);
}
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
}
}
private void ThrottleToggled(object sender, RoutedEventArgs e)
{
throttlebox.IsEnabled = true;
}
private void ThrottleUntoggled(object sender, RoutedEventArgs e)
{
throttlebox.IsEnabled = false;
throttlebox.Text = "";
Properties.Settings.Default.Throttle = 0;
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
}
private void ThrottleChanged(object sender, TextChangedEventArgs e)
{
try
{
float flt;
if (float.TryParse(throttlebox.Text, out flt))
{
Properties.Settings.Default.Throttle = float.Parse(throttlebox.Text);
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
}
}
catch
{
MessageBox.Show("Couldn't throttle download", "Index");
}
}
}
}