Skip to content

Instantly share code, notes, and snippets.

@maestrith
Created March 7, 2014 16:13
Show Gist options
  • Save maestrith/9414452 to your computer and use it in GitHub Desktop.
Save maestrith/9414452 to your computer and use it in GitHub Desktop.
Posted using AHK Studio
#SingleInstance,Force
tick:=A_TickCount
settings:=new xml("settings","lib\settings.xml"),files:=new xml("files")
global v:=[],settings,files
imagelist()
gui()
return
GuiDropFiles:
open(A_GuiEvent)
return
f1::
v.rb.show(10003)
return
gui(){
Gui,+Resize +hwndhwnd
hwnd(1,hwnd)
OnMessage(5,"Resize")
SysGet,Border,33
SysGet,Caption,4
v.border:=border,v.caption:=caption
Gui,3:+Parent1 -Caption +hwndwin3
Loop,2
new s(3,{main:1})
v.win2:=win2,v.win3:=win3
Gui,Add,StatusBar,hwndsb,StatusBar Info
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"
tb:=new toolbar(1,hwnd)
v.tb:=tb
tb.ImageList(v.ImageList)
tb.add(4,0x4,"Open","Open")
tb.add(8,0x4,"Save","Save")
tb.add(69,0x4,"icon_browser","Icon Browser")
tb.add(137,0x4,"Run","Run")
tb.show(1)
tb.SetMaxTextRows(0)
tb1:=new toolbar(1,hwnd)
v.tb1:=tb1
tb1.ImageList(v.ImageList)
tb1.add(110,0x4,"open_folder","Open Folder")
tb1.add(135,0x4,"google_search_selected","Google Search Selected")
tb1.add(261,0x4,"default","default")
tb1.add(126,0x4,"default","Happy 1!",1)
tb1.show(1)
tb1.SetMaxTextRows(0)
bar:=[]
mhwnd:=DllCall("GetMenu",uptr,hwnd(1))
bar.10000:={hwnd:tb.hwnd,id:10000,type:"toolbar"}
bar.10001:={hwnd:tb1.hwnd,id:10001,type:"toolbar"}
;bar.10002:={label:"Quick Find",type:"edit",pos:"w150",text:"Temporary",id:10002}
;bar.10003:={label:"Toolbar",type:"edit",pos:"w100",text:"Design",id:10003}
info:=newwin("quick_search")
bar.10002:={label:"Quick Search",hwnd:info.hwnd,height:info.h,idealwidth:info.w,id:10002}
set:=settings.sn("//rebar/control"),newline:=0
if (set.length){
while,ss:=set.item[A_Index-1]{
each:=sn(ss,"*")
while,ea:=each.item[A_Index-1]{
easy:=xml.ea(ea)
if !(easy.id){
if (ea.nodename="newline")
newline:=0x1
continue
}
bar[easy.id].width:=easy.width
if !bar[easy.id]
continue
rb.add(bar[easy.id],newline),newline:=0
list.=easy.id "|"
}
}
}else{
for a,b in bar
rb.add(b)
}
;for a,b in bar
;if !InStr(list,a)
;rb.add(b,1) ;,rb.hide(a)
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,3:Add,TreeView,Background0 c0xAAAAAA AltSubmit gtv
while,oo:=open.item[A_Index-1]
open(oo.text)
last:=settings.sn("//last/*")
for a,b in s.main{
csc({hwnd:b.sc})
tv:=files.ssn("//file[@file='" last.item[a-1].text "']/@tv").text
tv(tv)
}
v.rb:=rb
csc("Scintilla1")
Gui,3:Show,x0 y50 w500 h500
Gui,1:Show,%pos% %max%
}
file:
return
Default(){
m("You clicked a button")
}
newwin(info){
Gui,%info%:Default
Gui,-Caption +hwndnewwin +Parent1
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,x+5 ym gcase %case%,Case
Gui,Add,Checkbox,gregex %regex%,Regex
Gui,Add,Checkbox,x+5 ym gcase %greed%,Greed
Gui,Add,Button,gnext ym+2,Next
Gui,Add,Button,x+5 gsetselection,Set Selection
Gui,Show,Hide
WinGetPos,,,w,h,% "ahk_id" newwin
return {h:h,w:w,hwnd:newwin}
return
}
m(x*){
for a,b in x
list.=b "`n"
MsgBox,,AHK Stuido,% list
}
t(x*){
for a,b in x
list.=b "`n"
Tooltip,% list
}
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
t(yoffset,v.border+v.caption+rheight+4)
ControlMove,,,,%width%,,% "ahk_id" rebar.hw.1.hwnd
ControlMove,,,% v.border+v.caption+rheight+4,%width%,% height-rheight-4-v.StatusBar,% "ahk_id" v.win3
GuiControl,+Redraw,% v.sbhwnd
return
3GuiSize:
x:=0,max:=s.main.MaxIndex()
GuiControl,3:Move,SysTreeView321,x0 y0 w200 h%A_GuiHeight%
x+=200
for a,b in s.main{
if (A_Index!=max){
GuiControl,3:Move,% b.sc,% "x" x "w" round((A_GuiWidth-200)/max) " h" A_GuiHeight
x+=round((A_GuiWidth-200)/max)
}
else
GuiControl,3:Move,% b.sc,% "x" x "w" A_GuiWidth-x " h" A_GuiHeight
sleep,0
}
return
}
exit(){
GuiClose:
GuiEscape:
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()
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)
settings.save(1)
ExitApp
return
}
notify(){
notify:
if A_EventInfo=512
return csc(1)
sc:=csc()
if sc.sc!=NumGet(A_EventInfo)
return
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",4:"ch",7:"text",6:"modType",9:"linesadded",8:"length",3:"position"}
fn[b]:=NumGet(Info+(A_PtrSize*a))
if (fn.code=2008){
if fn.modtype&0x20
return
;if fn.modtype&0x02&&fn.linesadded
;SetTimer,fix_indent,1
if ((fn.modtype&0x01)||(fn.modtype&0x02))&&sc!=v.scratch{
update({sc:sc.2357})
}
;update({file:ssn(current(),"@file").text,sc:sc})
}
/*
if (fn.code=2001){
update({sc:sc.2357,text:sc.gettext()})
}
;t(fn.code,fn.ch)
*/
return
}
class rebar{
static hw:=[],keep:=[],cross:=[]
__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
Gui,%win%:Add,custom,ClassReBarWindow32 hwndrhwnd w500 h400 grebar +%code%
this.hwnd:=rhwnd,this.count:=count
this.keep[rhwnd]:=this
this.ahkid:="ahk_id" rhwnd
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){
;style=132
static id:=10000
mask|=0x20|0x100|0x2|0x10|0x200|0x40|0x08|0x1|0x4|0x80|0x20
style|=0x4|0x200|0x80
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 (gui.hwnd){
id:=gui.id?gui.id:++id
NumPut(gui.hwnd,band,32)
height:=gui.height?gui.height:this.getpos(gui.hwnd).h
if (gui.type="toolbar"){
VarSetCapacity(size,8)
SendMessage,0x400+99,0,&size,,% "ahk_id" gui.hwnd ;TB_GETIDEALSIZE
VarSetCapacity(rect,16)
SendMessage,0x400+29,0,&rect,,% "ahk_id" gui.hwnd
height:=NumGet(rect,12)
NumPut(height,band,40) ;minimum height
NumPut(NumGet(&size),band,68) ;ideal width
}else{
NumPut(height,band,40) ;minimum height
width:=gui.width?gui.width:NumGet(&size)+16
if gui.idealwidth
NumPut(gui.idealwidth,band,68) ;ideal width
}
NumPut(gui.width?gui.width:100,&band,44)
this.cross[gui.hwnd]:=id?gui.id:id
}else{
id:=gui.id?gui.id:++id
Gui,%win%:Add,% gui.type,% gui.pos " hwndctrl",% gui.text
v.toolbars[id?gui.id:id]:=1
NumPut(Ctrl,band,32)
width:=gui.width?gui.width:100
NumPut(width,band,44)
NumPut(this.getpos(ctrl).h,band,40)
}
for a,b in {0:80,4:mask,8:style,20:&BText,52:id?gui.id:id}
NumPut(b,band,a)
NumPut(0xff00ff,band,16)
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(){
for a,b in rebar.hw{
rem:=settings.ssn("//rebar"),rem.ParentNode.RemoveChild(rem)
top:=settings.add({path:"rebar/control",att:{id:b.id},dup:1})
SendMessage,0x400+12,0,0,,% b.ahkid
lasttop:=0
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
width:=NumGet(&band,44),id:=NumGet(&band,52)
VarSetCapacity(rect,16)
SendMessage,0x400+9,% A_Index-1,&rect,,% b.ahkid
y:=NumGet(rect,4)
if (y>lasttop)
settings.under({under:top,node:"newline"})
settings.under({under:top,node:"band",att:{width:width,id:id}})
lasttop:=y
}
}
}
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,3:+Redraw,SysTreeView321
}
if (code=-841){
;m(NumGet(A_EventInfo+8+4)) ;band number 0 based
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)
;m("Rect structure for what the chevron is covering","left=" NumGet(A_EventInfo+8,16),"Right=" NumGet(A_EventInfo+8,24))
}
return
}
}
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"
Gui,%win%:Add,custom,classScintilla hwndsc w500 h400 %pos% +1387331584 gnotify
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]]{
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)
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)
return this
}
__Delete(){
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="gettext"){
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=strget(&text,vv,"cp0")
return t
}
wp:=(wparam+0)!=""?"Int":"AStr"
if wparam.1
wp:="AStr"
if wparam=0
wp:="int"
return DllCall(this.fn,"Ptr",this.ptr,"UInt",code,int,lparam,wp,wparam,"Cdecl")
}
}
class toolbar{
static keep:=[],bbb:=[]
__New(win,parent,mask=""){
static count:=0
count++
mask:=mask?mask:0x800|0x0800|0x0100|0x0040|0x0008|0x0004|0x10|0x20
Gui,Add,Custom,ClassToolbarWindow32 hwndhwnd gtoolbar +%mask%
this.hwnd:=hwnd,this.count:=count
this.buttons:=[]
this.returnbutton:=[]
this.keep[hwnd]:=this
this.ahkid:="ahk_id" hwnd
this.parent:=parent
if !settings.ssn("//toolbar/control[@count='" count "']")
settings.add({path:"toolbar/control",att:{count:count},dup:1}),this.firstrun:=1
this.order[count]:=this
return this
}
ImageList(list){
SendMessage,0x400+48,0,list,,% "ahk_id " this.hwnd
}
add(image=0,state=0,func=0,text=0,hide=0){
static control:=10000
new:=[]
if (text){
VarSetCapacity(STR,StrLen(text)*2)
StrPut(Text,&STR,strlen(text)*2)
SendMessage,0x400+77,0,&STR,,% "ahk_id " this.Hwnd
Index:=ErrorLevel
}
iimage:=image>0?imagelist(image):image
this.buttons[control]:={control:control,image:iimage,state:state,text:text,index:index,hide:hide,func:func,iimage:image}
this.returnbutton.Insert(this.buttons[control])
if main:=settings.ssn("//toolbar/control[@count='" this.count "']/button[@text='" text "']")
for a,b in {control:control,index:index,func:func}
main.SetAttribute(a,b)
control++
}
show(reload=0){
if (reload&&this.firstrun=""){
find:=settings.ssn("//toolbar/control[@count='" this.count "']")
button:=sn(find,"*")
while,b:=button.item[A_Index-1]{
ea:=xml.ea(b)
this.addbutton(ea)
}
}else{
for a,b in this.buttons
if !b.hide
this.addbutton(b)
}
}
addbutton(info){
VarSetCapacity(button,20,0)
if !info.control{
NumPut(1,button,9)
SendMessage,1044,1,&button,,% "ahk_id" this.hwnd
return
}
if !IsFunc(info.func)
return
NumPut(this.buttons[info.control].image,Button,0,"int")
NumPut(info.control,Button,4,"int")
NumPut(info.state,button,8,"char")
NumPut(info.style,button,9,"char")
NumPut(info.Index,button, 8 + (A_PtrSize * 2), "ptr")
this.bbb:=button
SendMessage,1044,1,&button,,% "ahk_id" this.hwnd ;TB_ADDBUTTONSj
}
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
}
ideal(){
VarSetCapacity(size,8)
SendMessage,0x400+99,0,&size,,% "ahk_id" this.hwnd ;TB_GETIDEALSIZE
id:=rebar.cross[this.hwnd],parent:=DllCall("GetParent","uptr",this.hwnd)
NumPut(VarSetCapacity(band,80),&band,0),NumPut(0x200|0x40,band,4)
SendMessage,0x400+16,%id%,0,,% "ahk_id" parent
bandnum:=ErrorLevel
SendMessage,0x400+28,%bandnum%,&band,,% "ahk_id" parent ;getbandinfo
NumPut(NumGet(&size),&band,68)
NumPut(NumGet(&size)+20,&band,44)
SendMessage,0x400+11,%bandnum%,&band,,% "ahk_id" parent ;setbandinfow
}
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
this.customize()
if (code=-2){ ;left click
if GetKeyState("Ctrl","P"){
icon_browser([this.buttons[NumGet(A_EventInfo+12)],NumGet(A_EventInfo+12),this.ahkid])
}else
function:=this.buttons[NumGet(A_EventInfo+12)].func,%function%()
}
if (code=-708) ;toolbar change
this.ideal()
If (code=-720){
if info:=this.returnbutton[NumGet(A_EventInfo+12)+1]{
for a,b in [[info.image,0,"int"],[info.control,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)
for Control,this in toolbar.keep{
SendMessage,0x400+24,0,0,,% this.ahkid ;TB_BUTTONCOUNT
top:=settings.ssn("//toolbar/control[@count='" this.count "']"),rem:=sn(top,"*")
while,remove:=rem.item[A_Index-1]
remove.ParentNode.RemoveChild(remove)
Loop,%ErrorLevel%{
VarSetCapacity(button),info:=[]
SendMessage,0x400+23,% A_Index-1,&button,,% this.ahkid
if NumGet(&button,4)=0{
settings.under({under:top,node:"separator",text:1,dup:1})
continue
}
for a,b in {state:8,style:9}
info[a]:=NumGet(&button,b)
find:=this.buttons[NumGet(&button,4)],info.func:=find.func,info.image:=find.iimage
info.text:=find.text,settings.under({under:top,node:"button",att:info,dup: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
find:=this.ssn("//" info.path "[@" info.check "='" info.att[info.check] "']")
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
for a,b in path
nodes:=this.sn("//*[@" a "='" b "']/@*")
while,n:=nodes.item(A_Index-1)
list[n.nodename]:=n.text
return list
}
}
ssn(node,path){
return node.SelectSingleNode(path)
}
sn(node,path){
return node.SelectNodes(path)
}
hwnd(win,hwnd=""){
static window:=[]
if (win.rem){
Gui,% win.rem ":Destroy"
window.remove[win.rem]
}
if IsObject(win)
return "ahk_id" window[win.1]
if !hwnd
return window[win]
window[win]:=hwnd
}
imagelist(add=""){
static il,list:=[]
if !il
il:=IL_Create(322,1,1)
if Add{
if list[add]!=""
return list[add]
index:=IL_Add(il,"shell32.dll",++add)-1
list[add]:=index
return index
}
v.imagelist:=il
;Loop,322
;IL_Add(il,"shell32.dll",A_Index)
;return il
}
open(filelist=""){
if !filelist{
FileSelectFile,filename,,,,*.ahk
if ErrorLevel
return
if ff:=files.ssn("//main[@file='" filename "']"){
Gui,3:Default
tv:=ssn(ff.firstchild,"@tv").text
TV_Modify(tv,"Select Vis Focus")
return
}
FileRead,file,%filename%
gosub,addfile
}else{
for a,b in StrSplit(filelist,"`n"){
if files.ssn("//main[@file='" b "']")
continue
FileRead,file,%b%
filename:=b
gosub,addfile
}
}
return
addfile:
Gui,3:Default
top:=files.add({path:"main",att:{file:filename},dup:1})
SplitPath,filename,,dir
pos:=1
file1:=file
root:=TV_Add(filename)
files.under({under:top,node:"file",att:{file:filename,tv:root}})
while,pos:=RegExMatch(file,"i)(.+)(#Include)(.+)([\r\n|\r|\n])?",found,pos){
replace:=found1 found2 found3 found4
file1:=RegExReplace(file1,replace)
ff:=trim(found3)
for a,b in [dir "\" ff,ff]
if FileExist(b){
SplitPath,b,fn
child:=TV_Add(fn,root)
files.under({under:top,node:"file",att:{file:b,include:found2 found3,tv:child}})
FileRead,text,%b%
update({file:b,text:text})
break
}
pos+=StrLen(found1)
}
update({file:filename,text:Trim(file1,"`r`n")})
ff:=files.sn("//file")
if !settings.ssn("//open/file[text()='" filename "']")
settings.add({path:"open/file",text:filename,dup:1})
Gui,3:Default
TV_Modify(TV_GetChild(0),"Select Focus Vis")
return
}
save(){
info:=update("get"),now:=A_Now
for a in info.2{
if root:=files.ssn("//main[@file='" a "']"){
inc:=sn(root,"*/@include")
text:=info.1[a]
while,ii:=inc.item[A_Index-1]
text.="`r`n" ii.text
}else{
text:=info.1[a]
}
SplitPath,a,file,dir
if !FileExist(dir "\backup")
FileCreateDir,% dir "\backup"
if !FileExist(dir "\backup\" now)
FileCreateDir,% dir "\backup\" now
FileMove,%a%,% dir "\backup\" now "\" file,1
FileAppend,%text%,%a%,utf-8
}
update("clearupdated")
}
run(){
sc:=csc(),save()
main:=files.ssn("//*[@sc='"sc.2357 "']..")
file:=ssn(main,"@file").text
SplitPath,file,,dir
Run,%file%,%dir%
}
update(info){
static update:=[],updated:=[]
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().gettext()
return
}
}
tv(tv=0){
file:=files.ssn("//*[@tv='" tv "']")
sc:=csc()
if !doc:=ssn(file,"@sc"){
doc:=sc.2375
sc.2358(0,doc)
fn:=ssn(file,"@file").text
text:=update({get:fn})
sc.2181(0,text)
file.SetAttribute("sc",doc)
}else
sc.2358(0,doc.text)
return
tv:
if (A_GuiEvent="+")
return
if (A_GuiEvent="S"||A_GuiEvent="Normal"){
file:=files.ssn("//*[@tv='" A_EventInfo "']")
sc:=csc()
if !doc:=ssn(file,"@sc"){
doc:=sc.2375
sc.2358(0,doc)
fn:=ssn(file,"@file").text
text:=update({get:fn})
sc.2181(0,text)
file.SetAttribute("sc",doc)
}else
sc.2358(0,doc.text)
}
return
}
csc(set=0){
static current
if (set.hwnd)
return current:=s.ctrl[set.hwnd]
if (set=1){
ControlGetFocus,focus,% hwnd([1])
ControlGet,hwnd,hwnd,,%focus%,% hwnd([1])
current:=s.ctrl[hwnd]
return current
return
}
if InStr(set,"Scintilla"){
ControlGet,hwnd,hwnd,,%set%,% hwnd([1])
current:=s.ctrl[hwnd]
return current
}
return current
}
open_folder(){
sc:=csc()
file:=files.ssn("//*[@sc='" sc.2357 "']/@file").Text
SplitPath,file,,dir
Run,%dir%
}
icon_browser(change=""){
static ch
ch:=change
tempil:=IL_Create(322,1,1)
Loop,322
IL_Add(tempil,"shell32.dll",A_Index)
Gui,4:Destroy
Gui,4:Default
Gui,Add,ListView,w500 h400 hwndlv gicon,icons|stuff
LV_SetImageList(tempil)
Loop,322
LV_Add("icon" A_Index,A_Index)
GuiControl,4:+Icon,%lv%
Gui,Show,,Icon Browser
Gui,1:Default
return
icon:
if !LV_GetNext()
return
NumPut(VarSetCapacity(button,32),button,0)
NumPut(0x1|0x20,button,4)
NumPut(ch.2,button,8)
NumPut(LV_GetNext()-1,button,12)
SendMessage,0x400+64,% ch.2,&button,,% ch.3
Gui,4:Destroy
return
}
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%
}
qf(){
static list:=["case","regex","greed"],quickfind:=[]
case:
regex:
gosub qfcheck
settings.add({path:"Quick_Search",att:{case:v.qfinfo.1,regex:v.qfinfo.2,greed:v.qfinfo.3}})
qf:
gosub qfcheck
ControlGetText,find,Edit1,% hwnd(["quick_search"])
pre:="O",find1:=""
find1:=v.qfinfo.2?find:"\Q" find "\E"
pre.=v.qfinfo.3?"":"U"
pre.=v.qfinfo.1?"":"i"
find1:=pre ")(" find1 ")"
sc:=csc()
text:=sc.gettext()
if (find=""||find="."||find=".*")
return sc.2571
if sc.2508(0,start:=quickfind[sc.2357]){
;start:=sc.2508(0,start),
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
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_searchguiescape:
sc:=csc()
sc.2400
return
qfcheck:
v.qfinfo:=[]
Loop,4
{
ControlGet,value,Checked,,Button%A_Index%,% hwnd(["quick_search"])
v.qfinfo[A_Index]:=value
}
return
setselection:
sc:=csc()
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment