Jump to content

Recommended Posts

Posted

When using AutoIt for writing utilities and such, I tend to break them up into logical pieces that can be "modularized". My intent is to have less crowded code in my main file as well as create logical groups of functions. I put one or more functions into other files. These files are then included in my main program to provide the functionality. The other thing I tend to do when creating these groups and including them in a file is name them test-something.au3. That allows me to quickly "weed out" a development directory of files I dont use anymore. If the function(s) in a file become refined enough, I rename the include file and remove the test from its name.

For the most part, this works really well for me. The issue I run into is when I have multiple additional group files. I have trouble remembering where all my functions are. So I wrote this little program to show me where my functions are (which include file). I also included a capability to either include or exclude test files when searching for functions.

This program, when run, searches every .au3 file in the current directory and pulls out all the Func lines. If you click on the "include test functions" checkbox and press "reload", the program will search all au3 files that start with test as well. I am providing it in case others out there run into a similar issue. The program is rough and some of the code is pulled straight from the helpfile. I wrote it in a short amount of time and understand that it is not as neat as it could be. Anyway, here it is:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#AutoIt3Wrapper_Icon=..\images\Toolbox Folder Badged.ico
#AutoIt3Wrapper_Outfile=wheresmyfunction.exe
#AutoIt3Wrapper_Res_Description=Find functions in the scripts
#AutoIt3Wrapper_Res_Fileversion=1.5.0.0
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.13.8 (beta)
    Author:         
    
    
    
#ce ----------------------------------------------------------------------------
#include <file.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>

Global $s_searchdir = @ScriptDir
Local $a_statuswindows[2] = [500, -1]

#Region ### START Koda GUI section ### Form=e:\autoit\gpas programs\aio\wheresmyfunction.kxf
$Form2 = GUICreate("Wheres My Function", 796, 523, 304, 220)
$ListView1 = GUICtrlCreateListView("", 8, 8, 780, 449)
$Button1 = GUICtrlCreateButton("Exit", 670, 464, 121, 25, 0)
$Button2 = GUICtrlCreateButton("Reload", 544, 464, 121, 25, 0)
$Button3 = GUICtrlCreateButton("Open Directory", 416, 464, 121, 25, 0)
$Checkbox1 = GUICtrlCreateCheckbox("Include Test Functions", 16, 472, 129, 17)
$StatusBar1 = _GUICtrlStatusBar_Create($Form2)
_GUICtrlStatusBar_SetMinHeight($StatusBar1, 25)
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=e:\autoit\gpas programs\aio\wheresmyfunction.kxf

_GUICtrlListView_RegisterSortCallBack($ListView1)
_GUICtrlListView_AddColumn($ListView1, "File", 200)
_GUICtrlListView_AddColumn($ListView1, "Function", 600)
_SearchFunctions($s_searchdir)

;setup the status bar
_GUICtrlStatusBar_SetParts($StatusBar1, $a_statuswindows)
_GUICtrlStatusBar_SetText($StatusBar1, "Directory is: " & $s_searchdir)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Exit
        Case $ListView1
            _GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1))
        Case $Button2
            _GUICtrlListView_DeleteAllItems($ListView1)
            _SearchFunctions($s_searchdir)
        Case $Button3
            $s_searchdir = FileSelectFolder("Choose a folder.", 1, "", $s_searchdir)
            ConsoleWrite($s_searchdir)
            _GUICtrlListView_DeleteAllItems($ListView1)
            _SearchFunctions($s_searchdir)
    EndSwitch
    ;ConsoleWrite($file & @CRLF)
WEnd


Func _SearchFunctions($_searchdir)
    ConsoleWrite($_searchdir & @CRLF)
    $search = FileFindFirstFile($_searchdir & "\*.au3")
    
    While 1
        $file = FileFindNextFile($search)
        $s_filename = $file
        $file = $s_searchdir & "\" & $file


        If @error Then ExitLoop
        
        ConsoleWrite("FILE: " & $_searchdir & $file & @CRLF)
        If (StringRight($file, 3) = "au3") Then
            If (GUICtrlRead($Checkbox1) = 4) Then
                If Not (StringLeft($file, 4) = "test") Then
                    ;Open the file and pull all the function names and print them
                    Dim $aRecords
                    If Not _FileReadToArray($file, $aRecords) Then
                        ;MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
                        
                        ExitLoop
                    Else
                        For $x = 1 To $aRecords[0]
                            ;Msgbox(0,'Record:' & $x, $aRecords[$x])
                            If (StringLeft($aRecords[$x], 4) = "Func") Then
                                ConsoleWrite($file & ":" & $aRecords[$x] & @CRLF)
                                GUICtrlCreateListViewItem($s_filename & "|" & $aRecords[$x], $ListView1)
                            EndIf
                        Next
                        
                    EndIf
                EndIf
            Else
                Dim $aRecords
                If Not _FileReadToArray($file, $aRecords) Then
                    ;MsgBox(4096, "Error", " Error reading File     error:" & @error & " file:" & $file)
                    ConsoleWrite("ERROR: " & $_searchdir & $file & @CRLF)
                    ;ExitLoop
                Else
                    For $x = 1 To $aRecords[0]
                        ;Msgbox(0,'Record:' & $x, $aRecords[$x])
                        If (StringLeft($aRecords[$x], 4) = "Func") Then
                            ConsoleWrite($file & ":" & $aRecords[$x] & @CRLF)
                            GUICtrlCreateListViewItem($s_filename & "|" & $aRecords[$x], $ListView1)
                        EndIf
                    Next
                EndIf
            EndIf
        EndIf
    WEnd
    FileClose($search)
    
    _GUICtrlStatusBar_SetText($StatusBar1, "Directory is: " & $s_searchdir)
    ConsoleWrite(GUICtrlRead($Checkbox1))
EndFunc   ;==>_SearchFunctions

; Close the search handle
Posted

This is going to be useful. I like it.

Fixed a problem I encountered with Case $Button3

Added Search for text in lists.

Added Click on file to open in Scite. This works on my system because au3 files automatically open in Scite Editor when opened. That is, au3 file types are associated with Scite Editor.

This can be set in Windows Explorer menu Tools/ Folder Options/ File Types Tab/ Scroll down to au3 /High light Au3/ Click on Change button / Select Scite Text Editor / OK button / Close.

Good job, Reaper HGN.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#AutoIt3Wrapper_Icon=..\images\Toolbox Folder Badged.ico
#AutoIt3Wrapper_Outfile=wheresmyfunction.exe
#AutoIt3Wrapper_Res_Description=Find functions in the scripts
#AutoIt3Wrapper_Res_Fileversion=1.5.0.0
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.13.8 (beta)
    Author:
    
#ce ----------------------------------------------------------------------------
#include <file.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>

Global $s_searchdir = @ScriptDir, $ListView1, $find = -1
Local $a_statuswindows[2] = [500, -1]

#Region ### START Koda GUI section ### Form=e:\autoit\gpas programs\aio\wheresmyfunction.kxf
$Form2 = GUICreate("Wheres My Function", 796, 523, 304, 220)
$ListView1 = GUICtrlCreateListView("", 8, 8, 780, 449)
$Button1 = GUICtrlCreateButton("Exit", 670, 464, 121, 25, 0)
$Button2 = GUICtrlCreateButton("Reload", 544, 464, 121, 25, 0)
$Button3 = GUICtrlCreateButton("Open Directory", 416, 464, 121, 25, 0)

$input = GUICtrlCreateInput("", 150, 464, 171, 25, 0)
GUICtrlSetFont(-1, 10)
$searchbutton = GUICtrlCreateButton("Search", 328, 464, 71, 25, 0)
;GuiCtrlSetFont(-1,$winX * .01125,$winX * .25)
$Checkbox1 = GUICtrlCreateCheckbox("Include Test Functions", 16, 472, 129, 17)
$StatusBar1 = _GUICtrlStatusBar_Create($Form2)
_GUICtrlStatusBar_SetMinHeight($StatusBar1, 25)
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=e:\autoit\gpas programs\aio\wheresmyfunction.kxf
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlListView_RegisterSortCallBack($ListView1)
_GUICtrlListView_AddColumn($ListView1, "File", 200)
_GUICtrlListView_AddColumn($ListView1, "Function", 600)
_SearchFunctions($s_searchdir)
;setup the status bar
_GUICtrlStatusBar_SetParts($StatusBar1, $a_statuswindows)
_GUICtrlStatusBar_SetText($StatusBar1, "Directory is: " & $s_searchdir)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Exit
        Case $ListView1
            _GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1))
        Case $Button2
            _GUICtrlListView_DeleteAllItems($ListView1)
            _SearchFunctions($s_searchdir)
        Case $Button3
            $TempDir = FileSelectFolder("Choose a folder.", "", 4, $s_searchdir)
            If $TempDir <> "" Then
                $s_searchdir = $TempDir
                ;ConsoleWrite($s_searchdir)
                _GUICtrlListView_DeleteAllItems($ListView1)
                _SearchFunctions($s_searchdir)
            EndIf
        Case $searchbutton
            _SearchTxt()
    EndSwitch
    ;ConsoleWrite($file & @CRLF)
WEnd

Func _SearchFunctions($_searchdir)
    ;ConsoleWrite($_searchdir & @CRLF)
    $search = FileFindFirstFile($_searchdir & "\*.au3")
    
    While 1
        $file = FileFindNextFile($search)
        $s_filename = $file
        $file = $s_searchdir & "\" & $file
        If @error Then ExitLoop
        ;ConsoleWrite("FILE: " & $_searchdir & $file & @CRLF)
        If (StringRight($file, 3) = "au3") Then
            If (GUICtrlRead($Checkbox1) = 4) Then
                If Not (StringLeft($file, 4) = "test") Then
                    ;Open the file and pull all the function names and print them
                    Dim $aRecords
                    If Not _FileReadToArray($file, $aRecords) Then
                        ;MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
                        ExitLoop
                    Else
                        For $x = 1 To $aRecords[0]
                            ;Msgbox(0,'Record:' & $x, $aRecords[$x])
                            If (StringLeft($aRecords[$x], 4) = "Func") Then
                                ;ConsoleWrite($file & ":" & $aRecords[$x] & @CRLF)
                                GUICtrlCreateListViewItem($s_filename & "|" & $aRecords[$x], $ListView1)
                            EndIf
                        Next
                    EndIf
                EndIf
            Else
                Dim $aRecords
                If Not _FileReadToArray($file, $aRecords) Then
                    ;ConsoleWrite("ERROR: " & $_searchdir & $file & @CRLF)
                    ;ExitLoop
                Else
                    For $x = 1 To $aRecords[0]
                        If (StringLeft($aRecords[$x], 4) = "Func") Then
                            ;ConsoleWrite($file & ":" & $aRecords[$x] & @CRLF)
                            GUICtrlCreateListViewItem($s_filename & "|" & $aRecords[$x], $ListView1)
                        EndIf
                    Next
                EndIf
            EndIf
        EndIf
    WEnd
    FileClose($search)
    _GUICtrlStatusBar_SetText($StatusBar1, "Directory is: " & $s_searchdir)
    ;ConsoleWrite(GUICtrlRead($Checkbox1))
EndFunc   ;==>_SearchFunctions

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $ListView1
    If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    Local $item = _GUICtrlListView_GetItem($ListView1, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem"))
                    If DllStructGetData($tInfo, "SubItem") = 0 Then ShellExecute($s_searchdir & "\" & $item[3])
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _SearchTxt()
    $strText = GUICtrlRead($input, 1)
    If $strText = "" Then Return -6
    ;$current = _SearchTab()
    ;Switch $current
    ;   Case 1
    $list = $ListView1
    ;Case 2
    ;$list = $installedlistview
    ;EndSwitch

    $find = _GUICtrlListView_FindInText($list, $strText, $find)

    If $find <> -1 Then
        GUICtrlSetData($searchbutton, "Next")
        _GUICtrlListView_SetItemSelected($list, $find, True)
        _GUICtrlListView_Scroll($list, 0, -5000)
        _GUICtrlListView_Scroll($list, 0, $find * 7)
    Else
        GUICtrlSetData($searchbutton, "Search")
        _GUICtrlListView_SetItemSelected($list, 0, True)
        _GUICtrlListView_SetItemSelected($list, 0, False)
    EndIf
    _GUICtrlListView_EnsureVisible($ListView1, $find)
    
EndFunc   ;==>_SearchTxt
Posted

Nice!!! :mellow:

why not you create a function that can view the source...

like callibur.au3...

Zaini: I hadnt heard of callibur. Ill have to take a look at it. I guess I just whipped this together after the umpteenth time of opening the wrong include file to find a function I wanted to check.

Malkey: Thank you for the updates. Ill definitely use your version.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...