Hollowyearz

SnippetBrowser1.0

Dec 12th, 2013
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 7.22 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
  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.                 _SciTE_InsertText($sString)
  78.             Else
  79.                 MsgBox(0, "error!", "Nothing Selected")
  80.             EndIf
  81.         Case $openSelected   ;~ Opens Selected Path in SciTE Editor (New Tab)~
  82.             _openSelected()
  83.         Case $showSelected   ;~ Previews Selected Path in Preview Window with Syntax Hiliting (RESH.au3)~Thanks Beeje! ~
  84.             _showSelected()
  85.         Case $ClearAll   ;~ Empties ListView of foundPaths to Make Room for New Search~
  86.             _GUICtrlListView_DeleteAllItems($sBlistView)
  87.         Case $search   ;~ Searches Working Directory for "Text in File" Thanks guiness !~
  88.             _search()
  89.         Case $textSearch   ;~ Searches Preview for Text ~ Keep Clicking to Find Next ~ Thanks Melba23 ~
  90.             $sSearchTerm = GUICtrlRead($Input2)
  91.             If $sSearchTerm Then
  92.                 ; If new search then reset start
  93.                 If $sSearchTerm <> $sLastSearch Then
  94.                     $iSearchStart = 0
  95.                     $sLastSearch = $sSearchTerm
  96.                 EndIf
  97.                 _GUICtrlRichEdit_SetSel($hEdit, $iSearchStart, $iSearchStart)
  98.                 $iIndex = _GUICtrlRichEdit_FindText($hEdit, $sSearchTerm)
  99.                 _GUICtrlRichEdit_SetSel($hEdit, $iIndex, $iIndex + StringLen($sSearchTerm))
  100.                 $iSearchStart = $iIndex + StringLen($sSearchTerm)
  101.             EndIf
  102.     EndSwitch
  103. WEnd
  104. #EndRegion ; ==================while loop
  105.  
  106. #Region ; ==================functions
  107. Func _getFiles()     ;~ Populates ListView with Files from Working Directory~
  108.  
  109.     Local $FileList_A = _RecFileListToArray(@ScriptDir, "*au3", 1, 1, 0, 2)
  110.     For $i = 1 To $FileList_A[0]
  111.         _GUICtrlListView_AddItem($sBlistView, $FileList_A[$i] & @LF)
  112.         ConsoleWrite("$FileList_A[$i]: " & $FileList_A[$i] & @CR)
  113.     Next
  114. EndFunc   ;==>_getFiles
  115.  
  116. Func _showSelected()   ;~ Previews Selected Path in Preview Window with Syntax Hiliting (RESH.au3)~Thanks Beeje! ~
  117.     Local $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
  118.     If $iSelect[0] > 0 Then
  119.         Local $sSelect = StringTrimRight(_GUICtrlListView_GetItemText($sBlistView, $iSelect[1]), 1)
  120.         _GUICtrlRichEdit_SetText($hEdit, FileRead($sSelect))
  121.         _RESH_SyntaxHighlight($hEdit)
  122.     Else
  123.         MsgBox(0, "", "Nothing Selected")
  124.     EndIf
  125. EndFunc   ;==>_showSelected
  126.  
  127. Func _openSelected()     ;~ Opens Selected Path in SciTE Editor (New Tab)~
  128.     Local $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
  129.     If $iSelect[0] > 0 Then
  130.         Local $sSelect = StringTrimRight(_GUICtrlListView_GetItemText($sBlistView, $iSelect[1]), 1)
  131.         ShellExecute($sSelect)
  132.     Else
  133.         MsgBox(0, "", "Nothing Selected")
  134.     EndIf
  135. EndFunc   ;==>_openSelected
  136.  
  137. Func _search()     ;~ Searches Working Directory for "Text in File" Thanks guiness !~
  138.     Local $aArray = _FindInFile(GUICtrlRead($Input1), $sFolder, '*.au3')
  139.     $rows = UBound($aArray)
  140.     For $i = 0 To $rows - 1
  141.         GUICtrlCreateListViewItem($aArray[$i] & @LF, $sBlistView)
  142.     Next
  143. EndFunc   ;==>_search
  144.  
  145. Func _SciTE_InsertText($sString)     ;~ Takes Selected text and sends it to open SciTE Window where Cursor was~
  146.     $sString = _GUICtrlRichEdit_GetSelText($hEdit)
  147.     Return _SciTE_Send_Command(0, WinGetHandle("DirectorExtension"), "insert:" & $sString)
  148. EndFunc   ;==>_SciTE_InsertText
  149. Func _SciTE_Send_Command($hHandle, $hSciTE, $sString)
  150.     Local $ilParam, $tData
  151.     If StringStripWS($sString, 8) = "" Then
  152.         Return SetError(2, 0, 0) ; String is blank.
  153.     EndIf
  154.     $sString = ":" & Dec(StringTrimLeft($hHandle, 2)) & ":" & $sString
  155.     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sString = ' & $sString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
  156.     $tData = DllStructCreate("char[" & StringLen($sString) + 1 & "]") ; wchar
  157.     DllStructSetData($tData, 1, $sString)
  158.     $ilParam = DllStructCreate("ptr;dword;ptr") ; ulong_ptr;dword;ptr
  159.     DllStructSetData($ilParam, 1, 1) ; $ilParam, 1, 1
  160.     DllStructSetData($ilParam, 2, DllStructGetSize($tData))
  161.     DllStructSetData($ilParam, 3, DllStructGetPtr($tData))
  162.     _SendMessage($hSciTE, $WM_COPYDATA, $hHandle, DllStructGetPtr($ilParam))
  163.     Return Number(Not @error)
  164. EndFunc   ;==>_SciTE_Send_Command
  165. #EndRegion ; ==================functions
Advertisement
Add Comment
Please, Sign In to add comment