generated from Nigh/ahk-autoupdate-template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ahko_setup_gui.ahk
237 lines (218 loc) · 6.75 KB
/
ahko_setup_gui.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
h2FontStyle:="s18 w600 c505050 q5"
textFontStyle:="s12 w400 cblack q5"
clientWidth:=360
header_gap:=" y+10 "
item_gap:=" y+3 "
ahko_setup := Gui("+ToolWindow +AlwaysOnTop -DPIScale +OwnDialogs","ahko setup")
ahko_setup.SetFont(, "Consolas")
ahko_setup.SetFont(, "MV Boli")
ahko_setup.SetFont(, "Comic Sans MS")
ahko_setup.SetFont("s32 w700 cc07070")
ahko_setup.Add("Text", "x25 y5", "Setup")
ahko_setup.Add("Text", "x0 y+-66 +BackgroundTrans", "________")
ahko_setup.SetFont(h2FontStyle)
ahko_setup.Add("Text","x30 y+20 section", "UI type")
ahko_setup.SetFont(textFontStyle)
ahkoSetup_uiType:=ahko_setup.Add("DropDownList", item_gap "w" clientWidth, ["Native Gridview","GDIp Gridview","WebView"])
ahkoSetup_uiType.OnEvent("Change", uiType_update)
uiType_update(*) {
if(ahkoSetup_uiType.Value>2) {
MsgBox("This ui type is still under development","OK","Owner" ahko_setup.Hwnd)
ahkoSetup_uiType.Value := 1
}
}
ahko_setup.SetFont(h2FontStyle)
ahko_setup.Add("Text", "xs " header_gap, "Watch folder")
ahko_setup.SetFont(textFontStyle)
buttonWidth:=95
AhkoSetup_path:=ahko_setup.Add("Edit", item_gap "r1 w" clientWidth-buttonWidth-5, "")
pathSelectBtn := ahko_setup.Add("Button", "x+5 hp w" buttonWidth, "Select")
pathSelectBtn.OnEvent("Click", setup_path)
setup_path(*){
global AhkoSetup_path,ahko_setup
ahko_setup.Opt("+OwnDialogs")
newpath:=RegExReplace(DirSelect(,0), "\\$")
ahkoSetup_path.Value:=newpath
}
ahko_setup.SetFont(h2FontStyle)
ahko_setup.Add("Text", "xs " header_gap, "Hotkey")
ahko_setup.SetFont(textFontStyle)
ahkoSetup_hotkey:=ahko_setup.Add("Hotkey", item_gap "w" clientWidth-buttonWidth-5)
ahkoSetup_hotkey.OnEvent("Change", hotkeyText_update)
ahkoSetup_hotkeyWin:=ahko_setup.Add("CheckBox", "x+10 hp w" buttonWidth, "Win")
ahkoSetup_hotkeyWin.OnEvent("Click", hotkeyText_update)
ahko_setup.SetFont("s10")
ahko_setup.Add("Text", "xs" item_gap, "Hotkey is ")
ahkoSetup_hotkeyText:=ahko_setup.Add("Text", "x+0 hp cc07070 w260", "")
ahko_setup.SetFont(h2FontStyle)
ahko_setup.Add("Text", "xs " header_gap, "ahko where")
ahko_setup.SetFont(textFontStyle)
showAtDDL:=["Primary monitor","Follow mouse","Follow active window"]
For k, v in isFullScreen.monitors
{
showAtDDL.Push("Monitor #" k)
}
ahkoSetup_showAt:=ahko_setup.Add("DropDownList", item_gap "w" clientWidth, showAtDDL)
ahkoSetup_showAt.OnEvent("Change", showAt_update)
showat_from_ddl(dd) {
if(dd>=4) {
return dd-3
} else if(dd>=1) {
if(dd == 1) {
return 0
}
if(dd == 2) {
return 10
}
if(dd == 3) {
return 11
}
}
return 1
}
ddl_from_showat(sw) {
if(sw==0) {
return 1
}
if(sw==10) {
return 2
}
if(sw==11){
return 3
}
if(sw>=1 && sw<=9){
return sw+3
}
return 1
}
showAt_update(*) {
global showat
; MsgBox(ahkoSetup_showAt.Value)
if(ahkoSetup_showAt.Value>=4) {
showat:=showat_from_ddl(ahkoSetup_showAt.Value)
ahko_setup.Show(showat_monitor(showat))
} else {
showat:=showat_from_ddl(ahkoSetup_showAt.Value)
}
showat_monitor(n){
global isFullScreen, ahko_setup
ahko_setup.GetClientPos(,,&w,&h)
Return "x" Round(isFullScreen.monitors[n].l+isFullScreen.monitors[n].r-w)//2 " y" Round(isFullScreen.monitors[n].t+isFullScreen.monitors[n].b-h)//2
}
}
ahko_setup.SetFont(h2FontStyle)
ahko_setup.Add("Text", "xs " header_gap, "Other")
ahko_setup.SetFont(textFontStyle)
ahkoSetup_enable_fullscreen:=ahko_setup.Add("CheckBox", "y+-5 hp", "Enable in fullscreen")
ahkoSetup_enable_fullscreen.OnEvent("Click", enable_fullscreen_update)
ahkoSetup_autoStart:=ahko_setup.Add("CheckBox", "y+-10 hp", "Startup with Windows")
ahkoSetup_autoStart.OnEvent("Click", autoStartup_update)
ahko_setup.SetFont(textFontStyle)
saveBtn := ahko_setup.Add("Button", "xs y+30 h50 w" (clientWidth-40)//2, "Save")
saveBtn.OnEvent("Click", ahko_setup_save)
cancelBtn := ahko_setup.Add("Button", "x+40 hp w" (clientWidth-40)//2, "Cancel")
cancelBtn.OnEvent("Click", ahko_setup_cancel)
ahko_setup.Add("Link", "xs y+0 w" clientWidth " right", 'Visit <a href="https://github.com/Nigh/ahko">GitHub Page</a>')
hotkeyText_update(*) {
global
local hotkey_str:=""
if(ahkoSetup_hotkeyWin.Value) {
hotkey_str.="Win + "
}
if(InStr(ahkoSetup_hotkey.Value,"^")) {
hotkey_str.="Ctrl + "
}
if(InStr(ahkoSetup_hotkey.Value,"!")) {
hotkey_str.="Alt + "
}
if(InStr(ahkoSetup_hotkey.Value,"+")) {
hotkey_str.="Shift + "
}
hotkey_str.=RegExReplace(ahkoSetup_hotkey.Value, "#|\^|\!|\+|\<|\>")
ahkoSetup_hotkeyText.Value:=hotkey_str
}
ahko_setup_show(*) {
global
ahkoSetup_uiType.Value:=uiType
ahkoSetup_showAt.Value:=ddl_from_showat(showat)
ahkoSetup_path.Value:=path
ahkoSetup_hotkey.Value:=RegExReplace(hotkeys, "#")
ahkoSetup_hotkeyWin.Value:=RegExMatch(hotkeys, "#")
hotkeyText_update()
local autostart:=RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run","ahko","")
ahkoSetup_enable_fullscreen.Value:=fullscreen_enable
if(autostart!="") {
ahkoSetup_autoStart.Value:=1
} else {
ahkoSetup_autoStart.Value:=0
}
ahko_setup.show("w" clientWidth+60)
}
ahko_setup_cancel(*) {
global
ahko_setup.Hide()
}
; TODO: 未改动设置时无需重启
ahko_setup_save(*) {
global
if(ahko_setup_check())
{
hotkeyStr:=""
if(ahkoSetup_hotkeyWin.Value){
hotkeyStr:="#"
}
hotkeyStr.=ahkoSetup_hotkey.Value
IniWrite("path=" ahkoSetup_path.Value, "setting.ini", "dir")
IniWrite("key=" hotkeyStr, "setting.ini", "hotkey")
IniWrite("fullscreen=" fullscreen_enable, "setting.ini", "hotkey")
IniWrite("type=" ahkoSetup_uiType.Value, "setting.ini", "ui")
IniWrite("showat=" showat, "setting.ini", "settings")
MsgBox("In order for the changes to take effect`nahko is is about to be restarted","OK","Owner" ahko_setup.Hwnd)
Reload
}
}
ahko_setup_check(*) {
global
; MsgBox(ahkoSetup_hotkey.Value,,"Owner" ahko_setup.Hwnd)
if(ahkoSetup_uiType.Value<1 || ahkoSetup_uiType.Value>3) {
MsgBox("Invalid UI type","Error","Owner" ahko_setup.Hwnd)
Return False
}
if(!DirExist(ahkoSetup_path.Value)) {
MsgBox("Invalid watch folder","Error","Owner" ahko_setup.Hwnd)
Return False
}
if(RegExReplace(ahkoSetup_hotkey.Value, "#|\^|\!|\+|\<|\>")="") {
MsgBox("Invalid hotkey","Error","Owner" ahko_setup.Hwnd)
Return False
}
Return true
}
ahko_setup_autostart(b){
global
;@Ahk2Exe-IgnoreBegin
MsgBox("Only compiled script could be set auto start !","Error","Owner" ahko_setup.Hwnd)
Return
;@Ahk2Exe-IgnoreEnd
DirCreate(A_Temp "\ahko_temp")
FileInstall(".\set_auto_run\startup.exe", A_Temp "\ahko_temp\startup.exe",1)
if(b) {
runwait(A_Temp "\ahko_temp\startup.exe --name=ahko --target=" A_ScriptFullPath)
} else {
runwait(A_Temp "\ahko_temp\startup.exe --name=ahko --remove")
}
try {
FileDelete(A_Temp "\ahko_temp\startup.exe")
}
}
autoStartup_update(*)
{
global
ahko_setup_autostart(ahkoSetup_autoStart.Value)
}
enable_fullscreen_update(*)
{
global
fullscreen_enable:=ahkoSetup_enable_fullscreen.Value
}
; ahko_setup_show()