Hollowyearz

SnippetBrowser_1.0.1

Dec 15th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.35 KB | None | 0 0
  1. #cs ----------------------------------------------------------------------------
  2. SnippetBrowser1.0
  3. AutoIt Version: 3.3.9.24 Beta
  4.  
  5. Author: Bill
  6.  
  7. Script Function:
  8. Snippet Browser with Search and Syntax Hi-Liting
  9. #ce ----------------------------------------------------------------------------
  10. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  11. #AutoIt3Wrapper_Version=Beta
  12. #AutoIt3Wrapper_Icon=SnippetBrowserIcon.ico
  13. #AutoIt3Wrapper_UseUpx=n
  14. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  15. #Region ;==================#includes
  16. #include <Array.au3>
  17. #include <File.au3>
  18. #include <ButtonConstants.au3>
  19. #include <GuiButton.au3>
  20. #include <EditConstants.au3>
  21. #include <GuiEdit.au3>
  22. #include <GuiRichEdit.au3>
  23. #include <GUIConstantsEx.au3>
  24. #include <Constants.au3>
  25. #include <StaticConstants.au3>
  26. #include <WindowsConstants.au3>
  27. #include <ListviewConstants.au3>
  28. #include <GuiListView.au3>
  29. #include "_FindInFile.au3"
  30. #include "RESH.au3"
  31. #include "RecFileListToArray.au3"
  32. #EndRegion ;===============#includes
  33. Global $sBlistView, $sString, $aColorTable
  34. Global $sLastSearch = ""
  35. Global $iSearchStart = 0
  36. Global $sFolder = @ScriptDir ; works as browser in any folder you put the script in
  37. #Region ;==================GUI
  38. $Form1 = GUICreate("SnippetBrowser", 810, 680, 246, 140, $WS_SIZEBOX, $WS_EX_ACCEPTFILES)
  39. $Input1 = GUICtrlCreateInput("Search_Files", 10, 16, 160, 21)
  40. $sBlistView = GUICtrlCreateListView("Path", 10, 45, 790, 253, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
  41. _GUICtrlListView_SetColumnWidth($sBlistView, 0, 770)
  42. $search = GUICtrlCreateButton("File Search", 190, 14, 81, 25)
  43. GUICtrlSetTip(-1, "Search Through Working Dir for Text in File", "", 1, 1)
  44. $ClearAll = GUICtrlCreateButton("Clear", 290, 14, 81, 25)
  45. GUICtrlSetTip(-1, "Clear Path List for New Search", "", 1, 1)
  46. $getFiles = GUICtrlCreateButton("Get Files", 390, 14, 81, 25)
  47. GUICtrlSetTip(-1, "Populate List View with AutoIT Files from Working Dir", "", 1, 1)
  48. GUICtrlSetState($getFiles, $GUI_DEFBUTTON)
  49. $Input2 = GUICtrlCreateInput("Search_Text", 10, 306, 160, 21)
  50. $showSelected = GUICtrlCreateButton("Preview", 390, 305, 81, 25)
  51. GUICtrlSetTip(-1, "Shows Preview of Selected Path", "", 1, 1)
  52. $textSearch = GUICtrlCreateButton("Text Search", 190, 305, 81, 25)
  53. GUICtrlSetTip(-1, "Search Through Preview for Text", "", 1, 1)
  54. $label1 = GUICtrlCreateLabel($sFolder, 510, 20, 400, 25)
  55. GUICtrlSetTip(-1, "Working Directory", "", 1, 1)
  56. GUICtrlSetData($label1, $sFolder)
  57. $openSelected = GUICtrlCreateButton("Open in SciTE", 290, 305, 81, 25)
  58. GUICtrlSetTip(-1, "Open Selected Path in SciTE", "", 1, 1)
  59. $throwString = GUICtrlCreateButton("Throw String", 490, 305, 81, 25)
  60. GUICtrlSetTip(-1, "Sends Selected String to wherever your cursor was blinking in SciTE", "", 1, 1)
  61. $hEdit = _GUICtrlRichEdit_Create($Form1, "", 10, 336, 790, 310, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL))
  62. _GUICtrlRichEdit_SetBkColor($hEdit, 0xEFEFEF)
  63. GUISetState(@SW_SHOW, $Form1)
  64. #EndRegion ;==================GUI
  65.  
  66. #Region ; ==================while loop
  67. While 1
  68.     $nMsg = GUIGetMsg()
  69.     Switch $nMsg
  70.         Case $GUI_EVENT_CLOSE
  71.             Exit
  72.         Case $getFiles   ;~ Populates ListView with Files from Working Directory~
  73.             _getFiles()
  74.         Case $throwString   ;~ Takes Selected text and sends it to open SciTE Window where Cursor was~
  75.             $editSelTest = _GUICtrlRichEdit_IsTextSelected($hEdit)
  76.             If $editSelTest = True Then
  77.                 $sString = _GUICtrlRichEdit_GetSelText($hEdit) & @CRLF
  78.                 _SciTE_InsertText($sString)
  79.             Else
  80.                 MsgBox(0, "error!", "Nothing Selected")
  81.             EndIf
  82.         Case $openSelected   ;~ Opens Selected Path in SciTE Editor (New Tab)~
  83.             _openSelected()
  84.         Case $showSelected   ;~ Previews Selected Path in Preview Window with Syntax Hiliting (RESH.au3)~Thanks Beege! ~
  85.             _showSelected()
  86.         Case $ClearAll   ;~ Empties ListView of foundPaths to Make Room for New Search~
  87.             _GUICtrlListView_DeleteAllItems($sBlistView)
  88.         Case $search   ;~ Searches Working Directory for "Text in File" Thanks guinness !~
  89.             _search()
  90.         Case $textSearch   ;~ Searches Preview for Text ~ Keep Clicking to Find Next ~ Thanks Melba23 ~
  91.             $sSearchTerm = GUICtrlRead($Input2)
  92.             If $sSearchTerm Then
  93.                 ; If new search then reset start
  94.                 If $sSearchTerm <> $sLastSearch Then
  95.                     $iSearchStart = 0
  96.                     $sLastSearch = $sSearchTerm
  97.                 EndIf
  98.                 _GUICtrlRichEdit_SetSel($hEdit, $iSearchStart, $iSearchStart)
  99.                 $iIndex = _GUICtrlRichEdit_FindText($hEdit, $sSearchTerm)
  100.                 _GUICtrlRichEdit_SetSel($hEdit, $iIndex, $iIndex + StringLen($sSearchTerm))
  101.                 $iSearchStart = $iIndex + StringLen($sSearchTerm)
  102.             EndIf
  103.     EndSwitch
  104. WEnd
  105. #EndRegion ; ==================while loop
  106.  
  107. #Region ; ==================functions
  108. Func _getFiles()     ;~ Populates ListView with Files from Working Directory~
  109.  
  110.     Local $FileList_A = _RecFileListToArray(@ScriptDir, "*au3", 1, 1, 0, 2)
  111.     For $i = 1 To $FileList_A[0]
  112.         _GUICtrlListView_AddItem($sBlistView, $FileList_A[$i] & @LF)
  113.         ConsoleWrite("$FileList_A[$i]: " & $FileList_A[$i] & @CR)
  114.     Next
  115. EndFunc   ;==>_getFiles
  116.  
  117. Func _showSelected()   ;~ Previews Selected Path in Preview Window with Syntax Hiliting (RESH.au3)~Thanks Beege! ~
  118.             Local Enum $iMacros, $iStrings, $iSpecial, $iComments, $iVariables, $iOperators, $iNumbers, $iKeywords, _
  119.                 $iUDFs, $iSendKeys, $iFunctions, $iPreProc, $iComObjects
  120.         Local $aColorTable[13]
  121.         ;notice values can be either 0x or #
  122.         $aColorTable[$iMacros] = '#808000'
  123.         $aColorTable[$iStrings] = 0xFF0000
  124.         $aColorTable[$iSpecial] = '#DC143C'
  125.         $aColorTable[$iComments] = '#008000'
  126.         $aColorTable[$iVariables] = '#5A5A5A'
  127.         $aColorTable[$iOperators] = '#FF8000'
  128.         $aColorTable[$iNumbers] = 0x0000FF
  129.         $aColorTable[$iKeywords] = '#0000FF'
  130.         $aColorTable[$iUDFs] = '#0080FF'
  131.         $aColorTable[$iSendKeys] = '#808080'
  132.         $aColorTable[$iFunctions] = '#000090'
  133.         $aColorTable[$iPreProc] = '#808000'
  134.         $aColorTable[$iComObjects] = 0x993399
  135.     Local $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
  136.     If $iSelect[0] > 0 Then
  137.         Local $sSelect = StringTrimRight(_GUICtrlListView_GetItemText($sBlistView, $iSelect[1]), 1)
  138.         _GUICtrlRichEdit_SetText($hEdit, FileRead($sSelect))
  139.         _RESH_SetColorTable($aColorTable)
  140.         _RESH_SyntaxHighlight($hEdit)
  141.  
  142.     Else
  143.         MsgBox(0, "", "Nothing Selected")
  144.     EndIf
  145. EndFunc   ;==>_showSelected
  146.  
  147. Func _openSelected()     ;~ Opens Selected Path in SciTE Editor (New Tab)~
  148.     Local $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
  149.     If $iSelect[0] > 0 Then
  150.         Local $sSelect = StringTrimRight(_GUICtrlListView_GetItemText($sBlistView, $iSelect[1]), 1)
  151.         Return _SciTE_Send_Command(0, WinGetHandle("DirectorExtension"), 'open:' & StringReplace($sSelect, '\', '\\'))
  152.     Else
  153.         MsgBox(0, "", "Nothing Selected")
  154.     EndIf
  155. EndFunc   ;==>_openSelected
  156.  
  157. Func _search()     ;~ Searches Working Directory for "Text in File" Thanks guinness !~
  158.     Local $aArray = _FindInFile(GUICtrlRead($Input1), $sFolder, '*.au3')
  159.     $rows = UBound($aArray)
  160.     For $i = 0 To $rows - 1
  161.         GUICtrlCreateListViewItem($aArray[$i] & @LF, $sBlistView)
  162.     Next
  163. EndFunc   ;==>_search
  164.  
  165. Func _SciTE_InsertText($sString)
  166.     $sString = StringReplace($sString, '\', '\\')
  167.     _SciTE_ReplaceMarcos($sString)
  168.     Return _SciTE_Send_Command(0, WinGetHandle('DirectorExtension'), 'insert:' & $sString)
  169. EndFunc   ;==>_SciTE_InsertText
  170.  
  171. Func _SciTE_ReplaceMarcos(ByRef $sString)
  172.     $sString = StringReplace($sString, @TAB, '\t')
  173.     $sString = StringReplace($sString, @CR, '\r')
  174.     $sString = StringReplace($sString, @LF, '\n')
  175. EndFunc   ;==>_SciTE_ReplaceMarcos
  176.  
  177. Func _SciTE_Send_Command($hHandle, $hSciTE, $sString)
  178.     Local $ilParam, $tData
  179.     If StringStripWS($sString, 8) = "" Then
  180.         Return SetError(2, 0, 0) ; String is blank.
  181.     EndIf
  182.     $sString = ":" & Dec(StringTrimLeft($hHandle, 2)) & ":" & $sString
  183.     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sString = ' & $sString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
  184.     $tData = DllStructCreate("char[" & StringLen($sString) + 1 & "]") ; wchar
  185.     DllStructSetData($tData, 1, $sString)
  186.     $ilParam = DllStructCreate("ptr;dword;ptr") ; ulong_ptr;dword;ptr
  187.     DllStructSetData($ilParam, 1, 1) ; $ilParam, 1, 1
  188.     DllStructSetData($ilParam, 2, DllStructGetSize($tData))
  189.     DllStructSetData($ilParam, 3, DllStructGetPtr($tData))
  190.     _SendMessage($hSciTE, $WM_COPYDATA, $hHandle, DllStructGetPtr($ilParam))
  191.     Return Number(Not @error)
  192. EndFunc   ;==>_SciTE_Send_Command
  193. #EndRegion ; ==================functions
Advertisement
Add Comment
Please, Sign In to add comment