Page 1 of 1

Modules 2 Templates

Posted: Fri Feb 10, 2017 12:20 am
by Zebuddi123
12/2/2017: updated --- now uses map`s to make sure modules are unique and recursive search. Extensively tested (100+) a lot for me :) works with out problem.
;----------------------------------------------------------------------------------------------------------------------------------


Hi to all Another attempt at quick access to modules, this time a better implementation although I`ve enjoyed learning :) Ok so this time a modules directory is read(recursively) parses the the ensuing files
a templates.prefs compatible string is generated with a directory order, generated 1100+ line for all my modules completed in just under a second :)

modules
--> module filenames::
--> Xinclude module
--> UseModule
--> module::procedurename()
.......................................
.......................................
1. Program needs to be run with ide closed.
2. Re-parsing your modules directory to update replaces any existing modules section already there with the new re- parsed section.
3. All procedure declarations are parsed from the declare/endeclare section
4. backup of the templates.prefs
5. Ideal when not in a project (single file work)
6. wip more to add

Zebuddi. :)

Image
Image

Module PBAboutInfo SaveAS Module_PBAboutInfo.pbi

To Large Download @ https://www.dropbox.com/s/57hr5gcknhl8h ... o.pbi?dl=0

Code: Select all

;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;\	view 113
;\	
;\	Pure Modules To Templates... Zebuddi 12/2/2017
;\	
;\	A Small IDE Tool.
;\	
;\	The Idea behind this program is to parse recursivly through a 
;\	Module files Directory pulling all the Procedures within 
;\	the declare file/Procedure sections, creating a hierarchical templates.prefs 
;\	section for the pbide. All based hierarchically from a single 
;\	folder in the templates called "Modules", where subfolders are the module 
;\	names, the  sub components, ( include modulename, use 
;\	modulename, procedurenames) all at a click.
;\	
;\	The program parses the pb templates.prefs file for previous 
;\	installs via this program and replaces it with the current (via 
;\	running the program)  any other existing data created by the 
;\	user is replaced on creating the new templates.prefs file.
;\	
;\	  
;\	
;\	
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

XIncludeFile "Module_PBAboutInfo.pbi"

UseMD5Fingerprint()

Prototype.i GetModuleFileNameExW(hProcess.l,hModule.l,*lpFilename,nSize.i)
Prototype.i GetModuleFileNameExA(hProcess.l,hModule.l,*lpFilename,nSize.i)

CompilerIf #PB_Compiler_Unicode
	Global GetModuleFileNameEx.GetModuleFileNameExW
CompilerElse
	Global GetModuleFileNameEx.GetModuleFileNameExA
CompilerEndIf

Lib = OpenLibrary(#PB_Any,"psapi.dll")
If Lib
	CompilerIf #PB_Compiler_Unicode
		Global GetModuleFileNameEx.GetModuleFileNameExW = GetFunction(Lib,"GetModuleFileNameExW")
	CompilerElse
		Global GetModuleFileNameEx.GetModuleFileNameExA = GetFunction(Lib,"GetModuleFileNameExA")
	CompilerEndIf
Else
	MessageRequester("Warning", "Can not load Psapi.dll" ,#MB_ICONWARNING)
	End
EndIf



EnableExplicit
;{-- ENUMERATIONS
#File 					= 0
#DirectoryModules$	= "Directory: Modules  "
#CloseDirectory$	 	= "CloseDirectory"
#MyModulesDir$ 		= "C:\Users\dufus\Documents\Programming\Modules"
;}

;{ -- STRUCTURES

Structure PROCDATA
	sProcName.s
	sComment.s ; used to create a comment, after a declare procedure() ; this proc changes the  pointer etc: and added to the comment section in templates
EndStructure

Structure MODULEDATA
	sFileAndPath.s
	sModName.s 
	md5.s
	List _ll_ProcName_s.PROCDATA()
EndStructure : NewMap _m_ModuleProcedureData.MODULEDATA()

NewList List2Sort.MODULEDATA()
NewList _ll_ModulePathAndFileName_s.s()

;}

;{-- GLOBALS
Global giWinID.i, giStringModuleFolder, giStringTemplateFolder.i, giStringPattern.i,   giEvent.i, giButton.i, giStatusBar.i, gsDirectoryToSearch.s, gsTemplatesPrefsPath.s, gsMatchStringPattern.s, *buffer, bIsPBIde.b
;}

;{-- PROCEDURES

Procedure.i iCheckRunningExe(sExeName.s)
	Protected iHit.i = 0, iSnap.i, ImageName$, hProcess.i, FilePath$, Proc32.PROCESSENTRY32
	Proc32\dwSize = SizeOf(PROCESSENTRY32)
	iSnap = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0) 
	If iSnap
		If Process32First_(iSnap, @Proc32)
			While Process32Next_(iSnap, @Proc32)
				ImageName$ = PeekS(@Proc32\szExeFile)
				FilePath$ = Space(1024)
				hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, 0, Proc32\th32ProcessID)
				If hProcess
					GetModuleFileNameEx(hProcess, 0, @FilePath$, Len(FilePath$))
					CloseHandle_(hProcess)
				EndIf             
				If UCase(ImageName$) = UCase(sExeName)
					iHit = 1
				EndIf
			Wend
		EndIf
		CloseHandle_(iSnap)
	EndIf
	If iHit
		ProcedureReturn 1
	Else
		ProcedureReturn 0
	EndIf	
EndProcedure

Procedure.s iGetLastErrorAsText() ; 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.i SearchDirectory(dir$, List yourLinkedList.s(), pattern$="", recursive=1)
   Static level.l=-1
   If Not Right(dir$, 1) = "\"
      dir$+"\"
   EndIf
   Protected dir.l=ExamineDirectory(#PB_Any, dir$, pattern$)
   If dir
      While NextDirectoryEntry(dir)
         If DirectoryEntryName(dir) <> "." And DirectoryEntryName(dir) <> ".."
         	AddElement(yourLinkedList())
            	yourLinkedList() + dir$ + DirectoryEntryName(dir)
            If DirectoryEntryType(dir) = #PB_DirectoryEntry_Directory
               yourLinkedList()
            EndIf
         EndIf
      Wend
      FinishDirectory(dir)
   EndIf
   Protected all.l=ExamineDirectory(#PB_Any, dir$, "")
   If all
      While NextDirectoryEntry(all)
         If DirectoryEntryType(all) = #PB_DirectoryEntry_Directory And DirectoryEntryName(all) <> "." And DirectoryEntryName(all) <> ".."
            level+1
            SearchDirectory(dir$+DirectoryEntryName(all)+"\", yourLinkedList(), pattern$, recursive)
            level-1
         EndIf
      Wend
      FinishDirectory(all)
   EndIf
   ProcedureReturn ListSize(yourLinkedList())
EndProcedure

Procedure.i GetModuleProcedures( Map _m_ModuleProcedureData.MODULEDATA(), List _ll_ModulePathAndFileName_s.s())
	Protected  nbr.i, iSringFormat.i, iNbrBytes.i, sModData.s, *buffer, iDNbr.i, iPNbr.i, iIndex.i, filemapkey$, procmapkey$
	Protected  iRegexDeclareModule.i  		= CreateRegularExpression(#PB_Any, "DeclareModule.+EndDeclareModule", #PB_RegularExpression_MultiLine|#PB_RegularExpression_DotAll) 
	Protected iRegexDeclareProcedures.i  	= CreateRegularExpression(#PB_Any, "Declare *\w+ *\(.*\).*|Declare\.. *\w+ *\(.*\).*|Prototype *\w+ *\(.*\).*|Prototype\.. *\w+ *\(.*\).*|PrototypeC *\w+ *\(.*\).*|PrototypeC\.. *\w+ *\(.*\).*", #PB_RegularExpression_MultiLine)
	Protected iRegexModName.i			= CreateRegularExpression(#PB_Any, "(?<=DeclareModule\s)\w+")
	Protected iRegexRemovePrefix.i		= CreateRegularExpression(#PB_Any, "\..\s")
	Protected mapindex.i, iFindIDEOptions.i , fVal.f, fProgress.f

	fProgress = (100/ListSize(_ll_ModulePathAndFileName_s()))
	ForEach _ll_ModulePathAndFileName_s()
		
		If ReadFile(0, _ll_ModulePathAndFileName_s())
			
			StatusBarText(giStatusBar,  0, "Processing Module " + GetFilePart(_ll_ModulePathAndFileName_s()), #PB_StatusBar_Center)
			fVal + fProgress : StatusBarProgress(giStatusBar, 1, fVal) ; update the progress bar
			Delay(50)
			iSringFormat.i 		= ReadStringFormat(0)
			*buffer 			= AllocateMemory(Lof(0))
			iNbrBytes 			= ReadData(0, *buffer, Lof(0))
			sModData.s 		= PeekS(*buffer,Lof(0), iSringFormat)

			;{ -- remove ide option stuff for md5
			 iFindIDEOptions 	= FindString(sModData, "; IDE Options")
			 If iFindIDEOptions
			 	sModData 		= Left(sModData, (iFindIDEOptions - 1))
			 EndIf	
			 ;}

			;{ get module name
			If MatchRegularExpression(iRegexModName, sModData)
				Dim asModName.s(0)
				ExtractRegularExpression(iRegexModName, sModData, asModName())
				procmapkey$ =StringFingerprint(sModData, #PB_Cipher_MD5)
				mapindex + 1
				AddMapElement(_m_ModuleProcedureData(), procmapkey$)
				_m_ModuleProcedureData(procmapkey$)\sFileAndPath = _ll_ModulePathAndFileName_s()
				_m_ModuleProcedureData(procmapkey$)\sModName =  Trim(RemoveString(asModName(0), Chr(13))) + "::"
				;}
				
				;{ -- Extract the module procedure from the declaremodule section; public procedures
				If MatchRegularExpression(iRegexDeclareModule,sModData )
					Dim asDeclares.s(0)
					iDNbr =ExtractRegularExpression(iRegexDeclareModule, sModData, asDeclares())
					If iDNbr
						If MatchRegularExpression(iRegexDeclareProcedures, asDeclares(0))
							
						
							
							Dim _asProc.s(0)
							iPNbr = ExtractRegularExpression(iRegexDeclareProcedures, asDeclares(0), _asProc())
							
							For iIndex = 0 To iPNbr-1	
								_asProc(iIndex) = RemoveString(_asProc(iIndex), Chr(9))
								_asProc(iIndex) = Mid(_asProc(iIndex), FindString(_asProc(iIndex), Chr(32) ,1) + 1)
								AddElement(_m_ModuleProcedureData(procmapkey$)\_ll_ProcName_s())
								
								If FindString(_asProc(iIndex), Chr(59))
									_m_ModuleProcedureData(procmapkey$)\_ll_ProcName_s()\sProcName = Trim(Left(_asProc(iIndex), FindString(_asProc(iIndex), Chr(59)) - 1)); get proc name
									_m_ModuleProcedureData(procmapkey$)\_ll_ProcName_s()\sComment = Trim(Mid(_asProc(iIndex),  FindString(_asProc(iIndex), Chr(59)) + 1)) ; get comment
								Else
									_m_ModuleProcedureData(procmapkey$)\_ll_ProcName_s()\sProcName = Trim(_asProc(iIndex))
								EndIf
								
							Next
							FreeArray(_asProc())
						EndIf
					EndIf
					FreeArray(asDeclares())
				EndIf
				FreeArray(asModName())
			EndIf
			;}
			iNbrBytes =  0 : sModData = ""
			CloseFile(0)
		Else
			MessageRequester("File Error", iGetLastErrorAsText())
		EndIf
	Next

	;{-- clean up
	FreeMemory(*buffer)
	FreeArray(asDeclares())
	FreeArray(asModName())
	FreeArray(_asProc())
	FreeRegularExpression(iRegexDeclareModule)
	FreeRegularExpression(iRegexDeclareProcedures)
	FreeRegularExpression(iRegexModName)
	FreeRegularExpression(iRegexRemovePrefix)
	;}
	ProcedureReturn MapSize(_m_ModuleProcedureData())
	
EndProcedure

Procedure.s ParseOldTempleFile( sFilename.s) 
	Protected *buffer ,iRslt.i, sStringData.s, sNew.s
	StatusBarText(giStatusBar, 0, "Processing Old Templates.prefs File", #PB_StatusBar_Center)
	If ReadFile(0, sFilename) 
		*buffer 						= AllocateMemory(Lof(0))
		iRslt 							= ReadData(0, *buffer, Lof(0))
		sStringData 					= PeekS(*buffer,iRslt, ReadStringFormat(0)) ; always going to be "TEMPLATES:1.0"  as the first line for valid file.
		If FindString(sStringData, #DirectoryModules$)
			Protected iRegexRemove.i =  CreateRegularExpression(#PB_Any, #DirectoryModules$+".+?^" +#CloseDirectory$, #PB_RegularExpression_DotAll|#PB_RegularExpression_MultiLine|#PB_RegularExpression_AnyNewLine)	
			If MatchRegularExpression(iRegexRemove, sStringData)
				sNew = ReplaceRegularExpression(iRegexRemove, sStringData, "")
				FreeMemory(*buffer)
				CloseFile(0)
				FreeRegularExpression(iRegexRemove)
			EndIf 
		EndIf
		If sNew = ""
			ProcedureReturn sStringData
		Else
			ProcedureReturn sNew
		EndIf		
	Else
		MessageRequester( "Parse Error", "Unable to Parse Old Template File"  +#CRLF$ + iGetLastErrorAsText())
		CloseFile(0)
		ProcedureReturn ""
	EndIf
EndProcedure

Procedure.i UpdateTemplates(List _ll_ModulePathAndFileName_s.s(), Map _m_ModuleProcedureData.MODULEDATA(), List List2Sort.MODULEDATA() ) ; returns number of procs found
	Protected sIncludeFile.s, sTemplate.s, sComment.s, sCode.s, sDirectoryTitle.s ,sCompiledString.s,  iRslt.i, iTemplateFileBackUp.i, bRequestRslt.b, sNewModuleDataString.s
	Protected  iNbrProcs.i, iFilecount.i, iLineCount.i, iStartTimeMSec.i = ElapsedMilliseconds()
	Protected sIndent2 . s = Space(2) , sIndent4.s = Space(4) , sIndent6.s = Space(6) 
	
		If SearchDirectory(gsDirectoryToSearch,  _ll_ModulePathAndFileName_s() , gsMatchStringPattern, 1)
			If GetModuleProcedures( _m_ModuleProcedureData(),  _ll_ModulePathAndFileName_s())
				
				;{ -- Copy mapdata to linkedlist for sorting via module names
				With _m_ModuleProcedureData()
				ForEach _m_ModuleProcedureData()
					AddElement(List2Sort())
					List2Sort()\sFileAndPath = \sFileAndPath
					List2Sort()\sModName     = \sModName
					ForEach \_ll_ProcName_s()
						AddElement(List2Sort()\_ll_ProcName_s())
						List2Sort()\_ll_ProcName_s()\sProcName = \_ll_ProcName_s()\sProcName
						List2Sort()\_ll_ProcName_s()\sComment = \_ll_ProcName_s()\sComment
					Next
					iNbrProcs + ListSize(List2Sort()\_ll_ProcName_s())
				Next
				SortStructuredList(List2Sort(), #PB_Sort_Ascending, OffsetOf(MODULEDATA\sModName), TypeOf(MODULEDATA\sModName))
			EndWith
			;}

			;{ -- Sorts the procedures 
			With List2Sort()
				ForEach List2Sort()
					Protected NewList _ll_ProcSortList_s.PROCDATA() ; list for sorting the procedures within each module
					ForEach \_ll_ProcName_s()
						AddElement(_ll_ProcSortList_s()) : _ll_ProcSortList_s()\sProcName = \_ll_ProcName_s()\sProcName
					Next
					SortStructuredList(_ll_ProcSortList_s(),#PB_Sort_Ascending, OffsetOf(PROCDATA\sProcName), TypeOf(PROCDATA\sProcName))
					ResetList(List2Sort()\_ll_ProcName_s())
					FirstElement(List2Sort()\_ll_ProcName_s())
					ForEach _ll_ProcSortList_s()
						List2Sort()\_ll_ProcName_s()\sProcName = _ll_ProcSortList_s()\sProcName
						List2Sort()\_ll_ProcName_s()\sComment = \_ll_ProcName_s()\sComment
						NextElement(List2Sort()\_ll_ProcName_s())
					Next
					FreeList(_ll_ProcSortList_s())
				Next	
			EndWith
			;}
			
				;{ -- create all the new string data	
				With List2Sort()
					ForEach List2Sort()
					If ListSize(\_ll_ProcName_s()) > 0
						iFilecount + 1
						sIncludeFile 	= RemoveString(GetFilePart(\sFileAndPath), GetExtensionPart(gsMatchStringPattern))
						
						sDirectoryTitle 	=  sIndent2 + "Directory: " 	  + RemoveString(GetFilePart(\sModName), GetExtensionPart(gsMatchStringPattern)) + Chr(32) + "(" + Str(ListSize(\_ll_ProcName_s()))  + ")" +#CRLF$
						
						;{-- IncludeFile
						sTemplate 		= sIndent4 	+ "Template: " +"-> XIncludeFile " + Chr(34) + \sModName + Chr(34) +  #CRLF$
						sComment 		= sIndent6 	+ "Comment: " + "Insert`s the Statement  XIncludeFile " + Chr(34) + \sFileAndPath + Chr(34) +  "  at the current cursor position."+ #CRLF$
						sCode  			= sIndent6 	+  "Code:  XincludeFile " + Chr(34)  + \sFileAndPath+ Chr(34) + "\n" +#CRLF$
						;}
						sCompiledString + sDirectoryTitle + sTemplate + sComment + sCode :  sTemplate = "" : sComment = "" : sCode= "" : sDirectoryTitle = ""
						
						;{-- UseModule
						sTemplate		=  sIndent4 	+ "Template: " +"--> UseModule " + Left(\sModName, Len(\sModName) -2) + #CRLF$ 
						sComment 		= sIndent6 	+ "Comment: " +   "Insert`s the Statement  UseModule " + Chr(34) +  Left(\sModName, Len(\sModName) -2) + Chr(34)  + " at the current cursor position."+ #CRLF$ 
						sCode  			= sIndent6 	+  "Code:  UseModule  " + Left(\sModName, Len(\sModName) -2) + "\n" + #CRLF$ 
						;}
						
						iLineCount + 7
						sCompiledString + sDirectoryTitle  + sTemplate + sComment + sCode  : 	sTemplate = "" : sComment = "" : sCode ="" : sDirectoryTitle  =""
						
						ForEach \_ll_ProcName_s()
							;{-- procedures
							sTemplate 	= sIndent4 	+ "Template:  -> ++ " + Left(\_ll_ProcName_s()\sProcName, FindString(\_ll_ProcName_s()\sProcName, Chr(40)) -1) + Chr(40) + Chr(41) + #CRLF$
							
							If \_ll_ProcName_s()\sComment > ""
								;sComment 	= sIndent6 	+ "Comment: " + sIncludeFile +  \_ll_ProcName_s()\sProcName + "\n"  +
								sComment 	= sIndent6 	+ "Comment: " + \_ll_ProcName_s()\sComment + #CRLF$ 
							Else
								sComment 	= sIndent6 	+ "Comment: " + sIncludeFile + " Add`s the Procedure   " + \_ll_ProcName_s()\sProcName + " at the current cursor position." + #CRLF$
							EndIf
							
							sCode  		= sIndent6 	+  "Code:  " + \sModName +  \_ll_ProcName_s()\sProcName + "\n" +  #CRLF$
							iLineCount + 3
							;}
							sCompiledString + sTemplate + sComment + sCode : 	sTemplate = "" : sComment = "" : sCode = "" : sDirectoryTitle = ""
						Next	
						
						sCompiledString + sIndent2 + "CloseDirectory" + #CRLF$
					EndIf	
				Next
				;} 

				;{-- Back up the existing templates.prefs file
				iTemplateFileBackUp = CopyFile(gsTemplatesPrefsPath, ReplaceString(gsTemplatesPrefsPath, GetExtensionPart(gsTemplatesPrefsPath),"BackUp"))
				If Not iTemplateFileBackUp ; cannot create a backup
					bRequestRslt = MessageRequester("BackUp Error", "Continue Without Backing Up the Templates.prefs File ? ", #PB_MessageRequester_YesNo|#PB_MessageRequester_Warning)
				EndIf	
				;}
				;{ -- check to see if user wants to continue
				If iTemplateFileBackUp Or bRequestRslt = #PB_MessageRequester_Yes
					sNewModuleDataString =  ParseOldTempleFile(gsTemplatesPrefsPath) ; remove any predefined existing modules already created by this program and the rest.
					StatusBarText(giStatusBar, 0, "Replacing Old Templates.prefs File Data.", #PB_StatusBar_Center)
					sNewModuleDataString  = sNewModuleDataString + #DirectoryModules$  +  "  (" + Str(MapSize(_m_ModuleProcedureData()))  + "/"  + Str( iNbrProcs) + " )" +  #CRLF$ +  sCompiledString +#CRLF$ +  #CloseDirectory$ + #CRLF$ 
				EndIf	 
				If CreateFile(#File, gsTemplatesPrefsPath) ; open file append  new data
					iRslt =WriteString(0, sNewModuleDataString)
					CloseFile(#File)
					StatusBarText(giStatusBar, 0, "Update Process Completed.  Processed " + Str(iFilecount) + " File`s, Added " + Str( iLineCount) + " Lines. In " + Str( ElapsedMilliseconds() - iStartTimeMSec) + " ms", #PB_StatusBar_Center)
				Else
					MessageRequester("File Creation Error", iGetLastErrorAsText())
					If iRslt
						StatusBarText(giStatusBar, 0, "Templates.prefs update Complete", #PB_StatusBar_Center)
					Else
						MessageRequester("File Write Error", iGetLastErrorAsText())
					EndIf
				EndIf
				
			EndIf	
		Else
			MessageRequester("Module File Error", "No Module files found")
			End
		EndIf
	EndWith
EndProcedure

Procedure mywin(List _ll_ModulePathAndFileName_s.s(),  Map _m_ModuleProcedureData.MODULEDATA(), List List2Sort.MODULEDATA())
	Protected sTemplatePath.s {#MAX_PATH * 2}, bTemplateFile.b, bModuleDirectory.b,  sTemplatePrefsFile.s = "\PureBasic\Templates.prefs"
	
	;Make sure the ide is closed
	CompilerIf Not #PB_Compiler_Debugger
		While iCheckRunningExe("Purebasic.exe")
			MessageRequester("Program Intialization Error","Please Close The PBIde Before Continuing")
			Delay(1500)
			bIsPBIde = #True
		Wend
	CompilerEndIf
	
	giWinID = OpenWindow(#PB_Any, 0, 0, 600, 120 + MenuHeight(), "Pure Module Template Maker", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
	
	If CreateMenu(0, WindowID(giWinID))
		MenuTitle("About")
			MenuItem(0, "About --- Modules 2 Templates")
	EndIf 
	
	If giWinID
		
		giStringModuleFolder  		= StringGadget(#PB_Any, 120, 5, 475, 25, "")
		giStringTemplateFolder 	= StringGadget(#PB_Any, 120, 35, 475, 25, "")
		giStringPattern				= StringGadget(#PB_Any, 120, 65, 225, 25, "Module*.pbi")  	
		giButton					= ButtonGadget(#PB_Any, 347, 64, 248, 27, "Process Modules to Template Prefs") 
		
		TextGadget(2, 5, 65, 60, 25, "Pattern: (Module*.*)")
		TextGadget(0, 5, 10, 110, 25, "ModulesPath:")
		TextGadget(1, 5, 35, 110, 25, "Template Path:")
		
		giStatusBar = CreateStatusBar(#PB_Any, WindowID(giWinID))
		If giStatusBar
			AddStatusBarField(WindowWidth(giWinID) - 100)
			AddStatusBarField(100)
		EndIf
		
		SHGetSpecialFolderPath_(#Null, @sTemplatePath, #CSIDL_APPDATA ,0)
		
			bModuleDirectory = #True
			If FileSize(sTemplatePath + sTemplatePrefsFile ) ; check to see if templates.prefs exists
				SetGadgetText(giStringTemplateFolder, sTemplatePath + sTemplatePrefsFile)	
				bTemplateFile = #True
				SetGadgetText(giStringModuleFolder, #MyModulesDir$ )    ;    PathRequester("Select ModulesPath", "") )
				bModuleDirectory = #True
			Else
				SetGadgetText(giStringTemplateFolder, PathRequester("Select  Purebasic Prefs Path", ""))
				bTemplateFile = #True
				SetGadgetText(giStringModuleFolder, #MyModulesDir$ ) ;;     PathRequester("Select ModulesPath", ""))
				bModuleDirectory = #True
			EndIf	

		StatusBarText(giStatusBar, 0, "Ready to Process...", #PB_StatusBar_Center)
		Repeat
			giEvent = WaitWindowEvent()
			Select giEvent
					
				Case #PB_Event_Menu
					Select EventMenu()
						Case 0
							PBAboutInfo::about_purebasic(giWinID,  "Modules 2 Templates . Small Utility to create PB IDE Templates from Modules.")
					EndSelect
					
					
				Case #PB_Event_Gadget
					Select EventGadget()
						Case giButton	
							If Bool(bModuleDirectory = #True And bTemplateFile = #True)
								StatusBarText( giStatusBar, 0, "Processing Modules .....", #PB_StatusBar_Center) 
								gsTemplatesPrefsPath 	= GetGadgetText(giStringTemplateFolder)
								gsDirectoryToSearch 	= GetGadgetText(giStringModuleFolder)
								gsMatchStringPattern	= GetGadgetText(giStringPattern)
								UpdateTemplates(_ll_ModulePathAndFileName_s(), _m_ModuleProcedureData(), List2Sort())
								DisableGadget(giButton, #True) 
								Delay(1000)
								
								If bIsPBIde = #True
									StatusBarText(giStatusBar, 0, "Running the PB Ide", #PB_StatusBar_Center)
									Delay(1000)
									RunProgram(#PB_Compiler_Home +"\PureBasic.exe")
								EndIf
								
								Break
							EndIf	
					EndSelect
					
			EndSelect
			
		Until giEvent = #PB_Event_CloseWindow 
	Else
		MessageRequester("OpenWindow() Error", iGetLastErrorAsText())
	EndIf
EndProcedure
;}


;----------------------------------------- MAIN ------------------------------------
UseModule  PBAboutInfo

mywin(_ll_ModulePathAndFileName_s(), _m_ModuleProcedureData(), List2Sort())
;cleanup
FreeList(_ll_ModulePathAndFileName_s())
FreeList(List2Sort())
FreeMap(_m_ModuleProcedureData())

End

Re: Modules 2 Templates

Posted: Sun Feb 12, 2017 8:52 pm
by Zebuddi123
12/2/2017: updated --- now uses map`s to make sure modules are unique and recursive search. Extensively tested (100+) a lot for me :) works with out problem.

introduced a bug with XincludeFile fixed:
;----------------------------------------------------------------------------------------------------------------------------------

Code updated in first post. Zebuddi.

Re: Modules 2 Templates

Posted: Mon Feb 13, 2017 9:52 pm
by Zebuddi123
13.02.2017 Updated Modules List now sorted. zebuddi.

Re: Modules 2 Templates

Posted: Wed Feb 15, 2017 8:33 pm
by Zebuddi123
15/02/2017 Updated Shows totals (Modules (54/602)) umber of modules add and procedures available. Can use as a tool no argument.

1. will request ide be closed
2. updates the templates.prefs file
3. restart the ide.

Zebuddi.

Re: Modules 2 Templates

Posted: Thu Feb 16, 2017 7:15 pm
by Zebuddi123
16/02/2017 Updated: added
1. StatusBarProgress()
2. Now takes a single line comment after the Declare ProcedureName() ; like this comment is added to the comment section in the templates tool

zebuddi.