-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCube.ahk
262 lines (246 loc) · 7.82 KB
/
Cube.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#Include, .\cube\settings.ahk
#NoTrayIcon
#Persistent
#SingleInstance, force
SetWorkingDir % A_ScriptDir
SetCapsLockState, AlwaysOff
Menu, Tray, NoStandard
Menu, Menu, UseErrorLevel
SplitPath, A_ScriptFullPath, CubeFileName, CubeDir, CubeExtension, CubeNameNoExt, CubeDrive
global CubeFileName, CubeDir, CubeExtension, CubeNameNoExt, CubeDrive
global CubePathIcons := A_ScriptDir . "\" . CubeNameNoExt . "\icons\"
global CubePathMenus := A_ScriptDir . "\" . CubeNameNoExt . "\menus\"
global CubePathPlugins := A_ScriptDir . "\" . CubeNameNoExt . "\plugins\"
global Cube_Bases, Cube_Ext, Cube_RE, Cube_Translations
global Cube, CubeTypes
global CubeAutoClip
global CubeIcon
global CubeIconSize := A_ScreenDPI / 6
Gosub, Label_SetAuto
Gosub, Label_CreateMenu_RE
Gosub, Label_CreateMenu_Ext
Gosub, Label_CreateMenu_Bases
Return
Label_SetAuto:
CubeAutoClip := !CubeAutoClip
CubeIcon := CubePathIcons . (CubeAutoClip?"on":"off") ".png"
Menu, Tray, Icon, % CubeIcon, , % CubeIconSize
Return
Label_CreateMenu_RE:
For REType, Regulations in Cube_RE
{
For Index, Line in IniRead(GetMenuPath("RE\" . REType))
{
Label := Func("Cube_Run").Bind(Line[2])
Menu, % REType, Add, % Line[1], % Label
Menu, % REType, Icon, % Line[1], % GetIcon(Line), , % CubeIconSize
}
}
Return
Label_CreateMenu_Ext:
For Extension, ExtensionTypes in Cube_Ext
{
For Index, Line in IniRead(GetMenuPath("Ext\" . Extension))
{
Label := Func("Cube_Run").Bind(Line[2])
Menu, % Extension, Add, % Line[1], % Label
Menu, % Extension, Icon, % Line[1], % GetIcon(Line), , % CubeIconSize
}
For Index, ExtensionType in ExtensionTypes
{
If (DllCall("GetMenuItemCount", "ptr", MenuGetHandle(ExtensionType)) < 1)
{
For Index, Line in IniRead(GetMenuPath(ExtensionType))
{
Label := Func("Cube_Run").Bind(Line[2])
Menu, % ExtensionType, Add, % Line[1], % Label
Menu, % ExtensionType, Icon, % Line[1], % GetIcon(Line), , % CubeIconSize
}
}
}
}
Return
Label_CreateMenu_Bases:
For Index, Base in Cube_Bases
{
For Index, Line in IniRead(GetMenuPath(Base))
{
Label := Func("Cube_Run").Bind(Line[2])
Menu, % Base, Add, % Line[1], % Label
If Line[1]
Menu, % Base, Icon, % Line[1], % GetIcon(Line), , % CubeIconSize
}
}
Return
IniRead(ini, section:="Cube") {
Commands := []
IniRead, SectionContents, % ini, % section
Loop, parse, SectionContents, `n, `r ; 在 `r 之前指定 `n, 这样可以同时支持对 Windows 和 Unix 文件的解析.
{
Commands.push(StrSplit(A_LoopField, "=", 1))
}
Return Commands
}
Cube_Run(IniValue, ItemName, ItemPos, MenuName) {
If GetKeyState("Ctrl", "P")
{
Run, % "Edit " GetPluginPath(IniValue)
Return
}
Else
{
For k, v in Cube_URL
{
If (k = IniValue)
{
Run, % StrReplace(v, "%s", Cube)
Return
}
}
}
SplitPath, % GetPluginPath(IniValue), OutFileName, OutDir
Run, % GetPluginPath(IniValue), % OutDir, UseErrorLevel, OutputVarPID
; If (ErrorLevel = 0)
; {
; VarSetCapacity(CubeStruct, 3*A_PtrSize, 0)
; CubeInBytes := (StrLen(Cube)+1)*(A_IsUnicode?2:1)
; NumPut(CubeInBytes, CubeStruct, A_PtrSize)
; NumPut(&Cube, CubeStruct, 2*A_PtrSize)
; static WM_COPYDATA := 0x004A
; WinWait, % "ahk_pid " OutputVarPID
; SendMessage, WM_COPYDATA, 0, &CubeStruct,, % "ahk_pid " OutputVarPID
; }
}
GetPluginPath(PluginName) {
If FileExist(CubePathPlugins . PluginName . "\" . PluginName . ".ahk")
Return """" CubePathPlugins . PluginName . "\" . PluginName . ".ahk"""
}
GetMenuPath(Type) {
Return CubePathMenus . Type . ".ini"
}
GetIcon(icon) {
If (icon = ".ico")
Return Cube
Else If FileExist(CubePathPlugins . icon[2] . "\" . icon[2] . ".ico")
Return CubePathPlugins . icon[2] . "\" . icon[2] . ".ico"
Else If FileExist(CubePathIcons . "\menus\" . icon . ".ico")
Return CubePathIcons . "\menus\" . icon . ".ico"
Else If FileExist(CubePathIcons . "\urls\" . icon[2] . ".ico")
Return CubePathIcons . "\urls\" . icon[2] . ".ico"
Else If FileExist(CubePathIcons . "\urls\" . icon[2] . ".png")
Return CubePathIcons . "\urls\" . icon[2] . ".png"
Else
{
VarSetCapacity(FileInfo, FileSize:=A_PtrSize + 688) ;为 SHFILEINFOW 结构体申请内存.
If DllCall("shell32\SHGetFileInfoW", "Wstr", Cube, "UInt", 0, "Ptr", &FileInfo, "UInt", FileSize, "UInt", 0x110)
Return % "HICON:" NumGet(FileInfo, 0, "Ptr")
}
}
CapsLock Up::
If CubeAutoClip
{
Clipboard := ""
Send, ^c
ClipWait, 0.5, 0
If Not ErrorLevel
Gosub, Label_ShowMenu
}
else
Gosub, Label_ShowMenu
Return
+CapsLock::Gosub, Label_SetAuto
^CapsLock::SetCapsLockState % !GetKeyState("CapsLock", "T")
Label_ShowMenu:
If (Cube != Trim(Clipboard, " `t`n"))
{
Cube := Trim(Clipboard, " `t`n")
GetCubeTypes()
}
Menu, Menu, Show
Return
GetCubeTypes() {
CubeTypes := []
If Not Cube
Return
Else If DllCall("IsClipboardFormatAvailable", "UInt", 15) ; file
{
CubeTypes.push("FILE")
If InStr(FileExist(Cube), "D")
{
CubeTypes.push(RegExMatch(Cube,"^.:\\$") ? "DRIVE":"FOLDER")
Return OrganizeMenu()
}
If InStr(Cube, "`n")
{
CubeTypes.push("FILES")
Return OrganizeMenu()
}
SplitPath, Cube, , , OutExtension
If OutExtension
{
For Extension, ExtensionTypes in Cube_Ext
{
If ("." OutExtension = Extension)
{
CubeTypes.push(Extension)
For Index, ExtensionType in ExtensionTypes
CubeTypes.push(ExtensionType)
Return OrganizeMenu()
}
}
}
Return OrganizeMenu()
}
Else If DllCall("IsClipboardFormatAvailable", "UInt", 1) ; text
{
CubeTypes.push("TEXT")
If InStr(Cube, "`n")
{
CubeTypes.push("TEXTS")
Return OrganizeMenu()
}
For REType, Regulations in Cube_RE
{
For Index, Regulation in Regulations
{
If RegExMatch(Cube, Regulation)
{
CubeTypes.push(REType)
Return OrganizeMenu()
}
}
}
Return OrganizeMenu()
}
}
OrganizeMenu() {
Menu, Menu, Add
Menu, Menu, DeleteAll
FirstMenuName := (StrLen(Cube) > 17)?SubStr(Cube, 1, 17) . "...":Cube
Menu, Menu, Add, % FirstMenuName, OnExit
Menu, Menu, Disable, % FirstMenuName
Menu, Menu, Icon, % FirstMenuName, % CubeIcon, , % CubeIconSize
Menu, Menu, Add
For Index, CubeType in CubeTypes
{
MenuItemName := Cube_Translations[CubeType]
MenuItemName := MenuItemName?MenuItemName:CubeType
Menu, Menu, Add, % MenuItemName, % ":" CubeType
Menu, Menu, Icon, % MenuItemName, % GetIcon(CubeType), , % CubeIconSize
If (Index != CubeTypes.Length())
Menu, Menu, Add
}
}
AHK_NOTIFYICON(wParam, lParam) {
Static WM_USER = 0x0400
Static WM_LBUTTONUP = 0x0202
Static WM_RBUTTONUP = 0x0205
Static WM_MBUTTONUP = 0x0208
Static _______ := OnMessage(WM_USER + 4, "AHK_NOTIFYICON")
If (lParam = WM_LBUTTONUP)
Run, % CubeDir
Else If (lParam = WM_RBUTTONUP)
Gosub, Label_SetAuto
Else If (lParam = WM_MBUTTONUP)
Reload
}