-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudio.ahk
362 lines (362 loc) · 10.4 KB
/
Studio.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
global settings
Studio(ico:=0){
global x
if(ico)
Menu,Tray,Icon
Try
x:=ComObjActive("AHK-Studio")
Catch m
x:=ComObjActive("{DBD5A90A-A85C-11E4-B0C7-43449580656B}")
return x,x.autoclose(A_ScriptHwnd)
}
class GUIKeep{
static table:=[],showlist:=[]
__New(win,parent:=""){
#NoTrayIcon
Try
x:=ComObjActive("AHK-Studio")
Catch m
x:=ComObjActive("{DBD5A90A-A85C-11E4-B0C7-43449580656B}")
path:=x.path(),info:=x.style(),settings:=x.get("settings")
owner:=WinExist("ahk_id" parent)?parent:x.hwnd(1)
DetectHiddenWindows,On
if(FileExist(path "\AHKStudio.ico"))
Menu,Tray,Icon,%path%\AHKStudio.ico
Gui,%win%:Destroy
Gui,%win%:+owner%owner% +hwndhwnd -DPIScale
Gui,%win%:+ToolWindow
if(settings.ssn("//options/@Add_Margins_To_Windows").text!=1)
Gui,%win%:Margin,0,0
Gui,%win%:Font,% "c" info.color " s" info.size,% info.font
Gui,%win%:Color,% info.Background,% info.Background
this.x:=studio,this.gui:=[],this.sc:=[],this.hwnd:=hwnd,this.con:=[],this.ahkid:=this.id:="ahk_id" hwnd,this.win:=win,this.Table[win]:=this,this.var:=[]
for a,b in {border:A_OSVersion~="^10"?3:0,caption:DllCall("GetSystemMetrics",int,4,"int")}
this[a]:=b
Gui,%win%:+LabelGUIKeep.
Gui,%win%:Default
}
DropFiles(filelist,ctrl,x,y){
df:="DropFiles"
if(IsFunc(df))
%df%(filelist,ctrl,x,y)
}
Add(info*){
static
if(!info.1){
var:=[]
Gui,% this.win ":Submit",Nohide
for a in this.var
var[a]:=%a%
return var
}
for a,b in info{
i:=StrSplit(b,","),newpos:=""
if(i.1="s"){
for a,b in StrSplit("xywh")
RegExMatch(i.2,"i)\b" b "(\S*)\b",found),newpos.=found1!=""?b found1 " ":""
sc:=new sciclass(this.win,{pos:Trim(newpos)}),this.sc.push(sc)
hwnd:=sc.sc
}else{
Gui,% this.win ":Add",% i.1,% i.2 " hwndhwnd",% i.3
if(RegExMatch(i.2,"U)\bv(.*)\b",var))
this.var[var1]:=1
}
this.con[hwnd]:=[]
if(i.4!="")
this.con[hwnd,"pos"]:=i.4,this.resize:=1
}
}ContextMenu(a,b,c,d){
if(IsFunc(Function:=A_Gui "GuiContextMenu"))
%Function%(a,b)
}
Escape(){
this:=GUIKeep.table[A_Gui]
KeyWait,Escape,U
if(IsFunc(func:=A_Gui "Escape"))
return %func%()
else if(IsLabel(label:=A_Gui "Escape"))
SetTimer,%label%,-1
else
this.savepos(),this.exit()
}
savepos(){
if(!top:=settings.ssn("//gui/position[@window='" this.win "']"))
top:=settings.add("gui/position",,,1),top.SetAttribute("window",this.win)
top.text:=this.winpos().text
}
Exit(){
global x
this.savepos(),x.activate()
ExitApp
}
Close(a:=""){
this:=GUIKeep.table[A_Gui]
if(IsFunc(func:=A_Gui "Close"))
return %func%()
else if(IsLabel(label:=A_Gui "Close"))
SetTimer,%label%,-1
else
this.savepos(),this.exit()
}
Size(){
this:=GUIKeep.table[A_Gui],pos:=this.winpos()
for a,b in this.gui
for c,d in b
GuiControl,% this.win ":MoveDraw",%a%,% c (c~="y|h"?pos.h:pos.w)+d
}
Show(name){
this.getpos(),pos:=this.resize=1?"":"AutoSize",this.name:=name
if(this.resize=1)
Gui,% this.win ":+Resize"
GUIKeep.showlist.push(this)
SetTimer,guikeepshow,-100
return
GUIKeepShow:
while,this:=GUIKeep.Showlist.pop(){
Gui,% this.win ":Show",% settings.ssn("//gui/position[@window='" this.win "']").text " " pos,% this.name
this.size()
if(this.resize!=1)
Gui,% this.win ":Show",AutoSize
WinActivate,% this.id
}
return
}
__Get(){
return this.add()
}
GetPos(){
Gui,% this.win ":Show",AutoSize Hide
WinGet,cl,ControlListHWND,% this.ahkid
pos:=this.winpos(),ww:=pos.w,wh:=pos.h,flip:={x:"ww",y:"wh"}
for index,hwnd in StrSplit(cl,"`n"){
obj:=this.gui[hwnd]:=[]
ControlGetPos,x,y,w,h,,ahk_id%hwnd%
for c,d in StrSplit(this.con[hwnd].pos)
d~="w|h"?(obj[d]:=%d%-w%d%):d~="x|y"?(obj[d]:=%d%-(d="y"?wh+this.Caption+this.Border:ww+this.Border))
}
Gui,% this.win ":+MinSize"
}
WinPos(){
VarSetCapacity(rect,16),DllCall("GetClientRect",ptr,this.hwnd,ptr,&rect)
WinGetPos,x,y,,,% this.ahkid
w:=NumGet(rect,8,"int"),h:=NumGet(rect,12,"int"),text:=(x!=""&&y!=""&&w!=""&&h!="")?"x" x " y" y " w" w " h" h:""
return {x:x,y:y,w:w,h:h,text:text}
}
}
Exit(){
ExitApp
}
m(x*){
static list:={btn:{oc:1,ari:2,ync:3,yn:4,rc:5,ctc:6},ico:{"x":16,"?":32,"!":48,"i":64}}
list.title:="AHK Studio",list.def:=0,list.time:=0,value:=0
for a,b in x
obj:=StrSplit(b,":"),(vv:=List[obj.1,obj.2])?(value+=vv):(list[obj.1]!="")?(List[obj.1]:=obj.2):txt.=b "`n"
MsgBox,% (value+262144+(list.def?(list.def-1)*256:0)),% list.title,%txt%,% list.time
for a,b in {OK:value?"OK":"",Yes:"YES",No:"NO",Cancel:"CANCEL",Retry:"RETRY"}
IfMsgBox,%a%
return b
}
t(x*){
for a,b in x
msg.=b "`n"
Tooltip,%msg%
}
Class sciclass{
static ctrl:=[],main:=[],temp:=[]
__New(window,info){
Try
x:=ComObjActive("AHK-Studio")
Catch m
x:=ComObjActive("{DBD5A90A-A85C-11E4-B0C7-43449580656B}")
static int,count:=1
if !init
DllCall("LoadLibrary","str",x.path() "\scilexer.dll"),init:=1
win:=window?window:1,pos:=info.pos?info.pos:"x0 y0"
if info.hide
pos.=" Hide"
notify:=info.label?info.label:"notify"
Gui,%win%:Add,custom,classScintilla hwndsc w500 h400 %pos% +1387331584 g%notify%
this.sc:=sc,t:=[],s.ctrl[sc]:=this
for a,b in {fn:2184,ptr:2185}
this[a]:=DllCall("SendMessageA","UInt",sc,"int",b,int,0,int,0,"int")
v.focus:=sc,this.2660(1)
for a,b in [[2563,1],[2565,1],[2614,1],[2402,15,75],[2124,1]]{
b.2:=b.2?b.2:0,b.3:=b.3?b.3:0
this[b.1](b.2,b.3)
}
return this
}
__Get(x*){
return DllCall(this.fn,"Ptr",this.ptr,"UInt",x.1,int,0,int,0,"Cdecl")
}
__Call(code,lparam=0,wparam=0,extra=""){
if(code="getseltext"){
VarSetCapacity(text,this.2161),length:=this.2161(0,&text)
return StrGet(&text,length,"UTF-8")
}
if(code="textrange"){
cap:=VarSetCapacity(text,abs(lparam-wparam)),VarSetCapacity(textrange,12,0),NumPut(lparam,textrange,0),NumPut(wparam,textrange,4),NumPut(&text,textrange,8)
this.2162(0,&textrange)
return strget(&text,cap,"UTF-8")
}
if(code="getline"){
length:=this.2350(lparam),cap:=VarSetCapacity(text,length,0),this.2153(lparam,&text)
return StrGet(&text,length,"UTF-8")
}
if(code="gettext"){
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=strget(&text,vv,"UTF-8")
return t
}
if(code="getuni"){
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=StrGet(&text,vv,"UTF-8")
return t
}
wp:=(wparam+0)!=""?"Int":"AStr",lp:=(lparam+0)!=""?"Int":"AStr"
if(wparam.1)
wp:="AStr",wparam:=wparam.1
wparam:=wparam=""?0:wparam,lparam:=lparam=""?0:lparam
info:=DllCall(this.fn,"Ptr",this.ptr,"UInt",code,lp,lparam,wp,wparam,"Cdecl")
return info
}
show(){
GuiControl,+Show,% this.sc
}
}
EA(node){
ea:=[],all:=node.SelectNodes("@*")
while,aa:=all.item[A_Index-1]
ea[aa.NodeName]:=aa.text
return ea
}
Class XML{
keep:=[]
__New(param*){
if !FileExist(A_ScriptDir "\lib")
FileCreateDir,%A_ScriptDir%\lib
root:=param.1,file:=param.2
file:=file?file:root ".xml"
temp:=ComObjCreate("MSXML2.DOMDocument"),temp.setProperty("SelectionLanguage","XPath")
this.xml:=temp
if FileExist(file){
FObject:=FileOpen(file,"R","UTF-8"),info:=FObject.Read(FObject.Length),FObject.Close()
if(info=""){
this.xml:=this.CreateElement(temp,root)
FileDelete,%file%
}else
temp.loadxml(info),this.xml:=temp
}else
this.xml:=this.CreateElement(temp,root)
this.file:=file
xml.keep[root]:=this
}
CreateElement(doc,root){
return doc.AppendChild(this.xml.CreateElement(root)).parentnode
}
Search(node,find,return=""){
found:=this.xml.SelectNodes(node "[contains(.,'" RegExReplace(find,"&","')][contains(.,'") "')]")
while,ff:=found.item(a_index-1)
if (ff.text=find){
if return
return ff.SelectSingleNode("../" return)
return ff.SelectSingleNode("..")
}
}
Lang(info){
info:=info=""?"XPath":"XSLPattern"
this.xml.temp.setProperty("SelectionLanguage",info)
}
Add(path,att:="",text:="",dup:=0,list:=""){
p:="/",dup1:=this.ssn("//" path)?1:0,next:=this.ssn("//" path),last:=SubStr(path,InStr(path,"/",0,0)+1)
if !next.xml{
next:=this.ssn("//*")
Loop,Parse,path,/
last:=A_LoopField,p.="/" last,next:=this.ssn(p)?this.ssn(p):next.appendchild(this.xml.CreateElement(last))
}
if(dup&&dup1)
next:=next.parentnode.appendchild(this.xml.CreateElement(last))
for a,b in att
next.SetAttribute(a,b)
for a,b in StrSplit(list,",")
next.SetAttribute(b,att[b])
if(text!="")
next.text:=text
return next
}
Find(info*){
doc:=info.1.NodeName?info.1:this.xml
if(info.1.NodeName)
node:=info.2,find:=info.3
else
node:=info.1,find:=info.2
if InStr(find,"'")
return doc.SelectSingleNode(node "[.=concat('" RegExReplace(find,"'","'," Chr(34) "'" Chr(34) ",'") "')]/..")
else
return doc.SelectSingleNode(node "[.='" find "']/..")
}
Under(under,node:="",att:="",text:="",list:=""){
if(node="")
node:=under.node,att:=under.att,list:=under.list,under:=under.under
new:=under.appendchild(this.xml.createelement(node))
for a,b in att
new.SetAttribute(a,b)
for a,b in StrSplit(list,",")
new.SetAttribute(b,att[b])
if text
new.text:=text
return new
}
SSN(path){
return this.xml.SelectSingleNode(path)
}
SN(path){
return this.xml.SelectNodes(path)
}
__Get(x=""){
return this.xml.xml
}
Get(path,Default){
return value:=this.ssn(path).text!=""?this.ssn(path).text:Default
}
Transform(){
static
if !IsObject(xsl){
xsl:=ComObjCreate("MSXML2.DOMDocument")
style=<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">`n<xsl:output method="xml" indent="yes" encoding="UTF-8"/>`n<xsl:template match="@*|node()">`n<xsl:copy>`n<xsl:apply-templates select="@*|node()"/>`n<xsl:for-each select="@*">`n<xsl:text></xsl:text>`n</xsl:for-each>`n</xsl:copy>`n</xsl:template>`n</xsl:stylesheet>
xsl.loadXML(style),style:=null
}
this.xml.transformNodeToObject(xsl,this.xml)
}
Save(x*){
if x.1=1
this.Transform()
filename:=this.file?this.file:x.1.1
if(Trim(this[])="")
return
file:=FileOpen(filename,"W","UTF-8"),file.write(this[]),file.length(file.position)
}
EA(path){
list:=[]
if nodes:=path.nodename
nodes:=path.SelectNodes("@*")
else if path.text
nodes:=this.sn("//*[text()='" path.text "']/@*")
else if !IsObject(path)
nodes:=this.sn(path "/@*")
else
for a,b in path
nodes:=this.sn("//*[@" a "='" b "']/@*")
while,n:=nodes.item(A_Index-1)
list[n.nodename]:=n.text
return list
}
}
SSN(node,path){
return node.SelectSingleNode(path)
}
SN(node,path){
return node.SelectNodes(path)
}
ATT(node,info){
for a,b in info
node.setattribute(a,b)
}