Page 2 of 2

Posted: Mon Apr 09, 2007 12:12 am
by AND51
Here is my "AutoOpenIncludes" Tool

My code is shorter than TS-Soft ones! Moreover, I don't need GetPureBasicDirectory(), because the IDE whisperes its path to me! (So I don't need access to the registry => useful for people having PB on an USB-stick!)

The onliest thing that should be noticed is the delay time! If the time is too short, the IDE does react/load too slow and multiple IDE instances will be started. If it is too long, you must wait too long.
//Edit: Now there is a "global mutex", which causes multiple instances to wait until the previous instance is finished.

Code: Select all

; AutoOpenIncludes 
; Autor: André (AND51) Stapf 
; Requires: PB 4.00+ 
; Demo: No (Yes, if you leave out the API) 

EnableExplicit 

Define.s zeile, path=GetPathPart(GetEnvironmentVariable("PB_TOOL_Compiler")), file=ProgramParameter(), mutex="AutoOpenInclude"+GetEnvironmentVariable("PB_Tool_MainWindow") 
CreateMutex_(0, 1, @mutex) 
WaitForSingleObject_(mutex, 12345) 

Procedure runFile(file.s) 
   If FileSize(file) >= 0 
      RunProgram(file) ; There MUST be a delay in order to load all includes correctly! This is, because the IDE is so slow... 
      Delay(IntQ(FileSize(file)/2.3)) ; If this is too slow for you, define your own delay here! 
   EndIf 
EndProcedure 

If ReadFile(0, file) 
   Define format=ReadStringFormat(0), path.s=GetPathPart(file) 
    
   While Not Eof(0) 
      Define zeile.s=ReadString(0, format) 
      Define inc=FindString(zeile, "IncludeFile", 1), incX=FindString(zeile, "XIncludeFile", 1), incP=FindString(zeile, "IncludePath", 1), comment=FindString(zeile, ";", 1) 
      Define quoteL=0, quoteR=0 
       
      If comment <= inc And comment <= incX And comment <= incP And inc|incX|incP 
         If incP 
            quoteL=FindString(zeile, Chr(34), incP) 
            quoteR=FindString(zeile, Chr(34), quoteL+1) 
            path=Mid(zeile, quoteL+1, quoteR-quoteL-1)+"\" 
         EndIf 
         If incX 
            quoteL=FindString(zeile, Chr(34), incX) 
            quoteR=FindString(zeile, Chr(34), quoteL+1) 
            runFile(path+Mid(zeile, quoteL+1, quoteR-quoteL-1)) 
         EndIf 
         If inc And (inc-1 <> incX And Not incX) 
            quoteL=FindString(zeile, Chr(34), inc) 
            quoteR=FindString(zeile, Chr(34), quoteL+1) 
            runFile(path+Mid(zeile, quoteL+1, quoteR-quoteL-1)) 
         EndIf 
      EndIf 
       
      Delay(1) 
   Wend 
    
   CloseFile(0) 
EndIf
Please, configure it the same way as TS-Soft ones! However, here is the image again:
Image

Please, make sure to allow only 1 IDE instance at one (see you preferences).