-
Notifications
You must be signed in to change notification settings - Fork 15
/
ui-dash.ahk
200 lines (175 loc) · 6.61 KB
/
ui-dash.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
; Dash: AutoHotkey's "main menu".
; Run the script to show the GUI.
#include inc\bounce-v1.ahk
/* v1 stops here */
#requires AutoHotkey v2.0
#NoTrayIcon
#SingleInstance Force
#include inc\ui-base.ahk
#include ui-launcherconfig.ahk
#include ui-editor.ahk
#include ui-newscript.ahk
DashRegKey := 'HKCU\Software\AutoHotkey\Dash'
class AutoHotkeyDashGui extends AutoHotkeyUxGui {
__new() {
super.__new("AutoHotkey Dash")
lv := this.AddListMenu('vLV LV0x40 w250', ["Name", "Desc"])
lv.OnEvent("Click", "ItemClicked")
lv.OnEvent("ItemFocus", "ItemFocused")
lv.OnNotify(-155, "KeyPressed")
this.AddButton("xp yp wp yp Hidden Default").OnEvent("Click", "EnterPressed")
il := IL_Create(,, true)
lv.SetImageList(il, 0)
il2 := IL_Create(,, false)
lv.SetImageList(il2, 1)
addIcon(p*) =>(IL_Add(il, p*), IL_Add(il2, p*))
lv.Add("Icon" addIcon(A_AhkPath, 2)
, "New script", "Create a script or manage templates")
lv.Add("Icon" addIcon("imageres.dll", -111)
, "Compile", "Open Ahk2Exe - convert .ahk to .exe")
lv.Add("Icon" addIcon("imageres.dll", -99)
, "Help files (F1)")
lv.Add("Icon" addIcon(A_ScriptDir '\inc\spy.ico', 1)
, "Window spy")
lv.Add("Icon" addIcon("imageres.dll", -116)
, "Launch settings", "Configure how .ahk files are opened")
lv.Add("Icon" addIcon("notepad.exe", 1)
, "Editor settings", "Set your default script editor")
; lv.Add("Icon" addIcon("mmc.exe")
; , "Maintenance", "Repair settings or add/remove versions")
; lv.Add(, "Auto-start", "Run scripts automatically at logon")
; lv.Add(, "Downloads", "Get related tools")
lv.AutoSize()
lv.GetPos(,,, &h)
if !RegRead(DashRegKey, 'SuppressIntro', false) {
this.SetFont('s12')
this.AddText('yp x+m', "Welcome!")
this.SetFont('s9')
this.AddText('xp', "This is the Dash. It provides access to tools, settings and help files.")
this.AddText('xp', "To learn how to use AutoHotkey, refer to:")
this.AddLink('xp', "
(
`s • <a href="Program.htm">Using the Program</a>
• <a href="howto/WriteHotkeys.htm">How to Write Hotkeys</a>
• <a href="howto/SendKeys.htm">How to Send Keystrokes</a>
• <a href="howto/RunPrograms.htm">How to Run Programs</a>
• <a href="howto/ManageWindows.htm">How to Manage Windows</a>
• <a href="index.htm#Quick_Reference">Quick Reference</a>
)").OnEvent('Click', 'LinkClicked')
checkBox := this.AddCheckbox('Checked', "Show this info next time")
checkBox.GetPos(,,, &hc)
checkBox.Move(, h - hc)
checkBox.OnEvent('Click', 'SetIntroPref')
}
this.Show("Hide h" (h + this.MarginY*2))
}
LinkClicked(ctrl, id, href) {
if FileExist(chm := ROOT_DIR '\v2\AutoHotkey.chm')
Run 'hh.exe "ms-its:' chm '::docs/' href '"'
else
Run 'https://www.autohotkey.com/docs/v2/' href
}
SetIntroPref(checkBox, *) {
if checkBox.Value { ; Show intro
try RegDelete(DashRegKey, 'SuppressIntro')
} else
RegWrite(true, 'REG_DWORD', DashRegKey, 'SuppressIntro')
}
KeyPressed(lv, lParam) {
switch NumGet(lParam, A_PtrSize * 3, "Short") {
case 0x70: ; F1
ShowHelpFile()
}
}
EnterPressed(*) {
lv := this["LV"]
this.ItemClicked(lv, lv.GetNext(,'F'))
}
ItemClicked(lv, item) {
switch item && RegExReplace(lv.GetText(item), ' .*') {
case "New":
NewScriptGui.Show()
case "Compile":
if WinExist("Ahk2Exe ahk_class AutoHotkeyGUI")
WinActivate
else if FileExist(ROOT_DIR '\Compiler\Ahk2Exe.exe')
Run '"' ROOT_DIR '\Compiler\Ahk2Exe.exe"'
else
Run Format('"{1}" /script "{2}\install-ahk2exe.ahk"', A_AhkPath, A_ScriptDir)
case "Help":
ShowHelpFile()
case "Window":
try {
Run '"' A_MyDocuments '\AutoHotkey\WindowSpy.ahk"'
return
}
static AHK_FILE_WINDOWSPY := 0xFF7A ; 65402
static WM_COMMAND := 0x111 ; 273
SendMessage WM_COMMAND, AHK_FILE_WINDOWSPY, 0, A_ScriptHwnd
if WinWait("Window Spy ahk_class AutoHotkeyGUI",, 1)
WinActivate
case "Launch":
LauncherConfigGui.Show()
case "Editor":
DefaultEditorGui.Show()
}
}
ItemFocused(lv, item) {
static WM_CHANGEUISTATE := 0x127 ; 295
SendMessage WM_CHANGEUISTATE, 0x10001, 0, lv
}
}
ShowHelpFile() {
SetWorkingDir ROOT_DIR
main := Map(), sub := Map()
other := Map(), other.CaseSense := "off"
hashes := ReadHashes('UX\installed-files.csv', item => item.Path ~= 'i)\.chm$')
Loop Files "*.chm", "FR" {
SplitPath A_LoopFilePath,, &dir,, &name
if name = "AutoHotkey" {
if !(f := hashes.Get(A_LoopFilePath, false))
continue
v := GetMajor(f.Version)
if !(cur := main.Get(v, false)) || VerCompare(cur.Version, f.Version) < 0
main[v] := f
sub[f.Version] := f
}
else
other[A_LoopFilePath] := name (dir != "" && name != dir ? " (" dir ")" : "")
}
if sub.Count = 1 && other.Count = 0 {
for , f in main { ; Don't bother showing online options in this case.
Run f.Path
return
}
}
m := Menu()
if main.Count {
m.Add "Offline help", (*) => 0
m.Disable "1&"
}
for , f in main {
m.Add "v&" f.Version, openIt.Bind(f.Path)
sub.Delete(f.Version)
}
if sub.Count {
subm := Menu()
for , f in sub
subm.Insert "1&", "v" f.Version, openIt.Bind(f.Path)
m.Add "More", subm
}
m.Add "Online help", (*) => 0
m.Disable "Online help"
prefix := main.Count ? "v" : "v&"
m.Add prefix "1.1", (*) => Run("https://www.autohotkey.com/docs/v1/")
m.Add prefix "2.0", (*) => Run("https://www.autohotkey.com/docs/v2/")
if other.Count {
m.Add "Other files", (*) => 0
m.Disable "Other files"
}
for f, t in other
m.Add t, openIt.Bind(f)
m.Show
openIt(f, *) => Run(f)
}
AutoHotkeyDashGui.Show()