Hi all.
Rajat recently released
'Active GoTo'
And he has actually had the script for a while, so this is not new.
I was starting on this a few days before Active GoTo got a little kick along. And with some parts of Rajats code included, I managed to get mine off the ground
They both work similar, with searchNgoto as follows
-incremental search of text in lines
-listview of results
-Only made for PSPad as that is what I use.
-Auto update when changing Tabs
-Search for anything, '=' 'lv_' '(' 'Var'
-Just handy for a newbie like me.
-
Comments, Suggestions and Improvements all welcome.
(please, as still learning)
Thanks
dB
Code:
#Persistent
Version=PSPad searchNgoto v1c
; Use Win+TAB to start or refresh
; Escape to minimise
; Enter Key to Goto Line Number
; Double click to Goto
; Created by DoubleBogey, with some parts from Rajat
Process ,Priority,,High
SetBatchLines -1 ;Run forrest, Run
SetKeyDelay -1
SetTimer Update, 1000 ;refresh list every 1 Second
posiGui:=A_Screenwidth-285 ;position Search box on Right side of Screen
Return
#Tab:: ;win + Tab is hotkey
Gui, Destroy ;Destroy any Existing Gui
Gui, +AlwaysOnTop -Caption +Border +ToolWindow ;keep window ontop, take away Border, title bar thin
Gui, Add, Text, x4 y4 , Search for `: ;add text
Gui, Add, Edit, x+5 y2 w80 vSearchstring gSearchItems ;add edit box with Gosub
Gui, Add, Text, x+5 , Goto line
Gui, Add, Edit, x+5 w40 Number vLineNumberedit ,
Gui, Add, ListView, x2 y+5 w250 r30 vchoice gListBoxClick -Multi grid AltSubmit, #|Line Text
Gui, Add, Button, w0 h0 Default gHitEnter, OK
Gui, add, StatusBar,,There are %CountLines% matching Lines. Escape to Exit ;add Status bar to window
Gosub SearchItems ;initial fill ListView
Gui, Show, y120 x%posiGui%, %Version% ;show the Gui
Return
Update:
WinGetTitle, WinTitle, PSPad - [ ;get the title of the current active window
IfNotEqual, Wintitle, %titleold% ;If the window title has changed, then
{
Titleold=%wintitle% ;make the window titles the same
Gosub, SearchItems ;refresh the ListView
}
Return ;do not refresh the ListView
SearchItems:
WinGetTitle, WinTitle, PSPad - [ ;get the title of the current active PSPad window
WinGet, ThisWindowID, ID, %WinTitle% ;Retrieves the specified window's unique ID
StringTrimLeft, FileName, WinTitle, 9 ;trim 9 Spaces from the left
StringTrimRight, FileName, FileName, 1 ;trim 1 Spaces from the Right
StringRight, TheFileExt, FileName, 1 ;get the last letter of the File extension
IfEqual, TheFileExt, *, StringTrimRight, FileName, FileName, 1 ;if the last letter is *, trim 1 from Right
Gui Submit, NoHide ;dont hide Gui
LV_Delete() ;Destroys the current list in the ListView
Loop, Read, %filename% ;Read the file
IfInString, A_LoopReadline,%Searchstring% ;if search =
{
x1=%A_LoopReadline%
x1=%x1% ;remove whiteSpaces
LV_Add("",A_Index,x1) ;add the line to list view
}
CountLines:=LV_GetCount() ;Count Lines in ListView
LV_ModifyCol() ;auto width columns
SB_SetText("There are " . CountLines . " matching Lines. Escape to Exit") ;update the Status bar
GuiControlGet, lastss, , searchstring ;get the current value from the Input box
If searchstring <> %lastss% ;compare the current value against the end of loop
{ ;- for any keypresses whilst loop running
Goto, searchitems ;recompile search results if search string different
}
Return
ListBoxClick: ;if mouse clicked
Gui Submit, NoHide
If A_GuiEvent = DoubleClick ;doubleclick in Listview
{
LV_GetText(LineNumber,A_EventInfo,1) ;Line Number = value of column1
WinActivate, ahk_id %ThisWindowID%
WinWaitActive, ahk_id %ThisWindowID%
Send, ^g ;the PSPad shortcut to Goto line window
WinWaitActive, Goto Line ;wait until the Goto window is active
Send, %LineNumber%{Enter} ;Send the lineNumber followed by Enter
}
If A_GuiEvent = Normal ;singleclick in Listview
{
LV_GetText(LineNumber,A_EventInfo,1) ;Line Number = value of column1
GuiControl, , LineNumberedit, %LineNumber% ;update the Number edit box
}
Return
Hitenter: ;if the enter key is hit whilst search active
Gui Submit, NoHide ;get all the values from the Gui
WinActivate, ahk_id %ThisWindowID%
WinWaitActive, ahk_id %ThisWindowID%
Send, ^g ;Send the lineNumber followed by Enter
WinWaitActive, Goto Line ;wait until the Goto window is active
Send, %LineNumberedit%{Enter} ;Send the lineNumber followed by Enter
Return
GuiEscape:
Gui,destroy ;kill the GUI
return
GuiClose: ;shut me down
ExitApp