Advertisement
Najeebsk

SEARCH-TEXT2.ahk

Apr 16th, 2023 (edited)
1,453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*   INFO
  2.    NAJEEB SEARCH TEXT UTILITY 2023
  3.    Written by: Najeeb Shah Khan (najeebshahkhan@gmail.com)
  4.    Last Modified: 3-25-2023
  5. */
  6. ;#warn
  7. #NoEnv
  8. #LTrim
  9. #SingleInstance, Force
  10. Process, Priority, , A
  11. SendMode, Input
  12. SetBatchLines, -1
  13. ;#NoTrayIcon
  14. SetKeyDelay 0    ; In case SendInput is not available
  15. SetTitleMatchMode RegEx
  16. SetWorkingDir %A_WorkingDir% ;%A_ScriptDir%
  17. ;FileSelectFile, SelectedFile, 3, ,
  18. ;FileRead, MyCMD, %SelectedFile%
  19.  
  20. FileCreateDir, %A_ScriptDir%\DATA
  21. FileInstall , SEARCH-TEXT2.ahk, %A_ScriptDir%\DATA\SEARCH-TEXT2.ahk, 1
  22. FileInstall , S12.she, %A_ScriptDir%\DATA\S12.she, 1
  23. FileInstall , SkinH_EL.dll, %A_ScriptDir%\DATA\SkinH_EL.dll, 1
  24. FileSetAttrib +HS, %A_ScriptDir%\DATA\S12.she, 2
  25. FileSetAttrib +HS, %A_ScriptDir%\DATA\SkinH_EL.dll, 2
  26. FileSetAttrib +HS, %A_ScriptDir%\DATA\SEARCH-TEXT2.ahk, 2
  27. FileSetAttrib +HS, %A_ScriptDir%\DATA, 2
  28. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  29. SkinForm(Apply, A_ScriptDir . "\DATA\SkinH_EL.dll", A_ScriptDir . "\DATA\S12.she")
  30. OnExit, GetOut
  31. Gui,Color, 091D33, 091D33
  32. Gui,Font, s16 cDDDDDD, Calibri
  33. Gui,Add,Text,X50 Y7, ~~~************ NAJEEB SEARCH TEXT UTILITY 2023************~~~
  34. Gui,Font, s14 cDDDDDD, Calibri
  35. Gui, Add, ListBox, x10 y38 h550 w700 vresults gClip,
  36. Gui,Add,Text,X10 Y603,SEARCH TEXT
  37. Gui, Add, Edit, x120 y600 w480 vneedle grefresh,
  38. listboxvisible := true
  39. Gui, Add, Button,gBrowse x616 y600 w90 h30 , Browse
  40. Gui, Show, w720 h650, NAJEEB SEARCH A TEXT
  41. GuiControl, Focus, needle
  42. Return
  43.  
  44. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  45. Browse:
  46. FileSelectFile, SelectedFile, 3, , Open a file
  47. FileRead, FileContents, %SelectedFile%
  48. Sort, FileContents
  49. Return
  50. Refresh:
  51. Gui, Submit, NoHide ; Save the user's input without hiding the window
  52. choicelimit := 0 ; resets the listbox choices counter every time the user adds or removes a letter from the edit box
  53. GuiControl,, results, | ; this empties the previous listbox entries
  54. listbox:="" ; this empties variable that controls the listbox entries
  55. if (needle != "") ; if the user's entry isn't empty (if something typed into editbox)
  56. {
  57. Guicontrol, show, results ; show the listbox
  58. listboxvisible := true
  59. Loop, parse, FileContents, `n, `r ; parse the wordlist.txt in memory to find matches
  60.     {
  61.         haystack:=A_LoopField ; cycles each line 1 by 1 matching 1 word at a time
  62.         position := instr(haystack, needle) ; finds out where the user's entry matches the word at (left, middle, or end of word etc.) or if not at all
  63.         if (position = 1) ;if it matches from the left
  64.         {
  65.                                                 listbox.="|" . haystack ; add it to the listbox variable
  66.             choicelimit := choicelimit + 1 ; increase the counter which counts how many results are going to be in the listbox
  67.         }
  68.     }
  69. Loop, parse, FileContents, `n, `r ; parse the wordlist.txt in memory again for a different kind of matching (midstring match)
  70.     {
  71.         haystack:=A_LoopField ; cycles each line 1 by 1 matching 1 word at a time
  72.         position := instr(haystack, needle) ; finds out where the user's entry matches the word at (left, middle, or end of word etc.) or if not at all
  73.         if (position > 1) ; if it matches anywhere but from the left
  74.         {
  75.                                                 listbox.="|" . haystack ; add it to the listbox variable, importantly AFTER the above matches
  76.             choicelimit := choicelimit + 1 ; increase the counter which counts how many results are going to be in the listbox
  77.         }
  78.     }
  79. if (listbox = "" || listbox = "|") {
  80. listboxvisible := false
  81. return
  82. }
  83. GuiControl,, results, %listbox% ; add the matched words to the listbox entries
  84. GuiControl, choose, results, 1 ; choose the first one by default (highlight it)
  85. resultchosen := 1 ; store which choice is highlighted in a variable
  86. }
  87. return
  88. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  89. GetOut:
  90. ;GuiClose:
  91. Gui, Hide
  92. SkinForm(0)
  93. ExitApp
  94. return
  95.  
  96. SkinForm(Param1 = "Apply", DLL = "", SkinName = ""){
  97.     if(Param1 = Apply){
  98.         DllCall("LoadLibrary", str, DLL)
  99.         DllCall(DLL . "\SkinH_AttachEx", AStr,SkinName, Str,"mhgd")
  100.     }else if(Param1 = 0){
  101.         DllCall(DLL . "\USkinExit")
  102.         }
  103. }
  104. Clip:
  105.  Gui, Submit, NoHide
  106.   Clipboard := results
  107. Return
  108. ;=-=-=-=-=-=-=-=-=-=- END SCRIPT -=-=-=-=-=-=-=-=-=-=-=-
  109. #R::Reload
  110. #S::Suspend
  111. #P::Pause
  112. ESC::ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement