Basically the tool searches for all occurrences of the word under the cursor and displays the line nbr and the line itself in
the ide console log windows
thanks to RSBasic for the speech dll`s
usage:
set as tool in the tools section:
params : %FILE %WORD
Set Icon to tool bar (finder icon in the zip package) (ico file, pb source file, x2 dll files)
cursor over word and select finder icon in toolbar.
Zebuddi.
https://goo.gl/mtijCn dll`s & icon file/s
Code: Select all
EnableExplicit
;{ Thanks to RSBasic :) and all others not mentioned for use of there code
Define PBEx_Speech
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x86.dll")
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x64.dll")
CompilerEndIf
Prototype TextToSpeaker(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, Asynchronous, ErrorOutput)
Global TextToSpeaker.TextToSpeaker = GetFunction(PBEx_Speech, "TextToSpeaker")
;}
#Partition$ = "----------------------------------------------------------------------------------------------------------" +
"----------------------------------------------------------------------------------------------------------"
Structure LINEDATA
iLineNbr.i
sLine.s
EndStructure : NewMap _map_linedata.LINEDATA() : NewList _ll_linedata.LINEDATA()
Procedure.s sGetLastErrorAsText() ; Used to get Last Win32 API Error
Protected sMessage.s, iLastError.i, *ErrorBuffer
iLastError=GetLastError_()
If iLastError=1309 : iLastError=0 : EndIf
If iLastError
*ErrorBuffer = AllocateMemory(1024)
FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, iLastError, 0, *ErrorBuffer, 1024, 0)
sMessage = PeekS(*ErrorBuffer)
FreeMemory(*ErrorBuffer)
EndIf
ProcedureReturn sMessage
EndProcedure
Procedure WriteIDELog(Message$)
Protected CopyData.COPYDATASTRUCT
Protected IDEWindow = Val(GetEnvironmentVariable("PB_Tool_MainWindow"))
If IDEWindow And Message$
CopyData\dwData = ('L' << 16) | ('O' << 8) | 'G'
CopyData\cbData = StringByteLength(Message$, #PB_Ascii)
CopyData\lpData = AllocateMemory(CopyData\cbData + 1)
If CopyData\lpData
PokeS(CopyData\lpData, Message$, -1, #PB_Ascii)
SendMessage_(IDEWindow, #WM_COPYDATA, #Null, @CopyData)
FreeMemory(CopyData\lpData)
EndIf
EndIf
EndProcedure
Procedure.s ProcessFileToString(sFileName.s)
Protected *Buffer, iFileNbr.i, iFileSize.i, iNbrReadBytes.i, sReturn.s
If ReadFile(iFileNbr, sFileName)
iFileSize = Lof(iFileNbr)
*Buffer = AllocateMemory(iFileSize)
If *Buffer
ReadStringFormat(iFileNbr)
iNbrReadBytes = ReadData(iFileNbr, *Buffer, iFileSize)
If iNbrReadBytes ;= (iFileSize - bBom)
sReturn = PeekS(*Buffer, iNbrReadBytes, ReadStringFormat(iFileNbr))
FreeMemory(*Buffer)
CloseFile(iFileNbr)
ProcedureReturn sReturn
EndIf
Else
WriteIDELog("Finder: ---> [Memory Allocation Error ---> Failed To Allocate Memory" + Chr(32) +
" *Buffer " + Chr(32) + " ---> SysERR( " + sGetLastErrorAsText() + " )")
CloseFile(iFileNbr)
EndIf
Else
WriteIDELog("Finder: ---> [ ReadFile() Error ---> Failed To ReadFile() ] " + Chr(34) +
sFileName + Chr(34) + " ---> SysERR( " + sGetLastErrorAsText() + " )")
EndIf
EndProcedure
Procedure MapToList(Map _map_linedata.LINEDATA(), List _ll_linedata.LINEDATA())
ForEach _map_linedata()
AddElement(_ll_linedata())
_ll_linedata()\iLineNbr = Val(MapKey(_map_linedata()))
_ll_linedata()\sLine = _map_linedata()\sLine
Next
SortStructuredList(_ll_linedata(), #PB_Sort_Ascending, OffsetOf(LINEDATA\iLineNbr), TypeOf(LINEDATA\iLineNbr))
EndProcedure
Procedure processData(sString.s, sWordUnderCursor.s, Map _map_linedata.LINEDATA(), List _ll_linedata.LINEDATA())
If ProgramParameter(0) And ProgramParameter(1)
Protected iIndex.i, iNbrLinesInFile.i = CountString((sString + #CRLF$), #CRLF$)
For iIndex = 0 To iNbrLinesInFile
If FindString(StringField(sString, (iIndex + 1), #CRLF$), sWordUnderCursor)
AddMapElement(_map_linedata(), Str(iIndex + 1))
_map_linedata()\sLine = StringField(sString, (iIndex + 1), #CRLF$)
EndIf
Next
MapToList(_map_linedata(), _ll_linedata())
WriteIDELog(" ")
WriteIDELog(#Partition$)
ForEach _ll_linedata()
WriteIDELog( "[ " + sWordUnderCursor + " ] " + "Line @ " + RSet(Str(_ll_linedata()\iLineNbr), 5, "0") + ". " + _ll_linedata()\sLine)
Next
WriteIDELog("Hit`s: ---> " + ListSize(_ll_linedata()))
WriteIDELog(#Partition$)
WriteIDELog(" ")
FreeList(_ll_linedata())
FreeMap(_map_linedata())
Else
If Not Bool(ProgramParameter(1))
Define ErrorOutput$
WriteIDELog("You " + UserName() + " For got To put your word on the cursor. Or was it. The other way around.")
;large spaces required for pausing in speech
If Not TextToSpeaker("Hey " + UserName() + ". You forgot To put your word on the cursor. Or was it the other way around",
"Microsoft Hazel Desktop", 0.4, 100, 0, @ErrorOutput$)
WriteIDELog(ErrorOutput$)
EndIf
EndIf
EndIf
EndProcedure
;---------MAIN-------------
processData(ProcessFileToString(ProgramParameter(0)), ProgramParameter(1), _map_linedata(), _ll_linedata())
CloseLibrary(PBEx_Speech)
End