-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathGUI.ahk
More file actions
212 lines (187 loc) · 6.84 KB
/
GUI.ahk
File metadata and controls
212 lines (187 loc) · 6.84 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
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
; Created by Asger Juul Brunshøj
; Note: Save with encoding UTF-8 with BOM if possible.
; I had issues with special characters like in ¯\_(ツ)_/¯ that wouldn't work otherwise.
; Notepad will save UTF-8 files with BOM automatically (even though it does not say so).
; Some editors however save without BOM, and then special characters look messed up in the AHK GUI.
;-------------------------------------------------------------------------------
; AUTO EXECUTE
;-------------------------------------------------------------------------------
gui_autoexecute:
; Tomorrow Night Color Definitions:
cBackground := "c" . "1d1f21"
cCurrentLine := "c" . "282a2e"
cSelection := "c" . "373b41"
cForeground := "c" . "c5c8c6"
cComment := "c" . "969896"
cRed := "c" . "cc6666"
cOrange := "c" . "de935f"
cYellow := "c" . "f0c674"
cGreen := "c" . "b5bd68"
cAqua := "c" . "8abeb7"
cBlue := "c" . "81a2be"
cPurple := "c" . "b294bb"
gui_control_options := "xm w220 " . cForeground . " -E0x200"
; -E0x200 removes border around Edit controls
; Initialize variable to keep track of the state of the GUI
gui_state = closed
; Initialize search_urls as a variable set to zero
search_urls := 0
return
;-------------------------------------------------------------------------------
; LAUNCH GUI
;-------------------------------------------------------------------------------
CapsLock & Space::
gui_spawn:
if gui_state != closed
{
; If the GUI is already open, close it.
gui_destroy()
return
}
gui_state = main
Gui, Margin, 16, 16
Gui, Color, 1d1f21, 282a2e
Gui, +AlwaysOnTop -SysMenu +ToolWindow -caption +Border
Gui, Font, s11, Segoe UI
Gui, Add, Text, %gui_control_options% vgui_main_title, ¯\_(ツ)_/¯
Gui, Font, s10, Segoe UI
Gui, Add, Edit, %gui_control_options% vPedersen gFindus
Gui, Show,, myGUI
return
;-------------------------------------------------------------------------------
; GUI FUNCTIONS AND SUBROUTINES
;-------------------------------------------------------------------------------
; Automatically triggered on Escape key:
GuiEscape:
gui_destroy()
return
; The callback function when the text changes in the input field.
Findus:
Gui, Submit, NoHide
#Include %A_ScriptDir%\GUI\UserCommands.ahk
return
;
; gui_destroy: Destroy the GUI after use.
;
#WinActivateForce
gui_destroy() {
global gui_state
global gui_search_title
gui_state = closed
; Forget search title variable so the next search does not re-use it
; in case the next search does not set its own:
gui_search_title =
; Clear the tooltip
Gosub, gui_tooltip_clear
; Hide GUI
Gui, Destroy
; Bring focus back to another window found on the desktop
WinActivate
}
gui_change_title(message,color = "") {
; If parameter color is omitted, the message is assumed to be an error
; message, and given the color red.
If color =
{
global cRed
color := cRed
}
GuiControl,, gui_main_title, %message%
Gui, Font, s11 %color%
GuiControl, Font, gui_main_title
Gui, Font, s10 cffffff ; reset
}
;-------------------------------------------------------------------------------
; SEARCH ENGINES
;-------------------------------------------------------------------------------
;
; gui_search_add_elements: Add GUI controls to allow typing of a search query.
;
gui_search_add_elements:
Gui, Add, Text, %gui_control_options% %cYellow%, %gui_search_title%
Gui, Add, Edit, %gui_control_options% %cYellow% vgui_SearchEdit -WantReturn
Gui, Add, Button, x-10 y-10 w1 h1 +default ggui_SearchEnter ; hidden button
GuiControl, Disable, Pedersen
Gui, Show, AutoSize
return
gui_search(url) {
global
if gui_state != search
{
gui_state = search
; if gui_state is "main", then we are coming from the main window and
; GUI elements for the search field have not yet been added.
Gosub, gui_search_add_elements
}
; Assign the url to a variable.
; The variables will have names search_url1, search_url2, ...
search_urls := search_urls + 1
search_url%search_urls% := url
}
gui_SearchEnter:
Gui, Submit
gui_destroy()
query_safe := uriEncode(gui_SearchEdit)
Loop, %search_urls%
{
StringReplace, search_final_url, search_url%A_Index%, REPLACEME, %query_safe%
run %search_final_url%
}
search_urls := 0
return
;-------------------------------------------------------------------------------
; TOOLTIP
; The tooltip shows all defined commands, along with a description of what
; each command does. It gets the description from the comments in UserCommands.ahk.
; The code was improved and fixed for Windows 10 with the help of schmimae.
;-------------------------------------------------------------------------------
gui_tooltip_clear:
ToolTip
return
gui_commandlibrary:
; hidden GUI used to pass font options to tooltip:
CoordMode, Tooltip, Screen ; To make sure the tooltip coordinates is displayed according to the screen and not active window
Gui, 2:Font,s10, Lucida Console
Gui, 2:Add, Text, HwndhwndStatic
tooltiptext =
maxpadding = 0
StringCaseSense, Off ; Matching to both if/If in the IfInString command below
Loop, read, %A_ScriptDir%/GUI/UserCommands.ahk
{
; search for the string If Pedersen =, but search for each word individually because spacing between words might not be consistent. (might be improved with regex)
If Substr(A_LoopReadLine, 1, 1) != ";" ; Do not display commented commands
{
If A_LoopReadLine contains if
{
IfInString, A_LoopReadLine, Pedersen
IfInString, A_LoopReadLine, =
{
StringGetPos, setpos, A_LoopReadLine,=
StringTrimLeft, trimmed, A_LoopReadLine, setpos+1 ; trim everything that comes before the = sign
StringReplace, trimmed, trimmed, `%A_Space`%,{space}, All
tooltiptext .= trimmed
tooltiptext .= "`n"
; The following is used to correct padding:
StringGetPos, commentpos, trimmed,`;
if (maxpadding < commentpos)
maxpadding := commentpos
}
}
}
}
tooltiptextpadded =
Loop, Parse, tooltiptext,`n
{
line = %A_LoopField%
StringGetPos, commentpos, line, `;
spaces_to_insert := maxpadding - commentpos
Loop, %spaces_to_insert%
{
StringReplace, line, line,`;,%A_Space%`;
}
tooltiptextpadded .= line
tooltiptextpadded .= "`n"
}
Sort, tooltiptextpadded
ToolTip %tooltiptextpadded%, 3, 3, 1
return