#include #include #include #ToDo: Verify that I can_ # capture multi-line todo's_ # and that they can be many lines! #ToDo: Option to ignore some paths\files? Global Const $sToDoRegExp = "(?im)^\h*(#todo:? (?:.*_\R)*(?:.* *\R))" ; Global GUI Variables ; Global $hGUI, $hTreeView, $hOpenBttn, $hRefreshBttn #ToDo: Save search paths in Ini and add a way to edit paths Global $aSearchPaths = ["U:\Documents\AutoIt Files\", "U:\Documents\Personal AutoIt Include\"] Init() Main() Func Init() $hGUI = GUICreate("ToDo Items", 700, 500) $hTreeView = GUICtrlCreateTreeView(5, 5, 690, 470) $hOpenBttn = GUICtrlCreateButton("Open", 5, 475, 50, 20) $hRefreshBttn = GUICtrlCreateButton("Refresh", 60, 475, 50, 20) EndFunc Func Main() Local $avToDos[0][3] SearchForToDos($avToDos) GUISetState(@SW_SHOW, $hGUI) Local $iFound, $sCmd Local Const $sQuote = '"' While True Switch GUIGetMsg() Case $hRefreshBttn SearchForToDos($avToDos) Case $hOpenBttn $iFound = _ArraySearch($avToDos, GUICtrlRead($hTreeView, 1), Default, Default, Default, Default, Default, 2) If $iFound = -1 Then $sCmd = @ComSpec & " /c Start SciTE.exe " & $sQuote & "-open:" & StringReplace(GUICtrlRead($hTreeView, 1), "\", "\\") & $sQuote Else $sCmd = @ComSpec & " /c Start SciTE.exe " & $sQuote & "-open:" & StringReplace(GUICtrlRead($avToDos[$iFound][0], 1), "\", "\\") & $sQuote & " -goto:" & $avToDos[$iFound][1] EndIf Run($sCmd, "", @SW_HIDE) If _ErrMsg(@error, "Run - " & GUICtrlRead($hTreeView, 1)) Then Exit Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ;==>Main Func SearchForToDos(ByRef $avToDos) ; For each row For $i=0 to UBound($avToDos) - 1 GUICtrlDelete($avToDos[$i][0]) Next ReDim $avToDos[0][3] Local $myArray[0] ; For each path For $i=0 To UBound($aSearchPaths) - 1 _ArrayAdd($myArray, __Dir_FilesGet($aSearchPaths[$i], True, "au3", 50)) Next Local $hFile, $sFileContents, $asResult, $hParentTreeView, $iToCount=0 ; For each file found For $i=0 to UBound($myArray) -1 ; If it's an AutoIt file If StringRight($myArray[$i], 3) = "au3" Then If Not StringInStr($myArray[$i], "Backup\") Then ; Get the file contents $hFile = FileOpen($myArray[$i], $FO_READ) $sFileContents = FileRead($hFile) FileClose($hFile) ; If the contents of the file match the regular expression If StringRegExp($sFileContents, $sToDoRegExp, 0) Then ; Get the To-Do items $asResult = StringRegExp($sFileContents, $sToDoRegExp, 3) ReDim $avToDos[$iToCount + UBound($asResult)][3] ; Add the file $hParentTreeView = GUICtrlCreateTreeViewItem($myArray[$i], $hTreeView) For $z=0 to UBound($asResult) - 1 $avToDos[$iToCount][0] = $hParentTreeView $avToDos[$iToCount][1] = ScriptLine($sFileContents, $asResult[$z]) $avToDos[$iToCount][2] = PrettyPrintToDo($avToDos[$iToCount][1], $asResult[$z]) GUICtrlCreateTreeViewItem($avToDos[$iToCount][2], $hParentTreeView) $iToCount += 1 Next EndIf EndIf EndIf Next Return $avToDos EndFunc Func PrettyPrintToDo($iLine, $sToDo) ; Remove underscores with newlines (neither should be captured without the other) $sToDo = StringRegExpReplace($sToDo, "_\s+#", "") ; Remove tabs $sToDo = StringReplace($sToDo, @TAB, "") ; Replace weird capitalization $sToDo = StringReplace($sToDo, "#todo:", "#ToDo:") ; Replace multiple spaces with one space $sToDo = StringRegExpReplace($sToDo, " +", " ") ; Add the line number $sToDo = "(" & $iLine & ") --> " & $sToDo Return $sToDo EndFunc ; Gets the line of the match in the file contents Func ScriptLine($sContents, $sMatch) ; Get the character of the match Local $iCharMatch = StringInStr($sContents, $sMatch) ; Get the text before the match Local $sAboveMatch = StringLeft($sContents, $iCharMatch) ; Split the text into lines Local $aLines = StringSplit($sAboveMatch, @CRLF, 3) If IsArray($aLines) Then Return UBound($aLines) EndFunc Func _Debug($sMsg, $sPrefix = "+") ; Write to the console if we're not compiled If Not @Compiled Then If $sPrefix <> "" Then $sPrefix &= " " ConsoleWrite($sPrefix & $sMsg & @CRLF) EndIf EndFunc Func _ErrMsg($iError, $sMsg = "", $iExtended = 0) ; If there is an error, then write the error message If $iError Then If $iExtended <> 0 Then $sMsg = "Extended: " & $iExtended & " - " & $sMsg _Debug("Error: " & $iError & " - " & $sMsg, "!") EndIf ; Return the error Return $iError EndFunc Func __Dir_FilesGet($sDir, $bRecursive = False, $sExtension = Default, $iMaxRecursion = 1700) If $sExtension = Default Then $sExtension = "" If $bRecursive = Default Then $bRecursive = False If $iMaxRecursion = Default Then $iMaxRecursion = 1700 Local $aFiles[0], $aFolders[1], $aNewFolders[0] $aFolders[0] = $sDir ; If it's not a directory If Not (FileExists($sDir) And (StringInStr(StringLower(FileGetAttrib($sDir)), "d") <> 0)) Then Return SetError(2, 0, $aFiles) Local $sFile, $bIsDir ; While there are folders to process While UBound($aFolders) > 0 ; For each folder For $sDir In $aFolders ; Add a backslash if needed If Not (StringRight($sDir, 1) = "\") Then $sDir &= "\" ; Search Local $hSearch = FileFindFirstFile($sDir & "*") If @error = 1 Then ; Empty directory ElseIf $hSearch = -1 Then ; Invalid search! Return SetError(2, 0, $aFiles) Else $sFile = FileFindNextFile($hSearch) $bIsDir= @extended While $sFile <> "" $sFile = $sDir & $sFile If $bIsDir And $bRecursive Then If $iMaxRecursion > 0 Then ; Add to list of folders to process _ArrayAdd($aNewFolders, $sFile) EndIf Else If StringInStr($sFile, $sExtension) <> 0 Then _ArrayAdd($aFiles, $sFile) EndIf $sFile = FileFindNextFile($hSearch) $bIsDir= @extended WEnd ; Close the search handle FileClose($hSearch) EndIf Next ; Get the new list of folders to process $aFolders = $aNewFolders ; Reset the new folders ReDim $aNewFolders[0] ; Recursed $iMaxRecursion -= 1 If $iMaxRecursion = 0 Then Return SetError(3, 0, False) WEnd Return $aFiles EndFunc