Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs ----------------------------------------------------------------------------
- SnippetBrowser1.0
- AutoIt Version: 3.3.9.24 Beta
- Author: Bill
- Script Function:
- Snippet Browser with Search and Syntax Hi-Liting
- #ce ----------------------------------------------------------------------------
- #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
- #AutoIt3Wrapper_Version=Beta
- #AutoIt3Wrapper_Icon=SnippetBrowserIcon.ico
- #AutoIt3Wrapper_UseUpx=n
- #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
- #Region ;==================#includes
- #include <Array.au3>
- #include <File.au3>
- #include <ButtonConstants.au3>
- #include <GuiButton.au3>
- #include <EditConstants.au3>
- #include <GuiEdit.au3>
- #include <GuiRichEdit.au3>
- #include <GUIConstantsEx.au3>
- #include <Constants.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #include <ListviewConstants.au3>
- #include <GuiListView.au3>
- #include "_FindInFile.au3"
- #include "RESH.au3"
- #include "RecFileListToArray.au3"
- #EndRegion ;===============#includes
- Global $sBlistView, $sString
- Global $sLastSearch = ""
- Global $iSearchStart = 0
- Global $sFolder = @ScriptDir ; works as browser in any folder you put the script in
- #Region ;==================GUI
- $Form1 = GUICreate("SnippetBrowser", 810, 680, 246, 140, $WS_SIZEBOX, $WS_EX_ACCEPTFILES)
- $Input1 = GUICtrlCreateInput("Search_Files", 10, 16, 160, 21)
- $sBlistView = GUICtrlCreateListView("Path", 10, 45, 790, 253, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
- _GUICtrlListView_SetColumnWidth($sBlistView, 0, 770)
- $search = GUICtrlCreateButton("File Search", 190, 14, 81, 25)
- GUICtrlSetTip(-1, "Search Through Working Dir for Text in File", "", 1, 1)
- $ClearAll = GUICtrlCreateButton("Clear", 290, 14, 81, 25)
- GUICtrlSetTip(-1, "Clear Path List for New Search", "", 1, 1)
- $getFiles = GUICtrlCreateButton("Get Files", 390, 14, 81, 25)
- GUICtrlSetTip(-1, "Populate List View with AutoIT Files from Working Dir", "", 1, 1)
- GUICtrlSetState($getFiles, $GUI_DEFBUTTON)
- $Input2 = GUICtrlCreateInput("Search_Text", 10, 306, 160, 21)
- $showSelected = GUICtrlCreateButton("Preview", 390, 305, 81, 25)
- GUICtrlSetTip(-1, "Shows Preview of Selected Path", "", 1, 1)
- $textSearch = GUICtrlCreateButton("Text Search", 190, 305, 81, 25)
- GUICtrlSetTip(-1, "Search Through Preview for Text", "", 1, 1)
- $label1 = GUICtrlCreateLabel($sFolder, 510, 20, 400, 25)
- GUICtrlSetTip(-1, "Working Directory", "", 1, 1)
- GUICtrlSetData($label1, $sFolder)
- $openSelected = GUICtrlCreateButton("Open in SciTE", 290, 305, 81, 25)
- GUICtrlSetTip(-1, "Open Selected Path in SciTE", "", 1, 1)
- $throwString = GUICtrlCreateButton("Throw String", 490, 305, 81, 25)
- GUICtrlSetTip(-1, "Sends Selected String to wherever your cursor was blinking in SciTE", "", 1, 1)
- $hEdit = _GUICtrlRichEdit_Create($Form1, "", 10, 336, 790, 310, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL))
- _GUICtrlRichEdit_SetBkColor($hEdit, 0xEFEFEF)
- GUISetState(@SW_SHOW, $Form1)
- #EndRegion ;==================GUI
- #Region ; ==================while loop
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $getFiles ;~ Populates ListView with Files from Working Directory~
- _getFiles()
- Case $throwString ;~ Takes Selected text and sends it to open SciTE Window where Cursor was~
- $editSelTest = _GUICtrlRichEdit_IsTextSelected($hEdit)
- If $editSelTest = True Then
- _SciTE_InsertText($sString)
- Else
- MsgBox(0, "error!", "Nothing Selected")
- EndIf
- Case $openSelected ;~ Opens Selected Path in SciTE Editor (New Tab)~
- _openSelected()
- Case $showSelected ;~ Previews Selected Path in Preview Window with Syntax Hiliting (RESH.au3)~Thanks Beeje! ~
- _showSelected()
- Case $ClearAll ;~ Empties ListView of foundPaths to Make Room for New Search~
- _GUICtrlListView_DeleteAllItems($sBlistView)
- Case $search ;~ Searches Working Directory for "Text in File" Thanks guiness !~
- _search()
- Case $textSearch ;~ Searches Preview for Text ~ Keep Clicking to Find Next ~ Thanks Melba23 ~
- $sSearchTerm = GUICtrlRead($Input2)
- If $sSearchTerm Then
- ; If new search then reset start
- If $sSearchTerm <> $sLastSearch Then
- $iSearchStart = 0
- $sLastSearch = $sSearchTerm
- EndIf
- _GUICtrlRichEdit_SetSel($hEdit, $iSearchStart, $iSearchStart)
- $iIndex = _GUICtrlRichEdit_FindText($hEdit, $sSearchTerm)
- _GUICtrlRichEdit_SetSel($hEdit, $iIndex, $iIndex + StringLen($sSearchTerm))
- $iSearchStart = $iIndex + StringLen($sSearchTerm)
- EndIf
- EndSwitch
- WEnd
- #EndRegion ; ==================while loop
- #Region ; ==================functions
- Func _getFiles() ;~ Populates ListView with Files from Working Directory~
- Local $FileList_A = _RecFileListToArray(@ScriptDir, "*au3", 1, 1, 0, 2)
- For $i = 1 To $FileList_A[0]
- _GUICtrlListView_AddItem($sBlistView, $FileList_A[$i] & @LF)
- ConsoleWrite("$FileList_A[$i]: " & $FileList_A[$i] & @CR)
- Next
- EndFunc ;==>_getFiles
- Func _showSelected() ;~ Previews Selected Path in Preview Window with Syntax Hiliting (RESH.au3)~Thanks Beeje! ~
- Local $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
- If $iSelect[0] > 0 Then
- Local $sSelect = StringTrimRight(_GUICtrlListView_GetItemText($sBlistView, $iSelect[1]), 1)
- _GUICtrlRichEdit_SetText($hEdit, FileRead($sSelect))
- _RESH_SyntaxHighlight($hEdit)
- Else
- MsgBox(0, "", "Nothing Selected")
- EndIf
- EndFunc ;==>_showSelected
- Func _openSelected() ;~ Opens Selected Path in SciTE Editor (New Tab)~
- Local $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
- If $iSelect[0] > 0 Then
- Local $sSelect = StringTrimRight(_GUICtrlListView_GetItemText($sBlistView, $iSelect[1]), 1)
- ShellExecute($sSelect)
- Else
- MsgBox(0, "", "Nothing Selected")
- EndIf
- EndFunc ;==>_openSelected
- Func _search() ;~ Searches Working Directory for "Text in File" Thanks guiness !~
- Local $aArray = _FindInFile(GUICtrlRead($Input1), $sFolder, '*.au3')
- $rows = UBound($aArray)
- For $i = 0 To $rows - 1
- GUICtrlCreateListViewItem($aArray[$i] & @LF, $sBlistView)
- Next
- EndFunc ;==>_search
- Func _SciTE_InsertText($sString) ;~ Takes Selected text and sends it to open SciTE Window where Cursor was~
- $sString = _GUICtrlRichEdit_GetSelText($hEdit)
- Return _SciTE_Send_Command(0, WinGetHandle("DirectorExtension"), "insert:" & $sString)
- EndFunc ;==>_SciTE_InsertText
- Func _SciTE_Send_Command($hHandle, $hSciTE, $sString)
- Local $ilParam, $tData
- If StringStripWS($sString, 8) = "" Then
- Return SetError(2, 0, 0) ; String is blank.
- EndIf
- $sString = ":" & Dec(StringTrimLeft($hHandle, 2)) & ":" & $sString
- ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sString = ' & $sString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
- $tData = DllStructCreate("char[" & StringLen($sString) + 1 & "]") ; wchar
- DllStructSetData($tData, 1, $sString)
- $ilParam = DllStructCreate("ptr;dword;ptr") ; ulong_ptr;dword;ptr
- DllStructSetData($ilParam, 1, 1) ; $ilParam, 1, 1
- DllStructSetData($ilParam, 2, DllStructGetSize($tData))
- DllStructSetData($ilParam, 3, DllStructGetPtr($tData))
- _SendMessage($hSciTE, $WM_COPYDATA, $hHandle, DllStructGetPtr($ilParam))
- Return Number(Not @error)
- EndFunc ;==>_SciTE_Send_Command
- #EndRegion ; ==================functions
Advertisement
Add Comment
Please, Sign In to add comment