-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsWindow.xaml.cs
More file actions
176 lines (155 loc) · 5.99 KB
/
Copy pathSettingsWindow.xaml.cs
File metadata and controls
176 lines (155 loc) · 5.99 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
namespace CopyAlert
{
public partial class SettingsWindow : Window
{
private AppSettings _settings = AppSettings.Load();
private MainWindow _mainWindow;
public SettingsWindow(MainWindow mainWindow)
{
InitializeComponent();
_mainWindow = mainWindow;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_settings = AppSettings.Load();
SelectComboBoxItem(LocationTypeCombo, _settings.Location);
SelectComboBoxItem(NotificationStyleCombo, _settings.Style);
SelectComboBoxItem(AnimationModeCombo, _settings.Animation);
CustomXBox.Text = _settings.CustomX.ToString();
CustomYBox.Text = _settings.CustomY.ToString();
ShowDetailedInfoCheck.IsChecked = _settings.ShowDetailedClipboardInfo;
AutoStartCheck.IsChecked = _settings.AutoStart;
}
private void SelectComboBoxItem(System.Windows.Controls.ComboBox comboBox, Enum enumValue)
{
foreach (System.Windows.Controls.ComboBoxItem item in comboBox.Items)
{
if (item != null && item.Tag != null && item.Tag.ToString() == enumValue.ToString())
{
comboBox.SelectedItem = item;
break;
}
}
}
private void LocationTypeCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LocationTypeCombo.SelectedItem is ComboBoxItem item && item.Tag != null)
{
string? tag = item.Tag.ToString();
if (CustomCoordinatesPanel != null)
{
if (tag == "Custom")
{
CustomCoordinatesPanel.Visibility = Visibility.Visible;
}
else
{
CustomCoordinatesPanel.Visibility = Visibility.Collapsed;
}
}
}
}
private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
if (LocationTypeCombo.SelectedItem is System.Windows.Controls.ComboBoxItem item && item.Tag != null)
{
if (Enum.TryParse(item.Tag.ToString(), out LocationType loc))
{
_settings.Location = loc;
}
}
if (NotificationStyleCombo.SelectedItem is System.Windows.Controls.ComboBoxItem styleItem && styleItem.Tag != null)
{
if (Enum.TryParse(styleItem.Tag.ToString(), out NotificationStyle style))
{
_settings.Style = style;
}
}
if (AnimationModeCombo.SelectedItem is System.Windows.Controls.ComboBoxItem animationItem && animationItem.Tag != null)
{
if (Enum.TryParse(animationItem.Tag.ToString(), out PopupAnimationMode animationMode))
{
_settings.Animation = animationMode;
}
}
if (double.TryParse(CustomXBox.Text, out double x)) _settings.CustomX = x;
if (double.TryParse(CustomYBox.Text, out double y)) _settings.CustomY = y;
_settings.ShowDetailedClipboardInfo = ShowDetailedInfoCheck.IsChecked ?? true;
_settings.AutoStart = AutoStartCheck.IsChecked ?? false;
_settings.Save();
// apply auto start to registry
ApplyAutoStart(_settings.AutoStart);
// apply live
_mainWindow.ApplySettings();
this.Close();
}
private void DragPositionBtn_Click(object sender, RoutedEventArgs e)
{
_mainWindow.EnterDragMode(this);
this.Hide();
}
private void GitHubLogo_Click(object sender, RoutedEventArgs e)
{
OpenGitHubProfile();
}
private void GitHubUsername_Click(object sender, RoutedEventArgs e)
{
OpenGitHubProfile();
}
private void OpenGitHubProfile()
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = "https://github.com/kalpit118",
UseShellExecute = true
});
}
catch (Exception ex)
{
System.Windows.MessageBox.Show("Failed to open GitHub profile: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
public void OnDragModeComplete(double x, double y)
{
SelectComboBoxItem(LocationTypeCombo, LocationType.Custom);
CustomXBox.Text = ((int)x).ToString();
CustomYBox.Text = ((int)y).ToString();
this.Show();
this.Activate();
}
private void ApplyAutoStart(bool enable)
{
try
{
using RegistryKey? key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
if (key != null)
{
string appName = "CopyAlert";
if (enable)
{
string? path = Environment.ProcessPath;
if (!string.IsNullOrEmpty(path))
{
key.SetValue(appName, $"\"{path}\"");
}
}
else
{
key.DeleteValue(appName, false);
}
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show("Failed to update startup settings: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}