PageRenderTime 105ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/AutoHotkey.docset/Contents/Resources/Documents/scripts/Seek_(SearchTheStartMenu).htm

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