Page 1 of 1

[IDE Tool] Search in PB Files

Posted: Thu Mar 21, 2024 4:23 pm
by HeX0R
A small IDE tool born out of stupidity (see comment on top)

Code: Select all

;/------------------------
;|
;| IDE Tool
;| Search in Purebasic files
;|
;| ©HeX0R 2024
;| Last Update: 25.03.2024
;|
;| I got nuts, while trying to find a source of mine
;| ...well in fact I must have been drunk and saved it in a completely wrong subfolder with a completely stupid file name.
;| But I knew a small part of its content, so I decided to make a quick IDE tool, which can scan all my sources and outputs the filename(s) and path
;|
;| I kept it simple, but it must be used as an IDE tool, no parameters needed!
;| It reads some environment variables to get your main source path (which it scans) and
;| the currently open IDE (to open found sources with it)
;|
;|
;| The regex functionality is untested, not even sure, if that really makes sense.
;|
;| V1.02
;|
;|
;\------------------------




; ----------------------------------------------------------------------------
; "THE BEER-WARE LICENSE":
; <HeX0R@coderbu.de> wrote this file. as long as you retain this notice you
; can do whatever you want with this stuff. If we meet some day, and you think
; this stuff is worth it, you can buy me a beer in return
; (see address on https://hex0rs.coderbu.de/).
; Or just go out and drink a few on your own/with your friends ;)
;=============================================================================

CompilerIf #PB_Compiler_Thread = 0
	CompilerError "Please enable threadsafe!"
CompilerEndIf
CompilerSelect #PB_Compiler_OS
	CompilerCase #PB_OS_Windows
		#LineFeed = #CRLF$
	CompilerCase #PB_OS_Linux
		#LineFeed = #LF$
	CompilerCase #PB_OS_MacOS
		#LineFeed = #CR$
CompilerEndSelect
UsePNGImageDecoder()

Runtime Enumeration Gadgets
	#frame_search_for
	#string_search_for
	#checkbox_isregex
	#checkbox_casesensitive
	#button_go
	#frame_results
	#listview_results
	#progressbar
	#string_files
EndEnumeration

#MY_EVENT  = #PB_Event_FirstCustomValue
#SEARCH_IN = ";pb;pbi;pbp;pbf;xml;"

Enumeration
	#evType_CountFiles_Finished
	#evType_Search_Progress
	#evType_Searching_Finished
	#evType_Searching_Found
EndEnumeration

Structure ThreadControl
	ThreadID.i
	Stop.i
	Regex.i
	Text$
	CaseSensitive.i
EndStructure

Structure Results
	File$
	Line.i
EndStructure

Global SourceDir$, IDE$, Files, SearchThread.ThreadControl
Global NewList Results.Results()

Procedure.s GetXMLString()
	Protected XML$

	XML$ + "<?xml version='1.0' encoding='UTF-16'?>"
	XML$ + ""
	XML$ + "<dialogs><!--Created by Dialog Design0R V1.85 => get it from: https://hex0rs.coderbu.de/en/sdm_downloads/dialogdesign0r/-->"
	XML$ + "  <window flags='#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_Invisible | #PB_Window_ScreenCentered' text='Search in PB Files' minwidth='480' minheight='350' name='window_main' xpos='67' ypos='133'>"
	XML$ + "    <vbox expand='item:2'>"
	XML$ + "      <frame text='Search for' id='#frame_search_for'>"
	XML$ + "        <gridbox columns='4' colexpand='item:2'>"
	XML$ + "          <string colspan='3' id='#string_search_for'/>"
	XML$ + "          <vbox rowspan='2' align='top' expand='no'>"
	XML$ + "            <buttonimage width='32' height='32' disabled='yes' id='#button_go' onevent='OnClick_ButtonGo()'/>"
	XML$ + "          </vbox>"
	XML$ + "          <checkbox text='is regex' id='#checkbox_isregex'/>"
	XML$ + "          <empty/>"
	XML$ + "          <checkbox text='case sensitive' id='#checkbox_casesensitive'/>"
	XML$ + "          <empty/> "
	XML$ + "        </gridbox> "
	XML$ + "      </frame>"
	XML$ + "      <frame text='Results' id='#frame_results'>"
	XML$ + "        <listview id='#listview_results' onleftdoubleclick='OnDblClick_List()'/> "
	XML$ + "      </frame>"
	XML$ + "      <hbox expand='item:1'>"
	XML$ + "        <progressbar flags='#PB_ProgressBar_Smooth' min='0' max='100' id='#progressbar'/>"
	XML$ + "        <string flags='#PB_String_ReadOnly | #PB_String_BorderLess' width='100' id='#string_files'/>"
	XML$ + "      </hbox> "
	XML$ + "    </vbox> "
	XML$ + "  </window>"
	XML$ + "</dialogs><!--DDesign0R Definition: PureBasic|1|1|1|__|-|1|AddOn:3:0-->"

	ProcedureReturn XML$
EndProcedure

Procedure CountFiles(*T.ThreadControl, Path$ = "")
	Protected Dir, Name$, Ext$, Result
	
	Dir = ExamineDirectory(#PB_Any, SourceDir$ + Path$, "*.*")
	If Dir
		While NextDirectoryEntry(Dir)
			If *T\Stop
				FinishDirectory(Dir)
				ProcedureReturn Result
			EndIf
			Name$ = DirectoryEntryName(Dir)
			Select DirectoryEntryType(Dir)
				Case #PB_DirectoryEntry_File
					Ext$ = ";" + LCase(GetExtensionPart(Name$)) + ";"
					If FindString(#SEARCH_IN, Ext$)
						Result + 1
					EndIf
				Case #PB_DirectoryEntry_Directory
					If Name$ <> "." And Name$ <> ".."
						Result + CountFiles(*T, Path$ + Name$ + #PS$)
					EndIf
			EndSelect
		Wend
		FinishDirectory(Dir)
	EndIf
	
	ProcedureReturn Result
EndProcedure

Procedure CountFiles_Thread(*T.ThreadControl)
	Protected Num
	
	Num = CountFiles(*T)
	PostEvent(#MY_EVENT, 0, #evType_CountFiles_Finished, 0, Num)
EndProcedure

Procedure SearchFiles(*T.ThreadControl, Pos = 0, Path$ = "")
	Protected Dir, Name$, Ext$, BOM, Content$, N, O, P, a$
	
	Dir = ExamineDirectory(#PB_Any, SourceDir$ + Path$, "*.*")
	If Dir
		While NextDirectoryEntry(Dir)
			If *T\Stop
				FinishDirectory(Dir)
				ProcedureReturn Result
			EndIf
			Name$ = DirectoryEntryName(Dir)
			Select DirectoryEntryType(Dir)
				Case #PB_DirectoryEntry_File
					Ext$ = ";" + LCase(GetExtensionPart(Name$)) + ";"
					If FindString(#SEARCH_IN, Ext$)
						Pos + 1
						If ReadFile(0, SourceDir$ + Path$ + Name$)
							BOM      = ReadStringFormat(0)
							Content$ = ReadString(0, BOM | #PB_File_IgnoreEOL)
							CloseFile(0)
							If *T\Regex
								If ExamineRegularExpression(*T\Regex, Content$)
									If NextRegularExpressionMatch(*T\Regex)
										AddElement(Results())
										Results()\File$ = Path$ + Name$
										a$ = Left(Content$, RegularExpressionMatchPosition(*T\Regex))
										Results()\Line = CountString(a$, #LineFeed) + 1
										PostEvent(#MY_EVENT, 0, #evType_Searching_Found, 0, @Results())
									EndIf
								EndIf
							Else
								P = FindString(Content$, *T\Text$, 1, *T\CaseSensitive)
								If P
									AddElement(Results())
									Results()\File$ = Path$ + Name$
									a$ = Left(Content$, P)
									Results()\Line = CountString(a$, #LineFeed) + 1
									PostEvent(#MY_EVENT, 0, #evType_Searching_Found, 0, @Results())
								EndIf
							EndIf
						EndIf
					EndIf
				Case #PB_DirectoryEntry_Directory
					If Name$ <> "." And Name$ <> ".."
						Pos = SearchFiles(*T, Pos, Path$ + Name$ + #PS$)
					EndIf
			EndSelect
			
			N = Int((Pos * 100) / Files)
			If N <> O
				PostEvent(#MY_EVENT, 0, #evType_Search_Progress, 0, N)
				O = N
			EndIf
		Wend
		FinishDirectory(Dir)
	EndIf
	
	ProcedureReturn Pos
EndProcedure

Procedure SearchFiles_Thread(*T.ThreadControl)
	SearchFiles(*T)
	PostEvent(#MY_EVENT, 0, #evType_Searching_Finished)
EndProcedure
	
Runtime Procedure OnDblClick_List()
	Protected i, a$, *R.Results
	
	i = GetGadgetState(#listview_results)
	If i > - 1
		If GetGadgetItemText(#listview_results, i) <> "No Files found!"
			*R = GetGadgetItemData(#listview_results, i)
			RunProgram(IDE$, #DQUOTE$ + SourceDir$ + *R\File$ + #DQUOTE$ + " /L " + Str(*R\Line), "")
		EndIf
	EndIf
	
EndProcedure

Runtime Procedure OnClick_ButtonGo()
	Protected a$, Regex, SearchPath$, Count, CaseSensitive
	
	a$ = GetGadgetText(#string_search_for)
	If a$ = ""
		ProcedureReturn
	EndIf
	SearchThread\Regex = 0
	SearchThread\Text$ = a$
	RemoveWindowTimer(DialogWindow(0), 0)
	ClearList(Results())
	If GetGadgetState(#checkbox_isregex) And CreateRegularExpression(1, a$, #PB_RegularExpression_NoCase)
		SearchThread\Regex = 1
	EndIf
	If GetGadgetState(#checkbox_casesensitive)
		SearchThread\CaseSensitive = 0
	Else
		SearchThread\CaseSensitive = #PB_String_NoCase
	EndIf
	DisableGadget(#button_go, 1)
	ClearGadgetItems(#listview_results)
	SetGadgetText(#frame_results, "Results")
	SearchThread\ThreadID = CreateThread(@SearchFiles_Thread(), @SearchThread)
EndProcedure

Procedure TimerCallBack()
	SetGadgetState(#progressbar, 0)
	RemoveWindowTimer(DialogWindow(0), 0)
EndProcedure

Procedure main()
	Protected a$, *R.Results, CountThread.ThreadControl, P
	
	CompilerIf #PB_Compiler_Debugger And Defined(HOME_SOURCE, #PB_Constant)
		;for testing without being used as IDE Tool
		SourceDir$ = #HOME_SOURCE
		IDE$       = #HOME_IDE
	CompilerElse
		a$ = GetEnvironmentVariable("PB_TOOL_Preferences")
		If a$
			If OpenPreferences(a$)
				PreferenceGroup("Global")
				SourceDir$ = ReadPreferenceString("SourceDirectory", "")
				ClosePreferences()
				If SourceDir$ = ""
					SourceDir$ = GetCurrentDirectory()
				EndIf
			EndIf
		EndIf
		IDE$ = GetEnvironmentVariable("PB_TOOL_IDE")
	CompilerEndIf
	
	If SourceDir$ = ""
		MessageRequester("Error", "Need to be started out of PB!", #PB_MessageRequester_Error)
		ProcedureReturn
	EndIf
	
	CreateDialog(0)
	a$ = GetXMLString()
	ParseXML(0, a$)
	OpenXMLDialog(0, 0, "window_main")
	;SetGadgetFont(#string_search_for, LoadFont(0, "Arial", 18))
	SetActiveGadget(#string_search_for)
	SetGadgetAttribute(#button_go, #PB_Button_Image, CatchImage(0, ?IconGo))
	GadgetToolTip(#button_go, "Start Searching")
	AddKeyboardShortcut(DialogWindow(0), #PB_Shortcut_Return, 1)
	BindEvent(#PB_Event_Timer, @TimerCallBack())
	HideWindow(DialogWindow(0), 0)
	
	CountThread\ThreadID = CreateThread(@CountFiles_Thread(), @CountThread)

	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_CloseWindow
				Break
			Case #PB_Event_Menu
				If EventMenu() = 1 And GetActiveGadget() = #string_search_for
					OnClick_ButtonGo()
				EndIf
			Case #MY_EVENT
				Select EventGadget()
					Case #evType_CountFiles_Finished
						Files                = EventData()
						CountThread\ThreadID = 0
						SetGadgetText(#string_files, "Files: " + Str(Files))
						DisableGadget(#button_go, 0)
					Case #evType_Search_Progress
						SetGadgetState(#progressbar, EventData())
					Case #evType_Searching_Finished
						SearchThread\ThreadID = 0
						If SearchThread\Regex
							FreeRegularExpression(SearchThread\Regex)
						EndIf
						If CountGadgetItems(#listview_results) = 0
							AddGadgetItem(#listview_results, -1, "No Files found!")
						EndIf
						AddWindowTimer(DialogWindow(0), 0, 1000)
						DisableGadget(#button_go, 0)
					Case #evType_Searching_Found
						*R = EventData()
						If *R
							P = CountGadgetItems(#listview_results)
							AddGadgetItem(#listview_results, - 1, *R\File$)
							SetGadgetItemData(#listview_results, P, *R)
							SetGadgetText(#frame_results, "Results [" + Str(P + 1) + " Files]")
						EndIf
				EndSelect
		EndSelect
	ForEver
	
	If CountThread\ThreadID And IsThread(CountThread\ThreadID)
		CountThread\Stop = #True
		WaitThread(CountThread\ThreadID)
	EndIf
	
	If SearchThread\ThreadID And IsThread(SearchThread\ThreadID)
		SearchThread\Stop = #True
		WaitThread(SearchThread\ThreadID)
	EndIf

EndProcedure

main()
End

DataSection
	IconGo:
	Data.l $474E5089, $0A1A0A0D, $0D000000, $52444849, $20000000, $20000000, $00000608, $7A7A7300, $000000F4, $58457419, $666F5374, $72617774, $64410065, $2065626F, $67616D49, $61655265
	Data.l $C9717964, $00003C65, $44495507, $DA785441, $4C7B579C, $FF19E795, $E173D77D, $E404401C, $514C22B6, $AEACCBC4, $D976762A, $4BC62EBA, $D59A69AA, $1B6B76CE, $9D2D9B63, $36C4B2C9
	Data.l $FB6C87F8, $4B1DAE67, $75DB4CED, $31BB1AEB, $B6816283, $56D6B74B, $66C2F5A5, $7A05B50D, $7411C228, $C080B01C, $B7DF7DB9, $782EF9E7, $F710700E, $F7811F91, $F9F79EFD, $13F7F73D
	Data.l $F567CB30, $F7749AEE, $7427E2DC, $87547A51, $0030DCB8, $11F87E83, $440047F8, $5D4517E8, $703C2D7B, $87F395F9, $CD9E1E9E, $F6ADC2B9, $53F9EDD7, $AECBE8A9, $D2EAA977, $B08AABCD
	Data.l $6B0734BA, $95436416, $9AA34592, $845F3381, $8FD02E70, $11077FA6, $F55B4689, $3FFBA11B, $9DC7FE7A, $36F4CD80, $57774809, $A2A2F9BD, $B67EBBAA, $575B02A9, $C5A34116, $7A1AEBAE
	Data.l $448C3447, $FD97A4F5, $BF0288AA, $2473F984, $F1FFF448, $DE6A2096, $68B114FE, $D553A5F4, $25A29F5B, $280876ED, $2E9AFB95, $9B9059AF, $5583FD5F, $85C05F44, $0E7461AB, $0B574DC6
	Data.l $0E1A08D3, $966957E8, $BBE46F82, $F63A6BA0, $7CE0B6D5, $F4EFBFA0, $B4C54DFE, $010D9B1D, $43556D65, $55F793D7, $BBBCEC14, $1A831D04, $0617D3FE, $9591059D, $3B59A90B, $24827404
	Data.l $DDF32B02, $E1259058, $781D13D5, $DEF6BDF5, $CF37AA8F, $9E424C9F, $F763796A, $E4977BAE, $9BCA443D, $1EE8A27B, $ADC3818A, $184EB748, $488724C7, $FD186F4B, $DE760AA3, $61BC90B3
	Data.l $63428814, $9BFDE9F7, $212448EF, $72BCC625, $BBA1DD6F, $D86E1516, $E702A5B3, $195C5182, $ED264389, $0A2E9912, $4416E99C, $99582451, $4FAC242F, $58EF9BEC, $B8E88E18, $71B03511
	Data.l $5E2E2E45, $56A7CAFE, $39E82C6C, $2726F7F9, $C2021D31, $8BD59D8A, $FE4A0A32, $7AD8F358, $E29D324A, $6E4C831D, $DBB71C94, $A5416890, $6C7C990D, $72B0C385, $D10A9842, $D1709306
	Data.l $E456F7FB, $CAE5BEA1, $8B45199D, $E2ED76FE, $58AC03FB, $569F5C74, $D76EBCBC, $A4909777, $2881F688, $B969BF29, $572C8903, $1FF50965, $3F99E2B4, $2AA3C134, $5CD91A14, $592F7C4F
	Data.l $6ACF3046, $7A1533A3, $976FD1FF, $A2BC57C1, $104E758E, $35BB5A28, $9771E3DB, $FF3AA46F, $B4CC7AE2, $89CE6388, $6DD20894, $16D2DF5A, $D7C781C4, $342FE7E1, $6892EBC0, $26F7304D
	Data.l $C9C0EFBF, $7579009F, $50F9EAF3, $759CA514, $C2A4043A, $FB1E07CA, $4442B2CE, $C60752A8, $C5DBA6E2, $52EC9014, $56B8A718, $F60D70FF, $C8499EFC, $534498D4, $42394A59, $E816CE88
	Data.l $3CF2CA8F, $584E9114, $EDD648FC, $696771DF, $E9D7292E, $4FAEA9C5, $1A272972, $F3A84509, $436C6BED, $F0BB8ED5, $3C034D74, $4A0E852E, $933E0E1D, $CAC75965, $1E481C92, $CDD60EFF
	Data.l $AC86DC04, $C928AF96, $64459336, $8B016E2B, $8F3F7500, $BBF79A8A, $B5A1F7B0, $6FF3E9F8, $C2B6E3C2, $64294921, $97212B25, $90C16715, $9BACE55C, $1506C809, $2025C7AD, $12441D46
	Data.l $80EF5B52, $5115189F, $79F0111A, $39A5785D, $D647AA88, $C703C9E3, $C4284F4D, $62F79520, $7938D0D4, $16EB2759, $D9925561, $621984BD, $C27E089F, $AAA3951A, $59148682, $C5D8E2AE
	Data.l $E1E2FC7E, $6FD7616F, $B544CDEA, $D64938C2, $7E03782C, $274CEC9F, $A3EC4E41, $9E75C8BC, $6371E3AA, $6829CD91, $14B89698, $8D983CD5, $E3D52851, $94E92586, $6D4C6E9E, $242192D5
	Data.l $713946CD, $68172653, $409A9182, $86A20782, $5BB91708, $96D765B0, $37B9E264, $F65FC43E, $890AA36E, $30A2AB9B, $8B408095, $09D143FD, $6E01261D, $B611A39F, $20F33448, $ADCB0135
	Data.l $0E46927C, $94C51555, $8697925D, $F027B583, $11DB33FA, $1ECD31A6, $32657271, $18E93701, $F626448D, $E39FCB45, $437D1D1D, $B2DC29B4, $77BB2402, $8CD90DC6, $1A76717F, $813BAF5E
	Data.l $D3B6AA37, $4E8344A5, $62F204D4, $E90F592A, $BA93A4F8, $DD64E930, $1C3C5C7C, $DB386EEA, $229F0BD6, $2C0AA2CC, $63289A02, $7517A65E, $D7F027F5, $06E9DB7D, $ADD74064, $594A59EB
	Data.l $0D469162, $1F7B5CF8, $1B9743C6, $08133758, $F2F1FE07, $ABB6E6E1, $575052E4, $EC0BD99B, $1C7C8D33, $8FF32913, $F64713FD, $3EB8F293, $7C0EE5A3, $8D50772A, $0200E2A6, $987CBCEF
	Data.l $D191F375, $AECF9EE1, $9D034285, $87D0BAFF, $DCEDEA0C, $6EBB24CD, $41D9C093, $76586E56, $691D8E07, $B66AD1C2, $97C8FC9C, $CBD30815, $CCE990D8, $473B6A0C, $8F40764E, $910E758E
	Data.l $392DD64E, $0D8DA1D5, $5F4C1A5D, $ABFBE3BC, $8A12CC4A, $1A4E3273, $66B3CEAF, $AD360149, $5492485B, $3775BA35, $271C6E9C, $458647C2, $1C0F4128, $B7CE8F3D, $A3723E0E, $B120102F
	Data.l $A03EE771, $BF98C2D3, $ABE4B2AC, $9EF8BA98, $9ACCF365, $49E98DD6, $07DF3AF0, $33E5AE26, $4F133729, $01349CC4, $19B9FECF, $C7027AD7, $EEFF8EDB, $CEBB1235, $804134A9, $DB3DE9FF
	Data.l $F0BE2178, $E7F307BE, $0ACB7A66, $D16B14FD, $B729A92C, $AD50BB1E, $401981EF, $9CD3749E, $780AF0CE, $5A12F1B1, $7C0E0F3E, $1FE1E07C, $C71F6891, $8C95F27F, $F07ACDAF, $3DDBED64
	Data.l $2FEFEB59, $2EF4C9CC, $6A9BF22E, $0B3D36CC, $9CDD2737, $6687B948, $3817BA5D, $778AD0D8, $9A8476CF, $0B6DBD7F, $1843D31D, $224E8DB6, $F28CFEC0, $AA72B99C, $D6609DF6, $C3FD6DFA
	Data.l $1737CF71, $122B23CD, $79B883EF, $E46E9BEF, $D45C6852, $9AA8D3AE, $7E1AC2C6, $CE1CF879, $920F76B4, $59FCADF2, $F2E41841, $EA52EE9B, $44C22284, $9B6AA782, $E797B2C6, $2918EA9F
	Data.l $A0F74CCB, $6B3E6BE2, $B5D526CC, $119EC905, $32E3D44C, $358E0DE7, $47B7E277, $FED5D05B, $E799D379, $95B6EE76, $CB5F2687, $10987E53, $72F210E6, $5A586E97, $BF27E9BA, $99CDCDCA
	Data.l $1F3CAEBF, $A5015495, $EACA7E79, $0F85339B, $C9FE56E1, $F8F88397, $7F4E2F52, $91F18BD6, $D340AEA1, $B7FECF0B, $DA56C3F5, $5D276ABE, $CD3EB6EC, $CC411408, $E778E425, $FAFBCE16
	Data.l $BC5BDDC6, $13DF65F9, $DD12BEDD, $09CCA630, $CBE37223, $77F6BED1, $6A1D6F03, $C2B81B18, $E04FDE75, $EDD8EFDB, $EE259A7E, $3491362B, $83213A42, $51B849E0, $9C6F8627, $D9276430
	Data.l $F638ADA8, $4E9C7EFF, $079511E7, $A7453D9A, $DB8C3CFB, $654D15E5, $7FE7E4F1, $23000C02, $C26A9ABB, $0070CE62, $49000000, $AE444E45
	Data.b $42, $60, $82
EndDataSection

Re: [IDE Tool] Search in PB Files

Posted: Thu Mar 21, 2024 11:10 pm
by boddhi
Hi HeX0R,
HeX0R wrote: A small IDE tool born out of stupidity (see comment on top)
Thanks for sharing :wink:

It's a very useful little tool that proves that being drunk can sometimes be a good thing (just kidding! :mrgreen: ).

Two very minor possible improvements (easily done by anyone who wants to): Reset the progress bar when the job is done, and a "String not found" item when the search returns nothing.

This could help to understand that the process is over.

Re: [IDE Tool] Search in PB Files

Posted: Thu Mar 21, 2024 11:27 pm
by HeX0R
That was an easy one, added it!
Thanks!

btw.:
being drunk is never a bad idea
(guess half of the forum will agree with me :mrgreen:)

Re: [IDE Tool] Search in PB Files

Posted: Thu Mar 21, 2024 11:49 pm
by boddhi
HeX0R wrote: That was an easy one, added it!
Thanks!
So quickly? :)
I've already done but thanks :wink:
HeX0R wrote: being drunk is never a bad idea
(guess half of the forum will agree with me :mrgreen:)
Except when it's time to put the key in the keyhole! :mrgreen:
Note: In France, we're legally obliged to say: Alcohol abuse is dangerous for your health. Drink in moderation. :D

Re: [IDE Tool] Search in PB Files

Posted: Fri Mar 22, 2024 10:07 am
by dige
Thanks Hexor, that's certainly useful. How can I try it out? Which parameters are required?

Re: [IDE Tool] Search in PB Files

Posted: Fri Mar 22, 2024 10:18 am
by boddhi
[EDITED] because null and void. Wrong information given.

Re: [IDE Tool] Search in PB Files

Posted: Fri Mar 22, 2024 10:59 am
by HeX0R
You have to compile it to an exe and add it to the PB IDE tools.
No parameters needed, just add some menu shortcut (or not)
boddhi wrote: Fri Mar 22, 2024 10:18 am In debugger mode, you need to define #HOME_SOURCE and #HOME_IDE constants,
In exe mode, you must create "PB_TOOL_Preferences" and "PB_TOOL_IDE" environment variables with path to preferences tool file for the first and path to PB folder for the second.
Ehm no, that was not the intended way to use it.
#HOME_SOURCE and #HOME_IDE are defined in my pbp file and were just used for my own testing purposes.
I thought I described the usage clearly in the comments? No?

Re: [IDE Tool] Search in PB Files

Posted: Fri Mar 22, 2024 2:12 pm
by boddhi
Hello,
HeX0R wrote: You have to compile it to an exe and add it to the PB IDE tools.
No parameters needed, just add some menu shortcut (or not)
I thought I described the usage clearly in the comments? No?
Sorry, the first time I had trouble setting up the PB-IDE tool because I was getting a "Need to be started out of PB!" error.
So, testing in debugger mode, after assigning the constants, I saw that it worked, then in normal mode that the source wasn't accessing my prefs file, so I ended up manually creating the environment variables. It worked, so I stopped there.

After your last message, I went back to the original code, removed the environment variables and the item in PB-IDE tools, recompiled the code and reinstalled it in the Tools menu.

And it worked fine.

I'm sorry, I don't understand what I did wrong the first time. :oops:
I therefore delete my message to dige.

PS: You see, be drunk is not always a good idea! :mrgreen:

Re: [IDE Tool] Search in PB Files

Posted: Fri Mar 22, 2024 11:03 pm
by HeX0R
boddhi wrote: Fri Mar 22, 2024 2:12 pm I'm sorry, I don't understand what I did wrong the first time. :oops:
No need to apologize, providing the source means also, anyone can use it however it suits them best.
I just wanted to point out that this was not the way I thought it should be used.

Re: [IDE Tool] Search in PB Files

Posted: Mon Mar 25, 2024 3:14 pm
by Michael Vogel
Quick hack to show the source code matching the search text (maybe this should be shown in a text box instead of a tooltip)...
...maybe the number of the files in the result list should also be seen in the status line.

Anyhow there are some issues here, starting a second search immediately after the first, the program crashes.

Code: Select all

; Define
	;/------------------------
	;|
	;| IDE Tool
	;| Search in Purebasic files
	;|
	;| ©HeX0R 2024
	;| Last Update: 21.03.2024
	;|
	;| I got nuts, while trying to find a source of mine
	;| ...well in fact I must have been drunk and saved it in a completely wrong subfolder with a completely stupid file name.
	;| But I knew a small part of its content, so I decided to make a quick IDE tool, which can scan all my sources and outputs the filename(s) and path
	;|
	;| I kept it simple, but it must be used as an IDE tool, no parameters needed!
	;| It reads some environment variables to get your main source path (which it scans) and
	;| the currently open IDE (to open found sources with it)
	;|
	;|
	;| The regex functionality is untested, not even sure, if that really makes sense.
	;|
	;| V1.01
	;|
	;|
	;\------------------------

	#HOME_SOURCE="C:\Tools\Programmer\Source\"
	#HOME_IDE="?"

	; ----------------------------------------------------------------------------
	; "THE BEER-WARE LICENSE":
	; <HeX0R@coderbu.de> wrote this file. as long as you retain this notice you
	; can do whatever you want with this stuff. If we meet some day, and you think
	; this stuff is worth it, you can buy me a beer in return
	; (see address on https://hex0rs.coderbu.de/).
	; Or just go out and drink a few on your own/with your friends ;)
	;=============================================================================

	CompilerIf #PB_Compiler_Thread = 0
		CompilerError "Please enable threadsafe!"
	CompilerEndIf
	UsePNGImageDecoder()

	Runtime Enumeration Gadgets
		#frame_search_for
		#string_search_for
		#checkbox_isregex
		#checkbox_casesensitive
		#button_go
		#frame_results
		#listview_results
		#progressbar
		#string_files
	EndEnumeration

	#MY_EVENT  = #PB_Event_FirstCustomValue
	#SEARCH_IN = ";pb;pbi;pbp;pbf;xml;"

	Enumeration
		#evType_CountFiles_Finished
		#evType_Search_Progress
		#evType_Searching_Finished
		#evType_Searching_Found
	EndEnumeration

	Structure ThreadControl
		ThreadID.i
		Stop.i
		Regex.i
		Text$
		CaseSensitive.i
	EndStructure


	Global SourceDir$, IDE$, Files, SearchThread.ThreadControl

	Global Dim Founds.s(0)
	Global Fcount.i

	DataSection
		IconGo:
		Data.l $474E5089, $0A1A0A0D, $0D000000, $52444849, $20000000, $20000000, $00000608, $7A7A7300, $000000F4, $58457419, $666F5374, $72617774, $64410065, $2065626F, $67616D49, $61655265
		Data.l $C9717964, $00003C65, $44495507, $DA785441, $4C7B579C, $FF19E795, $E173D77D, $E404401C, $514C22B6, $AEACCBC4, $D976762A, $4BC62EBA, $D59A69AA, $1B6B76CE, $9D2D9B63, $36C4B2C9
		Data.l $FB6C87F8, $4B1DAE67, $75DB4CED, $31BB1AEB, $B6816283, $56D6B74B, $66C2F5A5, $7A05B50D, $7411C228, $C080B01C, $B7DF7DB9, $782EF9E7, $F710700E, $F7811F91, $F9F79EFD, $13F7F73D
		Data.l $F567CB30, $F7749AEE, $7427E2DC, $87547A51, $0030DCB8, $11F87E83, $440047F8, $5D4517E8, $703C2D7B, $87F395F9, $CD9E1E9E, $F6ADC2B9, $53F9EDD7, $AECBE8A9, $D2EAA977, $B08AABCD
		Data.l $6B0734BA, $95436416, $9AA34592, $845F3381, $8FD02E70, $11077FA6, $F55B4689, $3FFBA11B, $9DC7FE7A, $36F4CD80, $57774809, $A2A2F9BD, $B67EBBAA, $575B02A9, $C5A34116, $7A1AEBAE
		Data.l $448C3447, $FD97A4F5, $BF0288AA, $2473F984, $F1FFF448, $DE6A2096, $68B114FE, $D553A5F4, $25A29F5B, $280876ED, $2E9AFB95, $9B9059AF, $5583FD5F, $85C05F44, $0E7461AB, $0B574DC6
		Data.l $0E1A08D3, $966957E8, $BBE46F82, $F63A6BA0, $7CE0B6D5, $F4EFBFA0, $B4C54DFE, $010D9B1D, $43556D65, $55F793D7, $BBBCEC14, $1A831D04, $0617D3FE, $9591059D, $3B59A90B, $24827404
		Data.l $DDF32B02, $E1259058, $781D13D5, $DEF6BDF5, $CF37AA8F, $9E424C9F, $F763796A, $E4977BAE, $9BCA443D, $1EE8A27B, $ADC3818A, $184EB748, $488724C7, $FD186F4B, $DE760AA3, $61BC90B3
		Data.l $63428814, $9BFDE9F7, $212448EF, $72BCC625, $BBA1DD6F, $D86E1516, $E702A5B3, $195C5182, $ED264389, $0A2E9912, $4416E99C, $99582451, $4FAC242F, $58EF9BEC, $B8E88E18, $71B03511
		Data.l $5E2E2E45, $56A7CAFE, $39E82C6C, $2726F7F9, $C2021D31, $8BD59D8A, $FE4A0A32, $7AD8F358, $E29D324A, $6E4C831D, $DBB71C94, $A5416890, $6C7C990D, $72B0C385, $D10A9842, $D1709306
		Data.l $E456F7FB, $CAE5BEA1, $8B45199D, $E2ED76FE, $58AC03FB, $569F5C74, $D76EBCBC, $A4909777, $2881F688, $B969BF29, $572C8903, $1FF50965, $3F99E2B4, $2AA3C134, $5CD91A14, $592F7C4F
		Data.l $6ACF3046, $7A1533A3, $976FD1FF, $A2BC57C1, $104E758E, $35BB5A28, $9771E3DB, $FF3AA46F, $B4CC7AE2, $89CE6388, $6DD20894, $16D2DF5A, $D7C781C4, $342FE7E1, $6892EBC0, $26F7304D
		Data.l $C9C0EFBF, $7579009F, $50F9EAF3, $759CA514, $C2A4043A, $FB1E07CA, $4442B2CE, $C60752A8, $C5DBA6E2, $52EC9014, $56B8A718, $F60D70FF, $C8499EFC, $534498D4, $42394A59, $E816CE88
		Data.l $3CF2CA8F, $584E9114, $EDD648FC, $696771DF, $E9D7292E, $4FAEA9C5, $1A272972, $F3A84509, $436C6BED, $F0BB8ED5, $3C034D74, $4A0E852E, $933E0E1D, $CAC75965, $1E481C92, $CDD60EFF
		Data.l $AC86DC04, $C928AF96, $64459336, $8B016E2B, $8F3F7500, $BBF79A8A, $B5A1F7B0, $6FF3E9F8, $C2B6E3C2, $64294921, $97212B25, $90C16715, $9BACE55C, $1506C809, $2025C7AD, $12441D46
		Data.l $80EF5B52, $5115189F, $79F0111A, $39A5785D, $D647AA88, $C703C9E3, $C4284F4D, $62F79520, $7938D0D4, $16EB2759, $D9925561, $621984BD, $C27E089F, $AAA3951A, $59148682, $C5D8E2AE
		Data.l $E1E2FC7E, $6FD7616F, $B544CDEA, $D64938C2, $7E03782C, $274CEC9F, $A3EC4E41, $9E75C8BC, $6371E3AA, $6829CD91, $14B89698, $8D983CD5, $E3D52851, $94E92586, $6D4C6E9E, $242192D5
		Data.l $713946CD, $68172653, $409A9182, $86A20782, $5BB91708, $96D765B0, $37B9E264, $F65FC43E, $890AA36E, $30A2AB9B, $8B408095, $09D143FD, $6E01261D, $B611A39F, $20F33448, $ADCB0135
		Data.l $0E46927C, $94C51555, $8697925D, $F027B583, $11DB33FA, $1ECD31A6, $32657271, $18E93701, $F626448D, $E39FCB45, $437D1D1D, $B2DC29B4, $77BB2402, $8CD90DC6, $1A76717F, $813BAF5E
		Data.l $D3B6AA37, $4E8344A5, $62F204D4, $E90F592A, $BA93A4F8, $DD64E930, $1C3C5C7C, $DB386EEA, $229F0BD6, $2C0AA2CC, $63289A02, $7517A65E, $D7F027F5, $06E9DB7D, $ADD74064, $594A59EB
		Data.l $0D469162, $1F7B5CF8, $1B9743C6, $08133758, $F2F1FE07, $ABB6E6E1, $575052E4, $EC0BD99B, $1C7C8D33, $8FF32913, $F64713FD, $3EB8F293, $7C0EE5A3, $8D50772A, $0200E2A6, $987CBCEF
		Data.l $D191F375, $AECF9EE1, $9D034285, $87D0BAFF, $DCEDEA0C, $6EBB24CD, $41D9C093, $76586E56, $691D8E07, $B66AD1C2, $97C8FC9C, $CBD30815, $CCE990D8, $473B6A0C, $8F40764E, $910E758E
		Data.l $392DD64E, $0D8DA1D5, $5F4C1A5D, $ABFBE3BC, $8A12CC4A, $1A4E3273, $66B3CEAF, $AD360149, $5492485B, $3775BA35, $271C6E9C, $458647C2, $1C0F4128, $B7CE8F3D, $A3723E0E, $B120102F
		Data.l $A03EE771, $BF98C2D3, $ABE4B2AC, $9EF8BA98, $9ACCF365, $49E98DD6, $07DF3AF0, $33E5AE26, $4F133729, $01349CC4, $19B9FECF, $C7027AD7, $EEFF8EDB, $CEBB1235, $804134A9, $DB3DE9FF
		Data.l $F0BE2178, $E7F307BE, $0ACB7A66, $D16B14FD, $B729A92C, $AD50BB1E, $401981EF, $9CD3749E, $780AF0CE, $5A12F1B1, $7C0E0F3E, $1FE1E07C, $C71F6891, $8C95F27F, $F07ACDAF, $3DDBED64
		Data.l $2FEFEB59, $2EF4C9CC, $6A9BF22E, $0B3D36CC, $9CDD2737, $6687B948, $3817BA5D, $778AD0D8, $9A8476CF, $0B6DBD7F, $1843D31D, $224E8DB6, $F28CFEC0, $AA72B99C, $D6609DF6, $C3FD6DFA
		Data.l $1737CF71, $122B23CD, $79B883EF, $E46E9BEF, $D45C6852, $9AA8D3AE, $7E1AC2C6, $CE1CF879, $920F76B4, $59FCADF2, $F2E41841, $EA52EE9B, $44C22284, $9B6AA782, $E797B2C6, $2918EA9F
		Data.l $A0F74CCB, $6B3E6BE2, $B5D526CC, $119EC905, $32E3D44C, $358E0DE7, $47B7E277, $FED5D05B, $E799D379, $95B6EE76, $CB5F2687, $10987E53, $72F210E6, $5A586E97, $BF27E9BA, $99CDCDCA
		Data.l $1F3CAEBF, $A5015495, $EACA7E79, $0F85339B, $C9FE56E1, $F8F88397, $7F4E2F52, $91F18BD6, $D340AEA1, $B7FECF0B, $DA56C3F5, $5D276ABE, $CD3EB6EC, $CC411408, $E778E425, $FAFBCE16
		Data.l $BC5BDDC6, $13DF65F9, $DD12BEDD, $09CCA630, $CBE37223, $77F6BED1, $6A1D6F03, $C2B81B18, $E04FDE75, $EDD8EFDB, $EE259A7E, $3491362B, $83213A42, $51B849E0, $9C6F8627, $D9276430
		Data.l $F638ADA8, $4E9C7EFF, $079511E7, $A7453D9A, $DB8C3CFB, $654D15E5, $7FE7E4F1, $23000C02, $C26A9ABB, $0070CE62, $49000000, $AE444E45
		Data.b $42, $60, $82
	EndDataSection

; EndDefine
Procedure.s GetXMLString()
	Protected XML$

	XML$ + "<?xml version='1.0' encoding='UTF-16'?>"
	XML$ + ""
	XML$ + "<dialogs><!--Created by Dialog Design0R V1.85 => get it from: https://hex0rs.coderbu.de/en/sdm_downloads/dialogdesign0r/-->"
	XML$ + "  <window flags='#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_Invisible | #PB_Window_ScreenCentered' text='Search in PB Files' minwidth='480' minheight='350' name='window_main' xpos='67' ypos='133'>"
	XML$ + "    <vbox expand='item:2'>"
	XML$ + "      <frame text='Search for' id='#frame_search_for'>"
	XML$ + "        <gridbox columns='4' colexpand='item:2'>"
	XML$ + "          <string colspan='3' id='#string_search_for'/>"
	XML$ + "          <vbox rowspan='2' align='top' expand='no'>"
	XML$ + "            <buttonimage width='32' height='32' disabled='yes' id='#button_go' onevent='OnClick_ButtonGo()'/>"
	XML$ + "          </vbox>"
	XML$ + "          <checkbox text='is regex' id='#checkbox_isregex'/>"
	XML$ + "          <empty/>"
	XML$ + "          <checkbox text='case sensitive' id='#checkbox_casesensitive'/>"
	XML$ + "          <empty/> "
	XML$ + "        </gridbox> "
	XML$ + "      </frame>"
	XML$ + "      <frame text='Results' id='#frame_results'>"
	XML$ + "        <listview id='#listview_results' onevent='PopupInfo()' onleftdoubleclick='OnDblClick_List()'/> "
	XML$ + "      </frame>"
	XML$ + "      <hbox expand='item:1'>"
	XML$ + "        <progressbar flags='#PB_ProgressBar_Smooth' min='0' max='100' id='#progressbar'/>"
	XML$ + "        <string flags='#PB_String_ReadOnly | #PB_String_BorderLess' width='100' id='#string_files'/>"
	XML$ + "      </hbox> "
	XML$ + "    </vbox> "
	XML$ + "  </window>"
	XML$ + "</dialogs><!--DDesign0R Definition: PureBasic|1|1|1|__|-|1|AddOn:3:0-->"

	ProcedureReturn XML$
EndProcedure
Procedure CountFiles(*T.ThreadControl, Path$ = "")
	Protected Dir, Name$, Ext$, Result

	Dir = ExamineDirectory(#PB_Any, SourceDir$ + Path$, "*.*")
	If Dir
		While NextDirectoryEntry(Dir)
			If *T\Stop
				FinishDirectory(Dir)
				ProcedureReturn Result
			EndIf
			Name$ = DirectoryEntryName(Dir)
			Select DirectoryEntryType(Dir)
			Case #PB_DirectoryEntry_File
				Ext$ = ";" + LCase(GetExtensionPart(Name$)) + ";"
				If FindString(#SEARCH_IN, Ext$)
					Result + 1
				EndIf
			Case #PB_DirectoryEntry_Directory
				If Name$ <> "." And Name$ <> ".."
					Result + CountFiles(*T, Path$ + Name$ + #PS$)
				EndIf
			EndSelect
		Wend
		FinishDirectory(Dir)
	EndIf

	ProcedureReturn Result
EndProcedure
Procedure CountFiles_Thread(*T.ThreadControl)
	Protected Num

	Num = CountFiles(*T)
	PostEvent(#MY_EVENT, 0, #evType_CountFiles_Finished, 0, Num)
EndProcedure
Procedure.s Schnipp(*stop.Character,pos)

	#LinesAboveBelow=0

	Protected *s.Character
	Protected *start.Character
	Protected count

	*start=*stop+(pos-2)*SizeOf(Character)
	While *start>=*stop
		If *start\c=#CR
			If count=#LinesAboveBelow
				Break
			EndIf
			count+1
		EndIf
		*start-SizeOf(Character)
	Wend
	*start+SizeOf(Character)
	*start+SizeOf(Character)*Bool(*start\c=#LF)

	count=0
	*stop+(pos)*SizeOf(Character)
	While *stop\c
		If *stop\c=#CR
			If count=#LinesAboveBelow
				Break
			EndIf
			count+1
		EndIf
		*stop+SizeOf(Character)
	Wend

	ProcedureReturn PeekS(*start,(*stop-*start)/SizeOf(Character))

EndProcedure
Procedure SearchFiles(*T.ThreadControl, Pos = 0, Path$ = "")

	Protected Dir, Name$, Ext$, BOM, Content$, *utf8, N, O
	Protected find

	Dir = ExamineDirectory(#PB_Any, SourceDir$ + Path$, "*.*")
	If Dir
		While NextDirectoryEntry(Dir)
			If *T\Stop
				FinishDirectory(Dir)
				ProcedureReturn Result
			EndIf
			Name$ = DirectoryEntryName(Dir)
			Select DirectoryEntryType(Dir)
			Case #PB_DirectoryEntry_File
				Ext$ = ";" + LCase(GetExtensionPart(Name$)) + ";"
				If FindString(#SEARCH_IN, Ext$)
					Pos + 1
					If ReadFile(0, SourceDir$ + Path$ + Name$)
						BOM      = ReadStringFormat(0)
						Content$ = ReadString(0, BOM | #PB_File_IgnoreEOL)
						CloseFile(0)
						If *T\Regex
							If MatchRegularExpression(*T\Regex, Content$)
								*utf8 = UTF8(Path$ + Name$)
								PostEvent(#MY_EVENT, 0, #evType_Searching_Found, 0, *utf8)
							EndIf
						Else
							find=FindString(Content$, *T\Text$, 1, *T\CaseSensitive)
							If find
								*utf8=UTF8(Path$ + Name$)
								Founds(Fcount)=Schnipp(@Content$,find)
								If Fcount%100=0
									ReDim Founds(Fcount+100)
								EndIf
								Fcount+1
								PostEvent(#MY_EVENT, 0, #evType_Searching_Found, 0, *utf8)
							EndIf
						EndIf
					EndIf
				EndIf
			Case #PB_DirectoryEntry_Directory
				If Name$ <> "." And Name$ <> ".."
					Pos = SearchFiles(*T, Pos, Path$ + Name$ + #PS$)
				EndIf
			EndSelect

			N = Int((Pos * 100) / Files)
			If N <> O
				PostEvent(#MY_EVENT, 0, #evType_Search_Progress, 0, N)
				O = N
			EndIf
		Wend
		FinishDirectory(Dir)
	EndIf

	ProcedureReturn Pos

EndProcedure
Procedure SearchFiles_Thread(*T.ThreadControl)
	SearchFiles(*T)
	PostEvent(#MY_EVENT, 0, #evType_Searching_Finished)
EndProcedure
Runtime Procedure OnDblClick_List()
	Protected i, a$

	i = GetGadgetState(#listview_results)
	If i > - 1
		If GetGadgetItemText(#listview_results, i) <> "No Files found!"
			RunProgram(IDE$, #DQUOTE$ + SourceDir$ + GetGadgetItemText(#listview_results, i) + #DQUOTE$, "")
		EndIf
	EndIf

EndProcedure
Runtime Procedure OnClick_ButtonGo()
	Protected a$, Regex, SearchPath$, Count, CaseSensitive

	a$ = GetGadgetText(#string_search_for)
	If a$ = ""
		ProcedureReturn
	EndIf
	SearchThread\Regex = 0
	SearchThread\Text$ = a$
	RemoveWindowTimer(DialogWindow(0), 0)
	If GetGadgetState(#checkbox_isregex) And CreateRegularExpression(1, a$, #PB_RegularExpression_NoCase)
		SearchThread\Regex = 1
	EndIf
	If GetGadgetState(#checkbox_casesensitive)
		SearchThread\CaseSensitive = 0
	Else
		SearchThread\CaseSensitive = #PB_String_NoCase
	EndIf
	DisableGadget(#button_go, 1)
	ClearGadgetItems(#listview_results)
	SearchThread\ThreadID = CreateThread(@SearchFiles_Thread(), @SearchThread)
EndProcedure
Runtime Procedure PopupInfo()
	
	PostEvent(#MY_EVENT,0,#listview_results,0,0)
	
EndProcedure

Procedure TimerCallBack()
	SetGadgetState(#progressbar, 0)
	RemoveWindowTimer(DialogWindow(0), 0)
EndProcedure
Procedure main()

	Protected a$, *utf8, CountThread.ThreadControl
	Protected popup
	
	CompilerIf #PB_Compiler_Debugger And Defined(HOME_SOURCE,#PB_Constant)
		;for testing without being used as IDE Tool
		SourceDir$ = #HOME_SOURCE
		IDE$       = #HOME_IDE
	CompilerElse
		a$ = GetEnvironmentVariable("PB_TOOL_Preferences")
		If a$
			If OpenPreferences(a$)
				PreferenceGroup("Global")
				SourceDir$ = ReadPreferenceString("SourceDirectory", "")
				ClosePreferences()
				If SourceDir$ = ""
					SourceDir$ = GetCurrentDirectory()
				EndIf
			EndIf
		EndIf
		IDE$ = GetEnvironmentVariable("PB_TOOL_IDE")
	CompilerEndIf

	If SourceDir$ = ""
		MessageRequester("Error", "Need to be started out of PB!", #PB_MessageRequester_Error)
		ProcedureReturn
	EndIf

	CreateDialog(0)
	a$ = GetXMLString()
	ParseXML(0, a$)
	OpenXMLDialog(0, 0, "window_main")
	;SetGadgetFont(#string_search_for, LoadFont(0, "Arial", 18))
	SetActiveGadget(#string_search_for)
	SetGadgetAttribute(#button_go, #PB_Button_Image, CatchImage(0, ?IconGo))
	GadgetToolTip(#button_go, "Start Searching")
	AddKeyboardShortcut(DialogWindow(0), #PB_Shortcut_Return, 1)
	BindEvent(#PB_Event_Timer, @TimerCallBack())
	HideWindow(DialogWindow(0), 0)

	CountThread\ThreadID = CreateThread(@CountFiles_Thread(), @CountThread)

	Repeat
		Select WaitWindowEvent()
		Case #PB_Event_CloseWindow
			Break
		Case #PB_Event_Menu
			If EventMenu() = 1 And GetActiveGadget() = #string_search_for
				OnClick_ButtonGo()
			EndIf
		Case #MY_EVENT
			Select EventGadget()
			Case #listview_results
				popup=GetGadgetState(#listview_results)
				If popup>=0 And popup<Fcount
				GadgetToolTip(#listview_results,Founds(popup))
			EndIf
			
			Case #evType_CountFiles_Finished
				Files                = EventData()
				CountThread\ThreadID = 0
				SetGadgetText(#string_files, "Files: " + Str(Files))
				DisableGadget(#button_go, 0)
			Case #evType_Search_Progress
				SetGadgetState(#progressbar, EventData())
			Case #evType_Searching_Finished
				SearchThread\ThreadID = 0
				If SearchThread\Regex
					FreeRegularExpression(SearchThread\Regex)
				EndIf
				If CountGadgetItems(#listview_results) = 0
					AddGadgetItem(#listview_results, -1, "No Files found!")
				EndIf
				AddWindowTimer(DialogWindow(0), 0, 1000)
				DisableGadget(#button_go, 0)
			Case #evType_Searching_Found
				*utf8 = EventData()
				If *utf8
					AddGadgetItem(#listview_results, - 1, PeekS(*utf8, -1, #PB_UTF8))
					FreeMemory(*utf8)
				EndIf
			EndSelect
		EndSelect
	ForEver

	If CountThread\ThreadID And IsThread(CountThread\ThreadID)
		CountThread\Stop = #True
		WaitThread(CountThread\ThreadID)
	EndIf

	If SearchThread\ThreadID And IsThread(SearchThread\ThreadID)
		SearchThread\Stop = #True
		WaitThread(SearchThread\ThreadID)
	EndIf

EndProcedure
main()

Re: [IDE Tool] Search in PB Files

Posted: Mon Mar 25, 2024 5:04 pm
by HeX0R
Nice idea!
I implemented it quite different to yours now.
When doubleclicking on the found file, the line will be selected in the IDE

btw.:
Instead of adding the two constants in the source, you probably should add it to the compiler options (tab constants)