-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.xaml.cs
102 lines (85 loc) · 2.88 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
using System;
using System.Configuration;
using Wpf.Ui.Controls;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
namespace PowerTray
{
/// <summary>
/// Interaction logic for Settings.xaml
/// </summary>
public partial class Settings : FluentWindow
{
public Configuration AppConfig = ConfigurationManager.OpenMachineConfiguration();
public Settings()
{
InitializeComponent();
DefaultTray.ItemsSource = Enum.GetNames(typeof(App.DisplayedInfo));
TrayFontStyle.ItemsSource = Enum.GetNames(typeof(System.Drawing.FontStyle));
Load();
AdminLabel.IsEnabled = App.IsAdministrator();
Admin.IsEnabled = App.IsAdministrator();
PowerPlans.RefreshPowerPlans();
UpdatePlansList();
}
public void UpdatePlansList()
{
ACPlan.ItemsSource = App.plans.Select(o => o.Name).ToList();
BatteryPlan.ItemsSource = App.plans.Select(o => o.Name).ToList();
}
private void Load(bool update = true)
{
if (AppConfig.Sections["Options"] is null)
{
AppConfig.Sections.Add("Options", new Options());
}
if (update)
{
var OptionsSettingsSection = AppConfig.GetSection("Options");
DataContext = OptionsSettingsSection;
}
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
AppConfig.Save();
App.LoadSettings();
}
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
AppConfig.Sections.Remove("Options");
AppConfig.Save();
Load(false);
App.LoadSettings();
DataContext = null;
Load(true);
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void AutoSwitch_Click(object sender, RoutedEventArgs e)
{
Notif.IsEnabled = (bool)Auto.IsChecked;
NotifLabel.IsEnabled = (bool)Auto.IsChecked;
ACPlan.IsEnabled = (bool)Auto.IsChecked;
BatteryPlan.IsEnabled = (bool)Auto.IsChecked;
ACPlanLabel.IsEnabled = (bool)Auto.IsChecked;
BatteryPlanLabel.IsEnabled = (bool)Auto.IsChecked;
}
private void DefaultClick(object sender, RoutedEventArgs e)
{
Reset.IsEnabled = false;
PowerPlans.ManagePlans(false);
}
private void BatteryBoostClick(object sender, RoutedEventArgs e)
{
Boost.IsEnabled = false;
PowerPlans.ManagePlans(true);
}
private void AdvancedClick(object sender ,RoutedEventArgs e)
{
PowerPlans.Unlock();
}
}
}