#include #include #include #include #include #include #include #include ;#include Opt("GUIResizeMode", $GUI_DOCKALL) Opt("GUIDataSeparatorChar", "¶") Global $myext = ".au3" Global $gui2, $input_word, $case_cb, $radio_const, $radio_func, $radio_other, $input_kw Global $_word = "", $results, $go, $sel, $listview, $reset2, $exit2 Global $stop, $sText, $sFind, $gui2exists, $caretline $Dir = StringRegExpReplace(@Autoitexe, '(.+)\\[^\\]+', "$1") & "\Include\" $alist = _FileListToArray($Dir, "*" & $myext) ;_ArrayDisplay($alist) $gui = GUICreate("include viewer", 1000, 600, -1, 40, _ BitOr($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS), $WS_EX_ACCEPTFILES) GUISetBkColor(0x000000) $combo = GUICtrlCreateCombo("", 10, 7, 210, 20) GUICtrlSetBkColor(-1, 0xddffff) GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman") $combolist = @AutoItVersion & "¶" For $i = 1 to $alist[0] $combolist &= $alist[$i] & "¶" Next GUICtrlSetData($combo, $combolist, @AutoItVersion) GUICtrlCreateLabel("Rechercher :", 280, 14, 65, 17, 1) GUICtrlSetColor(-1, 0xddffff) $inputSearch = GUICtrlCreateInput("", 350, 10, 220, 21) GUICtrlSetBkColor(-1, 0xddffff) $btn_search = GuiCtrlCreateButton("Suivant (F3)", 580, 9, 90, 22, 1) GUICtrlSetBkColor(-1, 0x880000) GUICtrlSetColor(-1, 0xffffff) $btn_reset = GuiCtrlCreateButton("Reset", 690, 9, 60, 22, 1) GUICtrlSetBkColor(-1, 0x008800) GUICtrlSetColor(-1, 0xffffff) $btn_inc_search = GuiCtrlCreateButton("Fouiller dans les includes", 830, 9, 150, 22, 1) GUICtrlSetBkColor(-1, 0x880000) GUICtrlSetColor(-1, 0xffffff) $edit = GUICtrlCreateEdit("", 10, 40, 980, 550, $ES_AUTOVSCROLL + $WS_VSCROLL) GUICtrlSetBkColor(-1, 0xddffff) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") GUICtrlSetState($edit, $GUI_FOCUS) GUISetState() Local $AccelKeys[1][2] = [["{F3}", $btn_search]] GUISetAccelerators($AccelKeys) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") _GuiRecherche() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED $sText = FileRead(StringStripWS(@GUI_DRAGFILE, 3)) GUICtrlSetData($edit, $sText) Case $combo ;; If not StringInStr(GuiCtrlRead($combo), $myext) Then ContinueLoop $sText = FileRead($Dir & GuiCtrlRead($combo)) GUICtrlSetData($edit, $sText) GUICtrlSetState($edit, $GUI_FOCUS) Case $btn_search $stop = 0 $sFind = GUICtrlRead($inputSearch) _GUICtrlEdit_Find2(GuiCtrlGetHandle($edit), $sText, $sFind) Case $btn_reset $sFind = "" Case $btn_inc_search If $gui2exists = 0 Then $pos = ControlGetPos($gui, "", $edit) GUICtrlSetPos($edit, 10, 170, Default, $pos[3]-130) $gui2exists = 1 EndIf Case $exit2 If $gui2exists = 1 Then $pos = ControlGetPos($gui, "", $edit) GUICtrlSetPos($edit, 10, 40, Default, $pos[3]+130) GuiCtrlSetData($inputSearch, $_word) GuiCtrlSendMsg($edit, $EM_LINESCROLL, 0, $caretline - 2) $gui2exists = 0 EndIf Case $sel If IsArray($results) Then $indexLV = ControlListView($gui2, "", $listview, "GetSelected") $results0 = $results[$indexLV][0] If $results0 = "" Then $decr = 0 Do $decr += 1 $results0 = $results[$indexLV-$decr][0] Until $results0 <> "" EndIf GUICtrlSetData($combo, $combolist, $results0) GuiCtrlSetData($inputSearch, $_word) $sText = FileRead($Dir & $results0) GUICtrlSetData($edit, $sText) $iPos0 = StringInStr($sText, $results[$indexLV][2]) $iPos = StringInStr($sText, $_word, 0, 1, $iPos0) GUICtrlSetState($edit, $GUI_FOCUS) GuiCtrlSendMsg($edit, $EM_SETSEL, $iPos-1, ($iPos + StringLen($_word))-1) ;; GuiCtrlSendMsg($edit, $EM_SCROLLCARET, 0, 0) $firstvisibleline = GuiCtrlSendMsg($edit, $EM_GETFIRSTVISIBLELINE, 0, 0) $caretline = GuiCtrlSendMsg($edit, $EM_LINEFROMCHAR, -1, 0) GuiCtrlSendMsg($edit, $EM_LINESCROLL, 0, $caretline - $firstvisibleline - 2) EndIf Case $radio_const GUICtrlSetState($input_kw, $GUI_DISABLE) GUICtrlSetBkColor($input_kw, 0x555555) Case $radio_func GUICtrlSetState($input_kw, $GUI_DISABLE) GUICtrlSetBkColor($input_kw, 0x555555) Case $radio_other GUICtrlSetState($input_kw, $GUI_ENABLE) GUICtrlSetBkColor($input_kw, 0xddffff) Case $go $_folder = $Dir $_ext = $myext $_word = GUICtrlRead($input_word) If BitAND(GUICtrlRead($radio_const), $GUI_CHECKED) = $GUI_CHECKED Then $_keyword = " Const " ElseIf BitAND(GUICtrlRead($radio_func), $GUI_CHECKED) = $GUI_CHECKED Then $_keyword = "^Func " ElseIf BitAND(GUICtrlRead($radio_other), $GUI_CHECKED) = $GUI_CHECKED Then $_keyword = GUICtrlRead($input_kw) Else $_keyword = "" EndIf $_case = 0 If BitAND(GUICtrlRead($case_cb), $GUI_CHECKED) = $GUI_CHECKED Then $_case = 1 $results = _Search($_word, $_folder, $_ext, $_case, $_keyword) ;_ArrayDisplay($results) GuiCtrlSendMsg($listview, $LVM_DELETEALLITEMS, 0, 0) For $i = 0 to UBound($results)-1 GUICtrlCreateListViewItem($results[$i][0] &"¶"& $results[$i][1] &"¶"& $results[$i][2], $listview) Next Case $reset2 $results = "" $_word = "" GuiCtrlSetData($input_word, "") GuiCtrlSetData($input_kw, "") GuiCtrlSendMsg($listview, $LVM_DELETEALLITEMS, 0, 0) EndSwitch WEnd ;================================================= Func _GuiRecherche() $gui2 = GUICreate("Recherche", 1000, 130, 0, 40, $WS_CHILD, -1, $gui) GUISetBkColor(0x000000) GUICtrlCreateLabel("Rechercher :", 725, 15, 65, 17) GUICtrlSetColor(-1, 0xddffff) $input_word = GUICtrlCreateInput($_word, 795, 11, 195, 20) GUICtrlSetBkColor(-1, 0xddffff) $case_cb = GUICtrlCreateCheckbox("case sens.", 810, 38, 70, 18) GUICtrlSetColor(-1, 0xddffff) $radio_const = GUICtrlCreateRadio("Const", 725, 42, 55, 17) GUICtrlSetColor(-1, 0xddffff) $radio_func = GUICtrlCreateRadio("Func", 725, 65, 55, 17) GUICtrlSetColor(-1, 0xddffff) ;; GUICtrlSetState(-1, $GUI_CHECKED) $radio_other = GUICtrlCreateRadio("Autre mot-clé :", 780, 65, 90, 17) GUICtrlSetColor(-1, 0xddffff) $input_kw = GUICtrlCreateInput("", 878, 63, 110, 20) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetBkColor(-1, 0x555555) $go = GUICtrlCreateButton("Vazi", 725, 95, 50, 22) GUICtrlSetBkColor(-1, 0x880000) GUICtrlSetColor(-1, 0xddffff) $sel = GUICtrlCreateButton("Select zis one", 785, 95, 90, 22) GUICtrlSetBkColor(-1, 0x880000) GUICtrlSetColor(-1, 0xddffff) $reset2 = GUICtrlCreateButton("Reset", 885, 95, 50, 22) GUICtrlSetBkColor(-1, 0x008800) GUICtrlSetColor(-1, 0xddffff) $exit2 = GUICtrlCreateButton("Exit", 940, 95, 50, 22) GUICtrlSetBkColor(-1, 0x008800) GUICtrlSetColor(-1, 0xddffff) $listview = GUICtrlCreateListView("include ¶ligne ¶texte", 10, 6, 705, 115, -1, _ BitOr($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) GUICtrlSetBkColor(-1, 0xddffff) GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 2, 560) GUISetState(@SW_SHOWNA) EndFunc Func _Search($word, $folder, $ext = "", $casesense = 0, $keyword = "") Local $log, $file, $lines, $n, $title, $m Local $aFileList = _FileListToArray($folder, "*" & $ext, 1, 1) Local $arr[$aFileList[0]] For $i = 1 to $aFileList[0] $file = FileRead($aFileList[$i]) If StringInStr($file, $word) Then $arr[$n] = $aFileList[$i] $n += 1 EndIf Next Redim $arr[$n] ;_ArrayDisplay($arr) Local $aRes[5000][3] For $i = 0 to UBound($arr)-1 ; fichiers $title = 0 $file = FileRead($arr[$i]) $lines = StringRegExp($file, '(\N*)\R?', 3) For $j = 0 to UBound($lines)-1 ; lignes If StringInStr($lines[$j], $word, $casesense) AND _ ($keyword="" OR ($keyword<>"" and StringRegExp($lines[$j], $keyword)) ) Then If $title = 0 Then $aRes[$m][0] = StringRegExpReplace($arr[$i], '.+\\(.+)', "$1") ;~ $log &= StringRegExpReplace($arr[$i], '.+\\(.+)', "$1") & @crlf&@crlf $title = 1 EndIf $aRes[$m][1] = $j+1 $aRes[$m][2] = StringStripWS($lines[$j], 3) $m += 1 ;~ $log &= $j+1 & " - " & StringStripWS($lines[$j], 3) & @crlf EndIf Next ;~ If $title = 1 Then ;~ $log &= @crlf ;~ For $k = 1 to 100 ;~ $log &= "-" ;~ Next ;~ $log &= @crlf ;~ EndIf Next Redim $aRes[$m][3] ;; _ArrayDisplay($aRes) ;~ Msgbox(0,"", $log) If UBound($aRes) = 0 Then Return Msgbox(4096, "", 'Pas trouvé " ' & _ $word & ' " dans les includes ...' & @crlf & 'et pourtant j''ai bien cherché') Return $aRes EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $lParam Local $IdFrom = BitAnd($wParam, 0x0000FFFF) ;; Local $iCode = BitShift($wParam, 16) Switch $IdFrom Case $combo, $btn_reset, $btn_inc_search, $sel, $exit2 $stop = 1 EndSwitch Return 'GUI_RUNDEFMSG' EndFunc Func _GUICtrlEdit_Find2($hWnd, ByRef $sText, ByRef $sFind) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Local $iPos = 0, $iOccurance = 0 ;; Local $oldMode = Opt("GUIOnEventMode", 0) Local $aSel = _GUICtrlEdit_GetSel($hWnd) If (IsArray($aSel) And $aSel[0] <> $aSel[1]) Then ; text was selected when function was invoked $sFind = StringStripWS(StringMid($sText, $aSel[0] + 1, $aSel[1] - $aSel[0]), 3) GUICtrlSetData($inputSearch, $sFind) $iOccurance = 1 $iPos = $aSel[0] Local $iTPose While 1 ; set the current occurance so search starts from here $iTPose = StringInStr($sText, $sFind, 0, $iOccurance) If Not $iTPose Then $iOccurance = 0 ExitLoop ElseIf $iTPose = $iPos + 1 Then ; found the occurance ExitLoop EndIf $iOccurance += 1 WEnd EndIf If $sFind<>"" Then GUICtrlSetState($edit, $GUI_FOCUS) __GUICtrlEdit_FindText2($hWnd, $sText, $sFind, $iPos, $iOccurance) While not $stop If StringStripWS(GUICtrlRead($inputSearch), 3) = "" Then Exitloop Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btn_search Local $aSel = _GUICtrlEdit_GetSel($hWnd) If (IsArray($aSel) And $aSel[0] <> $aSel[1]) Then ; new selection Local $sFindNew = StringStripWS(StringMid($sText, $aSel[0] + 1, $aSel[1] - $aSel[0]), 3) If $sFindNew<>$sFind Then GUICtrlSetData($inputSearch, $sFindNew) EndIf If $sFind<>GUICtrlRead($inputSearch) Then $sFind = GUICtrlRead($inputSearch) $iOccurance = 1 EndIf GUICtrlSetState($edit, $GUI_FOCUS) __GUICtrlEdit_FindText2($hWnd, $sText, $sFind, $iPos, $iOccurance) EndSwitch WEnd GUICtrlSetData($inputSearch, "") _SendMessage($hWnd, $EM_SETSEL, -1, 0) _SendMessage($hWnd, $EM_LINESCROLL, 0, -_SendMessage($hWnd, $EM_GETLINECOUNT)) ;; Opt("GUIOnEventMode", $oldMode) EndIf EndFunc Func __GUICtrlEdit_FindText2($hWnd, ByRef $sText, ByRef $sFind, ByRef $iPos, ByRef $iOccurance) $iOccurance += 1 $iPos = StringInStr($sText, $sFind, 0, $iOccurance) If Not $iPos Then ; search and select $iOccurance = 1 _SendMessage($hWnd, $EM_SETSEL, -1, 0) _SendMessage($hWnd, $EM_SCROLLCARET) $iPos = StringInStr($sText, $sFind, 0, $iOccurance) If Not $iPos Then ; no more to find $iOccurance = 0 MsgBox(48, "Tilt", "Chaine recherchée introuvable") Else ; found it _SendMessage($hWnd, $EM_SETSEL, $iPos - 1, $iPos + StringLen($sFind) - 1) _SendMessage($hWnd, $EM_SCROLLCARET) EndIf Else ; set selection _SendMessage($hWnd, $EM_SETSEL, $iPos - 1, $iPos + StringLen($sFind) - 1) _SendMessage($hWnd, $EM_SCROLLCARET) EndIf EndFunc Func _GUICtrlEdit_GetSel($hWnd) Local $aSel[2] Local $wparam = DllStructCreate("uint Start") Local $lparam = DllStructCreate("uint End") _SendMessage($hWnd, $EM_GETSEL, $wparam, $lparam, 0, "struct*", "struct*") $aSel[0] = DllStructGetData($wparam, "Start") $aSel[1] = DllStructGetData($lparam, "End") Return $aSel EndFunc