-
Notifications
You must be signed in to change notification settings - Fork 31
/
SettingsForm.cs
140 lines (136 loc) · 4.83 KB
/
SettingsForm.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClickPaste
{
public partial class SettingsForm : Form
{
RadioButton[] _methods;
CheckBox[] _modifiers;
RadioButton[] _hotKeyModes;
public SettingsForm()
{
InitializeComponent();
_methods = new RadioButton[2];
_methods[0] = Method_Forms;
_methods[1] = Method_AutoIt;
_modifiers = new CheckBox[4];
_modifiers[0] = HotKey_Alt;
_modifiers[1] = HotKey_Control;
_modifiers[2] = HotKey_Shift;
_modifiers[3] = HotKey_Windows;
_hotKeyModes = new RadioButton[2];
_hotKeyModes[0] = hotKeyModeTarget;
_hotKeyModes[1] = hotKeyModeType;
foreach(var method in _methods)
{
method.Checked = (Properties.Settings.Default.TypeMethod == int.Parse(method.Tag.ToString()));
}
DelayMS.Text = Properties.Settings.Default.KeyDelayMS.ToString();
startDelayMS.Text = Properties.Settings.Default.StartDelayMS.ToString();
confirmOverActive.Checked = Properties.Settings.Default.Confirm;
confirmOver.Text = Properties.Settings.Default.ConfirmOver.ToString();
SetConfirmControls();
HotKey_Letter.Text = Properties.Settings.Default.HotKey;
foreach(var mod in _modifiers)
{
mod.Checked = (0 != (Properties.Settings.Default.HotKeyModifier & int.Parse(mod.Tag.ToString())));
}
foreach(var mode in _hotKeyModes)
{
mode.Checked = (Properties.Settings.Default.HotKeyMode == int.Parse(mode.Tag.ToString()));
}
}
private void HotKey_Letter_KeyDown(object sender, KeyEventArgs e)
{
switch(e.KeyCode)
{
case Keys.Alt:
case Keys.Menu:
case Keys.LMenu:
case Keys.RMenu:
case Keys.Shift:
case Keys.ShiftKey:
case Keys.LShiftKey:
case Keys.RShiftKey:
case Keys.Control:
case Keys.ControlKey:
case Keys.LControlKey:
case Keys.RControlKey:
case Keys.LWin:
case Keys.RWin:
case Keys.Return:
break;
case Keys.Delete:
case Keys.Back:
HotKey_Letter.Text = string.Empty;
break;
default:
HotKey_Letter.Text = e.KeyCode.ToString();
break;
}
e.SuppressKeyPress = true;
}
private void Done_Click(object sender, EventArgs e)
{
foreach(var method in _methods)
{
if (method.Checked)
{
Properties.Settings.Default.TypeMethod = int.Parse(method.Tag.ToString()); ;
}
}
int delay;
if (int.TryParse(DelayMS.Text, out delay))
{
Properties.Settings.Default.KeyDelayMS = delay;
}
int startDelay;
if (int.TryParse(startDelayMS.Text, out startDelay))
{
Properties.Settings.Default.StartDelayMS = startDelay;
}
Properties.Settings.Default.Confirm = confirmOverActive.Checked;
int co;
if (int.TryParse(confirmOver.Text, out co))
{
Properties.Settings.Default.ConfirmOver = co;
}
var letter = HotKey_Letter.Text;
if (letter.Length == 1) letter = letter.ToUpperInvariant(); // can't find 'v' but knows 'V'
Properties.Settings.Default.HotKey = letter;
int mods = 0;
foreach (var mod in _modifiers)
{
if (mod.Checked)
{
mods |= int.Parse(mod.Tag.ToString());
}
Properties.Settings.Default.HotKeyModifier = mods;
}
foreach(var mode in _hotKeyModes)
{
if (mode.Checked)
{
Properties.Settings.Default.HotKeyMode = int.Parse(mode.Tag.ToString()); ;
}
}
Properties.Settings.Default.Save();
}
private void SetConfirmControls()
{
confirmOver.Enabled = confirmOverActive.Checked;
}
private void confirmOverActive_CheckedChanged(object sender, EventArgs e)
{
SetConfirmControls();
}
}
}