-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE_Shortcuts.ahk
112 lines (104 loc) · 3.79 KB
/
E_Shortcuts.ahk
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
/*
* Copyright (C) 2023 NeonOrbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
IsWinKeyId(id) => InStr(id, "_wk")
IsHotKeyId(id) => InStr(id, "_hk")
ToWinKeyId(id) => StrReplace(id, "_hk") . "_wk"
ToHotKeyId(id) => StrReplace(id, "_wk") . "_hk"
HKGUI_ENTRIES := APP_HOTKEY_IDS
class Shortcuts {
controls := Map()
eventHandler := this.handleEvents.bind(this)
; Callback receives a map containing new hotkeys
__new(callback) {
this.controls.clear()
this.callback := BypassThisRef.bind(callback)
this.mainGui := Gui("+AlwaysOnTop")
for id in HKGUI_ENTRIES {
idWinKey := ToWinKeyId(id)
idHotKey := ToHotKeyId(id)
this.mainGui.add("Text", "xm w100", APP_DEFAULT_HOTKEY_FUNCTIONS[id] . ": ")
this.controls[idWinKey] := this.mainGui.add("CheckBox", "yp h20 Center v" . idWinKey, "Win +")
this.controls[idHotKey] := this.mainGui.add("Hotkey", "yp h20 v" . idHotKey)
this.controls[idWinKey].onEvent("Click", this.eventHandler)
}
this.mainGui.add("Button", "x20 vDefault", "Default").onEvent("Click", this.eventHandler)
this.mainGui.add("Button", "yp vSave", "Save Shortcuts").onEvent("Click", this.eventHandler)
this.mainGui.add("Button", "yp vCancel", "Cancel").onEvent("Click", this.eventHandler)
}
handleEvents(gc, *)
{
switch gc.name {
case "Default":
this.update(APP_DEFAULT_HOTKEYS)
case "Save":
this.onSave()
case "Cancel":
this.mainGui.destroy()
default:
if (this.controls.has(gc.name) and IsWinKeyId(gc.name)) {
cWinKey := this.controls[gc.name]
cHotKey := this.controls[ToHotKeyId(gc.name)]
cHotKey.opt(cWinKey.value ? "-Limit" : "Limit1")
if (!cWinKey.value) {
cHotKey.value := ""
}
}
}
}
show(values) {
this.update(values)
this.mainGui.show()
}
update(values) {
for key, value in values {
limit := ""
if InStr(value, "#") {
limit := "-Limit"
this.controls[ToWinKeyId(key)].value := true
value := StrReplace(value, "#")
} else {
limit := "Limit1"
}
cHotKey := this.controls[ToHotKeyId(key)]
cHotKey.value := value
cHotKey.opt(limit)
}
}
onSave() {
dup := ExSet()
hotkeys := Map()
this.mainGui.opt("+OwnDialogs")
for key in HKGUI_ENTRIES {
cHotKey := this.controls[ToHotKeyId(key)]
if (cHotKey.value) {
result := this.controls[ToWinKeyId(key)].value ? "#" : ""
result .= cHotKey.value
} else {
result := APP_DEFAULT_HOTKEYS[key]
}
if (dup.has(result)) {
this.update(APP_DEFAULT_HOTKEYS)
MsgBox("Failed: duplicate shortcuts!",, 0x30)
return
}
dup.add(result)
hotkeys[key] := result
}
this.update(hotkeys)
this.callback(hotkeys)
MsgBox("Saved Successfully")
}
}