Skip to content

Instantly share code, notes, and snippets.

@maestrith
Created April 2, 2014 23:30
Show Gist options
  • Save maestrith/9945432 to your computer and use it in GitHub Desktop.
Save maestrith/9945432 to your computer and use it in GitHub Desktop.
Posted using AHK Studio
#SingleInstance,Off
;download complete
DetectHiddenWindows,On
OnMessage(0x4a,"WM_COPYDATA")
if (AID:=OtherInstance()){
File=%1%
Send_WM_COPYDATA(AID,File)
ExitApp
}
SetWorkingDir,%A_ScriptDir%
settings:=new xml("settings","lib\settings.xml"),files:=new xml("files"),menus:=new xml("menus","lib\menus.xml"),commands:=new xml("commands","lib\commands.xml")
positions:=new xml("positions","lib\positions.xml"),vversion:=new xml("version","lib\version.xml"),access_token:=settings.ssn("//access_token").text
vault:=new xml("vault","lib\vault.xml")
global v:=[],settings,files,menus,commands,positions,vversion,access_token,vault,preset
v.color:=[],preset:=new xml("preset","lib\preset.xml")
if (A_PtrSize=8&&A_IsCompiled=""){
SplitPath,A_AhkPath,,dir
correct:=dir "\AutoHotkeyU32.exe"
if !FileExist(correct){
m("Requires AutoHotkey 1.1 to run")
ExitApp
}
run,"%correct%" "%A_ScriptName%",%A_ScriptDir%
ExitApp
return
}
filecheck(),v.quick:=[]
Menu,Tray,Icon,AHKStudio.ico
keywords(),gui()
openfile=%1%
if openfile contains .ahk,.txt,.ini
open(openfile)
return
GuiDropFiles:
open(A_GuiEvent)
return
about(){
about=
(
I want to thank all of the people who helped this project become a reality.
Chris Mallet - Creator of the original AutoHotkey
All of the people who helped him.
Lexikos - For all of the amazing work on AHK 1.1
All of the people who helped him.
Help from friends who have given me great ideas and bug reports
Uberi,Coco,Tidbit,GeekDude,joedf,budRich and everyone who I have not listed I am thankful.
All of the editors that I have used for giving me ideas for this project
License for Scintilla and SciTE
Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation.
NEIL HODGSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS, IN NO EVENT SHALL NEIL HODGSON BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
OR PERFORMANCE OF THIS SOFTWARE.
)
setup(11),hotkeys([11],{"Esc":"11GuiClose"})
Gui,Margin,0,0
sc:=new s(11,{pos:"x0 y0 w700 h500"}),csc({hwnd:sc})
Gui,Show,,AHK Studio Help
sc.2181(0,about),sc.2025(0)
return
}
addbutton(this){
static bar
v.bar:=bar:=this
ComObjError(1)
setup(12)
Gui,Add,ListView,w400 h300,Menu Items
menu:=menus.sn("//*")
while,mm:=menu.item[A_Index-1]{
mname:=clean(ssn(mm,"@name").text)
if (mname&&InStr(mname,"---")=0&&(IsFunc(mname)||IsLabel(mname)))
LV_Add("",mname)
}
Gui,Add,Button,gabrun,Add A Launch Button
Gui,Add,Button,gabmenu,Add A Menu Button
Gui,Show,,Add Buttons
return
this.add({icon:4,file:"shell32.dll",text:"flap",func:"flan",id:11100,state:4})
this.addbutton(11100)
return
12GuiEscape:
12GuiClose:
hwnd({rem:12})
return
abrun:
abmenu:
newid:=11099
while,settings.ssn("//toolbar/bar[@id='" bar.id "']/button[@id='" ++newid "']"){
}
under:=settings.ssn("//toolbar/bar[@id='" bar.id "']")
if (A_ThisLabel="abrun"){
FileSelectFile,filename
if ErrorLevel
return
SplitPath,filename,,,,nne
iconfile:=InStr(filename,".ahk")?A_AhkPath:filename
att:={icon:0,file:iconfile,text:nne,func:"runfile",id:newid,state:4,runfile:filename}
bar.add(att)
bar.addbutton(newid)
settings.under({under:under,node:"button",att:att})
}else{
LV_GetText(item,LV_GetNext())
text:=RegExReplace(item,"_"," ")
att:={icon:1,file:"shell32.dll",text:text,func:item,id:newid,state:4}
bar.add(att)
bar.addbutton(newid)
settings.under({under:under,node:"button",att:att})
}
return
outside:
m(bar.ahkid)
return
}
arrows(){
left:
right:
sc:=csc()
selcount:=sc.2570
pos:=[]
current:=sc.2008,canchor:=sc.2009
if selcount>1
loop,%selcount%{
pos[A_Index-1]:={caret:sc.2577(A_Index-1),anchor:sc.2579(A_Index-1)}
}
ControlGetFocus,Focus,% hwnd([1])
if !InStr(Focus,"scintilla"){
Send,{%A_ThisLabel%}
return
}
Send,{%A_ThisLabel%}
notify(sc)
for a,b in pos{
add:=A_ThisLabel="left"?-1:1
if (b.caret!=b.anchor){
if (A_ThisLabel="left"&&b.caret!=current){
use:=b.caret>b.anchor?b.anchor:b.caret
sc.2573(use,use)
}else if (A_ThisLabel="right"&&b.anchor!=canchor){
use:=b.caret>b.anchor?b.caret:b.anchor
sc.2573(use,use)
}
}else if (b.caret!=current)
sc.2573(b.caret+add,b.caret+add)
}
if selcount>1
sc.2606
return
+left:
+right:
ControlGetFocus,Focus,% hwnd([1])
if !InStr(Focus,"scintilla"){
Send,{%A_ThisLabel%}
return
}
Send,{%A_ThisLabel%}
sc:=csc()
selcount:=sc.2570,pos:=[]
if (selcount>1){
loop,%selcount%
pos[A_Index-1]:={start:sc.2577(A_Index-1),end:sc.2579(A_Index-1)}
for a,b in pos{
add:=A_ThisHotkey="+left"?-1:1
cursor:=b.start,anchor:=b.end+add
if A_Index=1
sc.2160(anchor,cursor)
else
sc.2573(cursor,anchor)
}
sc.2606
}else{
label:=SubStr(A_ThisLabel,2)
Send,+{%label%}
}
return
}
+!Down::
+!Up::
sc:=csc(),line:=sc.2166(sc.2008)
column:=sc.2129(sc.2008)
nl:=A_ThisLabel="+!up"?-1:1
next:=sc.2456(line+nl,column)
if (next){
sc.2573(next,next)
}
return
Check_For_Update(){
static version
version=0.001.4
Gui,55:Destroy
Gui,55:Default
Gui,Add,Edit,w500 h500,% URLDownloadToVar("http://files.maestrith.com/alpha/Studio/AHK Studio.text")
Gui,Add,Button,gautoupdate,Update
Gui,Show,,AHK Studio Version %version%
return
autoupdate:
version=0.001.4
save(),settings.save(1)
SplitPath,A_ScriptName,,,ext,name
if !InStr(ext,"exe"){
studio:=URLDownloadToVar("http://files.maestrith.com/alpha/Studio/AHK Studio.ahk")
if !InStr(studio,";download complete")
return m("There was an error. Please contact maestrith@gmail.com if this error continues")
FileMove,%A_ScriptName%,%name%%version%.ahk,1
FileAppend,%studio%,%A_ScriptName%
Run,%A_ScriptName%
ExitApp
}else{
URLDownloadToFile,http://files.maestrith.com/alpha/Studio/AHK Studio.exe,AHK Studio temp.exe
FileGetSize,size,AHK Studio temp.exe
if (size>1000){
FileMove,%A_ScriptName%,%name%%version%,1
FileMove,AHK Studio temp.exe,%A_ScriptName%,1
Run,%A_ScriptName%
ExitApp
}
}
return
55GuiEscape:
55GuiClose:
Gui,55:Destroy
return
}
automenu(){
automenu:
SetTimer,automenu,Off
if v.word
if (l:=commands.ssn("//Context/*/*[text()='" RegExReplace(v.word,"#") "']/@list").text)
sc:=csc(),sc.2100(0,l),v.word:=""
return
}
brace(){
brace:
sc:=csc(),cp:=sc.2008,line:=sc.2166(cp),min:=posinfo() ;,min:=mm(sc)
v.lastbrace:=A_ThisHotkey
if sc.2102
sc.2104
ControlGetFocus,Focus,A
if !InStr(Focus,"Scintilla"){
Send,{%A_ThisHotkey%}
return
}
selcount:=sc.2570
pos:=[],count:=0,rev:=[]
loop,%selcount%
{
pos[sc.2008]:={start:sc.2008,end:sc.2009}
sc.2606
count++
}
for a,b in pos
rev.Insert(pos[a])
if (A_ThisHotkey="{"&&sc.2128(line)=cp&&cp=sc.2136(line)){
sc.2003(cp,"{`n`n}")
fix_indent()
Send,{Down}
sc.2314
}else{
sc.2078()
for a in rev{
b:=rev[rev.maxindex()-A_Index+1]
mm:=[]
mm[b.start]:=1,mm[b.end]:=1
sc.2003(mm.MinIndex(),A_ThisHotkey)
sc.2003(mm.MaxIndex()+1,v.brace[A_ThisHotkey])
}
for a,b in rev{
if A_Index=1
sc.2160(b.start+1,b.end+1)
else
sc.2573(b.end+(A_Index*2)-1,b.start+(A_Index*2)-1)
}
sc.2079
}
width:=sc.2276(32,"a")
text1:="Last Entered Character: " A_ThisHotkey " Code:" Asc(A_ThisHotkey)
SB_SetText(text1,2),SB_SetParts(first,width*StrLen(text1 1),40)
last:=width*StrLen(text1 1)
replace()
return
}
bracesetup(win=1){
v.brace:=[]
autoadd:=settings.sn("//autoadd/*")
Hotkey,IfWinActive,% hwnd([win])
while,aa:=autoadd.item(a_index-1){
ea:=xml.ea(aa)
if (ea.trigger){
Hotkey,% Chr(ea.trigger),brace,On
v.brace[Chr(ea.trigger)]:=Chr(ea.add)
}
}
}
check_id(id){
http:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
http.Open("GET","https://api.github.com/gists/" id "/star")
http.SetRequestHeader("Authorization","Bearer " access_token)
http.send(),code:=http.ResponseText
http:=""
if InStr(code,"not found")
return
return id
}
class ftp{
__New(name){
ea:=settings.ea("//ftp/server[@name='" name "']"),this.error:=0
if !(ea.username!=""&&ea.password!=""&&ea.address!="")
return m("Please setup your ftp information"),ftp_servers()
port:=ea.port?ea.port:21
SplashTextOn,200,100,Logging In,Please Wait...
this.library:=DllCall("LoadLibrary","str","wininet.dll","Ptr")
this.Internet:=DllCall("wininet\InternetOpen","str",A_ScriptName,"UInt",AccessType,"str",Proxy,"str",ProxyBypass ,"UInt",0,"Ptr")
if !this.internet
this.cleanup(A_LastError)
this.connect:=DllCall("wininet\InternetConnect","PTR",this.internet,"str",ea.address,"uint",Port,"str",ea.Username,"str",ea.Password,"uint",1,"uint",flags,"uint",0,"Ptr")
if !this.connect{
this.cleanup(A_LastError)
SplashTextOff
}
VarSetCapacity(ret,40)
}
createfile(name){
list:=[]
SplitPath,name,filename,dir,,namenoext
IfNotExist,temp
FileCreateDir,temp
FileDelete,% "temp\" filename
file:=FileOpen("temp\" filename,2)
file.write(publish(1))
file.seek(0)
List[filename]:=file
FileDelete,% "temp\" namenoext ".text"
file:=FileOpen("temp\" namenoext ".text",2)
file.write(RegExReplace(vversion.ssn("//info[@file='" name "']").text,"\n","`r`n"))
file.seek(0)
List[namenoext ".text"]:=file
return list
}
put(file,dir,compile){
SplashTextOff
updir:="/" Trim(RegExReplace(dir,"\\","/"),"/")
this.cd("/" Trim(RegExReplace(dir,"\\","/"),"/"))
if !(this.internet!=0&&this.connection!=0)
return 0
SplitPath,file,name,dir,,namenoext
list:=this.createfile(file)
BufferSize:=4096
if compile
list[namenoext ".exe"]:=FileOpen(dir "\" namenoext ".exe","r")
upver:=vversion.ssn("//*[@file='" ssn(current(1),"@file").text "']/@upver").text
for a,b in list{
if upver{
ff:=!InStr(a,".exe")?A_ScriptDir "\temp\" a:dir "\" namenoext ".exe"
SplitPath,a,fname
SplashTextOn,300,50,Uploading file %a%,Please Wait...
ii:=DllCall("wininet\FtpPutFile",UPtr,this.connect,UPtr,&ff,UPtr,&fname,UInt,2,UInt,0,"cdecl")
SplashTextOff
}
else
{
ff:=DllCall("wininet\FtpDeleteFile",UPtr,this.connect,UPtr,&a,"cdecl")
this.file:=DllCall("wininet\FtpOpenFile",UPtr,this.connect,UPtr,&a,UInt,0x40000000,UInt,0x2,UPtr,0,"cdecl")
Progress,0,uploading,%a%,Uploading,Tahoma ;% cfont().font
if !this.file
this.cleanup(A_LastError)
length:=b.length,totalsize:=0
size:=1,b.seek(0)
while,size{
size:=b.rawread(buffer,BufferSize)
totalsize+=size
Progress,% (totalsize*100)/length
DllCall("wininet\InternetWriteFile","PTR",this.File,"PTR",&Buffer,"UInt",size,"UIntP",out,"cdecl")
sleep,10
}
close:=DllCall("wininet\InternetCloseHandle","UInt",this.file)
sleep,100
b.close()
}
}
t()
list:=""
Progress,Off
}
__Delete(){
this.cleanup
}
cleanup(error*){
if error.1
m(error.1)
SplashTextOff
if (error.1){
this.error:=1
MsgBox,48,AHK Studio,% this.GetLastError(error.1)
}
for a,b in [this.file,this.connect,this.internet]
DllCall("wininet\InternetCloseHandle","UInt",this.internet)
DllCall("FreeLibrary","UInt",this.library)
return 0
}
CD(dir){
available:=DllCall("wininet\FtpSetCurrentDirectory",UInt,this.connect,UPtr,&dir,"cdecl")
if !available
Loop,Parse,dir,/
this.createdir(A_LoopField),this.setdir(A_LoopField)
}
setdir(dir){
DllCall("wininet\FtpSetCurrentDirectory",UInt,this.connect,UPtr,&dir,"cdecl")
}
createdir(dir){
DllCall("wininet\FtpCreateDirectory",UPtr,this.connect,UPtr,&dir,"cdecl")
}
GetDir(){
cap:=VarSetCapacity(dir,128)
DllCall("wininet\FtpGetCurrentDirectory",UInt,this.connect,UInt,&dir,UInt,&cap,"cdecl")
return Trim(StrGet(&dir,128,"cp0"),"/")
}
;http://msdn.microsoft.com/en-us/library/ms679351
GetLastError(error){
size:=VarSetCapacity(buffer,1024)
if (error = 12003){ ;ERROR_INTERNET_EXTENDED_ERROR
VarSetCapacity(ErrorMsg,4)
DllCall("wininet\InternetGetLastResponseInfo","UIntP",&ErrorMsg,"PTR",&buffer,"UIntP",&size)
Return StrGet(&buffer,size)
}
DllCall("FormatMessage","UInt",0x00000800,"PTR",this.library,"UInt",error,"UInt",0,"Str",buffer,"UInt",size,"PTR",0)
Return buffer
}
}
class s{
static ctrl:=[],lc:="",main:=[]
__New(window,info){
static int
if !init
DllCall("LoadLibrary","str","scilexer.dll"),init:=1
win:=window?window:1
static count=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,s.ctrl[sc]:=this,t:=[]
for a,b in {fn:2184,ptr:2185}
this[a]:=DllCall("SendMessageA","UInt",sc,"int",b,int,0,int,0)
v.focus:=sc
this.2660(1)
for a,b in [[2563,1],[2565,1],[2614,1],[2402,0x15,75],[2124,1]]{
b.2:=b.2?b.2:0,b.3:=b.3?b.3:0
this[b.1](b.2,b.3)
}
if info.main
s.main.Insert(this)
this.2052(32,0),this.2051(32,0xaaaaaa),this.2050,this.2052(33,0x222222)
;for a,b in [[2036,5],[2029,0],[2124,1],[2260,1]]
;this.2029(0)
;this.2356(1) ;view EOL on
this.2069(0xAAAAAA),this.2067(1,0),this.2601(0xaa88aa)
this.2563(1),this.2614(1),this.2565(1),this.2402(0x15,75)
this.2660(1),this.2458(0)
this.2036(5),this.2124(1),this.2260(1),this.2122(5),this.2132(1)
;this.2359(0x13)
color(this)
return this
}
delete(x*){
if s.main.MaxIndex()=1
return m("Can not delete the last control")
this:=x.1
for a,b in s.main{
if (b.sc=this.sc)
s.main.remove(a)
}
DllCall("DestroyWindow",uptr,this.sc)
csc("Scintilla1").2400
Resize()
}
__Delete(x*){
m("should not happen")
}
__Get(x*){
return DllCall(this.fn,"Ptr",this.ptr,"UInt",x.1,int,0,int,0,"Cdecl")
}
__Call(code,lparam=0,wparam=0){
if (code="getseltext"){
VarSetCapacity(text,this.2161),length:=this.2161(0,&text)
return StrGet(&text,length,"cp0")
}
if (code="textrange"){
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,"","cp0")
}
if (code="getline"){
length:=this.2350(lparam)
cap:=VarSetCapacity(text,length,0),this.2153(lparam,&text)
return StrGet(&text,length,"cp0")
}
if (code="gettext"){
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=strget(&text,vv,"cp0")
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"
if wparam.1
wp:="AStr"
if wparam=0
wp:="int"
info:=DllCall(this.fn,"Ptr",this.ptr,"UInt",code,"int",lparam,wp,wparam,"Cdecl")
return info
}
show(){
GuiControl,+Show,% this.sc
}
}
clean(clean,tab=""){
clean:=RegExReplace(RegExReplace(clean,"&")," ","_")
if InStr(clean,"`t")
clean:=SubStr(clean,1,InStr(clean,"`t")-1)
return clean
}
close(){
sc:=csc(),save()
main:=files.ssn("//*[@sc='" sc.2357 "']..")
rem:=settings.sn("//file[text()='" ssn(main,"@file").text "']")
while,rr:=rem.item[A_Index-1]
rr.ParentNode.RemoveChild(rr)
udf:=update("get").1
close:=sn(main,"*")
Gui,1:Default
Gui,1:TreeView,SysTreeView321
while,cc:=close.item[A_Index-1]{
ea:=xml.ea(cc)
if ea.tv
TV_Delete(ea.tv)
if ea.sc
sc.2377(0,ea.sc)
udf.Remove(ea.file)
}
TV_Modify(TV_GetNext(0),"Select Vis Focus")
main.ParentNode.RemoveChild(main)
if files.sn("//*").length=1
new(1)
}
Code_Vault(){
static ev,mainfile
v.lastsc:=csc()
mainfile:=ssn(current(1),"@file").text
setup(19)
Gui,Add,ListView,w100 h400 AltSubmit gdisplayvault,Code
v.codevault:=new s(19,{pos:"x+10 w600 h400"}),csc({hwnd:v.codevault.sc}),hotkeys([19],{esc:"19GuiClose"})
sc:=csc(),sc.2400,sc.2171(1),bracesetup(19)
Gui,Add,Button,xm gaddcode,Add Code
Gui,Add,Button,x+10 ginsertcode,Insert Into Segment
pupulatevault:
locker:=vault.sn("//code")
LV_Delete()
while,ll:=locker.item[A_Index-1]
LV_Add("",ssn(ll,"@name").text)
LV_Modify(1,"Vis Focus Select")
Gui,Show,,Code Vault
Return
insertcode:
text:=csc().gettext()
sc:=v.lastsc
sc.2003(sc.2008,text)
fix_indent(sc)
return
19GuiClose:
19GuiEscape:
hwnd({rem:19})
Return
addcode:
InputBox,newcode,Name for code snippet,Please enter a name for a new code snippet.
if ErrorLevel
return
if !locker:=vault.ssn("//code[@name='" newcode "']")
locker:=vault.Add({path:"code",att:{name:newcode},dup:1})
Gosub,pupulatevault
return
displayvault:
sc:=csc()
if LV_GetNext()
sc.2171(0)
LV_GetText(code,LV_GetNext())
sc.2181(0,vault.ssn("//code[@name='" code "']").text),sc.2400
return
}
compile_main_gist(filename){
fn:=sn(current(1),"file/@file")
while,f:=fn.item(A_Index-1).text{
if A_Index=1
continue
SplitPath,f,filename
text.="`r`n" Chr(35) "Include " filename
}
return text
}
compile(){
main:=ssn(current(1),"@file").Text
SplitPath,main,,dir,,name
SplitPath,A_AhkPath,file,dirr
Loop,%dirr%\Ahk2Exe.exe,1,1
file:=A_LoopFileFullPath
FileDelete,temp.upload
FileAppend,% publish(1),temp.upload
SplashTextOn,200,100,Compiling,Please wait.
RunWait,%file% /in temp.upload /out "%dir%\%name%.exe"
If FileExist("upx.exe"){
SplashTextOn,,50,Compressing EXE,Please wait...
RunWait,upx.exe -9 "%dir%\%name%.exe",,Hide
SplashTextOff
}
FileDelete,temp.upload
SplashTextOff
}
connect(){
ScriptPath:=A_ScriptDir
if debug("check"){
debug("send","detatch")
sleep,500
debug("disconnect")
sleep,500
}
setup(13)
Gui,Add,ListView,w600 h300 gdebugconnect,Processes
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process"){
prog:=Trim(StrSplit(process.CommandLine,Chr(34)).4,Chr(34))
if (InStr(process.commandline,"autohotkey")&&prog!=A_ScriptFullPath&&prog)
LV_Add("",prog)
}
Gui,13:Show,,Open Processes
return
debugconnect:
Gui,13:Default
Gui,13:ListView,SysListView321
LV_GetText(scriptpath,A_EventInfo)
ifWinExist %ScriptPath% ahk_class AutoHotkey
{
socket:=debug("new")
PostMessage,DllCall("RegisterWindowMessage","str","AHK_ATTACH_DEBUGGER")
}
13GuiClose:
13GuiEscape:
hwnd({rem:13})
return
}
context(){
sc:=csc()
if sc.2102
return
cp:=sc.2008,kw:=v.kw,add:=0,pos:=cp-1,start:=sc.2128(sc.2166(cp))
if (start>=pos+1)
return
content:=sc.textrange(start,pos+1)
RegExMatch(content,"(#?\w+)",word)
search=U)"(.*)"
cb:=RegExReplace(content,search),RegExReplace(cb,"\)","",Count)
cou:=[],cbb:=cb
for a,b in ["(",")"]
while,pos:=InStr(cb,b,0,1,A_Index)
cou[pos]:=b
for a,b in cou{
if (b="(")
ccc++
else if (b=")")
ccc--
if ccc=0
cbb:=SubStr(cb,a+1)
}
cbb:=SubStr(cbb,1,InStr(cbb,"(",0,1,ccc))
RegExMatch(cbb,"(\w+)\($",command)
found:=kw[command1]?kw[command1]:kw[word1]
if !found
return
if syn:=commands.ssn("//Commands/*[text()='" found "']/@syntax").text
info:=found " " syn
else
{
root:=commands.sn("//Context/" found "/syntax")
while,r:=root.item(A_Index-1)
if cc:=RegExMatch(cb,"i)\b(" RegExReplace(r.text," ","|") ")\b",ff){
info:=ssn(r,"@syntax").text
break
}
if !cc
return
info:=SubStr(cb,1,cc+StrLen(ff)-1) " " info
}
RegExReplace(info,",","",count)
if !count
return sc.2207(0),sc.2200(start,info),sc.2204(0,StrLen(info))
newstr:=RegExReplace(SubStr(cb,InStr(cb,found,0,0)+StrLen(found)),"U)\((.*)\)")
newstr:=Trim(newstr,"(")
RegExReplace(newstr,",","",count)
ss:=InStr(info,",",0,1,count),ee:=InStr(info,",",0,1,count+1)
if !sc.2202
sc.2200(start,info),sc.2207(0xFF0000)
if (ss&&ee)
sc.2204(ss,ee)
else if (ss&&ee=0)
sc.2204(ss,StrLen(info))
else if (ss=0&&ee)
sc.2204(ss,ee)
else
sc.2207(0x0000FF),sc.2204(0,StrLen(info))
return
context:
SetTimer,context,Off
context()
return
}
convert_hotkey(key){
StringUpper,key,key
for a,b in [{Shift:"+"},{Ctrl:"^"},{Alt:"!"}]
for c,d in b
key:=RegExReplace(key,"\" d,c "+")
return key
}
Toggle_Multiple_Line_Comment(){
sc:=csc(),pos:=posinfo()
if (sc.2010(sc.2008)!=11&&sc.2010(sc.2009)!=11){
start:=sc.2128(sc.2166(pos.start)),end:=sc.2136(sc.2166(pos.end))
sc.2003(start,inline "/*`n")
if (pos.start=pos.end)
sc.2003(end+4,"*/`n")
else
sc.2003(end+4,"*/`n")
}else{
/*
top:=sc.2225(sc.2166(sc.2008))
bottom:=sc.2224(top,-1)
if (top>=0&&bottom>=0){
for a,b in [bottom,top]{
start:=sc.2167(b),end:=sc.2167(b+1)-start
if end<4
start:=start-(4-end),end:=4
sc.2645(start,end)
}
}
*/
}
fix_indent()
}
Create_Segment_From_Selection(){
pos:=posinfo(),sc:=csc()
if (pos.start=pos.end)
return m("Please select some text to create a new segment from")
else{
InputBox,newsegment,Please Name Your New Segment,Please enter a name for your new segment
if ErrorLevel
return
filename:=ssn(current(1),"@file").text,newsegment:=InStr(newsegment,".ahk")?newsegment:newsegment ".ahk"
SplitPath,filename,,dir
if FileExist(dir "\" newsegment)
return m("Segment name already exists. Please choose another")
clip:=Clipboard
sc.2177
new_segment(dir "\" newsegment,clipboard)
clipboard:=clip
}
}
csc(set=0){
static current
global findme
if (set.hwnd)
return current:=s.ctrl[set.hwnd]
if (set=1){
ControlGetFocus,focus,A
if !InStr(focus,"Scintilla")
return
ControlGet,hwnd,hwnd,,%focus%,A
if s.ctrl[hwnd]
current:=s.ctrl[hwnd]
current.2400
return current
return
}
if InStr(set,"Scintilla"){
ControlGet,hwnd,hwnd,,%set%,% hwnd([1])
current:=s.ctrl[hwnd]
return current
}
if !current{
ControlGet,hwnd,hwnd,,Scintilla1,% hwnd([1])
current:=s.ctrl[hwnd]
}
FINDME:=current
return current
}
current(parent=""){
sc:=csc()
node:=files.ssn("//*[@sc='" sc.2357 "']")
if parent
return node.parentnode
return node
}
runit(){
runit:
SetTimer,runit,Off
file:=v.running
SplitPath,file,,dir
Run,"%A_AhkPath%" /debug "%file%",%dir%,,pid
v.pid:=pid
SetTimer,checkerror,100
return
}
debug(info*){
static socket:="",running:=""
if (info.1="run"){
debug("new")
;sleep,200
v.running:=info.2
SetTimer,runit,50
}
if (info.1=0){
for a,b in [10002,10003,10004]
toolbar.list.10002.setstate(b,16)
for a,b in [10000,10001]
toolbar.list.10002.setstate(b,4)
}
if (info.1=1){
for a,b in [10002,10003,10004]
toolbar.list.10002.setstate(b,4)
for a,b in [10000,10001]
toolbar.list.10002.setstate(b,16)
}
if (info.1="new"){
if (socket>0){
debug("disconnect")
}
sock:=-1
DllCall("LoadLibrary","str","ws2_32","ptr"),VarSetCapacity(wsadata,394+A_PtrSize)
DllCall("ws2_32\WSAStartup","ushort",0,"ptr",&wsadata)
DllCall("ws2_32\WSAStartup","ushort",NumGet(wsadata,2,"ushort"),"ptr",&wsadata)
OnMessage(0x9987,"SocketEvent"),socket:=sock
next:=debug("addrinfo"),sockaddrlen:=NumGet(next+0,16,"uint"),sockaddr:=NumGet(next+0,16+(2*A_PtrSize),"ptr")
socket:=DllCall("ws2_32\socket","int",NumGet(next+0,4,"int"),"int",1,"int",6,"ptr")
if (DllCall("ws2_32\bind","ptr",socket,"ptr",sockaddr,"uint",sockaddrlen,"int")!=0)
return m(DllCall("ws2_32\WSAGetLastError")) ;,enable(debug("check"))
DllCall("ws2_32\freeaddrinfo","ptr",next)
debug("__eventProcRegister",socket,0x29)
DllCall("ws2_32\listen","ptr",socket,"int",32)
return socket
}
if (info.1="__eventProcRegister"){
DllCall("ws2_32\WSAAsyncSelect","ptr",socket,"ptr",A_ScriptHwnd,"uint",0x9987,"uint",info.3)
}
if (info.1="addrinfo"){
VarSetCapacity(hints,8*A_PtrSize,0)
for a,b in {6:8,1:12}
NumPut(a,hints,b)
DllCall("ws2_32\getaddrinfo",astr,"127.0.0.1",astr,"9000","uptr",hints,"ptr*",results)
return results
}
if (info.1="accept"){
if ((sock:=DllCall("ws2_32\accept","ptr",socket,"ptr",0,"int",0,"ptr"))!=-1){
socket:=sock
debug("__eventProcRegister","newsock",0x21)
return
}
}
if (info.1="receive"){
;Thank you Lexikos and fincs http://hkscript.org/download/tools/DBGP.ahk
VarSetCapacity(buffer)
while,DllCall("ws2_32\recv","ptr",socket,"char*",c,"int",1,"int",0){
if c=0
break
length.=chr(c)
}
VarSetCapacity(packet,++length)
received:=0
While(received<length){
r:=DllCall("ws2_32\recv","ptr",socket,"ptr",&packet+received,"int",length-received,"int",0)
if (r<1)
return m("An error occured",DllCall("GetLastError"))
received += r
sleep,100
}
info:=StrGet(&packet,"utf-8")
if InStr(info,"init"){
for a,b in v.breaks{
debug("send","breakpoint_set -t line -n " b)
sleep,200
}
}
if (info)
display(info)
}
if (info.1="send"){
message:=info.2,message.=Chr(0),len:=strlen(message),VarSetCapacity(buffer,len)
ll:=StrPut(info.2,&buffer,"utf-8")
if (DllCall("ws2_32\send",uint,socket,uptr,&buffer,"int",ll,"int",0,"cdecl")<1&&A_ThisLabel="menu"){
t("Currently there is no connection")
sleep,500
t()
}
}
if (info.1="detach"){
SetTimer,drop,10
return
drop:
SetTimer,drop,Off
debug("send","stderr -c 0")
SetTimer,dropnext,500
return
dropnext:
SetTimer,dropnext,Off
debug("send","detach")
SetTimer,droplast,500
return
droplast:
SetTimer,droplast,off
settimer,laster,500
debug("disconnect")
return
laster:
SetTimer,laster,Off
hwnd({rem:99}),debug(0)
return
}
if (info.1="disconnect"){
DllCall("ws2_32\WSAAsyncSelect","uint",socket,"ptr",A_ScriptHwnd,"uint",0,"uint",0)
DllCall("ws2_32\closesocket","uint",socket,"int")
DllCall("ws2_32\WSACleanup"),socket:=""
debug(0)
}
if (info.1="encode"){ ;original http://www.autohotkey.com/forum/viewtopic.php?p=238120#238120
text:=info.2!=""?info.2:return
cp:=0
VarSetCapacity(rawdata,StrPut(text,"utf-8")),sz:=StrPut(text,&rawdata,"utf-8")-1
DllCall("Crypt32.dll\CryptBinaryToString","ptr",&rawdata,"uint",sz,"uint",0x40000001,"ptr",0,"uint*",cp)
VarSetCapacity(str,cp*(A_IsUnicode?2:1))
DllCall("Crypt32.dll\CryptBinaryToString","ptr",&rawdata,"uint",sz,"uint",0x40000001,"str",str,"uint*",cp)
return str
}
if (info.1="decode"){ ;original http://www.autohotkey.com/forum/viewtopic.php?p=238120#238120
string:=info.2!=""?info.2:return
DllCall("Crypt32.dll\CryptStringToBinary","ptr",&string,"uint",StrLen(string),"uint",1,"ptr",0,"uint*",cp:=0,"ptr",0,"ptr",0) ;getsize
VarSetCapacity(bin,cp)
DllCall("Crypt32.dll\CryptStringToBinary","ptr",&string,"uint",StrLen(string),"uint",1,"ptr",&bin,"uint*",cp,"ptr",0,"ptr",0)
return StrGet(&bin,cp,"utf-8")
}
if (info.1="check")
return socket
}
checkerror:
SetTimer,checkerror,Off
checkerror()
return
checkerror(){
IfWinExist,% "ahk_pid" v.pid
WinGetText,text,% "ahk_pid" v.pid
if InStr(text,"error at line"){
for a,b in StrSplit(text,"`n")
if InStr(b,"error at line"){
RegExMatch(b,"(\d+)",find)
v.line:=find1-1
debug("disconnect")
file:=StrSplit(b,Chr(34)).2
if (file){
tv(files.ssn("//main[@file='" ssn(current(1),"@file").text "']/file[@file='" file "']/@tv").text)
csc().2400
}
SetTimer,selecterror,40
}
}
return
}
SocketEvent(info*){
if (info.3=0x9987){
if (info.2&0xFFFF=1)
debug("receive")
if (info.2&0xffff=8)
debug("accept")
if (info.2&0xFFFF=32)
debug("disconnect")
}
}
defaultfont(){
temp:=new xml("temp")
info=
(
<fonts>
<name>PlasticCodeWrap</name>
<author>joedf</author>
<font background="0x1D160B" bold="1" color="0xF8F8F2" font="Consolas" size="10" style="5" italic="0" strikeout="0" underline="0"/>
<font background="0x36342E" style="33" color="0xECEEEE"/>
<font style="0" color="0xF8F8F2"/>
<font style="1" color="0xE09A1E" bold="0" font="Consolas" italic="1" size="10" strikeout="0" underline="0"/>
<font style="2" color="0x833AFF"/>
<font style="3" color="0x39E455"/>
<font style="4" color="0xAFA600"/>
<font style="11" color="0xE09A1E" bold="0" font="Consolas" italic="1" size="10" strikeout="0" underline="0"/>
<font style="13" color="0x2929EF"/>
<font style="15" color="0x2D8BAA"/>
<font style="17" color="0x9A93EB"/>
<font style="18" color="0x54B4FF"/>
<font style="19" color="0x0000AE"/>
<font style="21" color="0x400080"/>
<font style="22" color="0x8000FF"/>
<font style="37" color="0xff00ff"/>
<font bool="1" code="2067" color="0xECE000"/>
<font bool="1" code="2068" color="0x3D2E16"/>
<font code="2069" color="0xFF8080"/>
<font code="2098" color="0x583F11"/>
<font code="2600" color="0x222222"/>
<font code="2601" color="0xAFA600"/>
<highlight>
<list1 list="1">custom list</list1>
</highlight>
</fonts>
)
top:=settings.ssn("//settings")
temp.xml.loadxml(info)
tt:=temp.ssn("//*")
top.appendchild(tt)
}
delete(){
backspace:
ControlGetFocus,Focus,% hwnd([1])
sc:=csc()
if !InStr(Focus,"Scintilla"){
ControlSend,%Focus%,{%A_ThisHotkey%}
return
}
if (sc.2009!=sc.2008){
text:=sc.getseltext()
if RegExMatch(text,"(\{|\})")
SetTimer,auto_delete,20
}else{
if (A_ThisHotkey="bs")
if RegExMatch(Chr(sc.2007(sc.2008-1)),"(\{|\})")
SetTimer,auto_delete,20
else if(A_ThisHotkey="Del")
if RegExMatch(Chr(sc.2007(sc.2008)),"(\{|\})")
SetTimer,auto_delete,20
}
ControlSend,%Focus%,{%A_ThisHotkey%}
update({sc:sc.2357})
return
}
display(store){
static recieve:=new xml("recieve")
start:=1
if !store
return
if !WinExist(hwnd([99])){
Gui,99:Default
Gui,99:Destroy
Gui,+hwndhwnd +Owner1
hwnd(99,hwnd)
sc:=v.debugwin:=new s(99,{pos:"w400 h600"})
Gui,99:Show,x0 y0 NA,Debug
Gui,1:Default
debug(1)
}
sc:=v.debugwin
recieve.xml.loadxml(store)
if info:=recieve.ssn("//stream[@type='stderr']"){
debug("send","stop"),debug(0)
info:=debug("decode",info.text)
sc.2003(sc.2006,"`r`n" info),sc.2629
sc:=csc("Scintilla1")
for a,b in StrSplit(info,"`n"){
if RegExMatch(b,"i)Error in.+include file " Chr(34) "(.+)" Chr(34),found)
tv(files.ssn("//main[@file='" ssn(current(1),"@file").text "']/file[@file='" found1 "']/@tv").text),sc.2400
if InStr(b,"--->"){
RegExMatch(b,"(\d+)",line)
v.line:=line-1
SetTimer,selecterror,100
debug("disconnect")
exit
}
}
}
if init:=recieve.ssn("//init"){
debug("send","stderr -c 2")
debug(1)
}
if recieve.ssn("//property"){
if property:=recieve.sn("//property"){
if property.length>1000
ToolTip,Compiling List Please Wait...,350,150
varbrowser()
list:=[],variablelist:=[],value:=[]
object:=recieve.sn("//response/property")
Gui,97:Default
GuiControl,97:-Redraw,SysTreeView321
TV_Delete()
while,oo:=object.item[A_Index-1]{
ea:=xml.ea(oo),value:=debug("decode",oo.text)
list[ea.fullname]:=TV_Add(ea.fullname a:=ea.type="object"?"":" = " value)
if (ea.type!="object")
variablelist[list[ea.fullname]]:={value:value,variable:ea.fullname}
descendant:=sn(oo,"descendant::*")
while,des:=descendant.item[A_Index-1]{
ea:=xml.ea(des),value:=debug("decode",des.text)
list[ea.fullname]:=TV_Add(ea.fullname a:=ea.type="object"?"":" = " value,list[prev:=SubStr(ea.fullname,1,InStr(ea.fullname,".",0,0)-1)],"Sort")
if (ea.type!="object")
variablelist[list[ea.fullname]]:={value:value,variable:ea.fullname}
}
}
v.variablelist:=variablelist
debug("send","run")
GuiControl,97:+Redraw,SysTreeView321
return t()
sc.2629
return t()
}
}else if command:=recieve.ssn("//response"){
if recieve.sn("//response").length>1
m("more info")
ea:=recieve.ea(command)
if (ea.status="stopped"&&ea.command="run"&&ea.reason="ok")
debug(0)
disp:="Command:"
for a,b in ea
if (a&&b)
disp.="`r`n" a " = " Chr(34) b Chr(34)
info:=disp
}
disp:=sc.2006?"`r`n" disp:disp
disp:=disp?disp:store
sc.2003(sc.2006,disp)
sc.2629
return
disp:=recieve[]
store:=disp?disp:store
return sock
99GuiEscape:
99GuiClose:
debug("detach")
/*
WinWaitClose,% hwnd
csc("Scintilla1")
*/
return
selecterror:
SetTimer,selecterror,Off
sc:=csc(),line:=v.line,sc.2400
start:=sc.2128(line),end:=sc.2136(line)
sc.2160(start,end)
return
}
varbrowser(){
if !WinExist(hwnd([97])){
setup(97)
Gui,Add,TreeView,w300 h400 gvalue AltSubmit
Gui,Add,Button,greloadvar,Reload Variables
Gui,Show,,Variable Browser
}
return
97GuiEscape:
97GuiClose:
hwnd({rem:97})
return
value:
if A_GuiEvent!=Normal
return
if value:=v.variablelist[A_EventInfo]{
ei:=A_EventInfo
InputBox,newvalue,% "Current value for " value.variable,% "Change value for " value.variable,,,,,,,,% value.value
if ErrorLevel
return
debug("send","property_set -n " value.variable " -- " debug("encode",newvalue))
TV_Modify(ei,"",value.variable " = " newvalue)
}
return
reloadvar:
listvars()
return
}
run_program(){
if !debug("check")
return m("Currently no file being debugged"),debug(0)
debug("send","run")
}
Run_Script(){
save(),debug("run",ssn(current(1),"@file").text)
}
step(){
if !debug("check")
return m("Currently no file being debugged"),debug(0)
debug("send","step_into")
}
listvars(){
if !debug("check")
return m("Currently no file being debugged"),debug(0)
debug("send","context_get -c 1")
}
stop(){
return debug("detach")
if !debug("check")
return m("Currently no file being debugged"),debug(0)
debug("send","detach")
sleep,500
hwnd({rem:99}),debug("disconnect")
WinWaitClose,% hwnd
debug(0)
csc("Scintilla1")
}
detach(){
debug("send","detach"),debug(0)
}
local(){
debug("send","context_get -c 0")
}
global(){
debug("send","context_get -c 1")
}
Dlg_Color(Color,hwnd){
static
if settings.ssn("//colorinput").text{
InputBox,color,Color Code,Input your color code,,,,,,,,%color%
if !ErrorLevel
return color
return
}
if !cc{
VarSetCapacity(cccc,16*A_PtrSize,0),cc:=1,size:=VarSetCapacity(CHOOSECOLOR,9*A_PtrSize,0)
Loop,16{
IniRead,col,color.ini,color,%A_Index%,0
NumPut(col,cccc,(A_Index-1)*4,"UInt")
}
}
NumPut(size,CHOOSECOLOR,0,"UInt"),NumPut(hwnd,CHOOSECOLOR,A_PtrSize,"UPtr")
,NumPut(Color,CHOOSECOLOR,3*A_PtrSize,"UInt"),NumPut(3,CHOOSECOLOR,5*A_PtrSize,"UInt")
,NumPut(&cccc,CHOOSECOLOR,4*A_PtrSize,"UPtr")
ret:=DllCall("comdlg32\ChooseColorW","UPtr",&CHOOSECOLOR,"UInt")
if !ret
exit
Loop,16
IniWrite,% NumGet(cccc,(A_Index-1)*4,"UInt"),color.ini,color,%A_Index%
IniWrite,% Color:=NumGet(CHOOSECOLOR,3*A_PtrSize,"UInt"),color.ini,default,color
return Color
}
Dlg_Font(ByRef Style,Effects=1,window=""){
VarSetCapacity(LOGFONT,60),strput(style.font,&logfont+28,32,"CP0")
LogPixels:=DllCall("GetDeviceCaps","uint",DllCall("GetDC","uint",0),"uint",90),Effects:=0x041+(Effects?0x100:0)
for a,b in font:={16:"bold",20:"italic",21:"underline",22:"strikeout"}
if style[b]
NumPut(b="bold"?700:1,logfont,a)
style.size?NumPut(Floor(style.size*logpixels/72),logfont,0):NumPut(16,LOGFONT,0)
VarSetCapacity(CHOOSEFONT,60,0),NumPut(60,CHOOSEFONT,0),NumPut(&LOGFONT,CHOOSEFONT,12),NumPut(Effects,CHOOSEFONT,20),NumPut(style.color,CHOOSEFONT,24),NumPut(window,CHOOSEFONT,4)
if !r:=DllCall("comdlg32\ChooseFontA","uint",&CHOOSEFONT)
return
Color:=NumGet(CHOOSEFONT,24)
bold:=NumGet(LOGFONT,16)>=700?1:0
style:={size:NumGet(CHOOSEFONT,16)//10,font:StrGet(&logfont+28,"CP0"),color:color}
for a,b in font
style[b]:=NumGet(LOGFONT,a,"UChar")?1:0
style["bold"]:=bold
return 1
}
Duplicate_Line(){
csc().2469
}
toggle_comment_line(){
sc:=csc(),sc.2078
pi:=posinfo(),sl:=sc.2166(pi.start),el:=sc.2166(pi.end),end:=pi.end,single:=sl=el?1:0
while,(sl<=el){
letter:=sc.textrange(min:=sc.2128(sl),min+1)
if (min>end&&!single)
break
if (letter=";")
sc.2190(min),sc.2192(min+1),sc.2194(0,""),end--
else
sc.2190(min),sc.2192(min),sc.2194(1,";"),end++
sl++
}
sc.2079
}
DynaRun(TempScript,debug=0){
;http://www.autohotkey.com/community/viewtopic.php?t=63916
if RegExMatch(tempscript,"i)(SetWorkingDir.+)",found){
FileCreateDir,temp
tempscript:=RegExReplace(tempscript,"i)(SetWorkingDir.+)","SetWorkingDir," A_ScriptDir "\temp",count,1)
}else
tempscript:="SetWorkingDir," A_ScriptDir "\temp`r`n" tempscript
StringReplace,TempScript,TempScript,`r`n,`n,All
if (debug=1){
if debug("check")
return m("Program running already"),debug("disconnect")
sock:=debug("new")
if sock<0
return m("something happened")
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
if instr(process.commandline,"pipe")&&instr(process.commandline,a_ahkpath)
Process,Close,% "ahk_pid" process.processid
}
static _:="uint"
@:=A_PtrSize?"Ptr":_
name:="AHK Studio Test"
pipe_ga:= DllCall("CreateNamedPipe","str","\\.\pipe\" name,_,2,_,0,_,255,_,0,_,0,@,0,@,0)
pipe:= DllCall("CreateNamedPipe","str","\\.\pipe\" name,_,2,_,0,_,255,_,0,_,0,@,0,@,0)
if (pipe=-1 or pipe_ga=-1)
Return 0
db:=debug=1?"/debug":""
Run, %A_AhkPath% %db% "\\.\pipe\%name%",,UseErrorLevel HIDE, PID
If ErrorLevel
MsgBox, 262144, ERROR,% "Could not open file:`n" __AHK_EXE_ """\\.\pipe\" name """"
DllCall("ConnectNamedPipe",@,pipe_ga,@,0)
DllCall("CloseHandle",@,pipe_ga)
DllCall("ConnectNamedPipe",@,pipe,@,0)
script:=(A_IsUnicode ? chr(0xfeff) : (chr(239) . chr(187) . chr(191))) . TempScript
if !DllCall("WriteFile",@,pipe,"str",script,_,(StrLen(script)+1)*(A_IsUnicode ? 2 : 1),_ "*",0,@,0)
Return A_LastError
DllCall("CloseHandle",@,pipe)
SetWorkingDir,%A_ScriptDir%
Return PID
}
edit_replacements(){
static
er:=setup(7),window({win:7,gui:["ListView,w400 h500,Value|Replacement","Text,,Value:","Edit,x+10 w200 vvalue","Text,xm,Replacement:","Edit,x+10 w200 vreplacement","Button,xm geradd Default,Add","Button,x+10 gerremove,Remove Selected"]}),sn:=settings.sn("//replacements/*")
while,val:=sn.item(A_Index-1)
LV_Add("",ssn(val,"@replace").text,val.text)
LV_Modify(1,"Select Focus Vis") ;,hotkey( {win:er,list:{"~Delete":"err","~BS":"err"}})
Gui,Show,,Replacements
return
eradd:
rep:=window({get:7})
if !(rep.replacement&&rep.value)
return m("both values are required")
if !settings.ssn("//replacements/*[@replace='" rep.value "']")
settings.add({path:"replacements/replacement",att:{replace:rep.value},text:rep.replacement,dup:1}),LV_Add("",rep.value,rep.replacement)
Loop,2
ControlSetText,Edit%A_Index%
ControlFocus,Edit1
return
err:
ControlGetFocus,focus,% hwnd([7])
if Focus=SysListView321
goto erremove
return
erremove:
Gui,7:Default
while,LV_GetNext(),LV_GetText(value,LV_GetNext())
rem:=settings.ssn("//replacements/*[@replace='" value "']"),LV_Delete(LV_GetNext()),rem.ParentNode.RemoveChild(rem)
return
7GuiClose:
7GuiEscape:
hwnd({rem:7})
return
}
exit(x=""){
GuiClose:
rem:=settings.ssn("//last"),rem.ParentNode.RemoveChild(rem)
for a,b in s.main{
file:=files.ssn("//*[@sc='" b.2357 "']/@file").text
if file
settings.add({path:"last/file",text:file,dup:1})
}
toolbar.save(),rebar.save(),save()
savegui(),menus.save(1),vault.save(1)
settings.save(1)
if (x=""||InStr(A_ThisLabel,"Gui"))
ExitApp
return
GuiEscape:
ControlGetFocus,Focus,% hwnd([1])
csc().2400
return
}
savegui(){
WinGet,max,MinMax,% hwnd([1])
text:=max
text:=max?settings.ssn("//gui/position[@window='1']").text:resize("get")
top:=settings.ssn("//gui/position[@window='1']")
if !top.text
top:=settings.add({path:"gui/position",att:{window:1}})
top.text:=text
top.SetAttribute("max",max)
}
filecheck(){
commandsdate:=20140402
menusdate:=20140330
if !settings.ssn("//autoadd")
for a,b in {60:62,123:125,34:34,39:39,91:93,40:41}
settings.add({path:"autoadd/key",att:{trigger:a,add:b},dup:1})
if !settings.ssn("//fonts").xml
defaultfont()
if (menus.ssn("//date").text!=menusdate){
names:=menus.sn("//*/@name")
while,nn:=names.item[A_Index-1]
list.=nn.text "`r`n"
list:=RegExReplace(list,"&")
SplashTextOn,,40,Downloading Required Files,Please Wait...
URLDownloadToFile,http://files.maestrith.com/alpha/Studio/menus.xml,lib\temp.xml
FileRead,menu,lib\temp.xml
temp:=new xml("temp")
temp.xml.loadxml(menu)
if menus.sn("//*").length=1
menus.xml.loadxml(menu)
else{
menu:=temp.sn("//*")
while,mm:=menu.item[A_Index-1]{
parent:=mm.nodename!="menu"?mm:parent
name:=ssn(mm,"@name").text
SplashTextOff
check:=RegExReplace(name,"&")
if !RegExMatch(list,"i)\b" check "\b"){
if !menus.ssn("//" mm.nodename "[@name='" name "']"){
top:=menus.ssn("//menu[@name='" ssn(mm.ParentNode,"@name").text "']")
top:=top?top:menus.ssn("//" mm.parentnode.nodename)
if top.xml
top.appendchild(mm.clonenode(1))
}
}
}
}
menus.add({path:"date",text:menusdate})
menus.save(1)
FileDelete,lib\temp.xml
}
if !FileExist("lib")
FileCreateDir,lib
FileGetTime,time,scilexer.dll,C
if (20140330120000>time)
FileDelete,scilexer.dll
FileInstall,scilexer.dll,scilexer.dll
FileInstall,lib\commands.xml,lib\commands.xml
if !(FileExist("lib\commands.xml")&&FileExist("scilexer.dll"))
SplashTextOn,,40,Downloading Required Files,Please Wait...
if (commands.ssn("//Date").text!=commandsdate)
FileDelete,lib\commands.xml
if !FileExist("lib\commands.xml")
FileAppend,% URLDownloadToVar("http://files.maestrith.com/alpha/Studio/commands.xml"),lib\commands.xml
if !FileExist("scilexer.dll")
URLDownloadToFile,http://files.maestrith.com/alpha/Studio/SciLexer.dll,SciLexer.dll
if !FileExist("AHKStudio.ico")
urldownloadtofile,http://files.maestrith.com/alpha/Studio/AHKStudio.ico,AHKStudio.ico
SplashTextOff
commands:=new xml("commands","lib\commands.xml")
}
Find_Nearest_Brace(){
sc:=csc()
line:=sc.2166(start:=sc.2008)
linestart:=sc.2128(line)
while,(linestart<start){
start--
current:=sc.2007(start)
if current in 41,125,93
start:=sc.2353(start)
if current in 40,123,91
{
sc.2351(start,sc.2353(start))
Break
}
}
}
find(){
static
file:=ssn(current(1),"@file").text
infopos:=positions.ssn("//*[@file='" file "']")
last:=ssn(infopos,"@search").text
hwfind:=setup(5)
search:=last?last:"Type in your query here"
ea:=settings.ea(settings.ssn("//search/find"))
for a,b in ["Edit,gfindcheck w500 vfind," search ,"TreeView,w500 h300 AltSubmit gstate","Checkbox,vregex,Regex Search","Checkbox,vgr x+10,Greed","Checkbox,xm vcs,Case Sensitive","Checkbox,vsort gfsort,Sort by Segment"]{
StringSplit,b,b,`,
Gui,5:Add,%b1%,%b2%,%b3%
b2:=b3:=""
}
Gui,5:Add,Button,gsearch Default,% " Search "
;snapshot(hwfind,4,{SysTreeView321:["w","h"],Button1:["y"],Button2:["y"],Button3:["y"],Button5:["y"],Button5:["y"],Edit1:["w"]})
Gui,5:Show
for a,b in ea
if b
GuiControl,,%a%,%b%
for a,b in xml.easyatt(settings.ssn("//search/find"))
GuiControl,5:,%a%,%b%
ControlSend,Edit1,^a,% hwnd([5])
return
findcheck:
ControlGetText,Button,Button5,% hwnd([5])
if (Button!="search")
ControlSetText,Button5,Search,% hwnd([5])
return
search:
ControlGetText,Button,Button5,% hwnd([5])
if (InStr(button,"search")){
Gui,5:Submit,Nohide
if !find
return
ff:="",ff.=gr?"":"U"
ff.=cs?"O)":"Oi)",refreshing:=1,foundinfo:=[]
main:=regex=0?"(.*)(\Q" find "\E)(.*)":"(" find ")"
f:=gr&&regex?ff "(" find ")":ff main
infopos.setattribute("search",find)
Gui,5:Default
GuiControl,5:-Redraw,SysTreeView321
list:=sn(current(1),"*/@file"),contents:=update("get").1,TV_Delete()
while,l:=list.item(A_Index-1){
out:=contents[l.text],found=1,r=0,fn:=l.text
SplitPath,fn,file
if !regex{
while,found:=RegExMatch(out,"`n" ff main,fo,found){
r:=sort&&A_Index=1?TV_Add(file):r
parent:=TV_Add(fo.value(),r)
foundinfo[parent]:={pos:fo.pos(2)-1,file:l.text,found:fo.len(2)}
found:=fo.pos(3)+StrLen(fo.value())
}
}
else
{
while,found:=RegExMatch(out,"`nOi)(.*" find ".*)",pof,found){
fff:=1,r:=sort&&A_Index=1?TV_Add(file):r
while,fff:=RegExMatch(pof.value(),ff main,fo,fff){
parent:=TV_Add(fo.value(1)" : "pof.value(),r)
foundinfo[parent]:={pos:found+fo.pos(1)-2,file:l.text,found:fo.len(1)}
fff:=fo.pos(1)+fo.len(1)
}
found+=pof.len(0)
}
}
}
if TV_GetCount()
ControlFocus,SysTreeView321
GuiControl,5:+Redraw,SysTreeView321
ControlSetText,Button5,Jump,% hwnd([5])
refreshing:=0
}
else if (Button="jump"){
Gui,5:Submit,Nohide
ea:=foundinfo[TV_GetSelection()]
sc:=csc()
tv(files.ssn("//*[@file='" ea.file "']/@tv").text)
Sleep,100
sc.2160(ea.pos,ea.pos+ea.found)
sc.2169
}
else
sel:=TV_GetSelection(),TV_Modify(sel,ec:=TV_Get(sel,"E")?"-Expand":"Expand")
state:
sel:=TV_GetSelection()
Gui,5:TreeView,SysTreeView321
if refreshing
return
ControlGetFocus,focus,% hwnd([5])
if !InStr(Focus,"SysTreeView321"){
ControlSetText,Button5,Search,% hwnd([5])
return
}
if TV_GetChild(sel)
ControlSetText,Button5,% TV_Get(sel,"E")?"Contract":"Expand",% hwnd([5])
else if TV_GetCount()
ControlSetText,Button5,Jump,% hwnd([5])
else
ControlSetText,Button5,Search,% hwnd([5])
return
sel:=TV_GetSelection()
if TV_GetChild(sel)
ControlSetText,Button5,% TV_Get(sel,"E")?"Contract":"Expand",% hwnd([5])
else
ControlSetText,Button5,Jump,% hwnd([5])
return
fsort:
ControlSetText,Button5,Search,% hwnd([5])
goto search
return
5GuiEscape:
5GuiClose:
Gui,5:Submit,NoHide
settings.add({path:"search/find",att:{regex:regex,cs:cs,sort:sort,gr:gr}}),foundinfo:=""
hwnd({rem:5})
return
}
fix_after(line){
return
fix_next:
SetTimer,fix_next,Off
sc:=csc()
line:=sc.2166(sc.2008)
indent:=sc.2127(line-1)
sc.2126(line,indent)
sc.2025(sc.2128(line))
return
}
fix_indent(sc=""){
critical
move_selected:
auto_delete:
if !sc
sc:=csc()
cpos:=sc.2008,begin:=cpos-sc.2128(sc.2166(cpos))
auto_indent:
fix_paste:
settimer,%A_ThisLabel%,off
next:=0,cpos:=0,indent:=0,add:=0
if !sc
sc:=csc()
sc.2078
lines:=sc.2154,pos:=0
text:=sc.gettext()
if !text
return
for a,b in strsplit(text,"`n","`n"){
b:=Trim(b),start:=0
if (SubStr(b,1,1)="(")
v.skip:=1
if (SubStr(b,0,1)=")"&&v.skip){
v.skip:=0
continue
}
if v.skip
continue
if InStr(b,";")
while,start:=RegExMatch(b,"\;",found,++start){
linestart:=sc.2128(a-1)
if (sc.2010(linestart+start-1)=1){
b:=Trim(SubStr(b,1,start-1))
break
}
}
add:=0
if (pos:=RegExMatch(lastb,"iUA)(\b(" v.indentregex ")(.+)?)\b",found)&&(SubStr(b,0,1)!="{")){
if InStr(v.color.indent,found)
add+=1
if (SubStr(lastb,0,1)="{")
add:=0
}
if (SubStr(b,1,1)="}"){
indent:=indent>0?indent-1:0
if (indent*5!=sc.2127(a-1))
sc.2126(a-1,indent*5)
}
if (SubStr(b,1,2)="*/"){
indent:=indent>0?indent-1:0
if (indent*5!=sc.2127(a-1))
sc.2126(a-1,indent*5)
}
if (SubStr(b,1,2)="/*"){
if (indent*5!=sc.2127(a-1))
sc.2126(a-1,indent*5)
indent++
}else if (SubStr(b,0,1)="{"){
if (indent*5!=sc.2127(a-1))
sc.2126(a-1,indent*5)
indent++
}else{
if (add){
prev:=sc.2127(a-2)
if (prev+5!=sc.2127(a-1))
sc.2126(a-1,prev+5)
}else if (indent*5!=sc.2127(a-1))
sc.2126(a-1,indent*5)
}
lastb:=b
}
if indent
ToolTip,Segment Open,0,0
else
t()
line:=sc.2166(sc.2008)
if (A_ThisLabel="auto_indent"){
begin:=A_ThisLabel="auto_indent"?sc.2128(line):begin+sc.2128(line)
sc.2160(begin,begin)
}
sc.2079
return
}
ftp_servers(){
setup(9)
Gui,Add,ListView,w300 h300,Server|Username|Password|Port
Gui,Add,Button,gnewserver,New Server
Gui,Add,Button,gdeleteserver,Delete Server
popftp()
Gui,Show,,FTP Server Settings
return
9GuiEscape:
9GuiClose:
hwnd({rem:9})
return
newserver:
InputBox,address,Server Address,Input the address of the server
if ErrorLevel
return
if settings.ssn("//ftp/server[@name='" name "']")
return m("Server Already Exists")
InputBox,username,Username,Username
if ErrorLevel
return
InputBox,password,Password,Password
if ErrorLevel
return
InputBox,port,Port,Port,,,,,,,,21
if ErrorLevel
return
settings.add({path:"ftp/server",att:{address:address,name:address,password:password,port:port,username:username},dup:1})
popftp()
return
deleteserver:
if !count:=LV_GetCount()
return
LV_GetText(server,count)
server:=settings.ssn("//ftp/server[@name='" server "']")
server.parentnode.removechild(server)
popftp()
return
}
popftp(){
servers:=settings.sn("//ftp/*"),LV_Delete()
while,ss:=servers.item[A_Index-1]{
ea:=settings.ea(ss)
LV_Add("",ea.address,ea.username,ea.password,ea.port)
}
Loop,4
LV_ModifyCol(A_Index,"AutoHDR")
}
full_backup(){
save(),sc:=csc()
SplashTextOn,300,100,Backing up...,Please wait, This may take some time if it has been a while since your last full backup.
cur:=ssn(current(1),"@file").Text
SplitPath,cur,,dir
backup:=dir "\backup\Full Backup" A_Now
FileCreateDir,%backup%
loop,%dir%\*.*
{
if InStr(a_loopfilename,".exe") || InStr(A_LoopFileName,".dll")
continue
filecopy,%A_LoopFileFullPath%,%backup%\%A_LoopFileName%
}
loop,%dir%\backup\*.*,2
if !InStr(A_LoopFileFullPath,"Full Backup")
fileremovedir,%a_loopfilefullpath%,1
SplashTextOff
}
get_access(){
if !access_token{
InputBox,access_token,This feature requires an access token from Github to use,Please enter your access token`nor press cancel to be taken to instructions on how to get an access token
if (ErrorLevel||access_token=""){
Run,http://www.autohotkey.com/board/topic/95515-ahk-11-create-a-gist-post/
Exit
}
settings.add({path:"access_token",text:access_token})
}
}
getpos(){
if !current(1).xml
return
sc:=csc(),current:=current(1)
fix:=positions.unique({path:"main",att:{file:ssn(current,"@file").text},check:"file"})
fix:=positions.unique({under:fix,path:"file",att:{start:sc.2008,end:sc.2009,scroll:sc.2152,file:ssn(current(),"@file").text},check:"file"})
fold:=0
while,sc.2618(fold)>=0,fold:=sc.2618(fold)
list.=fold ",",fold++
if list
fix.SetAttribute("fold",Trim(list,","))
else
fix.removeattribute("fold")
}
google_search_selected(){
sc:=csc(),text:=RegExReplace(sc.getseltext()," ","+")
if !text
return m("Select some text to search")
string:="http://www.google.com/search?q=" text
Run,%string%
}
gui(){
Gui,+Resize +hwndhwnd
hwnd(1,hwnd),ComObjError(0)
Hotkey,IfWinActive,% hwnd([1])
Hotkey,~Enter,checkqf,On
for a,b in ["+","!","^"]
Hotkey,%b%Enter,next,On
hotkeys([1],{"^v":"paste","bs":"backspace","Del":"backspace"})
hotkeys([1],{"+left":"+left","+right":"+right",left:"left","right":"right"})
OnMessage(5,"Resize")
SysGet,Border,33
SysGet,Caption,4
v.border:=border,v.caption:=caption
Gui,Menu,% menu("main")
new s(1,{main:1})
v.win2:=win2,v.win3:=win3
Gui,Add,StatusBar,hwndsb,StatusBar Info
SB_SetParts(400,400)
ControlGetPos,,,,h,,ahk_id%sb%
v.StatusBar:=h,v.sbhwnd:=sb
DetectHiddenWindows,On
rb:=new rebar(1,hwnd),v.rb:=rb
pos:=settings.ssn("//gui/position[@window='1']")
max:=ssn(pos,"@max").text?"Maximize":""
pos:=pos.text?pos.text:"w750 h500"
bar:=[],band:=[]
bar.10000:=[[4,"shell32.dll","Open","Open",10000,4],[8,"shell32.dll","Save","Save",10001,4],[137,"shell32.dll","Run","Run",10003,4],[249,"shell32.dll","Check_For_Update","Check For Update",10004,4],[100,"shell32.dll","New_Scintilla_Window","New Scintilla Window",10005,4],[271,"shell32.dll","Remove_Scintilla_Window","Remove Scintilla Window",10006,4]]
bar.10001:=[[110,"shell32.dll","open_folder","Open Folder",10000,4],[135,"shell32.dll","google_search_selected","Google Search Selected",10001,4],[261,"shell32.dll","Menu_Editor","Menu Editor",10003,4]]
bar.10002:=[[18,"shell32.dll","Connect","Connect",10000,4],[22,"shell32.dll","Run_Script","Debug Current Script",10001,4],[21,"shell32.dll","ListVars","List Variables",10002,4],[137,"shell32.dll","Run_Program","Run Program",10003,4],[27,"shell32.dll","stop","Stop",10004,4]]
;backward compatibility
if bardef:=settings.ssn("//toolbar/default"){
barvis:=settings.ssn("//toolbar/visible")
lbd:=sn(bardef,"*")
top:=settings.ssn("//toolbar")
while,ll:=lbd.item[A_Index-1]{
top.appendchild(ll)
lll:=sn(ll,"*")
while,llll:=lll.item[A_Index-1]{
vis:=ssn(barvis,"bar[@id='" ssn(ll,"@id").text "']/button[@id='" ssn(llll,"@id").text "']").xml?1:0
llll.setattribute("vis",vis)
}
}
for a,b in [bardef,barvis]
b.parentnode.removechild(b)
}
if bandvis:=settings.ssn("//rebar/visible"){
banddef:=settings.ssn("//rebar/default/bands")
lbd:=sn(bandvis,"*")
top:=settings.add({path:"rebar"})
while,ll:=lbd.item[A_Index-1]
ll.setattribute("vis",1),top.appendchild(ll)
for a,b in [banddef.parentnode,bandvis]
b.parentnode.removechild(b)
}
;/backward compatibility
for id,info in bar
for a,b in info{
if !top:=settings.ssn("//toolbar/bar[@id='" id "']")
top:=settings.add({path:"toolbar/bar",att:{id:id},dup:1})
if !button:=ssn(top,"button[@id='" b.5 "']")
button:=settings.under({under:top,node:"button"}),next:=1
if (next){
for a,c in {icon:b.1,file:b.2,func:b.3,text:b.4,id:b.5,state:b.6}
button.SetAttribute(a,c)
button.SetAttribute("vis",1),next:=0
}
if !settings.ssn("//rebar/band[@id='" id "']")
settings.add({path:"rebar/band",att:{id:id,vis:1},dup:1})
}
Gui,Add,Edit,w200 hwndedit
ControlGetPos,,,,h,,ahk_id%edit%
info:={hwnd:edit,ideal:220,id:11000,height:h,width:200,max:h}
band.11000:={label:"Quick Find",hwnd:info.hwnd,height:info.height,ideal:info.ideal,id:11000,max:info.max,int:1,width:150}
for a,b in band
if !settings.ssn("//rebar/band[@id='" a "']")
settings.add({path:"rebar/band",att:{id:a,width:150,vis:1},dup:1})
toolbars:=settings.sn("//toolbar/bar")
while,bb:=toolbars.item[A_Index-1]{
buttons:=sn(bb,"*")
tb:=new toolbar(1,hwnd,ssn(bb,"@id").text)
while,button:=buttons.item[A_Index-1]{
ea:=settings.ea(button)
tb.add(ea)
}
}
visible:=settings.sn("//toolbar/*/*[@vis='1']")
while,vis:=Visible.item[A_Index-1]{
tb:=toolbar.list[ssn(vis.parentnode,"@id").text]
tb.addbutton(ssn(vis,"@id").text)
}
bands:=settings.sn("//rebar/*[@vis='1']")
while,bb:=bands.item[A_Index-1]{
if (bb.nodename="newline"){
newline:=1
continue
}
ea:=settings.ea(bb)
if band[ea.id]
ea:=band[ea.id]
if !ea.width
ea.width:=toolbar.list[ea.id].barinfo().ideal+20
rb.add(ea,newline),newline:=0
}
msg:=["What do you think?`r`nRight Click a `r`nToolbar to customize it`r`nControl+Click a toolbar icon to change the icon","I like it"]
for a,b in s.main
b.2242(0,20),b.2242(1,0),b.2181(0,msg[A_Index])
open:=settings.sn("//open/*")
Gui,1:Add,TreeView,Background0 c0xAAAAAA AltSubmit gtv hwndtv
hwnd(100,tv),refreshthemes()
debug(0)
Gui,1:Show,%pos% %max%,AHK Studio
while,oo:=open.item[A_Index-1]
if FileExist(oo.text)
open(oo.text),last:=oo.text
else{
rem:=settings.sn("//file[text()='" oo.text "']")
while,rr:=rem.item[A_Index-1]
rr.ParentNode.RemoveChild(rr)
}
last:=settings.sn("//last/*")
for a,b in s.main{
tv:=files.ssn("//file[@file='" last.item[a-1].text "']/@tv").text
if (A_Index=1){
bstv:=tv
}
csc({hwnd:b.sc})
tv(tv)
}
if !last.length
new(1)
Resize()
WinSet,Redraw,,% hwnd([1])
if v.tv
tv(v.tv),m(v.tv)
csc("Scintilla1")
TV_Modify(bstv,"Select Vis Focus")
bracesetup(),options(),traymenu()
}
Default(){
m("You clicked a button")
}
newwin(info){
DetectHiddenWindows,On
Gui,%info%:Default
Gui,+hwndnewwin
hwnd(info,newwin)
Gui,Margin,0,0
Gui,Add,edit,y0 y2 w100 gqf
case:=settings.ssn("//Quick_Search/@case").text?"Checked":""
regex:=settings.ssn("//Quick_Search/@regex").text?"Checked":""
greed:=settings.ssn("//Quick_Search/@greed").text?"Checked":""
Gui,Add,Checkbox,xm gcase %case%,Case
Gui,Add,Checkbox,gregex %regex%,Regex
Gui,Add,Checkbox,x+5 gcase %greed%,Greed
Gui,Add,Button,xm gnext,Next
Gui,Add,Button,x+5 gsetselection,Set Search Area
Gui,-Caption
Gui,%info%:+parent1
Gui,Show,NA AutoSize
WinGetPos,,,w,h,% "ahk_id" newwin
return {h:h,w:w,hwnd:newwin}
}
help(){
help=
(
Quick Search:
Pressing Escape while using the Quick Search bar will return you to the main window
Toolbars:
Right Click on a toolbar to change the buttons that appear in them.
Shift+Drag buttons to re-arange them without using the Right Click option.
Control+Click a button to change its icon.
Alt+Click anywhere on a Toolbar to add a button
Control+Right Click to delete a button (can not be undone).
Menu:
Edit/Menu Editor allows you to change the way that the menus are arranged.
Auto Indent:
Full Auto will adjust the indent of your script whenever you add a {, }, or press the enter key.
Fix Next Line will just fix the next line adjusting for {, }, if statements, and a few others.
Edit/Fix Indent will fix the indentation of your document as though you had on Full Auto.
)
setup(11)
Gui,Margin,0,0
sc:=new s(11,{pos:"x0 y0 w800 h500"}),csc({hwnd:sc})
Gui,Show,,AHK Studio Help
sc.2181(0,help),sc.2025(0),hotkeys([11],{"Esc":"11GuiClose"})
return
11GuiClose:
hwnd({rem:11}),csc({hwnd:s.main.1})
return
}
hotkeys(win,item=""){
for a,b in item{
key:=a,label:=clean(b)
if IsFunc(label)
launch:="function"
if IsLabel(label)
launch:=clean(label)
if !(launch&&key)
return
for a,b in win{
Hotkey,IfWinActive,% hwnd([b])
Hotkey,%key%,%launch%,On
}
}
return
hotkey:
ControlFocus,Edit1,% hwnd([1])
return
function:
key:=menus.ssn("//*[@hotkey='" A_ThisHotkey "']")
func:=clean(ssn(key,"@name").text)
%func%()
return
}
hwnd(win,hwnd=""){
static window:=[]
if win=get
return window
if (win.rem){
Gui,1:-Disabled
Gui,% win.rem ":Destroy"
Gui,1:Default
window.remove[win.rem]
}
if IsObject(win)
return "ahk_id" window[win.1]
if !hwnd
return window[win]
window[win]:=hwnd
}
class icon_browser{
static start:="",window:=[],keep:=[]
__New(info){
win=85
Gui,%win%:Destroy
Gui,%win%:Default
Gui,Add,ListView,w700 h500 hwndlv gselect AltSubmit,Icons
Gui,Add,Button,gibprev,Previous 50 Icons
Gui,Add,Button,x+10 gibnext,Next 50 Icons
Gui,Add,Button,xm gloadfile,Load File
Gui,Add,Button,x+10 gloaddefault,Load Default Icons
Gui,Show,,Icon Browser
this.file:=info.1.file?info.1.file:"shell32.dll"
this.file:=InStr(this.file,".ahk")?A_AhkPath:this.file
GuiControl,+Icon,%lv%
this.create()
LV_SetImageList(this.il)
loop,50
LV_Add("Icon" IL_Add(this.il,this.file,A_Index),A_Index)
this.start:=50
window[win]:=1
this.win:=win
this.keep[1]:=this
this.id:=info.2,this.ahkid:=info.3,this.tb:=info.4
return
85GuiEscape:
Gui,85:Destroy
return
loaddefault:
this:=icon_browser.keep[1]
this.file:="shell32.dll"
this.start:=0
this.next()
return
}
select(num:=""){
Select:
if A_GuiEvent!=Normal
return
this:=icon_browser.keep[1]
LV_GetText(number,LV_GetNext())
number:=num="image"?0:number
NumPut(VarSetCapacity(button,32),button,0)
NumPut(0x1|0x20,button,4)
NumPut(this.id,button,8)
num:=this.tb.iconlist[this.file,number]!=""?this.tb.iconlist[this.file,number]:IL_Add(this.tb.imagelist,this.file,number)-1
this.tb.iconlist[this.file,number]:=num
NumPut(num,button,12)
SendMessage,0x400+64,% this.id,&button,,% this.ahkid
this.tb.id
btn:=settings.ssn("//toolbar/bar[@id='" this.tb.id "']/button[@id='" this.id "']")
btn.setattribute("icon",number-1),btn.setattribute("file",this.file)
return
}
load(){
loadfile:
this:=icon_browser.keep[1]
FileSelectFile,filename,,,,*.exe;*.dll;*.png;*.jpg;*.gif;*.bmp
if ErrorLevel
return
this.file:=filename
if filename contains .gif,.jpg,.png,.bmp
return this.select("image")
this.start:=0
this.next()
return
}
exit(){
for win in icon_browser.window
Gui,%win%:Destroy
}
create(){
this.il:=IL_Create(50,10,1)
}
next(){
ibnext:
ibprev:
this:=icon_browser.keep[1]
if (A_ThisLabel="ibprev"&&this.start>=50)
this.start:=this.start-100>=0?this.start-100:this.start-50
start:=this.start
LV_Delete()
GuiControl,85:-Redraw,SysListView321
this.create()
LV_SetImageList(this.il)
loop,50
LV_Add("Icon" IL_Add(this.il,this.file,A_Index+this.start),A_Index+this.start)
this.start+=50
GuiControl,85:+Redraw,SysListView321
return
}
}
json(info,filename){
if !RegExReplace(info,"\s"){
info="%filename%":{"content":";blank file"}
return info
}
if InStr(info,Chr(59) "auto_version")
info:=RegExReplace(info,Chr(59) "auto_version","Version=" newver)
for a,b in [["\","\\"],[Chr(34),"\" Chr(34)],["`n","\n"],["`t","\t"],["`r",""]]
StringReplace,info,info,% b.1,% b.2,All
next="%filename%":{"content":"%info%"}
return next
}
jump_to_project(){
projects:=files.sn("//main"),setup(15),hotkeys([15],{up:"jtpup",down:"jtpdown"})
Gui,Add,Edit,w500 gjtp
Gui,Add,ListView,w500 h400 -Multi,Projects
Gui,Add,Button,gjtp Default,Jump
while,pro:=projects.item[A_Index-1]
LV_Add("",ssn(pro,"@file").text)
LV_Modify(1,"Select Vis Focus")
Gui,Show,,Jump To Project
Return
15GuiClose:
15GuiEscape:
hwnd({rem:15})
Return
jtp:
if !LV_GetNext()
Return
LV_GetText(project,LV_GetNext())
tv:=files.ssn("//file[@file='" project "']..")
tv:=ssn(tv,"@last").text?ssn(tv,"file[@file='" ssn(tv,"@last").text "']/@tv").text:files.ssn("//file[@file='" project "']/@tv").text
tv(tv)
Return
jtpup:
jtpdown:
lv_select(15,add:=A_ThisLabel="jtpup"?-1:1)
Return
}
Jump_to_Segment(){
static list:=[]
setup(4),hotkeys([4],{up:"jtsup",down:"jtsdown"})
Gui,Add,edit,w200 gsortjts,Enter text here
Gui,Add,ListView,w200 h400 -Multi,Files
Gui,Add,Button,gjump Default,Jump to Segment
Gui,Show,,Jump To Segment
sc:=csc(),list:=[]
file:=files.sn("//*[@sc='" sc.2357 "']../file/@filename")
while,ff:=file.item[A_Index-1].text
LV_Add("",ff),list[ff]:=1
LV_Modify(1,"Select Vis Focus")
return
4GuiEscape:
hwnd({rem:4})
return
sortjts:
GuiControl,4:-Redraw,SysListView321
LV_Delete()
ControlGetText,find,Edit1,% hwnd([4])
for a in list
if InStr(a,find)
LV_Add("",a)
GuiControl,4:+Redraw,SysListView321
LV_Modify(1,"Select Vis Focus")
return
jtsup:
jtsdown:
return lv_select(4,A_ThisLabel="jtsup"?-1:1)
jump:
Gui,4:Default
LV_GetText(file,LV_GetNext()),sc:=csc()
file:=files.ssn("//*[@sc='" sc.2357 "']../file[@filename='" file "']")
tv(ssn(file,"@tv").text)
hwnd({rem:4})
csc().2400
return
}
keywords(){
v.keywords:=[],v.kw:=[],v.custom:=[],v.kk:=[],var:=[]
colors:=commands.sn("//Color/*")
while,color:=colors.item[A_Index-1]{
text:=color.text
all.=text " "
stringlower,text,text
v.color[color.nodename]:=text
}
personal:=settings.ssn("//Variables").text
all.=personal
StringLower,per,personal
v.color.Personal:=Trim(per)
v.indentregex:=RegExReplace(v.color.indent," ","|")
command:=commands.ssn("//Commands/Commands").text
Loop,Parse,command,%A_Space%,%A_Space%
v.kw[A_LoopField]:=A_LoopField,all.=" " A_LoopField
Sort,All,UD%A_Space%
Loop,Parse,all,%a_space%
v.keywords[SubStr(A_LoopField,1,1)].=A_LoopField " "
return
}
lastfiles(){
rem:=settings.ssn("//last"),rem.ParentNode.RemoveChild(rem)
for a,b in s.main{
file:=files.ssn("//*[@sc='" b.2357 "']/@file").text
if file
settings.add({path:"last/file",text:file,dup:1})
}
}
LV_Select(win,add){
Gui,%win%:Default
next:=LV_GetNext()+Add
LV_Modify(next>0&&next<=LV_GetCount()?next:LV_GetNext(),"Select Vis Focus")
}
marginwidth(sc=""){
sc:=sc?sc:sc:=v.sc
sc.2242(0,sc.2276(32,"a" sc.2154))
}
menu_editor(x=0){
static hwnd
main:="main"
if !x{
Gui,2:destroy
Gui,2:+hwndhwnd +Owner1
setup(2)
Gui,2:Add,Text,,Control+UP/DOWN/LEFT/RIGHT will move items
hotkeys([2],{"Del":"deletenode"})
Hotkey,^up,moveup,On
Hotkey,^down,movedown,On
Hotkey,^left,moveover,On
Hotkey,^right,moveunder,On
Gui,2:Add,TreeView,w500 h400 hwndhwnd
Gui,2:Add,Button,gaddmenu,Add A New Menu
Gui,2:Add,Button,gmenudefault,Re-Load Defaults
Gui,2:Add,Button,gchangeitem,Change Item
Gui,2:Add,Button,gedithotkey Default,Edit Hotkey
Gui,2:Add,Button,gaddsep,Add Separator
Gui,2:Show,,Menu Editor
}
Gui,2:Default
list:=menus.sn("//main/descendant::*")
root:=0
GuiControl,2:-Redraw,SysTreeView321
del:=[],next:=0
TV_Delete()
while,ll:=list.item[A_Index-1]{
hotkey:=ssn(ll,"@hotkey").text
hot:=convert_hotkey(hotkey)
hot:=hot?" - Hotkey = " hot:""
hotkey:=hotkey?"`t" convert_hotkey(hotkey):""
parent:=ssn(ll.ParentNode,"@tv").text?ssn(ll.ParentNode,"@tv").text:0
root:=TV_Add(ssn(ll,"@name").text hot,parent)
ll.SetAttribute("tv",root)
deletelist.Insert(clean(ssn(ll,"@name").text))
if ssn(ll,"@last").text
count:=A_Index
}
while,ll:=list.item[A_Index-1]
TV_Modify(ssn(ll,"@tv").text,"Expand")
if !x{
while,ll:=list.item[A_Index-1]{
menu:=ssn(ll,"@name").text,parent:=ssn(ll.ParentNode,"@name").text
parent:=parent?parent:main
Menu,% clean(Parent),Delete,% ssn(ll,"@name").text
Menu,% clean(parent),DeleteAll
}
}
tv:=menus.ssn("//*[@last]")
if tv
TV_Modify(ssn(tv,"@tv").text,"Select"),tv.removeattribute("last")
top:=count>10?count-10:0
tv:=ssn(list.item[top],"@tv").text
TV_Modify(tv,"VisFirst")
GuiControl,2:+Redraw,SysTreeView321
ControlFocus,SysTreeView321,% hwnd([2])
return
menudefault:
SplashTextOn,,40,Downloading Required Files,Please Wait...
menus.xml.save("lib\menusbackup " a_now ".xml")
URLDownloadToFile,http://files.maestrith.com/alpha/Studio/menus.xml,lib\temp.xml
FileRead,menu,lib\temp.xml
menus.xml.loadxml(menu)
menus.save(1)
SplashTextOff
menu_editor(1)
return
2GuiEscape:
2GuiClose:
hwnd({rem:2})
list:=menus.sn("//main/descendant::*")
while,rem:=list.item[A_Index-1]
rem.removeattribute("tv")
menus.save(1)
all:=menus.sn("//*")
main:="main"
Gui,1:Menu
while,aa:=all.item[A_Index-1]{
menu:=ssn(aa,"@name").text,parent:=ssn(aa.ParentNode,"@name").text
parent:=parent?parent:"main"
Menu,% clean(Parent),Delete,% ssn(aa,"@name").text
}
Menu,main,Delete
Gui,1:Menu,% menu("main")
return
addmenu:
Gui,2:Default
top:=menus.ssn("//*[@tv='" TV_GetSelection() "']")
InputBox,newname,New Menu Item,Enter a new name (`&File for &File)
if ErrorLevel
return
if (ssn(top,"@menu").text="")
main:=top.ParentNode
new:=menus.under({under:main,node:"menu",att:{name:newname,last:1}})
main.insertbefore(new,top)
under.insertbefore(above,move)
menu_editor(1)
return
moveup:
Gui,2:Default
if prev:=TV_GetPrev(TV_GetSelection()){
move:=menus.ssn("//*[@tv='" TV_GetSelection() "']")
above:=menus.ssn("//*[@tv='" prev "']")
move.SetAttribute("last",1)
under:=move.parentnode
under.insertbefore(move,above)
menu_editor(1)
}
return
movedown:
Gui,2:Default
if next:=TV_GetNext(TV_GetSelection()){
move:=menus.ssn("//*[@tv='" TV_GetSelection() "']")
above:=menus.ssn("//*[@tv='" next "']")
move.SetAttribute("last",1)
under:=move.parentnode
under.insertbefore(above,move)
menu_editor(1)
}
return
deletenode:
Gui,2:Default
top:=menus.ssn("//*[@tv='" TV_GetSelection() "']")
top.ParentNode.RemoveChild(top)
TV_Delete(TV_GetSelection())
return
moveunder:
Gui,2:Default
top:=menus.ssn("//*[@tv='" TV_GetSelection() "']")
if top.nextsibling.xml{
under:=top.nextsibling.childnodes
if under.length
top.SetAttribute("last",1),top.nextsibling.insertbefore(top,under.item[0])
else
top.SetAttribute("last",1),top.nextsibling.appendchild(top)
menu_editor(1)
}
return
moveover:
Gui,2:Default
if !TV_GetParent(TV_GetSelection())
return
top:=menus.ssn("//*[@tv='" TV_GetSelection() "']")
if (ssn(top.ParentNode,"@name").text!=""&&top.ParentNode.ParentNode.xml)
before:=top.ParentNode,top.SetAttribute("last",1),top.ParentNode.ParentNode.insertbefore(top,before)
menu_editor(1)
return
changeitem:
Gui,2:Default
current:=TV_GetSelection()
item:=menus.ssn("//*[@tv='" current "']")
item.setattribute("last",1)
InputBox,newitem,Change Menu Name,Input a new name,,,,,,,,% ssn(item,"@name").text
if ErrorLevel
return
menus.ssn("//*[@tv='" current "']/@name").text:=newitem
menu_editor(1)
return
edithotkey:
changehotkey()
return
98GuiEscape:
hwnd({rem:98})
WinActivate,% hwnd([2])
menu_editor(1)
return
addsep:
Gui,2:Default
top:=menus.ssn("//*[@tv='" TV_GetSelection() "']")
main:=top.ParentNode
new:=menus.under({under:main,node:"separator",att:{name:"-------",last:1}})
main.insertbefore(new,top)
main.insertbefore(top,new)
menu_editor(1)
return
}
changehotkey(){
static hk,hotkey
Gui,2:Default
hotkey:=menus.ssn("//*[@tv='" TV_GetSelection() "']")
setup(98,1)
Gui,Add,Hotkey,gehk vhk,% ssn(Hotkey,"@hotkey").text
Gui,Show,,Hotkey
return
ehk:
Gui,98:Submit,NoHide
Hotkey.setattribute("hotkey",hk),Hotkey.setattribute("last",1)
return
}
menu(menuname){
menu:=menus.sn("//" menuname "/descendant::*")
list:=[]
Menu,main,UseErrorLevel,On
while,mm:=menu.item[A_Index-1]{
if !ssn(mm,"@clean")
mm.SetAttribute("clean",clean(ssn(mm,"@name").text))
if IsLabel(clean(ssn(mm,"@name").text))
route:=clean(ssn(mm,"@name").text)
else
route:="menuroute"
if hotkey:=ssn(mm,"@hotkey").text{
ea:=xml.ea(mm),key:=[]
key[ea.hotkey]:=ea.name
Hotkeys([1,3],key)
}
hotkey:=hotkey?"`t" convert_hotkey(hotkey):""
if mm.childnodes.length>0
list.Insert({menu:ssn(mm,"@name").text,under:clean(ssn(mm.ParentNode,"@name").Text)})
else if !clean(ssn(mm.ParentNode,"@name").text){
list.Insert({top:ssn(mm,"@name").text,route:route})
continue
}else{
name:=clean(ssn(mm.ParentNode,"@name").text)
if (mm.nodename="separator"){
Menu,%name%,Add
continue
}
Menu,%name%,Add,% ssn(mm,"@name").text hotkey,%route%
if value:=settings.ssn("//*/@" clean(ssn(mm,"@name").text)).text{
Menu,% name,Check,% ssn(mm,"@name").text hotkey
v.options[clean(ssn(mm,"@name").text)]:=value
}
}
}
for a,b in list{
if b.top{
Menu,%menuname%,Add,% b.top,% b.route
continue
}
b.under:=b.under?b.under:menuname
Menu,% b.under,Add,% b.menu,% ":" clean(b.menu)
}
return menuname
menuroute:
item:=clean(A_ThisMenuItem)
%item%()
return
show:
WinActivate,% hwnd([1])
return
}
move_selected_lines_up(){
csc().2620
if (v.options.full_auto){
SetTimer,move_selected,20
Sleep,50
}
}
move_selected_lines_down(){
csc().2621
if (v.options.full_auto){
SetTimer,move_selected,20
Sleep,50
}
}
Msgbox_Creator(){
static
msgbox:=setup(17)
Gui,Add,Text,Section hwndheight,Title:
h:=cgp(height).h*1.25
Gui,Add,Edit,w320
Gui,Add,Text,,Text:
Gui,Add,Edit,w320 hwndedit
pos:=cgp(edit)
Gui,Add,GroupBox,% "x" pos.x " y" pos.y+pos.h+10 " w320 R8 hwndgb Section",Buttons and Icons
Gui,Add,Radio,xs+10 ys+%h% Checked,OK
list=OK/Cancel,Abort/Retry/Ignore,Yes/No/Cancel,Yes/No,Retry/Cancel,Cancel/Try Again/Continue
Loop,Parse,list,`,
Gui,Add,Radio,hwndlast,%A_LoopField%
Gui,Add,Checkbox,,Help
pos:=cgp(last),nx:=pos.x+pos.w+20
for a,b in [4,3,2,5]
if A_Index=1
Gui,Add,Picture,x%nx% ys+%h% Icon4 Section,%A_WinDir%\system32\user32.dll
else
Gui,Add,Picture,Icon%b% ,%A_WinDir%\system32\user32.dll
color:=RGB(settings.ssn("//font[@style='5']/@background").text)
Gui,Color,%color%,%color%
Gui,Add,Radio,y+10 Checked vicon1,No Icon
Gui,Add,Radio,ys+8 xs+40 section vicon2
Gui,Add,Radio,ys+40 section xs vicon3
Gui,Add,Radio,ys+40 section xs vicon4
Gui,Add,Radio,ys+40 xs vicon5
Gui,Add,GroupBox,ym x340 R4 Section hwndgb1,Modal
Gui,Add,Radio,xs+10 ys+%h% Checked,Normal
Gui,Add,Radio,,Task Modal
Gui,Add,Radio,,Always On Top
Gui,Add,Radio,,System Modal
pos:=cgp(gb1)
Gui,Add,GroupBox,% "x" pos.x " y" pos.y+pos.h " R1 hwndgb2 Section",Default Button
Gui,Add,Radio,xs+10 ys+%h% Checked,1st
Gui,Add,Radio,x+10,2nd
Gui,Add,Radio,x+10,3rd
pos:=cgp(gb2)
Gui,Add,GroupBox,% "x" pos.x " y" pos.y+pos.h " R1 hwndgb3 Section",Alignment
Gui,Add,Checkbox,xs+10 ys+%h%,Right
Gui,Add,Checkbox,x+10,Reverse
pos:=cgp(gb3)
Gui,Add,GroupBox,% "x" pos.x " y" pos.y+pos.h " R3 hwndgb4 Section",Timeout and Insert
Gui,Add,Text,xs+10 ys+%h% Section,Timeout:
Gui,Add,Edit,w50 x+5 number
Gui,Add,Button,x+5 hwndthird gmbcopy,Copy
Gui,Add,Button,xs gmbtest Default,Test
Gui,Add,Button,x+5 gmbinsert,Insert
Gui,Add,Button,x+5 gmbreset,Reset
pos:=cgp(third),pos1:=cgp(gb1),w:=pos.x+pos.w+10-pos1.x
Loop,4
{
con:=gb%A_Index%
ControlMove,,,,%w%,,ahk_id%con%
}
Gui,Show,AutoSize,Msgbox Creator
return
mbcopy:
Clipboard:=compilebox(msgbox)
MsgBox,0,Complete,Text coppied to the clipboard,.5
return
mbreset:
Loop,3
ControlSetText,Edit%A_Index%,,% hwnd([17])
for a,b in {2:1,10:1,16:1,21:1,9:0,25:0,26:0}
GuiControl,17:,Button%a%,%b%
return
mbinsert:
sc:=csc(),sc.2003(sc.2008,compilebox(msgbox))
return
17GuiEscape:
17GuiClose:
hwnd({rem:17})
return
mbtest:
dynarun(compilebox(msgbox))
return
}
cgp(Control){
SysGet,Border,7
SysGet,Caption,4
pos:=[]
ControlGetPos,x,y,w,h,,ahk_id%control%
return pos:={x:x-border,y:y-Border-Caption,w:w,h:h}
}
compilebox(win){
static list:={2:0,3:1,4:2,5:3,6:4,7:5,8:6,9:16384,11:16,12:32,13:48
,14:64,17:8192,18:262144,19:4096,22:256,23:512,25:524288,26:1048576}
total=0
for a,b in ["Edit1","Edit2","Edit3"]
ControlGetText,edit%a%,Edit%a%,ahk_id%win%
for a,b in list{
ControlGet,value,Checked,,Button%a%
if value
total+=b
}
edit1:=edit1?edit1:"Testing"
msg=MsgBox,%total%,%edit1%,%edit2%
msg.=edit3?"," edit3:""
return msg
}
m(x*){
for a,b in x
list.=b "`n"
MsgBox,,AHK Studio,% list
}
t(x*){
for a,b in x
list.=b "`n"
Tooltip,% list
}
Post_Multiple_Segment_Gist(){
get_access()
ea:=xml.ea(vversion.ssn("//*[@file='" ssn(current(1),"@file").text "']")),newver:=ea.version "." ea.increment
fi:=sn(current(1),"file/@file"),file:=ssn(current(1),"@file").text
id:=positions.ssn("//main[@file='" file "']/@multiple_id").text
url:="https://api.github.com/gists"
if id
id:=check_id(id)
SplitPath,file,filename
desc=Posted using AHK Studio
json={"description":"%desc%","public":true,"files":
json.="{"
udf:=update("get").1
while,f:=fi.item(A_Index-1).text{
SplitPath,f,filename
info:=udf[f]
if a_index=1
info.=compile_main_gist(f)
json.=json(info,filename)
if (fi.length!=A_Index)
json.=","
}
StringTrimRight,json,json,1
json.="}}"
http:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
if id
http.Open("PATCH",url "/" id)
else
http.Open("POST",url)
http.SetRequestHeader("Authorization","Bearer " access_token)
SplashTextOn,,50,Updating Gist,Please wait...
http.send(json)
codes:=http.ResponseText
for a,b in ["html_url","id"]{
split=":"
RegExMatch(codes,"U)" b split "(.*)" chr(34),found)
if b=html_url
clipboard:=RegExReplace(found1,"\\")
else
id:=found1
}
SplashTextOff
if id{
positions.unique({path:"main",att:{file:file,multiple_id:id},check:"file"})
m("URL Coppied to clipboard")
}
else
m("Something went wrong. Here is what the server sent back","","",codes,http.GetAllResponseHeaders())
}
new_segment(new="",text=""){
cur:=ssn(current(1),"@file").Text
SplitPath,cur,,dir,,func
if !new
{
FileSelectFile,new,s,%dir%\,Create a new Segment,*.ahk
if ErrorLevel
return
SplitPath,new,filename,dir,,func
new:=InStr(new,".ahk")?new:new ".ahk"
}
if node:=ssn(current(1),"file[@file='" new "']")
return tv(ssn(node,"@tv").Text)
SplitPath,new,file,newdir,,function
incfile:=(newdir=dir)?file:new
top:=TV_Add(file,ssn(current(1),"file/@tv").text),func:=clean(func)
select:=files.under({node:"file",att:{file:new,filename:file,include:Chr(35) "Include " incfile,tv:top},under:current(1)})
mainfile:=ssn(current(1),"@file").text
main:=update({get:mainfile}),main.="`n#Include " new
update({file:mainfile,text:main})
current(1).firstchild.removeattribute("sc")
if (text=""){
MsgBox,36,Insert Function?,Add a new function named %func% to the new Segment?
IfMsgBox,Yes
text:=func "(){`r`n`r`n}"
}
update({file:new,text:text})
update({edited:cur}),update({edited:new})
;future add a way to add stuff to the new file
tv(top)
}
new(filename=""){
if (filename=1){
index:=0
if !FileExist(A_WorkingDir "\Projects")
FileCreateDir,% A_WorkingDir "\Projects"
if !FileExist(A_WorkingDir "\Projects\Untitled")
FileCreateDir,% A_WorkingDir "\Projects\Untitled"
while,FileExist(A_WorkingDir "\Projects\Untitled\Untitled" A_Index)
index:=A_Index
index++
FileCreateDir,% A_WorkingDir "\Projects\Untitled\Untitled" index
filename:=A_WorkingDir "\Projects\Untitled\Untitled" index "\Untitled.ahk"
FileAppend,`;New File,%filename%
}else if (filename=""){
FileSelectFile,filename,S,,Create A New Project,*.ahk
if ErrorLevel
return
filename:=InStr(filename,".ahk")?filename:filename ".ahk"
FileAppend,`;New File,%filename%
}
Gui,1:Default
Gui,1:TreeView,SysTreeView321
root:=open(filename,1)
TV_Modify(root,"Select Vis Focus")
}
New_Scintilla_Window(file=""){
sc:=csc()
doc:=sc.2357
sc:=new s(1,{main:1,hide:1})
csc(sc)
if file{
newdoc:=files.ssn("//*[@file='" file "']")
m(newdoc.xml)
}else{
sc.2358(0,doc)
}
Resize()
sc.show()
}
Remove_Scintilla_Window(){
sc:=csc()
s.delete(sc)
}
Next_Found(){
sc:=csc()
sc.2606
sc.2169
}
notify(csc=""){
notify:
static last,painted:=0
if A_EventInfo=512
return csc(1)
sc:=csc?csc:csc()
csc:=""
if sc.sc!=NumGet(A_EventInfo){
if (sc.2353(sc.2008-1)>0){
sc.2351(sc.2008-1,sc.2353(sc.2008-1)),v.highlight:=1
}else if (sc.2353(sc.2008)>0){
sc.2351(sc.2008,sc.2353(sc.2008)),v.highlight:=1
}else if v.highlight{
sc.2351(-1,-1),v.highlight:=0
}
text:="Line:" sc.2166(sc.2008)+1 " Column:" sc.2129(sc.2008)
width:=sc.2276(32,"a")
SB_SetText(text)
SB_SetParts(width*StrLen(text "1"),last)
first:=width*StrLen(text "1")
}
fn:=[ ],info:=A_EventInfo
;,2:"id",4:"position",5:"ch",6:"modifiers",7:"modType",8:"text",9:"length",10:"linesAdded",11:"macMessage",12:"macwParam",13:"maclParam",14:"line",15:"foldLevelNow",16:"foldLevelPrev",17:"margin",18:"listType",19:"x",20:"y",21:"token",22:"annotLinesAdded",23:"updated"}
for a,b in {0:"Obj",2:"Code",3:"position",4:"ch",5:"mod",6:"modType",7:"text",8:"length",9:"linesadded",10:"msg",11:"wparam",12:"lparam",13:"line",14:"fold",22:"updated"}
fn[b]:=NumGet(Info+(A_PtrSize*a))
cpos:=sc.2008
if (fn.code=2022){
actext:=StrGet(fn.text,"cp0")
selcount:=sc.2570
Loop,%selcount%
{
b:=sc.2577(A_Index-1),start:=sc.2266(b,1),text:=sc.textrange(start,b)
if !InStr(actext,text){
b:=sc.2577(A_Index-1),sc.2003(b,actext)
}else{
b:=sc.2579(A_Index-1)
if (l:=commands.ssn("//Context/*/*[text()='" RegExReplace(actext,"#") "']/@list").text){
if !v.lastbrace
v.word:=actext,actext:=actext ","
}
sc.2190(start),sc.2192(b),sc.2194(StrLen(actext),actext)
b:=sc.2579(A_Index-1),sc.2578(A_Index-1,b+StrLen(actext)),sc.2576(A_Index-1,b+StrLen(actext))
}
}
sc.2101
if !v.lastbrace
SetTimer,automenu,10
v.lastbrace:=""
}
;if (fn.code=2027)
;switch this out with 2027 and use GetKeyState("Control","P") and stuff
if (fn.code=2019){
v.style:={style:sc.2010(fn.position),mod:fn.mod}
if fn.mod=0
SetTimer,styleclick,1
if fn.mod=2
SetTimer,editfont,1
if fn.mod=4
SetTimer,editback,1
}
if (fn.code=2008){
if ((fn.modtype&0x01)||(fn.modtype&0x02)){
update({sc:sc.2357})
v.word:=sc.textrange(sc.2266(cpos,1),sc.2267(cpos,1))
}
if fn.linesadded
marginwidth(sc)
if (sc.sc=v.codevault.sc){
LV_GetText(code,LV_GetNext())
if !locker:=vault.ssn("//code[@name='" code "']")
locker:=vault.Add({path:"code",att:{name:code},dup:1})
locker.text:=sc.gettext()
}
}
if (fn.code=2004&&sc.sc=v.codevault.sc){
m("Please create or select a code snippet")
}
if (fn.code=2001){
if ((fn.ch=10||fn.ch=123||fn.ch=125)&&v.options.full_auto&&sc.2102=0){
if fn.ch=10
SetTimer,auto_indent,50
else
SetTimer,auto_delete,250
}else if (fn.ch=10&&v.options.fix_next_line){
SetTimer,fix_next,50
}
cpos:=sc.2008,start:=sc.2266(cpos,1),end:=sc.2267(cpos,1),word:=sc.textrange(sc.2266(cpos,1),cpos)
if (StrLen(word)>1&&sc.2102=0){
list:=Trim(v.keywords[SubStr(word,1,1)])
if list&&instr(list,word)
sc.2100(StrLen(word),list)
}
style:=sc.2010(sc.2008-2)
settimer,context,150
c:=fn.ch
lll=44,32
if c in %lll%
replace()
}
if (fn.code=2010){
margin:=NumGet(info+64)
if margin=0
return theme({margin:margin,mod:fn.mod})
scpos:=NumGet(info+12)
modifier:=NumGet(info+20)
if margin=2
sc.2231(sc.2166(scpos))
}
if (fn.code=2001){
width:=sc.2276(32,"aaa")
text1:="Last Entered Character: " Chr(fn.ch) " Code:" fn.ch
SB_SetText(text1,2),SB_SetParts(first,width*StrLen(text1 1),40)
last:=width*StrLen(text1 1)
}
if (fn.code=2007){
if (sc.2353(sc.2008-1)>0){
sc.2351(sc.2008-1,sc.2353(sc.2008-1)),v.highlight:=1
}else if (sc.2353(sc.2008)>0){
sc.2351(sc.2008,sc.2353(sc.2008)),v.highlight:=1
}else if v.highlight{
sc.2351(-1,-1),v.highlight:=0
} text:="Line:" sc.2166(sc.2008)+1 " Column:" sc.2129(sc.2008)
width:=sc.2276(32,"a")
SB_SetText(text)
SB_SetParts(width*StrLen(text "1"),last)
first:=width*StrLen(text "1")
}
return
Full_Auto:
Fix_Next_Line:
onoff:=settings.ssn("//Auto_Indent/@ " A_ThisLabel).text?0:1
att:=[],att[A_ThisLabel]:=onoff
settings.add({path:"Auto_Indent",att:att})
Menu,%A_ThisMenu%,ToggleCheck,%A_ThisMenuItem%
v.options[A_ThisLabel]:=onoff
return
}
Send_WM_COPYDATA(AID,String,Key=25565){
VarSetCapacity(Struct,12,0)
NumPut(StrPut(string,"utf-8")*2,struct,4),NumPut(&string,struct,8)
SendMessage,0x4a,%Key%,&Struct,,ahk_id %AID% ahk_class AutoHotkey
}
WM_COPYDATA(wParam,lParam){
if wParam != 25565
return false
file:=StrGet(NumGet(lparam+8))
if (file){
open(file)
v.tv:=files.ssn("//main[@file='" file "']/file/@tv").text
tv(v.tv)
WinActivate,% hwnd([1])
}
return true
}
OtherInstance(){
WinGet,Wins,List,%A_ScriptFullPath% ahk_class AutoHotkey
Loop, %Wins%
if (Wins%A_Index% != A_ScriptHwnd)
return Wins%A_Index%
return 0
}
open_folder(){
sc:=csc()
file:=files.ssn("//*[@sc='" sc.2357 "']/@file").Text
SplitPath,file,,dir
Run,%dir%
}
open(filelist="",show=""){
static root,top
if !filelist{
FileSelectFile,filename,,,,*.ahk
if ErrorLevel
return
if ff:=files.ssn("//main[@file='" filename "']"){
Gui,1:Default
tv:=ssn(ff.firstchild,"@tv").text
TV_Modify(tv,"Select Vis Focus")
return
}
fff:=FileOpen(filename,"RW","utf-8")
file1:=file:=fff.read(fff.length)
gosub,addfile
Gui,1:TreeView,SysTreeView321
TV_Modify(root,"Select Vis Focus")
}else{
for a,b in StrSplit(filelist,"`n"){
if files.ssn("//main[@file='" b "']")
continue
fff:=FileOpen(b,"RW","utf-8")
file1:=file:=fff.read(fff.length)
filename:=b
gosub,addfile
if show
tv(root)
}
}
return root
addfile:
Gui,1:Default
SplitPath,filename,fn,dir
top:=files.add({path:"main",att:{file:filename},dup:1})
pos:=1
root:=TV_Add(fn)
;file:=file1:=RegExReplace(file1,"(\r|\r\n)","`n")
StringReplace,file,file,`r`n,`n,All
StringReplace,file,file,`r,`n,All
file1:=file
files.under({under:top,node:"file",att:{file:filename,tv:root,filename:fn}})
for a,b in strsplit(file1,"`n"){
if InStr(b,"#include")
while,(d:=substr(b,instr(b," ",0,1,a_index)+1))&&instr(b," ",0,1,a_index){
newfn:=FileExist(dir "\" d)?dir "\" d:FileExist(d)?d:""
if newfn
break
}
if (newfn){
StringReplace,file1,file1,%b%,,All
}
if !newfn
continue
if ssn(top,"file[@file='" newfn "']")
continue
SplitPath,newfn,fn
child:=TV_Add(fn,root,"Sort")
top:=files.ssn("//main[@file='" filename "']")
files.under({under:top,node:"file",att:{file:newfn,include:b,tv:child,filename:fn}})
ffff:=FileOpen(newfn,"RW","utf-8")
text:=ffff.read(ffff.length)
StringReplace,text,text,`r`n,`n,All
update({file:newfn,text:text})
}
update({file:filename,text:Trim(file,"`r`n")})
ff:=files.sn("//file")
if !settings.ssn("//open/file[text()='" filename "']")
settings.add({path:"open/file",text:filename,dup:1})
Gui,1:Default
TV_Modify(TV_GetChild(0),"Select Focus Vis")
return
}
options(){
static list:={show_eol:2356,Show_Caret_Line:2096,show_whitespace:2021,word_wrap:2268}
Show_EOL:
Show_Caret_Line:
Show_WhiteSpace:
sc:=csc()
onoff:=settings.ssn("//options/@ " A_ThisLabel).text?0:1
att:=[],att[A_ThisLabel]:=onoff
settings.add({path:"options",att:att})
togglemenu(A_ThisLabel)
v.options[A_ThisLabel]:=onoff
sc[list[A_ThisLabel]](onoff)
option:=settings.ssn("//options")
ea:=settings.ea(option)
for c,d in s.main
for a,b in ea
d[list[a]](b)
return
Small_Icons:
onoff:=settings.ssn("//options/@ " A_ThisLabel).text?0:1
att:=[],att[A_ThisLabel]:=onoff
settings.add({path:"options",att:att})
togglemenu(A_ThisLabel)
m("Requires a reboot to take effect.")
return
word_wrap:
onoff:=settings.ssn("//options/@ " A_ThisLabel).text?0:1
att:=[],att[A_ThisLabel]:=onoff
settings.add({path:"options",att:att})
togglemenu(A_ThisLabel)
csc().2268(onoff)
return
}
paste(){
paste:
ControlGetFocus,Focus,% hwnd([1])
if !InStr(Focus,"Scintilla"){
ControlSend,%focus%,^v
return
}
csc().2179
if InStr(Clipboard,"`n")||InStr(Clipboard,"`r")
SetTimer,fix_paste,On
return
}
Personal_Variable_List(){
static
qf:=setup(6)
Gui,Add,ListView,w200 h400,Variables
Gui,Add,Edit,w200 vvariable
Gui,Add,Button,gaddvar Default,Add
Gui,Add,Button,x+10 gvdelete,Delete Selected
ControlFocus,Edit1,% hwnd([6])
Gui,Show,,Variables
vars:=settings.sn("//Variables/*")
while,vv:=vars.item(A_Index-1)
LV_Add("",vv.text)
ControlFocus,Edit1,% hwnd([6])
return
vdelete:
while,LV_GetNext(){
LV_GetText(string,LV_GetNext())
this:=settings.ssn("//Variable[text()='" string "']")
this.parentnode.removechild(this)
LV_Delete(LV_GetNext())
}
return
addvar:
Gui,6:Submit,Nohide
if !variable
return
if !settings.ssn("//Variables/Variable[text()='" variable "']")
settings.add({path:"Variables/Variable",text:variable,dup:1}),LV_Add("",variable)
settings.Transform()
ControlSetText,Edit1,,% hwnd([6])
return
6GuiClose:
6GuiEscape:
keywords(),hwnd({rem:6})
refreshthemes()
return
}
posinfo(){
sc:=csc()
current:=sc.2008
line:=sc.2166(current),se:=[]
ind:=sc.2128(line)
lineend:=sc.2136(line)
se[current]:=1,se[sc.2009]:=1
return {current:current,line:line,ind:ind,lineend:lineend,start:se.minindex(),end:se.maxindex()}
}
post_all_in_one_gist(info=""){
url:="https://api.github.com/gists"
info:=info?info:publish(1)
get_access()
file:=ssn(current(1),"@file").text
id:=positions.ssn("//main[@file='" file "']/@id").text
SplitPath,file,filename
info:=RegExReplace(info,"([" Chr(34) "\\])","\$1")
for a,b in {"`n":"\n","`t":"\t","`r":""}
StringReplace,info,info,%a%,%b%,All
desc=Posted using AHK Studio
http:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
json={"description":"%desc%","public":true,"files":{"%filename%":{"content":"%info%"}}}
check_id(id)
if id
http.Open("PATCH",url "/" id)
else
http.Open("POST",url)
if access_token
http.SetRequestHeader("Authorization","Bearer " access_token)
http.send(json)
codes:=http.ResponseText
split:=http.option(1)
SplitPath,split,fname
for a,b in ["html_url","id"]{
split=":"
RegExMatch(codes,"U)" b split "(.*)" chr(34),found)
if b=html_url
clipboard:=RegExReplace(found1,"\\")
else
id:=found1
}
if id{
positions.unique({path:"main",att:{file:file,id:id},check:"file"})
TrayTip,AHK Studio,Gist URL coppied to Clipboard,1
}
else
m("Something went wrong. Here is what the server sent back","","",codes)
}
publish(return=""){
sc:=csc(),text:=update("get").1,save()
mainfile:=ssn(current(1),"@file").text
publish:=update({get:mainfile})
includes:=sn(current(1),"*/@include/..")
while,ii:=includes.item[A_Index-1]
if InStr(publish,ssn(ii,"@include").text)
StringReplace,publish,publish,% ssn(ii,"@include").text,% update({get:ssn(ii,"@file").text}),All
ea:=xml.ea(vversion.ssn("//*[@file='" ssn(current(1),"@file").text "']"))
newver:=ea.version "." ea.increment
if InStr(publish,Chr(59) "auto_version")
publish:=RegExReplace(publish,Chr(59) "auto_version",newver)
aa:=vversion.ea("//info[@file='" ssn(current(1),"@file").text "']")
repver:=aa.versstyle?newver:"Version=" newver
if InStr(publish,Chr(59) "auto_version")
publish:=RegExReplace(publish,Chr(59) "auto_version",repver)
if return
return publish
StringReplace,publish,publish,`n,`r`n,All
Clipboard:=publish
MsgBox,,AHK Studio,Project compiled and coppied to your clipboard,.6
}
qf(){
static quickfind:=[],find
qf:
ControlGetText,find,Edit1,% hwnd([1])
pre:="O",find1:=""
find1:=v.options.regex?find:"\Q" find "\E"
pre.=v.options.greed?"":"U"
pre.=v.options.case_sensitive?"":"i"
find1:=pre ")(" find1 ")"
sc:=csc()
if (find=""||find="."||find=".*"||find="\"){
sc.2571
return
}
text:=sc.getuni()
if sc.2508(0,start:=quickfind[sc.2357]+1)!=""{
end:=sc.2509(0,start)
if end
text:=SubStr(text,1,end)
}
pos:=start?start:1
pos:=pos=0?1:pos
sc.2571
while,pos:=RegExMatch(text,find1,found,pos){
if (A_Index=1&&found.len())
sc.2160(pos-1+found.len(),pos-1)
else
sc.2573(pos-1+found.len(),pos-1)
pos+=found.len()
}
sc.2574(0)
sc.2169
return
next:
sc:=csc()
sc.2606
sc.2169
return
Quick_Find_Settingsguiescape:
sc:=csc()
sc.2400
return
clear_selection:
sc:=csc(),sc.2505(0,sc.2006)
quickfind.remove(sc.2357),qf()
return
set_selection:
sc:=csc()
if (sc.2008=sc.2009)
goto clear_selection
sc.2505(0,sc.2006)
minmax:=[]
minmax[sc.2008]:=1,minmax[sc.2009]:=1
for a,b in s.main
b.2080(0,8),b.2082(0,0xff00ff)
quickfind[sc.2357]:=MinMax.MinIndex()
sc.2504(MinMax.MinIndex(),MinMax.MaxIndex()-MinMax.MinIndex()),sc.2571,qf()
return
quick_find:
gosub,set_selection
ControlFocus,Edit1,% hwnd([1])
Send,^A
qf()
return
Case_Sensitive:
Regex:
Greed:
onoff:=settings.ssn("//Quick_Find_Settings/@ " A_ThisLabel).text?0:1
att:=[],att[A_ThisLabel]:=onoff
settings.add({path:"Quick_Find_Settings",att:att})
togglemenu(A_ThisLabel)
v.options[A_ThisLabel]:=onoff
goto qf
return
checkqf:
ControlGetFocus,Focus,% hwnd([1])
if (Focus="Edit1")
goto qf
return
}
togglemenu(Label){
item:=menus.ssn("//*[@clean='" Label "']")
menu:=ssn(item.ParentNode,"@clean").text
item:=ssn(item,"@name").text
Menu,%Menu%,ToggleCheck,%item%
}
class rebar{
static hw:=[],keep:=[]
__New(win=1,hwnd="",special=""){
static id:=0
id:=hwnd.id?hwnd.id:++id
this.id:=id
code:=0x10000000|0x40000000
code|=0x200|0x400|0x8000|0x2000|0x40
Gui,%win%:Add,custom,ClassReBarWindow32 hwndrhwnd w500 h400 grebar +%code% Background0
this.hwnd:=rhwnd,this.count:=count
this.keep[rhwnd]:=this
this.ahkid:="ahk_id" rhwnd
v.rebarahkid:=this.ahkid
this.parent:=hwnd
Loop,2
SendMessage,0x400+19,0,0xff0000,,% this.ahkid
rebar.hw.insert(this)
}
hide(id){
SendMessage,0x400+16,id,0,,% this.ahkid ;RB_IDTOINDEX
SendMessage,0x400+35,%errorlevel%,0,,% this.ahkid ;RB_SHOWBAND
}
show(id){
SendMessage,0x400+16,id,0,,% this.ahkid ;RB_IDTOINDEX
SendMessage,0x400+35,%errorlevel%,1,,% this.ahkid ;RB_SHOWBAND
}
add(gui,style="",mask=132){
static id:=10000,struct:={hwnd:32,height:40,width:44,id:52,max:60,int:64,ideal:68}
mask|=0x20|0x100|0x2|0x10|0x200|0x40|0x08|0x1|0x4|0x80
style|=0x4|0x200|0x80
if gui.max
style|=0x40
VarSetCapacity(BAND,80,0)
if gui.label
VarSetCapacity(BText,StrLen(gui.label)*2),StrPut(gui.label,&BText,"utf-8")
win:=gui.win?gui.win:1
NumPut(225525,band,12)
if hwnd:=toolbar.list[gui.id].hwnd
gui.hwnd:=hwnd
if hh:=toolbar.list[gui.id].barinfo().height
gui.height:=hh
for a,b in gui{
if struct[a]
NumPut(b,band,struct[a])
}
for a,b in {0:80,4:mask,8:style,20:&BText}
if b
NumPut(b,band,a)
SendMessage,0x400+1,-1,&BAND,,% "ahk_id" this.hwnd
}
getpos(hwnd){
ControlGetPos,x,y,w,h,,ahk_id%hwnd%
return {x:x,y:y,w:w,h:h}
}
save(){
lasttop:=0
for a,b in rebar.hw{
vis:=settings.sn("//rebar/band/@vis")
top:=settings.ssn("//rebar")
while,vv:=vis.item[A_Index-1]
vv.text:=0
newline:=sn(top,"newline")
while,new:=newline.item[A_Index-1]
new.parentnode.removechild(new)
SendMessage,0x400+12,0,0,,% b.ahkid ;RB_GETBANDCOUNT
Loop,%ErrorLevel%{
NumPut(VarSetCapacity(band,80),&band,0),NumPut(0x140,&band,4) ;get the width and id of the band
SendMessage,0x400+28,% A_Index-1,&band,,% b.ahkid ;RB_GETBANDINFOW
id:=NumGet(&band,52)
VarSetCapacity(rect,16)
SendMessage,0x400+9,% A_Index-1,&rect,,% b.ahkid ;RB_GETRECT
y:=NumGet(rect,4),width:=NumGet(rect,8)-NumGet(rect,0)
if (y>lasttop)
settings.under({under:top,node:"newline",att:{vis:1}})
lasttop:=y
next:=settings.ssn("//rebar/band[@id='" id "']"),next.SetAttribute("width",width)
next.setattribute("vis",1),next.parentnode.appendchild(next)
}
}
}
notify(){
rebar:
code:=NumGet(A_EventInfo,8,"int")
this:=rebar.keep[NumGet(A_EventInfo)]
if (code=-841)
m("Chevron Pushed")
if (code=-831&&NumGet(A_EventInfo)=this.hwnd){
Resize()
GuiControl,1:+Redraw,SysTreeView321
}
if (code=-841){
NumPut(VarSetCapacity(band,80),band,0)
NumPut(0x10,band,4)
bd:=NumGet(A_EventInfo+12)
SendMessage,0x400+28,%bd%,&band,,% this.ahkid
childwindowhwnd:=NumGet(band,32)
}
return
}
}
redo(){
csc().2011
}
refreshthemes(){
refresh(),theme:=csc(1)
Loop,31
v.theme.2409(A_Index,1)
ea:=settings.ea("//fonts/font[@style='5']")
hwnd:=hwnd("get")
for win,b in hwnd{
if win>99
return
winget,controllist,ControlList,% "ahk_id" b
Gui,%win%:Default
Gui,%win%:font,% "c" RGB(ea.color) " s" ea.size,% ea.font
loop,Parse,ControlList,`n
{
if (win=1&&A_LoopField="Edit1")
Gui,1:font,% "Normal s10",% ea.font
GuiControl,% "+background" RGB(ea.Background) " c" rgb(ea.color),%A_LoopField%
GuiControl,% "font",%A_LoopField%
}
}
}
Remove_Segment(){
current:=current()
filename:=ssn(current(1),"@file").Text
include:=ssn(current(),"@include").text
if (ssn(current,"@file").text=filename)
return m("You can not remove the main file from the project")
MsgBox,260,Remove Segment from this Project?,Remove it?
IfMsgBox,No
return
MsgBox,308,Delete this file from the computer?,Permanently delete this file?
IfMsgBox,Yes
FileDelete,% ssn(current,"@file").text
mainfile:=update({get:filename})
StringReplace,mainfile,mainfile,%include%,,All
update({file:filename,text:mainfile})
scin:=ssn(current(1),"file").removeattribute("sc") ;,scin.ParentNode.removechild(scin)
TV(ssn(current(1),"@tv").text)
Gui,1:TreeView,SysTreeView32
TV_Delete(ssn(current,"@tv").text)
tv(ssn(current.previousSibling,"@tv").text)
current.parentnode.removechild(current)
up:=update({edited:filename})
}
Remove_Spaces_From_Selected(){
sc:=csc(),pos:=posinfo()
replace:=sc.textrange(pos.start,pos.end)
replace:=RegExReplace(replace," ")
sc.2170(0,replace)
}
replace_selected(){
InputBox,replace,Replace Selected,Input text to replace what is selected
if ErrorLevel
return
sc:=csc()
clip:=Clipboard
strip:="``r,``n,``r``n,\r,\n,\r\n"
for a,b in StrSplit(strip,","){
replace:=RegExReplace(replace,"i)\Q" b "\E",Chr(13))
}
sc.2614(1)
Clipboard:=replace
sc.2179
Clipboard:=clip
}
replace(){
sc:=csc(),cp:=sc.2008
sc:=csc()
selcount:=sc.2570
loop,%selcount%
{
word:=sc.textrange(start:=sc.2266(sc.2577(A_Index-1)-1,1),end:=sc.2267(sc.2577(A_Index-1)-1,1))
if w:=settings.ssn("//replacements/*[@replace='" word "']").text
sc.2190(start),sc.2192(end),sc.2194(StrLen(w),w)
}
v.word:=w?w:word
if !v.lastbrace
SetTimer,automenu,10
}
resize(info*){
static width,height,rheight,band
if (info.1="get"){
WinGetPos,x,y,,,% hwnd([1])
return size:="x" x " y" y " w" width " h" height
}
if (A_Gui=1){
height:=info.2>>16?info.2>>16:height,width:=info.2&0xffff?info.2&0xffff:width
SendMessage,0x400+27,0,0,,% "ahk_id" rebar.hw.1.hwnd
rheight:=ErrorLevel
}
ControlGetPos,,y,,h,,% "ahk_id" rebar.hw.1.hwnd
yoffset:=y+h
ControlMove,,,,%width%,,% "ahk_id" rebar.hw.1.hwnd
hh:=height-h-v.StatusBar-2
;ControlMove,,,%yoffset%,%width%,%hh%,% "ahk_id" v.win3
x:=0,max:=s.main.MaxIndex()
GuiControl,1:Move,SysTreeView321,x0 y%h% w200 h%hh%
x+=200
for a,b in s.main{
if (A_Index!=max){
GuiControl,1:Move,% b.sc,% "x" x " y" h "w" round((width-200)/max) " h" hh
x+=round((width-200)/max)
}
else
GuiControl,1:Move,% b.sc,% "x" x " y" h "w" width-x " h" hh
sleep,0
}
GuiControl,+Redraw,% v.sbhwnd
return
}
restore_current_file(){
file:=ssn(current(),"@file").text
SplitPath,file,filename,dir
restore:=setup(16)
Gui,+Resize
Gui,Add,ListView,x0 y0 w350 h480 altsubmit grestore,Backup
Gui,Add,Edit,x+10 w550 h480
Gui,Add,Button,x0 grestorefile Default,Restore selected file
SplashTextOn,,50,Collecting backup files,Please wait...
loop,% dir "\backup\" filename,1,1
{
StringSplit,new,A_LoopFileDir,\
last:=new0,d:=new%last%
lv_add("",d)
}
LV_Modify(1,"select Focus")
SplashTextOff
Gui,Show,,Restore
Restore:
file:=ssn(current(),"@file").text
SplitPath,file,filename,dir
LV_GetText(bdir,LV_GetNext())
FileRead,contents,% dir "\backup\" bdir "\" filename
ControlSetText,Edit1,%contents%
return
restorefile:
file:=ssn(current(),"@file").text
SplitPath,file,filename,dir
LV_GetText(bdir,LV_GetNext())
;FileRead,contents,% dir "\backup\" bdir "\" filename
oldfile:=dir "\backup\" bdir "\" filename
fff:=FileOpen(oldfile,"RW","utf-8")
contents1:=fff.read(fff.length)
length:=VarSetCapacity(text,strput(contents,"utf-8"))
StrPut(contents1,&text,length,"utf-8")
;sc.2037(65001),sc.2181(0,&text),set(),sc.2175
csc().2181(0,&text)
16GuiClose:
16GuiEscape:
hwnd({rem:16})
return
}
rgb(c){
setformat,IntegerFast,H
c:=(c&255)<<16 | (c&65280) | (c>>16),c:=SubStr(c,1)
SetFormat, integerfast,D
return c
}
run_selected_text(){
dynarun(csc().getseltext())
}
run(){
sc:=csc(),save()
main:=files.ssn("//*[@sc='" sc.2357 "']..")
file:=ssn(main,"@file").text
if (file=A_ScriptFullPath)
exit(1)
SplitPath,file,,dir
Run,%file%,%dir%
if (file=A_ScriptFullPath)
ExitApp
}
runfile(file){
SplitPath,file,,dir
run,%file%,%dir%
}
save(){
info:=update("get"),now:=A_Now
for filename in info.2{
;if root:=files.ssn("//main[@file='" filename "']"){
;inc:=sn(root,"*/@include")
;text:=info.1[filename]
;while,ii:=inc.item[A_Index-1]
;text.="`r`n" ii.text
;}
;else{
text:=info.1[filename]
;}
SplitPath,filename,file,dir
if !FileExist(dir "\backup")
FileCreateDir,% dir "\backup"
if !FileExist(dir "\backup\" now)
FileCreateDir,% dir "\backup\" now
FileMove,%filename%,% dir "\backup\" now "\" file,1
StringReplace,text,text,`n,`r`n,All
FileAppend,%text%,%filename%,utf-8
}
getpos(),savegui(),positions.save(1),vversion.save(1)
lastfiles()
update("clearupdated")
}
scintilla_code_lookup(){
static scintilla,slist,cs
if !FileExist("lib\scintilla.xml"){
SplashTextOn,300,100,Downloading definitions,Please wait
URLDownloadToFile,http://files.maestrith.com/scintilla/scintilla.xml,lib\scintilla.xml
SplashTextOff
}
if !IsObject(scintilla)
scintilla:=new xml("scintilla","lib\scintilla.xml")
if scintilla.ssn("//date").text!=20140129
m("File may be out of date (or maestrith forgot to update this)")
;scintilla:=show_scintilla_code_in_line(1),
slist:=scintilla.sn("//item"),scl:=setup(8,1)
Gui,Add,Edit,Uppercase w500 gcodesort vcs
Gui,Add,ListView,w720 h500 -Multi,Name|Code|Syntax
Gui,Add,Button,ginsert Default,Insert code into script
Gui,Add,Button,gdocsite,Goto Scintilla Document Site
while,sl:=slist.item(A_Index-1)
LV_Add("",ssn(sl,"@name").text,ssn(sl,"@code").text,ssn(sl,"@syntax").text)
Gui,show,,Scintilla Code Lookup
Loop,3
LV_ModifyCol(A_Index,"AutoHDR")
hotkeys([8],{up:"sclup",down:"scldn"})
return
sclup:
scldn:
return lv_select(8,A_ThisLabel="sclup"?-1:1)
docsite:
Run,http://www.scintilla.org/ScintillaDoc.html
return
codesort:
Gui,8:Submit,Nohide
Gui,8:Default
GuiControl,-Redraw,SysListView321
LV_Delete()
slist:=scintilla.sn("//*[contains(@name,'" cs "')]")
while,sl:=slist.item(A_Index-1)
LV_Add("",ssn(sl,"@name").text,ssn(sl,"@code").text,ssn(sl,"@syntax").text)
LV_Modify(1,"Select Vis Focus")
GuiControl,+Redraw,SysListView321
return
insert:
LV_GetText(code,LV_GetNext(),2)
sc:=csc()
DllCall(sc.fn,"Ptr",sc.ptr,"UInt",2003,int,sc.2008,astr,code,"Cdecl")
npos:=sc.2008+StrLen(code)
sc.2160(npos,npos)
return
lookupud:
Gui,8:Default
count:=A_ThisHotkey="up"?-1:+1,pos:=LV_GetNext()+count<1?1:LV_GetNext()+count,LV_Modify(pos,"Select Focus Vis")
return
8GuiClose:
8GuiEscape:
hwnd({rem:8})
;Destroy(8)
return
}
Scratch_Pad(){
static file
if !IsObject(file){
FileCreateDir,Projects
file:=FileOpen("projects\Scratch Pad.ahk","rw")
}
setup(14)
v.scratch:=new s(14,{pos:"w500 h300"}),hotkeys([14],{Esc:"14guiclose"})
csc({hwnd:v.scratch.sc}),v.scratch.2181(0,file.read(file.length))
Gui,Add,Button,gsprun,Run
Gui,Add,Button,x+10 gspdyna,Dyna Run
Gui,Add,Button,x+10 gspkill,Kill Process
Gui,Show,,Scratch Pad
bracesetup(14)
return
14GuiClose:
gosub spsave
hwnd({rem:14})
csc("Scintilla1")
goto spkill
return
sprun:
gosub spsave
Run,projects\Scratch Pad.ahk,,,pid
v.scratchpid:=pid
return
spdyna:
v.scratchpid:=dynarun(v.scratch.getText())
return
spkill:
if (v.scratchpid){
while,WinExist("ahk_pid" v.scratchpid){
WinClose,% "ahk_pid" v.scratchpid " ahk_class AutoHotkey",, 2
Sleep,500
if WinExist("ahk_pid" v.scratchpid)
MsgBox,51,Unable to close the previous script,Try again?
IfMsgBox,no
break
IfMsgBox,Cancel
break
}
}
return
spsave:
file.seek(0)
file.write(v.scratch.gettext())
file.length(file.position),file.seek(0)
return
}
set_as_default_editor(){
pgm=
(
RegWrite,REG_SZ,HKEY_LOCAL_MACHINE,SOFTWARE\Classes\AutoHotkeyScript\Shell\Edit\Command,,"%A_AhkPath%" "%A_ScriptFullPath%" "```%1"
)
m("The program must be run as administrator to use this feature.")
dynarun(pgm)
}
set(){
sc:=csc()
color(sc)
}
refresh(){
for a,b in s.Ctrl
color(b)
}
color(con){
static options:={show_eol:2356,Show_Caret_Line:2096}
list:={Font:2056,Size:2055,Color:2051,Background:2052,Bold:2053,Italic:2054,Underline:2059}
nodes:=settings.sn("//fonts/*")
while,n:=nodes.item(A_Index-1){
ea:=settings.ea(n)
if (ea.style=33)
for a,b in [2290,2291]
con[b](1,ea.Background)
ea.style:=ea.style=5?32:ea.style
for a,b in ea{
if list[a]&&ea.style!=""
con[list[a]](ea.style,b)
else if ea.code&&ea.bool!=1
con[ea.code](ea.color,0)
else if ea.code&&ea.bool
con[ea.code](ea.bool,ea.color)
if ea.style=32
con.2050
}
}
for a,b in [[2040,25,13],[2040,26,15],[2040,27,11],[2040,28,10],[2040,29,9],[2040,30,12],[2040,31,14],[2244,2,0xFE000000],[2242,0,20],[2242,2,13],[2460,3],[2462,1],[2134,1],[2260,1],[2246,2,1],[2115,1],[2242,1,0],[2029,2],[2031,2]]
con[b.1](b.2,b.3)
con.2132(1)con.2242(2,13),con.2077(0,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#_")
con.2115(1),con.2036(5)
con.2056(38,"Tahoma")
con.4006(0,"asm"),con.2212,con.2371
;con.2037(65001)
con.2080(7,6)
con.2082(7,0xff00ff)
con.2498(1,7)
for a,b in options
if v.options[a]
con[b](b)
kwind:={indent:1,Directives:2,KeyNames:8,builtin:4,keywords:5,functions:6,Commands:3,flow:7,Personal:0}
for a,b in v.color
con.4005(kwind[a],RegExReplace(b,"#"))
}
setpos(tv){
static
Sleep,0
sc:=csc()
GuiControl,-Redraw,% sc.sc
node:=files.ssn("//*[@tv='" tv "']")
file:=ssn(node,"@file").text
parent:=ssn(node,"../@file").text
posinfo:=positions.ssn("//main[@file='" parent "']/file[@file='" file "']")
doc:=ssn(node,"@sc").text
ea:=xml.ea(posinfo),fold:=ea.fold
if ea.start
sc.2613(ea.scroll),sc.2160(ea.start,ea.end)
Loop,Parse,fold,`,
if A_LoopField is number
sc.2231(A_LoopField)
GuiControl,+Redraw,% sc.sc
}
setup(window,nodisable=""){
ea:=settings.ea(settings.ssn("//fonts/font[@style='5']"))
Background:=ea.Background,font:=ea.font,color:=RGB(ea.color)
Background:=Background?Background:0
size:=10
Gui,%window%:Destroy
Gui,%window%:Default
Gui,+hwndhwnd
if !nodisable{
Gui,+Owner1 -0x20000
Gui,1:+Disabled
}
Gui,+Owner1
Gui,color,% RGB(Background),% RGB(Background)
Gui,Font,% "s" size " c" color " bold",%font%
Gui,%window%:Default
v.window[window]:=1,hwnd(window,hwnd)
return hwnd
}
show_scintilla_code_in_line(get=""){
static scintilla
if !FileExist("lib\scintilla.xml"){
SplashTextOn,300,100,Downloading definitions,Please wait
URLDownloadToFile,http://files.maestrith.com/scintilla/scintilla.xml,lib\scintilla.xml
SplashTextOff
}
if !IsObject(scintilla)
scintilla:=new xml("scintilla","lib\scintilla.xml")
if Get
return scintilla
sc:=csc()
text:=sc.textrange(sc.2128(sc.2166(sc.2008)),sc.2136(sc.2166(sc.2008)))
pos=1
while,pos:=RegExMatch(text,"(\d\d\d\d)",found,pos){
codes:=scintilla.sn("//*[@code='" found1 "']")
list.="Code : " found1 " = "
while,c:=codes.item(A_Index-1)
list.=ssn(c,"@name").text " "
pos+=5
list.="`n"
}
if list
m(list)
}
sn(node,path){
return node.SelectNodes(path)
}
social(){
Run,http://goo.gl/9odUcj
}
Sort_Selected(){
static text,del
sc:=csc(),text:=sc.getseltext()
if !Text
return m("Please select some text first.")
setup(18)
Gui,Add,Edit,w200 vdel
Gui,Add,Button,x+10 gsortdel,Sort By Delimeter
Gui,Add,Button,xm gsortbyslash,Sort By \
Gui,Add,Edit,w500 h500,%text%
Gui,Add,Button,greplace,Replace Selected
Gui,Show,,Sort Selected
return
sortbyslash:
Sort,text,\ ;%del%
StringReplace,text,text,`n,`r`n,all
ControlSetText,Edit2,%text%,% hwnd([18])
Return
sortdel:
Gui,18:Submit,Nohide
Sort,text,D%del%
StringReplace,text,text,`n,`r`n,all
ControlSetText,Edit2,%text%,% hwnd([18])
return
18GuiClose:
18GuiEscape:
hwnd({rem:18})
replace:
Gui,18:Submit
StringReplace,text,text,`r`n,`n,all
csc().2170(0,text)
hwnd({rem:18})
Return
}
ssn(node,path){
return node.SelectSingleNode(path)
}
testing(){
m("This is a test")
}
+Esc::
;Menu,Tray,Icon,shell32.dll,1,1
sc:=csc()
m(sc.2010(sc.2008))
return
Add_Spaces_After_Commas(){
sc:=csc()
m(sc.getselection())
}
Add_Spaces_Before_Commas(){
}
Theme(info=""){
if info
goto returnedinfo
hwnd({rem:3})
setup(3),hotkeys([3],{Esc:"3GuiClose"}),v.themelist:=[]
Gui,3:Default
Gui,+hwndhwnd Owner1
Gui,Add,TreeView,w200 h500 gthemetv AltSubmit
theme:=new s(3,{pos:"x+10 w500 h500"}),v.theme:=theme
theme.2181(0,themetext()),csc({hwnd:theme.sc}),hotkeys([3],{Delete:"themedelete"})
Gui,Add,Button,Hidden x0 y0 gthemetv Default,go
fix_indent()
Loop,31
theme.2409(A_Index,1)
Gui,Show,,Theme Editor
theme.2246(0,1),theme.2400,theme.2563(0)
v.themelist:=[]
color:=TV_Add("Color")
for a,b in ["Background","Default Background Color","Default Font Style","Caret","Caret Line Background","End Of Line Color","Reset To Default","Indent Guide","Multiple Selection Foreground","Multiple Selection Background"
,"Main Selection Foreground","Main Selection Background"]
v.themelist[TV_Add(b,color,"Sort")]:=b
options:=TV_Add("Theme Options")
for a,b in ["Edit Theme Name","Edit Author","Download Themes","Export Theme","Import Theme","Save Theme"]
v.themelist[TV_Add(b,options,"Sort")]:=b
v.themelist[TV_Add("Color Input Method")]:="Color Input Method"
themes:=TV_Add("Themes"),v.themetv:=themes
tlist:=preset.sn("//preset/fonts/name")
while,n:=tlist.item(A_Index-1)
v.themelist[TV_Add(n.text,themes)]:="themes list"
TV_Add("More Coming Soon...")
for a,b in [color,options,themes]
TV_Modify(b,"Expand")
return event:=""
themetv:
event:=v.themelist[TV_GetSelection()]
if (A_GuiEvent!="normal"&&A_GuiEvent!="K")
return
if (event="Themes List"){
TV_GetText(theme,TV_GetSelection())
overwrite:=preset.ssn("//name[text()='" theme "']..")
clone:=overwrite.clonenode(1)
rem:=settings.ssn("//fonts"),rem.ParentNode.RemoveChild(rem)
settings.ssn("*").appendchild(clone)
csc().2181(0,themetext())
refreshthemes()
}
if (event="export theme"){
FileCreateDir,Themes
name:=settings.ssn("//fonts/name").text
temp:=new xml("fonts","Themes\" name ".xml")
font:=settings.ssn("//fonts")
clone:=font.clonenode(1)
temp.xml.loadxml(clone.xml)
temp.save(1)
m("Theme saved to " A_ScriptDir "\Themes\" name ".xml")
}
if (event="import theme"){
FileSelectFile,theme,,,,*.xml
if ErrorLevel
return
temp:=ComObjCreate("MSXML2.DOMDocument"),temp.setProperty("SelectionLanguage","XPath")
temp.load(theme)
if !(ssn(temp,"//name").xml&&ssn(temp,"//author").xml&&ssn(temp,"//fonts").xml)
return m("Theme not compatible")
top:=ssn(temp,"*")
rem:=settings.ssn("//fonts")
rem.ParentNode.RemoveChild(rem)
tt:=settings.ssn("*")
tt.appendchild(top)
event:="Save Theme"
}
if (event="Edit Author"){
author:=settings.ssn("//fonts/author")
InputBox,newauthor,New Author,Enter your name,,,,,,,,% author.text
if ErrorLevel
return event:=""
author.text:=newauthor
csc().2181(0,themetext())
}
if (event="Edit Theme Name"){
themename:=settings.ssn("//fonts/name")
InputBox,newtheme,New Theme Name,Enter the new theme name,,,,,,,,% themename.Text
if ErrorLevel
return event:=""
themename.text:=newtheme
csc().2181(0,themetext())
}
if (event="Color Input Method"){
method:=settings.ssn("//colorinput").text?0:1
settings.add({path:"colorinput",text:method})
mode:={0:"Gui",1:"Hex"}
m("Your current color input mode is now set to " mode[method])
}
if (v.themelist[TV_GetParent(A_EventInfo)]="Download Themes"){
temp:=new xml("temp"),TV_GetText(filename,A_EventInfo)
info:=URLDownloadToVar("http://files.maestrith.com/AHKStudio/themes/" filename)
temp.xml.loadxml(SubStr(info,InStr(info,"<")))
rem:=settings.ssn("//fonts"),rem.ParentNode.RemoveChild(rem)
settings.ssn("*").appendchild(temp.ssn("*"))
csc().2181(0,themetext()),event:="save theme"
refreshthemes()
}
if (event="save theme"){
FileCreateDir,Themes
font:=settings.ssn("//fonts")
clone:=font.clonenode(1)
name:=settings.ssn("//fonts/name").text
rem:=preset.ssn("//fonts/name[text()='" name "']..")
if rem
rem.ParentNode.removechild(rem)
Else
v.themelist[TV_Add(name,v.themetv,"Sort")]:="themes list"
top:=preset.ssn("*")
top.appendchild(clone)
preset.save(1)
tlist:=preset.sn("//preset/*")
noadd:=0
}
if (event="Download Themes"){
parent:=TV_GetSelection()
if child:=TV_GetChild(parent){
list:=[]
list[child]:=1
while,child:=TV_GetNext(child)
list[child]:=1
for a,b in List
TV_Delete(a)
}
SplashTextOn,200,50,Downloading Themes,Please Wait...
wb:=ComObjCreate("HTMLfile")
wb.write(URLDownloadToVar("http://files.maestrith.com/AHKStudio/themes/"))
while,aa:=wb.links.item[A_Index-1].innerhtml
if InStr(aa,".xml")
TV_Add(aa,parent)
SplashTextOff,wb:=""
TV_Modify(parent,"Expand")
}
if InStr(event,"Main Selection"){
code:=InStr(event,"foreground")?2067:2068
main:=settings.ssn("//fonts/font[@code='" code "']")
color:=dlg_color(ssn(main,"@color").text,(hwnd(3)))
if !ErrorLevel
main.setattribute("color",color)
refreshthemes()
}
if InStr(event,"Multiple Selection"){
code:=InStr(event,"fore")?2600:2601
multi:=settings.ssn("//fonts/font[@code='" code "']")
color:=dlg_color(ssn(multi,"@color").text,(hwnd(3)))
if !ErrorLevel
multi.setattribute("color",color)
refreshthemes()
}
if (event="Indent Guide"){
guide:=settings.ssn("//fonts/font[@style='37']")
color:=dlg_color(ssn(guide,"@color").text,hwnd(3))
if !ErrorLevel
guide.setattribute("color",color)
refreshthemes()
}
if (event="End Of Line Color"){
eol:=settings.ssn("//fonts/font[@style='0']")
color:=dlg_color(ssn(eol,"@color").text,hwnd(3))
if !ErrorLevel
eol.setattribute("color",color)
refreshthemes()
}
if (event="Default Font Style"){
rem:=settings.sn("//fonts/font[@style!='5' and @font]")
while,rr:=rem.item[A_Index-1]
rr.removeattribute("font")
refreshthemes()
}
if (event="Caret Line Background"){
cb:=settings.ssn("//fonts/font[@code='" 2098 "']")
color:=dlg_color(ssn(cb,"@color").text,hwnd(3))
if !ErrorLevel
cb.setattribute("color",color)
refreshthemes()
}
if (event="caret"){
caret:=settings.ssn("//fonts/font[@code='2069']")
color:=dlg_color(ssn(caret,"@color").text,hwnd(3))
if !ErrorLevel
caret.setattribute("color",color)
refreshthemes()
}
if (event="Default Background Color"||event="Background"){
if InStr(event,"Default"){
rem:=settings.sn("//fonts/font[@style!='5' and @style!=33 and @background]")
while,rr:=rem.item[A_Index-1]
rr.removeattribute("background")
}
if !style:=settings.ssn("//fonts/font[@style='5']")
style:=settings.add({path:"fonts/font",att:{style:5}})
default:=settings.ea("//fonts/font[@style='5']")
color:=dlg_color(default.Background,hwnd(3))
if ErrorLevel
return event:=""
style.setattribute("background",color)
refreshthemes()
}
if (event="reset to default"){
rem:=settings.ssn("//fonts")
rem.parentnode.removechild(rem)
defaultfont()
refreshthemes()
}
event:=""
return
3GuiEscape:
3GuiClose:
hwnd({rem:3}),csc("Scintilla1").2400
return
returnedinfo:
if (info.style){
styleclick:
SetTimer,%A_ThisLabel%,Off
st:=v.style.style,mod:=v.style.mod
if !style:=settings.ssn("//fonts/font[@style='" st "']")
style:=settings.add({path:"fonts/font",att:{style:st},dup:1})
color:=dlg_color(ssn(style,"@color").text,hwnd(3))
if ErrorLevel
return
style.setattribute("color",color)
Loop,2
settings.Transform()
refreshthemes()
return
}
if (info.editfont){
editfont:
SetTimer,%A_ThisLabel%,Off
if !style:=settings.ssn("//fonts/font[@style='" v.style.style "']")
style:=settings.add({path:"fonts/font",att:{style:v.style.style}})
font:=settings.ea("//fonts/font[@style='" v.style.style "']")
compare:=default:=settings.ea("//fonts/font[@style='5']")
for a,b in font
default[a]:=b
dlg_font(Default,1,hwnd(3))
for a,b in compare{
if a not in style,Background
if (default[a]!=b)
style.setattribute(a,Default[a])
}
refreshthemes()
return
}
if (info.editback){
editback:
SetTimer,%A_ThisLabel%,Off
if !style:=settings.ssn("//fonts/font[@style='" v.style.style "']")
style:=settings.add({path:"fonts/font",att:{style:v.style.style}})
default:=settings.ea("//fonts/font[@style='5']")
font:=settings.ea("//fonts/font[@style='" v.style.style "']")
color:=font.Background?font.Background:default.Background
color:=dlg_color(color,hwnd(3))
if ErrorLevel
return
style.setattribute("background",color)
refreshthemes()
return
}
if (info.margin!=""){
style:=settings.ssn("//fonts/font[@style='33']")
if (info.mod=0){
color:=ssn(style,"@color").text
color:=dlg_color(color,hwnd(3))
if ErrorLevel
return
style.setattribute("color",color)
refreshthemes()
}
if (info.mod=4){
color:=ssn(style,"@background").text
color:=dlg_color(color,hwnd(3))
if ErrorLevel
return
style.setattribute("background",color)
refreshthemes()
}
}
return
themedelete:
Gui,3:Default
if (v.themelist[TV_GetSelection()]="themes list"){
TV_GetText(theme,TV_GetSelection())
rem:=preset.ssn("//name[text()='" theme "']..")
rem.ParentNode.RemoveChild(rem)
TV_Delete(TV_GetSelection())
}
return
}
themetext(theme=1){
if name:=settings.ssn("//fonts/name").text
header:=name "`r`n`r`n"
if author:=settings.ssn("//fonts/author").text
header.="Theme by " author "`r`n`r`n"
out=%header%/*`r`nMulti-Line`r`ncomments`r`n*/`r`n`r`nSelect the text to change the colors`nThis is a sample of normal text`n`"incomplete quote`n"complete quote"`n`;comment`n0123456789`n()[]^&*()+~#\/!`%,{`}``b``a``c``k``t``i``c``k`n
for a,b in v.color
out.=a " = " b "`n"
th:=theme=1?settings.sn("//custom/highlight/*"):theme
while,tt:=th.item(A_Index-1)
out.="Custom List " ssn(tt,"@list").text " = " tt.text "`n"
out.="`nLeft Click to edit the fonts color`nControl+Click to edit the font style, size, italic...etc`nAlt+Click to change the Background color`nThis works for the Line Numbers as well"
return out
}
class toolbar{
static keep:=[],order:=[],list:=[],imagelist:=""
__New(win,parent,id,mask=""){
static count:=0
count++
mask:=mask?mask:0x800|0x0800|0x0100|0x0040|0x0008|0x0004|0x10|0x20
Gui,Add,Custom,ClassToolbarWindow32 hwndhwnd gtoolbar +%mask% Background0
this.iconlist:=[]
this.hwnd:=hwnd,this.count:=count
this.buttons:=[],this.returnbutton:=[]
this.keep[hwnd]:=this,this.ahkid:="ahk_id" hwnd
this.parent:=parent,this.order[count]:=this
onoff:=settings.ssn("//options/@Small_Icons").text?0:1
this.imagelist:=IL_Create(20,1,onoff)
this.SetImageList()
this.list[id]:=this,this.id:=id
this.setmaxtextrows()
return this
}
setstate(button,state){
SendMessage,0x400+17,button,0<<16|state&0xffff,,% this.ahkid
}
SetImageList(){
SendMessage,0x400+48,0,% this.imagelist,,% "ahk_id " this.hwnd
}
il(icon="",file=""){
if (icon!=""){
if this.iconlist[file,icon]!=""
return this.iconlist[file,icon]
if file contains .gif,.jpg,.png,.bmp
index:=IL_Add(this.imagelist,file)-1
else
index:=IL_Add(this.imagelist,file,icon+1)-1
this.iconlist[file,icon+1]:=index
return index
}
}
add(info){
new:=[]
if (info.text){
VarSetCapacity(STR,StrLen(info.text)*2)
StrPut(info.text,&STR,strlen(info.text)*2)
SendMessage,0x400+77,0,&STR,,% "ahk_id " this.Hwnd
Index:=ErrorLevel
}
iimage:=this.il(info.icon,info.file)
this.buttons[info.id]:={icon:iimage,state:info.state,text:info.text,index:index,func:info.func,iimage:info.icon,file:info.file,id:info.id,runfile:info.runfile}
this.returnbutton.Insert(this.buttons[info.id])
}
addbutton(id){
VarSetCapacity(button,20,0)
info:=this.buttons[id]
if !info.id{
NumPut(1,button,9)
SendMessage,1044,1,&button,,% "ahk_id" this.hwnd
return
}
if (IsFunc(info.func)=0&&IsLabel(info.func)=0)
return
NumPut(info.icon,Button,0,"int")
NumPut(info.id,Button,4,"int")
NumPut(info.state,button,8,"char")
NumPut(info.style,button,9,"char")
NumPut(info.Index,button, 8 + (A_PtrSize * 2), "ptr")
SendMessage,1044,1,&button,,% "ahk_id" this.hwnd ;TB_ADDBUTTONSW
}
SetMaxTextRows(MaxRows=0){
SendMessage,0x043C,MaxRows, 0,, % "ahk_id " this.Hwnd
return (ErrorLevel = "FAIL") ? False : True
}
Customize(){
SendMessage,0x041B, 0, 0,, % "ahk_id " this.Hwnd
return (ErrorLevel = "FAIL") ? False : True
}
barinfo(){
VarSetCapacity(size,8)
VarSetCapacity(rect,16)
WinGetPos,,,w,,% "ahk_id" this.hwnd
SendMessage,0x400+29,0,&rect,,% "ahk_id" this.hwnd
height:=NumGet(rect,12)
SendMessage,0x400+99,0,&size,,% "ahk_id" this.hwnd ;TB_GETIDEALSIZE
ideal:=NumGet(&size)
return info:={ideal:ideal,id:this.id,height:height,hwnd:this.hwnd,width:ideal+20}
}
ideal(){
VarSetCapacity(size,8)
SendMessage,0x400+99,0,&size,,% "ahk_id" this.hwnd ;TB_GETIDEALSIZE
parent:=DllCall("GetParent","uptr",this.hwnd),parent:="ahk_id" parent
NumPut(VarSetCapacity(band,80),&band,0),NumPut(0x200|0x40,band,4)
SendMessage,0x400+16,% this.id,0,,% parent
bandnum:=ErrorLevel
SendMessage,0x400+28,%bandnum%,&band,,% parent ;getbandinfo
NumPut(0x200|0x40,band,4)
NumPut(NumGet(&size),&band,68)
NumPut(NumGet(&size)+20,&band,44)
SendMessage,0x400+11,%bandnum%,&band,,% parent ;setbandinfow
}
delete(button){
rem:=settings.ssn("//toolbar/bar[@id='" this.id "']/button[@id='" button.id "']")
rem.ParentNode.RemoveChild(rem)
SendMessage,0x400+25,% button.id,0,,% this.ahkid
SendMessage,0x400+22,%ErrorLevel%,0,,% this.ahkid
this.buttons[button.id]:=""
;button.id button.index
}
notify(){
toolbar:
code:=NumGet(A_EventInfo+8,0,"Int"),Hwnd:=NumGet(A_EventInfo)
this:=toolbar.keep[hwnd]
If(Hwnd!=this.Hwnd)
return
if (code=-5) ;right click
if GetKeyState("Ctrl","P")&&this.id!=10002
this.delete(this.buttons[NumGet(A_EventInfo+12)])
else
this.customize()
if (code=-2){ ;left click
button:=this.buttons[NumGet(A_EventInfo+12)]
if GetKeyState("Alt","P")&&this.id!=10002
addbutton(this)
else if GetKeyState("Ctrl","P"){
if button
new icon_browser([this.buttons[NumGet(A_EventInfo+12)],NumGet(A_EventInfo+12),this.ahkid,this])
}else if !button.runfile{
fun:=IsFunc(button.func)?button.func:""
if fun
%fun%()
if IsLabel(button.func){
lab:=button.func
SetTimer,%lab%,10
sleep,12
SetTimer,%lab%,off
}
}
else if button.runfile
runfile(button.runfile)
}
if (code=-708) ;toolbar change
this.ideal()
If (code=-720){
if info:=this.returnbutton[NumGet(A_EventInfo+12)+1]{
for a,b in [[info.icon,0,"int"],[info.id,4,"int"],[info.state,8,"char"],[info.style,9,"char"],[info.index,16,"int"]]
NumPut(b.1,A_EventInfo+16,b.2,b.3)
PostMessage,1,,,,% "ahk_id" this.parent
}
}
if (code=-723) ;TBN_INITCUSTOMIZE
PostMessage,1,,,,% "ahk_id" this.parent
If (code=-706) ;TBN_QUERYINSERT
PostMessage,1,,,,% "ahk_id" this.parent
If (code=-707) ;TBN_QUERYDELETE
PostMessage,1,,,,% "ahk_id" this.parent
return
}
save(){
VarSetCapacity(button)
vis:=settings.sn("//toolbar/*/*/@vis")
while,vv:=vis.item[A_Index-1]
vv.text:=0
sep:=settings.sn("//toolbar/*/separator")
while,vv:=sep.item[A_Index-1]
vv.parentnode.removechild(vv)
for Control,this in this.order{
SendMessage,0x400+24,0,0,,% this.ahkid ;TB_BUTTONCOUNT
top:=settings.ssn("//toolbar")
Loop,%ErrorLevel%{
VarSetCapacity(button,80)
SendMessage,0x400+23,% A_Index-1,&button,,% this.ahkid ;TB_GETBUTTON
if NumGet(&button,4)=0{
bar:=ssn(top,"bar[@id='" this.id "']")
new:=settings.under({under:bar,node:"separator",text:1,att:{vis:1},dup:1})
before:=1
continue
}
id:=NumGet(&button,4)
next:=ssn(top,"bar[@id='" this.id "']/button[@id='" id "']")
next.setattribute("vis",1),next.parentnode.appendchild(next)
if before
top.insertbefore(next,new),before:=0
}
}
}
}
traymenu(){
Menu,Tray,NoStandard
Menu,Tray,Add,Show AHK Studio,show
Menu,Tray,Default,Show AHK Studio
Menu,Tray,Standard
}
tv(tv=0){
Gui,1:Default
Gui,1:TreeView,% hwnd(100)
TV_Modify(tv,"Select Vis Focus")
return
tv:
if (A_GuiEvent="+"||A_EventInfo=0)
return
if ((A_GuiEvent="S"||A_GuiEvent="Normal")){
getpos(),count:=0
ei:=TV_GetSelection(),sc:=csc()
file:=files.ssn("//*[@tv='" ei "']")
if !ssn(file,"@tv").text
return
if !doc:=ssn(file,"@sc"){
tvtop:
Sleep,10
doc:=sc.2375
if !doc
doc:=sc.2376(0,doc)
if !(doc){
count++
if count=3
return m("error")
goto tvtop
}
sc.2358(0,doc)
fn:=ssn(file,"@file").text
tt:=update({get:fn})
length:=VarSetCapacity(text,strput(tt,"utf-8"))
StrPut(tt,&text,length,"utf-8")
sc.2037(65001),sc.2181(0,&text),set(),sc.2175
file.SetAttribute("sc",doc)
}else
sc.2358(0,doc.text)
setpos(ei),marginwidth(sc)
current(1).SetAttribute("last",ssn(file,"@file").text)
}
return
}
undo(){
csc().2176
}
update(info){
static update:=[],updated:=[]
if (info.edited)
return updated[info.edited]:=1
if (info="clearupdated")
return updated:=[]
if (info="get")
return [update,updated]
if (info.file&&info.text)
return update[info.file]:=info.text
if (info.get)
return update[info.get]
if (info.sc){
fn:=files.ssn("//*[@sc='" info.sc "']/@file").text
if !fn
return
updated[fn]:=1
update[fn]:=csc().getuni()
return
}
}
upload(winname="Upload"){
static
uphwnd:=setup(10)
window({win:10,gui:["Text,Section,Version:","Edit,w200 vversion x+5 ys-2","text,x+5,.","Edit,x+5 w100 vincrement","UpDown,gincrement Range0-2000 0x80","Text,xs,Version Information:","Edit,w400 h400 vversioninfo"
,"Text,Section,Upload directory:","Edit,vdir w200 x+10 ys-2","Text,section xm,Ftp Server:","DDL,x+10 ys-2 w200 vserver","Checkbox,vcompile xm,Compile","Checkbox,vgistversion xm Disabled,Update Gist Version","Checkbox,vupver,Upload without progress bar (a bit more stable)","Checkbox,vversstyle,Remove (Version=) from the " chr(59) "auto_version"
,"Button,w200 gupload1 xm Default,Upload"]})
file:=ssn(current(1),"@file").text
list:=settings.sn("//ftp/server/@name"),lst:="|Choose a server...|"
while,ll:=list.item[A_Index-1]
lst.="|" ll.text
GuiControl,10:,ComboBox1,%lst%
Gui,show,AutoSize,%winname%
node:=vversion.ssn("//info[@file='" file "']")
GuiControl,10:ChooseString,ComboBox1,% ssn(node,"@server").text
list:={compile:"Button1",version:"Edit1",increment:"Edit2",dir:"Edit4",gistversion:"Button2",upver:"Button3",versstyle:"Button4"}
for a,b in vversion.ea(node)
GuiControl,10:,% list[a],%b%
GuiControl,10:,Edit3,% vversion.ssn("//info[@file='" file "']").text
ControlFocus,Edit3,% hwnd([10])
Send,^{Home}{Down}
return
upload1:
w:=window({get:10})
ControlGetText,server,ComboBox1,ahk_id%uphwnd%
if (server="Choose a server..."||server="")
return m("Please choose a server")
gosub 10guiescape
if w.compile
compile()
f:=new ftp(server)
if f.Error
return
r:=f.put(file,w.dir,w.compile)
/*
if w.gistversion
gist_post_version()
*/
if r
m("Transfer complete")
return
10GuiEscape:
10GuiClose:
file:=ssn(current(1),"@file").text
att:=[],win:=window({get:10})
for a,b in win
if a=versioninfo
text:=b
else
att[a]:=b
att.file:=file
uq:=vversion.unique({path:"info",att:att,check:"file"}),uq.text:=text
vversion.Transform(),vversion.save()
hwnd({rem:10})
ftp.cleanup()
return
increment:
info:=window({get:10})
ver:=info.version "." info.increment,
search:=info.versioninfo
if !RegExMatch(search,"\b" ver)
ControlSetText,Edit3,% ver "`r`n`r`n" RegExReplace(info.versioninfo,"\n","`r`n"),% hwnd([10])
ControlFocus,Edit3,% hwnd([10])
Send,^{Home}{Down}
return
}
URLDownloadToVar(url){
http:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
http.Open("GET",url),http.Send()
return http.ResponseText
}
window(info){
static
static variables:=[]
if info.get{
vars:=[],win:=info.get
Gui,%win%:Submit,Nohide
for a,b in variables[info.get]
vars[a]:=%a%
return vars
}
for a,b in info.gui{
StringSplit,b,b,`,
Gui,Add,%b1%,%b2% hwndpoo,%b3%
RegExMatch(b2,"U)\bv(.*\b)",found)
b2:=b3:=""
if found1
variables[info.win,found1]:=1
}
}
class xml{
keep:=[]
__New(param*){
if !FileExist(lib)
FileCreateDir,lib
root:=param.1,file:=param.2
file:=file?file:root ".xml"
temp:=ComObjCreate("MSXML2.DOMDocument"),temp.setProperty("SelectionLanguage","XPath")
this.xml:=temp
ifexist %file%
temp.load(file),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)
}
unique(info){
if (info.check&&info.text)
return
if info.under{
if info.check
find:=info.under.SelectSingleNode("*[@" info.check "='" info.att[info.check] "']")
if info.Text
find:=this.cssn(info.under,"*[text()='" info.text "']")
if !find
find:=this.under({under:info.under,att:info.att,node:info.path})
for a,b in info.att
find.SetAttribute(a,b)
}
else
{
if info.check
find:=this.ssn("//" info.path "[@" info.check "='" info.att[info.check] "']")
else if info.text
find:=this.ssn("//" info.path "[text()='" info.text "']")
if !find
find:=this.add({path:info.path,att:info.att,dup:1})
for a,b in info.att
find.SetAttribute(a,b)
}
if info.text
find.text:=info.text
return find
}
add(info){
path:=info.path,p:="/",dup:=this.ssn("//" path)?1:0
if next:=this.ssn("//" path)?this.ssn("//" path):this.ssn("//*")
Loop,Parse,path,/
last:=A_LoopField,p.="/" last,next:=this.ssn(p)?this.ssn(p):next.appendchild(this.xml.CreateElement(last))
if (info.dup&&dup)
next:=next.parentnode.appendchild(this.xml.CreateElement(last))
for a,b in info.att
next.SetAttribute(a,b)
if info.text!=""
next.text:=info.text
return next
}
find(info){
if info.att.1&&info.text
return m("You can only search by either the attribut or the text, not both")
search:=info.path?"//" info.path:"//*"
for a,b in info.att
search.="[@" a "='" b "']"
if info.text
search.="[text()='" info.text "']"
current:=this.ssn(search)
return current
}
under(info){
new:=info.under.appendchild(this.xml.createelement(info.node))
for a,b in info.att
new.SetAttribute(a,b)
new.text:=info.text
return new
}
ssn(node){
return this.xml.SelectSingleNode(node)
}
sn(node){
return this.xml.SelectNodes(node)
}
__Get(x=""){
return this.xml.xml
}
transform(){
static
if !IsObject(xsl){
xsl:=ComObjCreate("MSXML2.DOMDocument")
style=
(
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:for-each select="@*">
<xsl:text></xsl:text>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</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
file:=fileopen(filename,"rw")
file.seek(0)
file.write(this[])
file.length(file.position)
}
remove(rem){
if !IsObject(rem)
rem:=this.ssn(rem)
rem.ParentNode.RemoveChild(rem)
}
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment