accommodated the goodies all along while having the multi-level thing kept.
also enabled mouse wheel for the find next match, in which, i devised a donkey way to have the reversed direction implemented. it works fine if there are not tons of matches in the result. otherwise, the {wheelup} will be a bit sluggish. (hoping someone can provide a better method for it.)
for the mouse wheel to work, you have to move your mouse pointer away (out of the "control" namely "Edit2", i.e. the big text box) while the gui is active. otherwise, the mouse wheel will do only the usual operation i.e. scroll the stuff.
still, some more cosmetic touches for this version.
wish it works all well.
Code: Select all
Haystack0=
(
The Road Not Taken
BY ROBERT FROST
Two roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;
Then took the other, as just as fair,
And having perhaps the better claim,
Because it was grassy and wanted wear;
Though as for that the passing there
Had worn them really about the same,
And both that morning equally lay
In leaves no step had trodden black.
Oh, I kept the first for another day!
Yet knowing how way leads on to way,
I doubted if I should ever come back.
I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference.
)
n := 1, pn := n - 1, Haystack%n% := Haystack%pn%
gui, font, s10
gui, add, text,, `t`tOptions:
gui, add, checkbox, ym vfayt checked tabstop gfaythdlr, Instant Filter (aka Find As You Type)
gui, add, checkbox, ym vcase checked tabstop goptshdlr, Case Insensitive
gui, add, checkbox, ym vwhole tabstop goptshdlr, Whole Word
gui, font, s18, arial new
gui, add, text, xm section, Filter:
w := a_screenwidth - 257
gui, add, edit, w%w% ys gspathdlr
gui, add, button, h38 ys default, Go
Gui, Add, Button, h38 ys, Back
h := a_screenheight - 143, w := a_screenwidth - 30
gui, add, edit, readonly x10 h%h% w%w% hscroll vscroll +hwndhEdit
gui, show,, The Text Filter,, The Text Filter - Level %n% ( Base %blc% Lines )
skipwork = 0
renewGui:
guicontrol,, Edit2, % Haystack%n%
controlfocus, Edit1, A
setwintitle:
strreplace(Haystack%n%,"`n",,blc), blc += strlen(Haystack%n%) and substr(Haystack%n%,0) != "`n" ? 1 : 0
winsettitle, The Text Filter,, The Text Filter - Level %n% ( Base %blc% Lines )
return
faythdlr:
if fayt()
if (Haystack%n% != Haystack%pn%)
{ Needle%n% := spat()
theHaystack := Haystack%n%, theNeedle := Needle%n%
n += 1, pn := n - 1
Haystack%n% := theHaystack, Needle%n% := theNeedle
gosub, setwintitle
}
optshdlr:
controlfocus, Edit1, A
goto, spathdlr
buttongo:
controlfocus, Edit1, A
progress, zh0 w380 c10 fs18, `nCommitting This Level`n,, Prompt, Segoe UI
commitlevel = 1
spathdlr:
if skipwork
{ skipwork = 0
return
}else if not fayt() and not commitlevel
return
gui, submit, nohide
Needle%n% := spat()
if not strlen(Needle%n%) and commitlevel
{ commitlevel = 0
goto, buttonback
}
r := (case ? "i" : "") "m`a)^(?!"
loop, parse, Needle%n%, % a_space
if substr(a_loopfield,1,1) = "-"
r .= "(?!.*" substr(a_loopfield,2) ")"
else r .= "(?=.*" (whole ? "\b" : "") a_loopfield (whole ? "\b" : "") ")"
r .= ").*\R?"
theHaystack := regexreplace(Haystack%pn%,r)
if commitlevel
{ if (theHaystack = Haystack%pn%)
{ progress, off
msgbox, Result No Change Thus Not Anew Level
}else
{ if not fayt()
Haystack%n% := theHaystack
n += 1, pn := n - 1
Haystack%n% := theHaystack
Send, ^a
}
commitlevel = 0
sleep, 500
progress, off
}else Haystack%n% := theHaystack
goto, renewGui
buttonback:
controlfocus, Edit1, A
Needle%n% := spat()
if (n = 1) and (Haystack1 != Haystack0)
Haystack1 := Haystack0, Needle1 := ""
else if (Haystack%n% = Haystack%pn%) and (Needle%n% = Needle%pn%)
if n > 2
n -= 2, pn := n - 1
else if n = 2
n := 1, pn := n - 1, Haystack1 := Haystack0, Needle1 := ""
else n = 0
else n -= 1, pn := n - 1
if n
{ skipwork = 1
gosub, renewGui
guicontrol,, Edit1, % Needle%n%
send, ^a
if (n = 1) and (Haystack1 = Haystack0)
{ progress, zh0 w380 c10 fs18, `nReturned To The Origin`n,, Prompt, Segoe UI
sleep, 500
progress, off
}else
{ progress, zh0 w380 c10 fs18, `nReturned To Level %n%`n,, Prompt, Segoe UI
sleep, 500
progress, off
}
return
}else exitapp
guiescape:
guiclose:
exitapp
spat() {
guicontrolget, spat,, Edit1
return spat
}
fayt() {
guicontrolget, fayt,, Button1
return fayt
}
~Bs::
~Del::
if fayt()
goto, spathdlr
else return
focusedcontrol() {
controlgetfocus, foco
return foco
}
#if, winactive("The Text Filter") and focusedcontrol() = "Edit1"
`::
tab::controlfocus, Edit2, A
~up::wheelup
~down::wheeldown
~left::wheelleft
~right::wheelright
#if, winactive("The Text Filter") and focusedcontrol() = "Edit2"
Tab::ControlFocus, Edit1, A
~space::pgdn
~+space::pgup
~s::home
~e::end
~t::^home
~b::^end
`::
~enter::
controlget, cln, currentline,, Edit2, A
hays := strsplit(Haystack%n%,"`n","`r")
clipboard := hays[cln]
msgbox,,, Has Put This Line Into Clipboard, 3
exitapp
~f::
nextmatch:
controlgettext, sPat, Edit1, A
if sPat
{ r := case ? "i)" : ""
loop, parse, sPat, % a_space
if substr(a_loopfield,1,1) != "-"
r .= (whole ? "\b" : "") a_loopfield (whole ? "\b" : "") "|"
}else
{ controlget, sPat, selected,, Edit2, A
r := sPat ? (case ? "i)" : "") (whole ? "\b" : "") sPat (whole ? "\b" : "") : ""
}
if r
{ if substr(r,0) = "|"
r := substr(r,1,strlen(r)-1)
controlgettext, hays, Edit2, A
if regexmatch(hays,r)
{ starthere:
if a_thishotkey = ~wheelup
{ gosub, compute_cp
gosub, reverseway
mpos -= 1
}else
{ controlget, slctd, selected,, Edit2, A
if slctd
send, {left}{right}
gosub, compute_cp
mpos := regexmatch(hays,r,nm,cp) - 1
}
if mpos >= 0
{ cp := mpos + strlen(nm)
sendmessage, 0xb1, mpos, cp,, ahk_id %hEdit% ;EM_SETSEL
sendmessage, 0xb7, 0, 0,, ahk_id %hEdit% ;EM_SCROLLCARET
}else if (mpos < 0) and a_thishotkey != ~wheelup
{ send, ^{home}
goto, starthere
}
}else msgbox, Target Not Found
}
return
compute_cp:
controlget, cln, currentline,, Edit2, A
controlget, cco, currentcol,, Edit2, A
cp := cln > 1 ? instr(hays,"`r`n",,,cln-1) + 1 + cco : cco
return
reverseway:
if cp > 1
{ mpos := 0, pmax := cp - 1
loop
{ npos := regexmatch(hays,r,pm,mpos+1)
if npos between 1 and %pmax%
mpos := npos, nm := pm
else break
}
if (npos > pmax) and mpos > 0
return
}
mpos := cp - 1, pmax := strlen(hays)
loop
{ npos := regexmatch(hays,r,pm,mpos+1)
if npos between %cp% and %pmax%
mpos := npos, nm := pm
else break
}
return
#ifwinactive, The Text Filter
~wheelup::
~wheeldown::
mousegetpos,,,, moc
if (moc != "Edit2")
{ controlfocus, Edit2, A
goto, nextmatch
}else return
#ifwinactive
some minor adjustments.
fixed a minor bug: added "controlfocus, Edit1, A' for buttongo and buttonback.
fixed a minor bug: changed from blc += substr(Haystack%n%,0) = "`n" ? 0 : 1 to blc += strlen(Haystack%n%) and substr(Haystack%n%,0) != "`n" ? 1 : 0