home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 August / maximum-cd-2010-08.iso / DiscContents / AutoHotkey104805_Install.exe / AutoHotkey.chm / docs / scripts / seek_(searchthestartmenu).ahk < prev    next >
Encoding:
Text File  |  2009-09-25  |  24.8 KB  |  825 lines

  1. ; Seek -- by Phi
  2. ; http://www.autohotkey.com
  3. ; Navigating the Start Menu can be a hassle, especially
  4. ; if you have installed many programs over time. 'Seek'
  5. ; lets you specify a case-insensitive key word/phrase
  6. ; that it will use to filter only the matching programs
  7. ; and directories from the Start Menu, so that you can
  8. ; easily open your target program from a handful of
  9. ; matched entries. This eliminates the drudgery of
  10. ; searching and traversing the Start Menu.
  11.  
  12. ;*****************************************************************
  13. ;
  14. ;  Program : Seek
  15. ;  Coder   : Phi
  16. ;  Updated : Mon Jan 31 10:08:37 2005
  17. ;
  18. ;  What do you seek, my friend?
  19. ;
  20. ;*****************************************************************
  21. ;
  22. ;  I have a lot of fun coding this, and hope you will
  23. ;  enjoy using it too. Feel free to drop me an email with
  24. ;  your comments and feedback at: phi1618 (*a.t*) gmail
  25. ;  :D0T: com.
  26. ;
  27. ;  Options:
  28. ;    -cache Use the cached directory-listing if available
  29. ;           (this is the default mode when no option is specified)
  30. ;    -scan  Force a directory scan to retrieve the latest
  31. ;           directory listing
  32. ;    -scex  Scan & exit (this is useful for scheduling the
  33. ;           potentially time-consuming directory-scanning as
  34. ;           a background job)
  35. ;    -help  Show this help
  36. ;
  37. ;*****************************************************************
  38. ;
  39. ; HOW TO 'SEEK':
  40. ;
  41. ; 1. 'Seek' is an AutoHotkey script. You can either run it
  42. ;    as Seek.ahk (original script) or Seek.exe (compiled
  43. ;    executable).
  44. ;
  45. ;    To obtain Seek.exe, you can download Seek.zip (includes
  46. ;    both the source code and the compiled binary) from
  47. ;    http://home.ripway.com/2004-10/188589/
  48. ;    Otherwise, you can compile Seek.ahk on your own by
  49. ;    using AutoHotkey's Ahk2Exe.exe compiler, or you can
  50. ;    ask me for a copy via email. The filesize is small at
  51. ;    about 200 kbytes. I can be reached at: phi1618 (*a.t*)
  52. ;    gmail :D0T: com.
  53. ;
  54. ;    To use Seek.ahk, first, you'll need to install
  55. ;    AutoHotkey v1.0.25 or higher on your PC (download from
  56. ;    http://www.autohotkey.com). Next, run the command:
  57. ;
  58. ;    X:\myTools\AutoHotkey\AutoHotkey.exe Y:\myAHK\Seek.ahk
  59. ;
  60. ;    Remember to replace X:\myTools and Y:\myAHK with
  61. ;    the proper directory names on your PC.
  62. ;
  63. ; 2. You can place the executable Seek.exe anywhere you
  64. ;    want. There is no installation required, it doesn't
  65. ;    write anything to your registry, and it doesn't
  66. ;    access the Internet at all (no phoning home). To
  67. ;    uninstall, simply delete Seek.exe.
  68. ;
  69. ;    The only 2 files 'Seek' creates are placed in your
  70. ;    TMP directory:
  71. ;
  72. ;      a. _Seek.key  (cache file for last query string)
  73. ;      b. _Seek.list (cache file for directory listing)
  74. ;
  75. ;    If you're a purist, you can delete them manually
  76. ;    when you decide to remove 'Seek' from your system.
  77. ;
  78. ; 3. The most convenient way to run 'Seek' is via a
  79. ;    shortcut/hotkey. If you are not already using any
  80. ;    hotkey management program on your PC, I highly
  81. ;    recommend AutoHotkey. If you don't intend to install
  82. ;    any hotkey management program at the moment, you can
  83. ;    make use of Windows shortcut feature and bind a
  84. ;    shortcut key (e.g. ALT-F1) to launch 'Seek'. This is
  85. ;    important so that you can run 'Seek' at anytime and
  86. ;    anywhere.
  87. ;
  88. ; 4. When you run 'Seek' for the first time, it'll scan
  89. ;    your Start Menu, and save the directory listing into
  90. ;    a cache file.
  91. ;
  92. ;    The following directories are included in the scanning:
  93. ;    - %A_StartMenu%
  94. ;    - %A_StartMenuCommon%
  95. ;
  96. ;    By default, subsequent runs will read from the
  97. ;    cache file so as to reduce the loading time. For
  98. ;    more info on options, run 'Seek.exe -help'. If you
  99. ;    think your Start Menu doesn't contain too many
  100. ;    programs, you can choose not to use the cache and
  101. ;    instruct 'Seek' to always do a directory scan (via
  102. ;    option -scan).  That way, you will always get the
  103. ;    latest listing.
  104. ;
  105. ; 5. When you run 'Seek', a window will appear, waiting
  106. ;    for you to enter a key word/phrase. After you have
  107. ;    entered a query string, a list of matching records
  108. ;    will be displayed. Next, you need to highlight an
  109. ;    entry and press <Enter> or click on the 'Open'
  110. ;    button to run the selected program or open the
  111. ;    selected directory.
  112. ;
  113. ;*****************************************************************
  114. ;
  115. ; TECHNICAL NOTES:
  116. ;
  117. ; - 'Seek' requires Chris Mallett's AutoHotkey v1.0.25
  118. ;   or higher version (http://www.autohotkey.com).
  119. ;   Thanks to Chris for his great work on AutoHotkey. :)
  120. ;
  121. ; - The following environment variables must be valid:
  122. ;   a. TMP
  123. ;
  124. ;*****************************************************************
  125. ;
  126. ; KNOWN PROBLEMS:
  127. ;
  128. ; - Nil
  129. ;
  130. ;*****************************************************************
  131. ;
  132. ; IMPLEMENTED SUGGESTIONS:
  133. ;
  134. ; - Highlight 1st matching record by default so that
  135. ;   user can just hit <Enter> to run it.
  136. ;   (Suggested by Yih Yeong)
  137. ;
  138. ; - Enable double-click on the listing of the search
  139. ;   results to launch the program.
  140. ;   (Suggested by Yih Yeong & Jack)
  141. ;
  142. ; - Auto real-time incremental search.
  143. ;   (Suggested by Rajat)
  144. ;
  145. ; - Fuzzy search when user enters multiple query strings,
  146. ;   separated by space.
  147. ;   (Suggested by Rajat)
  148. ;
  149. ;*****************************************************************
  150. ;
  151. ; SUGGESTED FEATURES (MAY OR MAY NOT BE IMPLEMENTED):
  152. ;
  153. ; - Log the launch history. List the most frequently
  154. ;   used programs at the top of the search results.
  155. ;   (Suggested by Yih Yeong)
  156. ;
  157. ; - Instead of using list box, can it display a series
  158. ;   of application icons so that hovering the cursor
  159. ;   over the icon will display a tooltip containing the
  160. ;   program information (path, etc).
  161. ;   (Suggested by Yih Yeong)
  162. ;
  163. ; - Instead of matching text in the middle, match only
  164. ;   those program/directory names that begin with the
  165. ;   query string.
  166. ;   (Suggested by Stefan)
  167. ;
  168. ; - Add favorites management. Launch group of programs
  169. ;   in a single run.
  170. ;   (Suggested by Atomhrt)
  171. ;
  172. ; - Integrate Seek into the Windows taskbar/toolbar so that
  173. ;   it is always available and there is no need to bind a
  174. ;   hotkey to launch Seek.
  175. ;   (Suggested by Deniz Akay)
  176. ;
  177. ; - Search by wildcards/regex.
  178. ;   (Suggested by Steve)
  179. ;
  180. ;*****************************************************************
  181. ;
  182. ; CHANGE HISTORY:
  183. ;
  184. ; * v1.1.0
  185. ; - Initial release.
  186. ;
  187. ; * v1.1.1
  188. ; - Removed maximise-window option since some programs don't
  189. ;   function well with it.
  190. ; - Added double-click detection to trigger 'Open' function.
  191. ;
  192. ; * v2.0.0
  193. ; - Integrated the 'Seek' popup window into the output screen
  194. ;   so that user can re-enter the query string to search for
  195. ;   something else without having to exit and run Seek again.
  196. ; - Added 'Scan Start-Menu' button.
  197. ; - Added real-time incremental search which will auto
  198. ;   filter for matching records while you type away,
  199. ;   without waiting for you to press <Enter>.
  200. ; - Added internal switch (TrackKeyPhrase) to track search-string.
  201. ; - Added internal switch (ToolTipFilename) to show filename
  202. ;   using tooltip.
  203. ;
  204. ; * v2.0.1
  205. ; - Added horizontal scrollbar to ListBox so that very
  206. ;   long records will not be cut-off in the middle.
  207. ;
  208. ; * v2.0.2
  209. ; - Allowed user to add their own customised list of directories
  210. ;   to be included in the scanning. User just needs to create a
  211. ;   text file 'Seek.dir' in the same directory as Seek.exe or
  212. ;   Seek.ahk, and specify the full path of the directory to be
  213. ;   added, one directory per line. Do not enclose the path in
  214. ;   quotes or double-quotes.
  215. ;
  216. ; * v2.0.3
  217. ; - Added /on option to DIR-command to sort by name.
  218. ; - Fuzzy search when user enters multiple query strings,
  219. ;   separated by space, for e.g. "med pla". It's a match
  220. ;   when all the strings ("med" & "pla") are found. This
  221. ;   will match "Media Player", "Macromedia Flash Player",
  222. ;   "Play Medieval King", "medpla", "plamed".
  223. ; - Corrected tab-movement sequence by adding all buttons
  224. ;   right from the start, but disable them until they can
  225. ;   be used.
  226. ; - Added status bar to replace tooltip-feedback.
  227. ; - Removed obsolete internal switch (ToolTipFilename).
  228. ; - Replaced the use of "dir" command with AutoHotkey's
  229. ;   own "Loop" command for scanning directory contents.
  230. ;   "dir" cannot handle extended character set and thus
  231. ;   non-English (e.g German) directory and filename are
  232. ;   captured wrongly. (Thanks Wolfgang Bujatti and
  233. ;   Sietse Fliege for testing this modification)
  234. ; - Added internal switch (ScanMode) to define whether
  235. ;   files and/or directories are to be included in scan.
  236. ; - Replaced hardcoded directory paths of Start Menu with
  237. ;   built-in variables A_StartMenu, A_StartMenuCommon.
  238. ;   With this, Seek now works for different locales with
  239. ;   different naming convention of the Start Menu.
  240. ;   (Thanks Wolfgang Bujatti and Sietse Fliege for help
  241. ;   in testing another method before these new variables
  242. ;   are available.)
  243. ; - Added the pre-selection of the last-run program
  244. ;   record so that a quick double-<ENTER> will run it.
  245. ;
  246. ;*****************************************************************
  247.  
  248. ;**************************
  249. ;<--- BEGIN OF PROGRAM --->
  250. ;**************************
  251.  
  252. ;==== Your Customisation ===================================
  253.  
  254. ; Specify which program to use when opening a directory.
  255. ; If the program cannot be found or is not specified
  256. ; (i.e. variable is unassigned or assigned a null value),
  257. ; the default Explorer will be used.
  258. dirExplorer = E:\utl\xplorer2_lite\xplorer2.exe
  259.  
  260. ; User's customised list of additional directories to be
  261. ; included in the scanning. The full path must not be
  262. ; enclosed by quotes or double-quotes. If this file is
  263. ; missing, only the default directories will be scanned.
  264. SeekMyDir = %A_ScriptDir%\Seek.dir
  265.  
  266. ; Specify the filename and directory location to save
  267. ; the cached directory/program listing. There is no
  268. ; need to change this unless you want to.
  269. dirListing = %A_Temp%\_Seek.list
  270.  
  271. ; Specify the filename and directory location to save
  272. ; the cached key word/phrase of last search. There is
  273. ; no need to change this unless you want to.
  274. keyPhrase = %A_Temp%\_Seek.key
  275.  
  276. ; Track search string (ON/OFF)
  277. ; If ON, the last-used query string will be re-used as
  278. ; the default query string the next time you run Seek.
  279. ; If OFF, the last-used query string will not be tracked
  280. ; and there will not be a default query string value the
  281. ; next time you run Seek.
  282. TrackKeyPhrase = ON
  283.  
  284. ; Specify what should be included in scan.
  285. ; 0: Directories are excluded (only files).
  286. ; 1: All files and directories are included.
  287. ; 2: Only directories are included (no files).
  288. ScanMode = 1
  289.  
  290. ;...........................................................
  291.  
  292. ; INIT
  293. ;#NoTrayIcon
  294. StringCaseSense, Off
  295. version = Seek v2.0.3
  296.  
  297. ; DISPLAY HELP INSTRUCTIONS
  298. If 1 in --help,-help,/h,-h,/?,-?
  299. {
  300.     MsgBox,, %version%, Navigating the Start Menu can be a hassle, especially if you have installed many programs over time. 'Seek' lets you specify a case-insensitive key word/phrase that it will use to filter only the matching programs and directories from the Start Menu, so that you can easily open your target program from a handful of matched entries. This eliminates the drudgery of searching and traversing the Start Menu.`n`nI have a lot of fun coding this, and hope you will enjoy using it too. Feel free to drop me an email with your comments and feedback at: phi1618 (*a.t*) gmail :D0T: com.`n`nOptions:`n  -cache`tUse the cached directory-listing if available (this is the default mode when no option is specified)`n  -scan`tForce a directory scan to retrieve the latest directory listing`n  -scex`tScan & exit (this is useful for scheduling the potentially time-consuming directory-scanning as a background job)`n  -help`tShow this help
  301.     Goto QuitNoSave
  302. }
  303.  
  304. ; CHECK THAT THE MANDATORY ENVIRONMENT VARIABLES EXIST AND ARE VALID
  305. ; *TMP*
  306. IfNotExist, %A_Temp% ; PATH DOES NOT EXIST
  307. {
  308.     MsgBox This mandatory environment variable is either not defined or invalid:`n`n    TMP = %A_Temp%`n`nPlease fix it before running Seek.
  309.     Goto QuitNoSave
  310. }
  311.  
  312. ; IF NOT SCAN-AND-EXIT
  313. IfNotEqual 1, -scex
  314. {
  315.     ; RETRIEVE THE LAST USED KEY-PHRASE FROM CACHE FILE
  316.     ; TO BE USED AS THE DEFAULT QUERY STRING
  317.     If TrackKeyPhrase = ON
  318.     {
  319.         FileReadLine, PrevKeyPhrase, %keyPhrase%, 1
  320.         FileReadLine, PrevOpenTarget, %keyPhrase%, 2
  321.     }
  322.     NewKeyPhrase = %PrevKeyPhrase%
  323.     NewOpenTarget = %PrevOpenTarget%
  324.  
  325.     ; ADD THE TEXT BOX FOR USER TO ENTER THE QUERY STRING
  326.     Gui, 1:Add, Edit, vFilename W600, %NewKeyPhrase%
  327.  
  328.     ; ADD MY FAV TAGLINE
  329.     Gui, 1:Add, Text, X625 Y10, What do you seek, my friend?
  330.  
  331.     ; ADD THE STATUS BAR FOR PROVIDING FEEDBACK TO USER
  332.     Gui, 1:Add, Text, vStatusBar X10 Y31 R1 W764
  333.  
  334.     ; ADD THE SELECTION LISTBOX FOR DISPLAYING SEARCH RESULTS
  335.     Gui, 1:Add, ListBox, vOpenTarget gTargetSelection X10 Y53 R28 W764 HScroll Disabled, %List%
  336.  
  337.     ; ADD THESE BUTTONS, BUT DISABLE THEM FOR NOW
  338.     Gui, 1:Add, Button, gButtonOPEN vButtonOPEN Default X10 Y446 Disabled, Open
  339.     Gui, 1:Add, Button, gButtonOPENDIR vButtonOPENDIR X59 Y446 Disabled, Open Directory
  340.     Gui, 1:Add, Button, gButtonSCANSTARTMENU vButtonSCANSTARTMENU X340 Y446 Disabled, Scan Start-Menu
  341.  
  342.     ; ADD THE EXIT BUTTON
  343.     Gui, 1:Add, Button, gButtonEXIT X743 Y446, Exit
  344.  
  345.     ; POP-UP THE QUERY WINDOW
  346.     Gui, 1:Show, Center, %version%
  347. }
  348.  
  349. ; ENABLE RE-SCANNING OF LATEST DIRECTORY LISTING
  350. If 1 in -scan,-scex
  351.     rescan = Y
  352. ; CHECK WHETHER THE DIRECTORY LISTING CACHE FILE ALREADY EXISTS. IF NOT, DO A RE-SCAN.
  353. Else IfNotExist, %dirListing%
  354.     rescan = Y
  355.  
  356. If rescan = Y ; DO A RE-SCAN
  357. {
  358.     ; SHOW STATUS UNLESS USER SPECIFIES SCAN-AND-EXIT OPTION
  359.     IfNotEqual 1, -scex
  360.         GuiControl,, StatusBar, Scanning directory listing...
  361.  
  362.     ; SCAN START-MENU AND STORE DIRECTORY/PROGRAM LISTINGS IN CACHE FILE
  363.     Gosub ScanStartMenu
  364.  
  365.     ; QUIT IF USER SPECIFIES SCAN-AND-EXIT OPTION
  366.     IfEqual 1, -scex, Goto, QuitNoSave
  367. }
  368.  
  369. GuiControl,, StatusBar, Retrieving last query result...
  370.  
  371. ; RETRIEVE THE MATCHING LIST FOR THE LAST USED KEY-PHRASE
  372. Gosub SilentFindMatches
  373.  
  374. ; REMOVE THE STATUS TEXT
  375. GuiControl,, StatusBar,
  376.  
  377. ; DIRECTORY LISTING IS NOW LOADED. ENABLE THE OTHER BUTTONS.
  378. ; THESE BUTTONS ARE DISABLED EARLIER BECAUSE THEY SHOULD NOT
  379. ; BE FUNCTIONAL UNTIL THIS PART OF THE SCRIPT.
  380. GuiControl, 1:Enable, ButtonOPEN
  381. GuiControl, 1:Enable, ButtonOPENDIR
  382. GuiControl, 1:Enable, ButtonSCANSTARTMENU
  383.  
  384. ; TURN ON INCREMENTAL SEARCH
  385. SetTimer, tIncrementalSearch, 500
  386.  
  387. ; REFRESH THE GUI
  388. Gosub EnterQuery
  389.  
  390. Return
  391.  
  392. ;***********************************************************
  393. ;                                                          *
  394. ;                 END OF MAIN PROGRAM                      *
  395. ;                                                          *
  396. ;***********************************************************
  397.  
  398.  
  399. ;=== BEGIN ButtonSCANSTARTMENU EVENT =======================
  400.  
  401. ButtonSCANSTARTMENU:
  402.  
  403. Gui, 1:Submit, NoHide
  404. GuiControl,, StatusBar, Scanning directory listing...
  405.  
  406. ; DISABLE LISTBOX WHILE SCANNING IS IN PROGRESS
  407. GuiControl, 1:Disable, OpenTarget
  408. GuiControl, 1:Disable, ButtonEXIT
  409. GuiControl, 1:Disable, ButtonOPEN
  410. GuiControl, 1:Disable, ButtonOPENDIR
  411. GuiControl, 1:Disable, ButtonSCANSTARTMENU
  412.  
  413. ; DO THE SCANNING
  414. Gosub ScanStartMenu
  415.  
  416. ; INFORM USER THAT SCANNING HAS COMPLETED
  417. If Filename =
  418. {
  419.     ; IF QUERY STRING IS EMPTY...
  420.     GuiControl, 1:Enable, ButtonEXIT
  421.     GuiControl, 1:Enable, ButtonOPEN
  422.     GuiControl, 1:Enable, ButtonSCANSTARTMENU
  423.     GuiControl,, StatusBar, Scan completed.
  424.     Gosub EnterQuery
  425. }
  426. Else
  427. {
  428.     ; IF QUERY STRING EXISTS...
  429.     ; FILTER FOR SEARCH STRING WITH THE NEW LISTING
  430.     NewKeyPhrase =
  431.     Gosub FindMatches
  432. }
  433. Return
  434.  
  435. ;... END ButtonSCANSTARTMENU EVENT .........................
  436.  
  437.  
  438. ;=== BEGIN ScanStartMenu SUBROUTINE ========================
  439. ; SCAN THE START-MENU AND STORE THE DIRECTORY/PROGRAM
  440. ; LISTINGS IN A CACHE FILE
  441. ScanStartMenu:
  442.  
  443. ; DEFINE THE DIRECTORY PATHS TO RETRIEVE.
  444. ; THE PATH MUST NOT BE ENCLOSED BY QUOTES OR DOUBLE-QUOTES.
  445. ;
  446. ; FOR ENGLISH VERSION OF WINDOWS
  447. scanPath = %A_StartMenu%|%A_StartMenuCommon%
  448.  
  449. ; INCLUDE ADDITIONAL USER-DEFINED PATHS FOR SCANNING
  450. IfExist, %SeekMyDir%
  451. {
  452.     Loop, read, %SeekMyDir%
  453.     {
  454.         IfNotExist, %A_LoopReadLine%
  455.             MsgBox, 8192, %version%, Processing your customised directory list...`n`n"%A_LoopReadLine%" does not exist and will be excluded from the scanning.`nPlease update [ %SeekMyDir% ].
  456.         Else
  457.             scanPath = %scanPath%|%A_LoopReadLine%
  458.     } 
  459. }
  460.  
  461. ; DELETE EXISTING FILE BEFORE CREATING A NEW VERSION
  462. FileDelete, %dirListing%
  463.  
  464. ; SCAN DIRECTORY LISTING (DELIMITER = |) BY RECURSING
  465. ; EACH DIRECTORY TO RETRIEVE THE CONTENTS. HIDDEN FILES
  466. ; ARE EXCLUDED.
  467. Loop, parse, scanPath, |
  468. {
  469.     Loop, %A_LoopField%\*, %ScanMode%, 1
  470.     {
  471.         FileGetAttrib, fileAttrib, %A_LoopFileFullPath%
  472.         IfNotInString, fileAttrib, H ; EXCLUDE HIDDEN FILE
  473.             FileAppend, %A_LoopFileFullPath%`n, %dirListing%
  474.     }
  475. }
  476.  
  477. Return
  478.  
  479. ;... END ScanStartMenu SUBROUTINE ..........................
  480.  
  481.  
  482. ;=== BEGIN FindMatches SUBROUTINE ==========================
  483. ; SEARCH AND DISPLAY ALL MATCHING RECORDS IN THE LISTBOX
  484. FindMatches:
  485.  
  486. Gui, 1:Submit, NoHide
  487. CurFilename = %Filename%
  488. GuiControl,, StatusBar, 
  489.  
  490. ; CHECK FOR EMPTY QUERY STRING
  491. If CurFilename =
  492. {
  493.     MsgBox, 8192, %version%, Please enter the key word/phrase to search for.
  494.     Goto EnterQuery
  495. }
  496.  
  497. ; tIncrementalSearch IS BEING INTERRUPTED. LET IT FINISHES.
  498. If NewKeyPhrase <> %CurFilename%
  499. {
  500.     ; INFORM USER THAT PATIENCE IS A VIRTUE
  501.     GuiControl,, StatusBar, Seeking...
  502.     ResumeFindMatches = TRUE
  503.     Return
  504. }
  505.  
  506. If List = |
  507. {
  508.     ; NOT EVEN A SINGLE MATCHING RECORD IS FOUND.
  509.     ; LET USER MODIFY THE QUERY STRING AND TRY AGAIN.
  510.     MsgBox, 8192, %version%, The query string "%CurFilename%" does not match any record. Try again.
  511.     GuiControl, 1:Disable, ButtonOPENDIR
  512.     GuiControl, 1:Enable, ButtonSCANSTARTMENU
  513.     Goto EnterQuery
  514. }
  515. Else
  516. {
  517.     ; SELECT THE FIRST RECORD IF NO OTHER RECORD HAS BEEN SELECTED
  518.     Gui, 1:Submit, NoHide
  519.     GuiControl, 1:Enable, OpenTarget
  520.     GuiControl, 1:Enable, ButtonOPEN
  521.     GuiControl, 1:Enable, ButtonOPENDIR
  522.     GuiControl, 1:Enable, ButtonSCANSTARTMENU
  523.     GuiControl, Focus, OpenTarget
  524.     If OpenTarget =
  525.         GuiControl, 1:Choose, OpenTarget, |1
  526. }
  527.  
  528. ; REFRESH GUI
  529. Gui, 1:Show, Center, %version%
  530.  
  531. Return
  532.  
  533. ;... END FindMatches SUBROUTINE ............................
  534.  
  535.  
  536. ;=== BEGIN SilentFindMatches SUBROUTINE ====================
  537.  
  538. SilentFindMatches:
  539.  
  540. Gui, 1:Submit, NoHide
  541. sfmFilename = %Filename%
  542.  
  543. ; FILTER MATCHING RECORDS BASED ON USER QUERY STRING
  544. List = |
  545. If sfmFilename <>
  546. {
  547.     Loop, read, %dirListing%
  548.     {
  549.         Gui, 1:Submit, NoHide
  550.         tFilename = %Filename%
  551.         If sfmFilename <> %tFilename%
  552.         {
  553.             ; USER HAS CHANGED THE SEARCH STRING. THERE IS NO POINT
  554.             ; TO CONTINUE SEARCHING USING THE OLD STRING, SO ABORT.
  555.             Return
  556.         }
  557.         Else
  558.         {
  559.             ; APPEND MATCHING RECORDS INTO THE LIST
  560.             SplitPath, A_LoopReadLine, name, dir, ext, name_no_ext, drive
  561.             MatchFound = Y
  562.             Loop, parse, sfmFilename, %A_Space%
  563.             {
  564.                 IfNotInString, name, %A_LoopField%
  565.                 {
  566.                     MatchFound = N
  567.                     Break
  568.                 }
  569.             }
  570.             IfEqual, MatchFound, Y
  571.             {
  572.                 ; ADD RECORD TO LIST
  573.                 List = %List%%A_LoopReadLine%|
  574.  
  575.                 ; PRE-SELECT IF THIS MATCHES THE LAST-RUN PROGRAM
  576.                 If (A_LoopReadLine = PrevOpenTarget && sfmFilename = PrevKeyPhrase)
  577.                     List = %List%|
  578.             }
  579.         }
  580.     }
  581. }
  582.  
  583. ; REFRESH LIST WITH SEARCH RESULTS
  584. GuiControl, 1:, OpenTarget, %List%
  585.  
  586. If List = |
  587. {
  588.     ; NO MATCHING RECORD IS FOUND
  589.     ; DISABLE LISTBOX
  590.     GuiControl, 1:Disable, OpenTarget
  591.     GuiControl, 1:Disable, ButtonOPENDIR
  592. }
  593. Else
  594. {
  595.     ; MATCHING RECORDS ARE FOUND
  596.     ; ENABLE LISTBOX
  597.     GuiControl, 1:Enable, OpenTarget
  598.     GuiControl, 1:Enable, ButtonOPENDIR
  599. }
  600.  
  601. ; REFRESH GUI
  602. Gui, 1:Show, Center, %version%
  603.  
  604. Return
  605.  
  606. ;... END SilentFindMatches SUBROUTINE ......................
  607.  
  608.  
  609. ;=== BEGIN EnterQuery SUBROUTINE ===========================
  610. ; REFRESH GUI AND LET USER ENTERS SEARCH STRING
  611. EnterQuery:
  612. GuiControl, Focus, Filename
  613. GuiControl, 1:Enable, ButtonOPEN
  614. Gui, 1:Show, Center, %version%
  615. Return
  616. ;... END EnterQuery SUBROUTINE .............................
  617.  
  618.  
  619. ;=== BEGIN TargetSelection EVENT ===========================
  620.  
  621. TargetSelection:
  622. Gui, 1:Submit, NoHide
  623.  
  624. ; DOUBLE-CLICK DETECTION TO LAUNCH PROGRAM
  625. If A_GuiControlEvent = DoubleClick
  626. {
  627.     Gosub ButtonOPEN
  628. }
  629. Else
  630. {
  631.     ; STUB - FOR FUTURE USE
  632.     If A_GuiControlEvent = Normal
  633.     {
  634.         ; DO NOTHING FOR NOW
  635.     }
  636. }
  637.  
  638. Return
  639.  
  640. ;... END TargetSelection EVENT .............................
  641.  
  642.  
  643. ;=== BEGIN ButtonOPEN EVENT ================================
  644.  
  645. ; USER CLICKED ON 'OPEN' BUTTON OR PRESSED <ENTER>
  646. ButtonOPEN:
  647. Gui, 1:Submit, NoHide
  648.  
  649. ; FIND OUT WHERE THE KEYBOARD FOCUS WAS. IF IT'S THE
  650. ; TEXT FIELD, RUN THE QUERY TO FIND MATCHES. ELSE, IT
  651. ; MUST BE FROM THE LISTBOX.
  652. GuiControlGet, focusControl, 1:Focus
  653. If focusControl = Edit1
  654. {
  655.     GuiControl, Focus, OpenTarget
  656.     GuiControl, 1:Disable, OpenTarget
  657.     GuiControl, 1:Disable, ButtonOPENDIR
  658.     GuiControl, 1:Disable, ButtonSCANSTARTMENU
  659.     Goto FindMatches
  660. }
  661.  
  662. ; NO RECORD FROM THE LISTBOX IS SELECTED
  663. If OpenTarget =
  664. {
  665.     MsgBox, 8192, %version%, Please make a selection before hitting <Enter>.`nPress <Esc> to exit.
  666.     Goto EnterQuery
  667. }
  668.  
  669. ; SELECTED RECORD DOES NOT EXIST (FILE OR DIRECTORY NOT FOUND)
  670. IfNotExist, %OpenTarget%
  671. {
  672.     MsgBox, 8192, %version%, %OpenTarget% does not exist. This means that the directory cache is outdated. You may click on the 'Scan Start-Menu' button below to update the directory cache with your latest directory listing now.
  673.     Goto EnterQuery
  674. }
  675.  
  676. ; CHECK WHETHER THE SELECTED RECORD IS A FILE OR DIRECTORY
  677. FileGetAttrib, fileAttrib, %OpenTarget%
  678. IfInString, fileAttrib, D ; IS DIRECTORY
  679. {
  680.     Gosub sOpenDir
  681. }
  682. Else If fileAttrib <> ; IS FILE
  683. {
  684.     Run, %OpenTarget%
  685. }
  686. Else
  687. {
  688.     MsgBox %OpenTarget% is neither a DIRECTORY or a FILE. This shouldn't happen. Seek cannot proceed. Quitting...
  689. }
  690.  
  691. Goto Quit
  692.  
  693. ;... END ButtonOPEN EVENT ..................................
  694.  
  695.  
  696. ;=== BEGIN ButtonOPENDIR EVENT =============================
  697.  
  698. ; USER CLICKED ON 'OPEN DIRECTORY' BUTTON
  699. ButtonOPENDIR:
  700. Gui, 1:Submit, NoHide
  701.  
  702. ; CHECK THAT USER HAS SELECTED A RECORD ALREADY
  703. If OpenTarget =
  704. {
  705.     MsgBox, 8192, %version%, Please make a selection first.
  706.     Goto EnterQuery
  707. }
  708.  
  709. ; RUN SUBROUTINE TO OPEN A DIRECTORY
  710. Gosub sOpenDir
  711.  
  712. Goto Quit
  713.  
  714. ;... END ButtonOPENDIR EVENT ...............................
  715.  
  716.  
  717. ;=== BEGIN sOpenDir SUBROUTINE =============================
  718.  
  719. sOpenDir:
  720.  
  721. ; IF USER SELECTED A FILE-RECORD INSTEAD OF A DIRECTORY-RECORD,
  722. ; EXTRACT THE DIRECTORY PATH. (I'M USING DriveGet INSTEAD OF
  723. ; FileGetAttrib TO ALLOW THE SCENARIO WHEREBY OpenTarget IS
  724. ; INVALID BUT THE DIRECTORY PATH OF OpenTarget IS VALID.
  725. DriveGet, status, status, %OpenTarget%
  726. If status <> Ready ; NOT A DIRECTORY
  727. {
  728.     SplitPath, OpenTarget, name, dir, ext, name_no_ext, drive
  729.     OpenTarget = %dir%
  730. }
  731.  
  732. ; CHECK WHETHER DIRECTORY EXISTS
  733. IfNotExist, %OpenTarget%
  734. {
  735.     MsgBox, 8192, %version%, %OpenTarget% does not exist. This means that the directory cache is outdated. You may click on the 'Scan Start-Menu' button below to update the directory cache with your latest directory listing now.
  736.     Goto EnterQuery
  737. }
  738.  
  739. ; OPEN THE DIRECTORY
  740. IfExist, %dirExplorer%
  741. {
  742.     Run, "%dirExplorer%" "%OpenTarget%", , Max ; OPEN WITH CUSTOMISED FILE EXPLORER
  743. }
  744. Else
  745. {
  746.     Run, %OpenTarget%, , Max ; OPEN WITH DEFAULT WINDOWS FILE EXPLORER
  747. }
  748. Return
  749.  
  750. ;... END sOpenDir SUBROUTINE ...............................
  751.  
  752.  
  753. ;=== BEGIN tIncrementalSearch EVENT ========================
  754. ; AUTOMATICALLY CONDUCT REAL-TIME INCREMENTAL SEARCH
  755. ; TO FIND MATCHING RECORDS WITHOUT WAITING FOR USER
  756. ; TO PRESS <ENTER>
  757. tIncrementalSearch:
  758.  
  759. Loop
  760. ; REPEAT SEARCHING UNTIL USER HAS STOPPED CHANGING THE QUERY STRING
  761. {
  762.     Gui, 1:Submit, NoHide
  763.     CurFilename = %Filename%
  764.     If NewKeyPhrase <> %CurFilename%
  765.     {
  766.         OpenTarget =
  767.         Gosub SilentFindMatches
  768.         NewKeyPhrase = %CurFilename%
  769.         Sleep, 100 ; DON'T HOG THE CPU!
  770.     }
  771.     Else
  772.     {
  773.         ; QUERY STRING HAS STOPPED CHANGING
  774.         Break
  775.     }
  776. }
  777.  
  778. ; USER HAS HIT <ENTER> TO LOOK FOR MATCHING RECORDS.
  779. ; RUN FindMatches NOW.
  780. If ResumeFindMatches = TRUE
  781. {
  782.     ResumeFindMatches = FALSE
  783.     Gosub FindMatches
  784. }
  785.  
  786. ; CONTINUE MONITORING FOR CHANGES
  787. SetTimer, tIncrementalSearch, 500
  788.  
  789. Return
  790.  
  791. ;... END tIncrementalSearch EVENT ..........................
  792.  
  793.  
  794. ;=== BEGIN Quit SUBROUTINE =================================
  795.  
  796. Quit:
  797. ButtonEXIT:
  798. GuiClose:
  799. GuiEscape:
  800.  
  801. Gui, 1:Submit, NoHide
  802.  
  803. ; SAVE THE KEY WORD/PHRASE FOR NEXT RUN IF IT HAS CHANGED
  804. If TrackKeyPhrase = ON
  805. {
  806.     If (PrevKeyPhrase <> Filename || PrevOpenTarget <> OpenTarget)
  807.     {
  808.         FileDelete, %keyPhrase%
  809.         FileAppend, %Filename%`n, %keyPhrase%
  810.         FileAppend, %OpenTarget%`n, %keyPhrase%
  811.     }
  812. }
  813.  
  814. QuitNoSave:
  815. ExitApp ; JOB DONE. G'DAY!
  816.  
  817. ;... END Quit SUBROUTINE ...................................
  818.  
  819.  
  820. ;************************
  821. ;<--- END OF PROGRAM --->
  822. ;************************
  823.  
  824. ; /* vim: set noexpandtab shiftwidth=4: */
  825.