The IDE’s find panel has its powers, but many times I just wish to do a quick find in the current method only and have the cursor go right to that spot. Pressing Find Next would then move the cursor to the next match, and when reaching the bottom of the file, start searching from the top again.
I have created two scripts to accomplish just that. I call them Find and Find Next. I bind Ctrl+F
to File > IDE Scripts > Find.xojo_script
and Ctrl+G
to File > IDE Scripts > Find Next.xojo_script
. On OS X, I have begun using KeyboardMaestro and am enjoying it quite a bit for all sorts of automated Xojo tasks and general keyboard tasks.
These scripts are likely to be modified and changed, so I have added them to my GitHub repo https://github.com/jcowgar/xojo-ide-scripts-misc
Find.xojo_script
[code]
//
// Setup
//
const kFilename = “~/.cowgar-xojo-find”
//
// Utility Methods
//
sub WriteFile(filename as String, content as String)
content = ReplaceAll(content, “”"", “”"")
call DoShellCommand("printf """ + content + """ > " + filename)
end sub
//
// Find Code
//
dim cursorPosition as Integer = SelStart
dim find as String = Input(“Find what?”)
if find.Trim = “” then
Beep
return
end if
dim pos as Integer = Instr(SelStart, Text, find)
if pos = 0 then
Beep
return
end if
SelStart = pos - 1
WriteFile("~/.cowgar-xojo-find", Str(pos) + “,” + find)[/code]
Find Next.xojo_script
[code]
//
// Setup
//
const kStateFilename = “~/.cowgar-xojo-find”
//
// Utility Methods
//
sub WriteFile(filename as String, content as String)
content = ReplaceAll(content, “”"", “”"")
call DoShellCommand("printf """ + content + """ > " + filename)
end sub
function ReadFile(filename as String) as String
return DoShellCommand("cat " + filename)
end function
function ReadFindData(byref startPosition as Integer, byref find as String) as Boolean
dim content as String = ReadFile(kStateFilename).Trim
if content = "" or InStr(content,",") = 0 then
return false
end if
startPosition = Val(NthField(content, ",", 1))
find = NthField(content, ",", 2).Trim
return (find <> "")
end function
//
// Find Next
//
dim cursorPosition as Integer = SelStart
dim startPosition as Integer
dim find as String
if not ReadFindData(startPosition, find) then
Beep
return
end if
dim pos as Integer = Instr(startPosition + 1, Text, find)
WriteFile(kStateFilename, Str(pos) + “,” + find)
if pos = 0 then
Beep
return
end if
SelStart = pos - 1[/code]