Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 267.96 KB | None | 0 0
  1. ;-- Original coding for the HiEdit control written by skwire.
  2. ;-- Original highlighting file for the HiEdit control provided by skwire.
  3. ;**********************************************
  4. ;* *
  5. ;* *
  6. ;* *
  7. ;* *
  8. ;* Main program *
  9. ;* *
  10. ;* *
  11. ;* *
  12. ;* *
  13. ;**********************************************
  14. $Version:="2.2"
  15.  
  16. ;*************************
  17. ;* *
  18. ;* AHK environment *
  19. ;* *
  20. ;*************************
  21. #ClipboardTimeout 1500
  22. #NoEnv
  23. #NoTrayIcon
  24. #SingleInstance Off
  25. ListLines Off
  26. SetBatchLines 30ms ;-- A little bump in speed
  27.  
  28. ;-- Is this program already running?
  29. AlreadyRunning()
  30.  
  31. ;********************
  32. ;* *
  33. ;* Initialize *
  34. ;* *
  35. ;********************
  36. ;[==========]
  37. ;[ Global ]
  38. ;[==========]
  39. SplitPath A_ScriptName,,,,$ScriptName
  40. $ConfigFile :=A_ScriptDir . "\" . $ScriptName . ".ini"
  41. $EditDir :=A_ScriptDir . "\Edit"
  42. $EditFile :=$EditDir . "\" . $ScriptName . "_EditScript.ahk"
  43. $EditBackupFile :=$EditDir . "\" . $ScriptName . "_EditScript.bak"
  44. $HelpFile :=A_ScriptDir . "\" . $ScriptName . ".chm"
  45. $LibDir :=A_ScriptDir . "\Lib"
  46. $RPDir :=A_ScriptDir . "\Restore"
  47. $RunDir :=A_ScriptDir . "\Run"
  48. $RunFile :=$RunDir . "\" . $ScriptName . "_RunScript.ahk"
  49.  
  50. $Resize :=True
  51. $Running :=False
  52. $BatchLines :=A_BatchLines
  53. Dlg_Flags :="d"
  54.  
  55. ;[=============]
  56. ;[ Constants ]
  57. ;[=============]
  58.  
  59. Run :=0
  60. ;-- General Win32
  61. WM_USER :=0x400 ;-- 1024
  62. WM_RBUTTONUP :=0x205 ;-- 517
  63.  
  64. ;-- Edit
  65. EM_LINESCROLL :=0xB6
  66. EM_SCROLLCARET :=0xB7
  67.  
  68. ;-- Cursor
  69. IDC_WAIT :=0x32514
  70.  
  71. ;-- Toolbar
  72. TB_LOADIMAGES :=0x432
  73.  
  74. IDB_STD_SMALL_COLOR :=0x0
  75. IDB_STD_LARGE_COLOR :=0x1
  76. IDB_VIEW_SMALL_COLOR :=0x4
  77. IDB_VIEW_LARGE_COLOR :=0x5
  78. IDB_HIST_SMALL_COLOR :=0x8
  79. IDB_HIST_LARGE_COLOR :=0x9
  80.  
  81. HINST_COMMCTRL :=0xFFFFFFFF ; (-1)
  82.  
  83. TB_GETMETRICS :=WM_USER+101
  84. TB_SETMETRICS :=WM_USER+102
  85. TBMF_PAD :=0x00000001
  86. TBMF_BARPAD :=0x00000002 ;-- Not used (msdn)
  87. TBMF_BUTTONSPACING :=0x00000004
  88.  
  89. TB_GETPADDING :=0x456
  90. TB_SETPADDING :=0x457
  91.  
  92. ;-- GetLocaleInfo
  93. LOCALE_USER_DEFAULT :=0x400
  94. LOCALE_IMEASURE :=0xD
  95. LOCALE_RETURN_NUMBER :=0x20000000
  96.  
  97. ;-- Page Setup
  98. PSD_MARGINS :=0x2
  99. PSD_INTHOUSANDTHSOFINCHES :=0x4
  100. PSD_INHUNDREDTHSOFMILLIMETERS :=0x8
  101. PSD_DISABLEMARGINS :=0x10
  102. PSD_DISABLEPRINTER :=0x20 ;-- Obsolete (msdn)
  103. PSD_DISABLEORIENTATION :=0x100
  104. PSD_DISABLEPAPER :=0x200
  105. PSD_RETURNDEFAULT :=0x400
  106. PSD_ENABLEPAGESETUPTEMPLATE :=0x8000
  107.  
  108. ;-- Page/Printer
  109. DMORIENT_PORTRAIT :=0x1
  110. DMORIENT_LANDSCAPE :=0x2
  111.  
  112. ;-- Data
  113. $FieldDelimiter :=Chr(139) . Chr(134) . Chr(155)
  114. $RecordDelimiter :=Chr(171) . Chr(135) . Chr(187)
  115. $iniBorder :=Chr(142)
  116.  
  117. ;-- Font
  118. $DefaultFont :="Lucida Console"
  119. $DefaultFontSize :=10
  120. $RPViewerDefaultFontSize :=8
  121. $MinimumFontSize :=01
  122. $MaximumFontSize :=99
  123.  
  124. ;-- Menu items
  125. s_About_MI :="&About..."
  126. s_AlwaysOnTop_MI :="&Always On Top`tCtrl+Shift+A"
  127. s_BlockComment_MI :="Block Comment`tCtrl+Q"
  128. s_BlockUncomment_MI :="Block Uncomment`tCtrl+Shift+Q"
  129. s_ClearRunWorkspaceOnExit_MI :="Clear Run Workspace on Exit"
  130. s_ClearRunWorkspaceOnRun_MI :="Clear Run Workspace on Run"
  131. s_ConvertCase_MI :="Con&vert Case"
  132. s_Copy_MI :="&Copy`tCtrl+C"
  133. s_Cut_MI :="Cu&t`tCtrl+X"
  134. s_Delete_MI :="Delete`tDel"
  135. s_File_Stop_MI :="S&top`tF10"
  136. s_Find_MI :="&Find...`tCtrl+F"
  137. s_FindNext_MI :="Find &Next`tF3"
  138. s_FindPrevious_MI :="Find Previous`tShift+F3"
  139. s_Goto_MI :="&Go To...`tCtrl+G"
  140. s_Help_MI :="&Help`tF1"
  141. s_LineNumbersBar_MI :="&Line Numbers Bar`tCtrl+L"
  142. s_MenuBar_MI :="&Menu Bar`tCtrl+Shift+M"
  143. s_Menubar_Stop_MI :="S&top"
  144. s_New_MI :="&New`tCtrl+N"
  145. s_PageSetup_MI :="Page Set&up...`tCtrl+Shift+P"
  146. s_Paste_MI :="&Paste`tCtrl+V"
  147. s_PasteC_MI :="PasteC`tF5"
  148. s_Prepend_New_MI :="Prepend N&ew`tCtrl+Shift+N"
  149. s_Print_MI :="&Print...`tCtrl+P"
  150. s_Redo_MI :="&Redo`tCtrl+Y"
  151. s_Replace_MI :="R&eplace...`tCtrl+H"
  152. s_Run_MI :="&Run`tF9"
  153. s_RunDebug_MI :="Append Debug Script"
  154. s_RunPrompt_MI :="Prompt For Parameters"
  155. s_RunSelected_MI :="Run Selec&ted`tCtrl+F9"
  156. s_RunWait_MI :="Wait For Script to Complete"
  157. s_Save_MI :="&Save`tCtrl+S"
  158. s_SaveTo_MI :="S&ave To...`tF12"
  159. s_SelectAll_MI :="Select A&ll`tCtrl+A"
  160. s_StatusBar_MI :="&Status Bar`tCtrl+Shift+S"
  161. s_ToolBar_MI :="&Toolbar`tCtrl+T"
  162. s_Undo_MI :="&Undo`tCtrl+Z"
  163.  
  164. ;[==================]
  165. ;[ System metrics ]
  166. ;[==================]
  167. SysGet SM_CYCAPTION,4
  168. ;-- Height of a regular size caption area (title bar), in pixels.
  169.  
  170. SysGet SM_CYMENU,15
  171. ;-- Height of a single-line menu bar, in pixels.
  172.  
  173. SysGet SM_CXSIZEFRAME,32
  174. ;-- The width (in pixels) of the horizontal border for a window that can be
  175. ; resized.
  176.  
  177. SysGet SM_CYSIZEFRAME,33
  178. ;-- The height (in pixels) of the vertical border for a window that can be
  179. ; resized.
  180.  
  181. ;-- Collect work area dimensions for primary monitor
  182. SysGet $MonitorWorkArea,MonitorWorkArea
  183. $MonitorWorkAreaWidth:=$MonitorWorkAreaRight-$MonitorWorkAreaLeft
  184.  
  185.  
  186. ;-- Compute maximum width of toolbar and GUI object
  187. $MaxGUIW:=$MonitorWorkAreaWidth
  188. ;-- Width of the GUI when maximized (no vertical borders)
  189.  
  190. ;[=================]
  191. ;[ GetLocaleInfo ]
  192. ;[=================]
  193. ;-- Get locale system of measurement (0=Metric, 1=English)
  194. VarSetCapacity(lpLCData,4,0)
  195. DllCall("GetLocaleInfo"
  196. ,"UInt",LOCALE_USER_DEFAULT
  197. ,"UInt",LOCALE_IMEASURE|LOCALE_RETURN_NUMBER
  198. ,"UInt",&lpLCData
  199. ,"UInt",4)
  200.  
  201. if NumGet(lpLCData,0,"Unit")=0 ;-- 0=HiMetric (hundredths of millimeters)
  202. $MarginDefault:=1270 ;-- 12.7 mm (0.5 inch)
  203. else ;-- 1=HiEnglish (thousandths of inches)
  204. $MarginDefault:=500 ;-- 0.5 inch
  205.  
  206.  
  207. ;*****************
  208. ;* *
  209. ;* Process *
  210. ;* *
  211. ;*****************
  212. ;-- Set to full speed just to get started
  213. SetBatchLines -1
  214.  
  215. ;-- Process
  216. gosub ReadConfiguration
  217. gosub QAHKGUI
  218.  
  219. ;-- Reset speed to program default
  220. SetBatchLines %$BatchLines%
  221. return
  222.  
  223.  
  224.  
  225. ;*******************************************
  226. ;* *
  227. ;* *
  228. ;* *
  229. ;* *
  230. ;* Functions *
  231. ;* *
  232. ;* *
  233. ;* *
  234. ;* *
  235. ;*******************************************
  236. #include _Functions\AddCommas.ahk
  237. #include _Functions\AlreadyRunning.ahk
  238. #include _Functions\Attach.ahk
  239. #include _Functions\CompressFileName.ahk
  240. #include _Functions\DDLManager.ahk
  241. #include _Functions\Dlg.ahk
  242. #include _Functions\FileMD5.ahk
  243. #include _Functions\HiEdit.ahk
  244. #include _Functions\InfoGUI.ahk
  245. #include _Functions\MRUManager.ahk
  246. #include _Functions\PopupXY.ahk
  247. #include _Functions\SecondsToHHMMSS.ahk
  248. #include _Functions\SetSystemCursor.ahk
  249. #include _Functions\SystemMessage.ahk
  250. #include _Functions\Toolbar.ahk
  251.  
  252.  
  253. ;**********************
  254. ;* *
  255. ;* WM_RBUTTONUP *
  256. ;* *
  257. ;**********************
  258. WM_RBUTTONUP(wParam,lParam,msg,hWnd)
  259. {
  260. SetTimer QAHKGUI_ContextMenu2,0
  261. Return 0
  262. }
  263.  
  264.  
  265. ;***********************
  266. ;* *
  267. ;* Block Comment *
  268. ;* *
  269. ;***********************
  270. HE_BlockComment(hEdit,p_Cmd="",p_BCChars="")
  271. {
  272. ;[=============]
  273. ;[ Intialize ]
  274. ;[=============]
  275. l_NewText:=""
  276. l_XFactor:=0
  277.  
  278. ;[==============]
  279. ;[ Parameters ]
  280. ;[==============]
  281. ;-- p_Cmd
  282. if p_Cmd not in Add,Insert,Remove,Delete
  283. p_Cmd=Insert
  284.  
  285. ;-- p_BCChars
  286. if StrLen(p_BCChars)=0
  287. p_BCChars:=";;;;;" ;-- 5 semicolons (default)
  288. ;-- Programming note: This was added as a convenience and as a
  289. ; fail-safe. The p_BCChars parameter cannot be empty/null.
  290.  
  291. ;[===============]
  292. ;[ Preliminary ]
  293. ;[===============]
  294. ;-- Get user select positions
  295. HE_GetSel(hEdit,l_StartSelPos,l_EndSelPos)
  296.  
  297. ;-- Get position of the beginning of the line
  298. l_FirstCharPos:=HE_LineIndex(hEdit,HE_LineFromChar(hEdit,l_StartSelPos))
  299.  
  300. ;-- Reselect if the user selection does not start at the beginning of the line
  301. if (l_FirstCharPos<>l_StartSelPos)
  302. HE_SetSel(hEdit,l_FirstCharPos,l_EndSelPos)
  303.  
  304. ;-- Get selected text
  305. l_SelectedText:=HE_GetSelText(hEdit)
  306.  
  307. ;[=========]
  308. ;[ Shift ]
  309. ;[=========]
  310. if p_Cmd in Add,Insert
  311. {
  312. ;--------------
  313. ;-- Add/Insert
  314. ;--------------
  315. if StrLen(l_SelectedText)=0
  316. l_NewText:=p_BCChars
  317. else
  318. {
  319. ;-- Is last character a NL?
  320. l_LastSelChar:=""
  321. if SubStr(l_SelectedText,0)="`n"
  322. {
  323. l_LastSelChar:="`n"
  324. StringTrimRight l_SelectedText,l_SelectedText,1
  325. }
  326.  
  327. ;-- Shift it
  328. Loop Parse,l_SelectedText,`n,`r
  329. {
  330. if StrLen(l_NewText)=0
  331. l_NewText:=p_BCChars . A_LoopField
  332. else
  333. l_NewText.="`n" . p_BCChars . A_LoopField
  334. }
  335.  
  336. ;-- Append last char if needed
  337. if StrLen(l_LastSelChar)
  338. l_NewText.=l_LastSelChar
  339. }
  340.  
  341. ;-- Replace selected text with l_NewText
  342. HE_ReplaceSel(hEdit,l_NewText)
  343.  
  344. ;-- Calculate new start/end select positions
  345. if (l_StartSelPos=l_EndSelPos) ;-- User selected nothing
  346. {
  347. l_NewStartSelPos:=l_StartSelPos+StrLen(p_BCChars)
  348. l_NewEndSelPos :=l_NewStartSelPos
  349. }
  350. else
  351. ;-- Cursor on the 1st char of the line?
  352. if (l_StartSelPos=l_FirstCharPos)
  353. {
  354. l_NewStartSelPos:=l_StartSelPos
  355. l_NewEndSelPos :=l_StartSelPos+StrLen(l_NewText)
  356. }
  357. else
  358. {
  359. l_NewStartSelPos:=l_StartSelPos+StrLen(p_BCChars)
  360. l_NewEndSelPos :=l_StartSelPos+StrLen(l_NewText)-(l_StartSelPos-l_FirstCharPos)
  361. }
  362.  
  363. ;-- Reselect text
  364. HE_SetSel(hEdit,l_NewStartSelPos,l_NewEndSelPos)
  365. }
  366. else
  367. {
  368. ;-----------------
  369. ;-- Remove/Delete
  370. ;-----------------
  371. ;-- On a single line at the beginning of the line?
  372. if StrLen(l_SelectedText)=0
  373. {
  374. ;-- Able to look forward?
  375. if (l_StartSelPos<=(HE_GetTextLength(hEdit)-StrLen(p_BCChars)))
  376. ;-- Look forward to see if the first characters are at the
  377. ; beginning of the a comment block
  378. if HE_GetTextRange(hEdit,l_StartSelPos,l_StartSelPos+StrLen(p_BCChars))=p_BCChars
  379. {
  380. ;-- Reselect and recapture
  381. HE_SetSel(hEdit,l_StartSelPos,l_StartSelPos+StrLen(p_BCChars))
  382. l_SelectedText:=HE_GetSelText(hEdit)
  383. }
  384. }
  385.  
  386. ;-- Process
  387. if StrLen(l_SelectedText)
  388. {
  389. ;-- Remove p_BCChars from the beginning of each line
  390. Loop Parse,l_SelectedText,`n
  391. {
  392. l_LoopField:=A_LoopField
  393.  
  394. ;-- Remove p_BCChars if first characters
  395. if SubStr(l_LoopField,1,StrLen(p_BCChars))=p_BCChars
  396. StringTrimLeft l_LoopField,l_LoopField,% StrLen(p_BCChars)
  397.  
  398. ;-- Append to l_NewText
  399. if A_Index=1
  400. l_NewText:=l_LoopField
  401. else
  402. l_NewText.="`n" . l_LoopField
  403. }
  404. }
  405.  
  406. ;-- Replace selected text with l_NewText
  407. HE_ReplaceSel(hEdit,l_NewText)
  408.  
  409. ;-- Calculate XFactor for reselection
  410. if SubStr(l_SelectedText,1,StrLen(p_BCChars))=p_BCChars
  411. {
  412. if (l_StartSelPos>l_FirstCharPos)
  413. if (l_StartSelPos-l_FirstCharPos)>StrLen(p_BCChars)
  414. l_XFactor:=StrLen(p_BCChars)
  415. else
  416. l_XFactor:=l_StartSelPos-l_FirstCharPos
  417. }
  418.  
  419. ;-- Calculate new start/end select positions
  420. if StrLen(l_SelectedText)=0 ;-- Nothing programmatically selected
  421. or (l_SelectedText=l_NewText) ;-- Nothing changed
  422. {
  423. l_NewStartSelPos:=l_StartSelPos
  424. l_NewEndSelPos :=l_EndSelPos
  425. }
  426. else
  427. {
  428. l_NewStartSelPos:=l_StartSelPos-l_XFactor
  429. l_NewEndSelPos :=l_StartSelPos+StrLen(l_NewText)-(l_StartSelPos-l_FirstCharPos)
  430. }
  431.  
  432. ;-- Reselect text
  433. HE_SetSel(hEdit,l_NewStartSelPos,l_NewEndSelPos)
  434. }
  435.  
  436. ;[===============]
  437. ;[ Scroll left ]
  438. ;[===============]
  439. HE_LineScroll(hEdit,-999999)
  440. ;-- Fixes a display problem that sometimes occurs if working with lines
  441. ; that are wider than the control
  442.  
  443. return
  444. }
  445.  
  446.  
  447. ;********************
  448. ;* *
  449. ;* Shift Line *
  450. ;* *
  451. ;********************
  452. HE_ShiftLine(hEdit,p_Cmd="",p_Chars="")
  453. {
  454. ;[=============]
  455. ;[ Intialize ]
  456. ;[=============]
  457. l_NewText=
  458. l_Reselect:=True
  459.  
  460. ;[==============]
  461. ;[ Parameters ]
  462. ;[==============]
  463. ;-----------
  464. ;-- p_Chars
  465. ;-----------
  466. if StrLen(p_Chars)=0
  467. {
  468. p_Chars:=" " ;-- 4 spaces (Default)
  469. l_AllSpaces:=True
  470. }
  471. else
  472. {
  473. l_AllSpaces:=True
  474. Loop Parse,p_Chars
  475. {
  476. if (A_LoopField<>A_Space)
  477. {
  478. l_AllSpaces:=False
  479. Break
  480. }
  481. }
  482. }
  483.  
  484. ;---------
  485. ;-- p_Cmd
  486. ;---------
  487. if p_Cmd not in Add,Insert,Remove,Delete
  488. p_Cmd=Insert
  489.  
  490. ;[===========]
  491. ;[ Process ]
  492. ;[===========]
  493. ;-- Get select positions
  494. HE_GetSel(hEdit,l_StartSelPos,l_EndSelPos)
  495.  
  496. ;-- Get selected text
  497. l_SelectedText:=HE_GetSelText(hEdit)
  498.  
  499. ;[==============]
  500. ;[ Shift line ]
  501. ;[==============]
  502. if p_Cmd in Insert,Add
  503. {
  504. ;----------------------------
  505. ;-- Insert/Add (Shift right)
  506. ;----------------------------
  507. if StrLen(l_SelectedText)=0
  508. {
  509. l_NewText:=p_Chars
  510.  
  511. ;-- If necessary, trim to account for column spacing
  512. if l_AllSpaces
  513. StringTrimRight
  514. ,l_NewText
  515. ,l_NewText
  516. ,% Mod(l_StartSelPos-HE_LineIndex(hEdit,-1),StrLen(l_NewText))
  517.  
  518. ;-- Programming note: This small adjustment (only performed if
  519. ; p_Chars contains only space characters) helps to insure that
  520. ; text is shifted to columns that are equal to a factor of the
  521. ; length of p_Chars.
  522. }
  523. else
  524. {
  525. ;-- Is last character a NL?
  526. l_LastSelChar=
  527. if SubStr(l_SelectedText,0)="`n"
  528. {
  529. l_LastSelChar:="`n"
  530. StringTrimRight l_SelectedText,l_SelectedText,1
  531. }
  532.  
  533. ;-- Single line?
  534. if InStr(l_SelectedText . l_LastSelChar,"`n")=0
  535. and HE_GetLine(hEdit)<>l_SelectedText
  536. {
  537. l_NewText :=p_Chars
  538. l_Reselect:=False
  539. }
  540. else
  541. ;- Shift it
  542. {
  543. Loop Parse,l_SelectedText,`n
  544. {
  545. if StrLen(l_NewText)=0
  546. l_NewText:=p_Chars . A_LoopField
  547. else
  548. l_NewText.="`n" . p_Chars . A_LoopField
  549. }
  550. }
  551.  
  552. ;-- Append last char (if needed)
  553. l_NewText.=l_LastSelChar
  554. }
  555. }
  556. else
  557. {
  558. ;-----------------------
  559. ;-- Remove (Shift left)
  560. ;-----------------------
  561. if StrLen(l_SelectedText)=0
  562. {
  563. ;-- Check to see if the preceding chars are equal to p_Chars
  564. l_StartLinePos:=HE_LineIndex(hEdit,-1)
  565. if (l_StartSelPos>l_StartLinePos)
  566. {
  567. ;-- Get the line in question
  568. l_CurrentLine:=HE_GetLine(hEdit,-1)
  569.  
  570. ;-- Init l_NewStartSelPos
  571. l_NewStartSelPos:=l_StartSelPos
  572.  
  573. ;-- Enough characters to match p_Chars?
  574. if (l_StartSelPos-l_StartLinePos)>=StrLen(p_Chars)
  575. {
  576. if SubStr(l_CurrentLine,(l_StartSelPos-l_StartLinePos+1)-StrLen(p_Chars),StrLen(p_Chars))=p_Chars
  577. l_NewStartSelPos:=l_StartSelPos-StrLen(p_Chars)
  578. }
  579.  
  580. ;-- One more chance. If p_Chars are "all spaces", look for any
  581. ; trailing spaces.
  582. if l_AllSpaces and (l_NewStartSelPos=l_StartSelPos)
  583. {
  584. Loop % StrLen(p_Chars)
  585. {
  586. if SubStr(l_CurrentLine,(l_StartSelPos-l_StartLinePos+1)-A_Index,1)=A_Space
  587. l_NewStartSelPos--
  588. else
  589. Break
  590. }
  591. }
  592.  
  593. ;-- Reselect if necessary
  594. if (l_NewStartSelPos<>l_StartSelPos)
  595. {
  596. l_StartSelPos:=l_NewStartSelPos
  597. HE_SetSel(hEdit,l_StartSelPos,l_EndSelPos)
  598.  
  599. ;-- Get selected text
  600. l_SelectedText:=HE_GetSelText(hEdit)
  601. }
  602. }
  603. }
  604.  
  605. if StrLen(l_SelectedText)
  606. {
  607. ;-- Remove p_Chars from the beginning of each line
  608. if StrLen(l_SelectedText)
  609. {
  610. Loop Parse,l_SelectedText,`n
  611. {
  612. ;-- Assign to l_LoopField
  613. l_LoopField:=A_LoopField
  614.  
  615. ;-- All spaces?
  616. if l_AllSpaces
  617. {
  618. ;-- Remove full or partial space indention
  619. Loop % StrLen(p_Chars)
  620. {
  621. ;-- Not a space?
  622. if SubStr(l_LoopField,1,1)<>A_Space
  623. Break
  624.  
  625. ;-- Trim it
  626. StringTrimLeft l_LoopField,l_LoopField,1
  627. }
  628. }
  629. else
  630. {
  631. ;-- Remove p_Chars if leading characters and exact
  632. if SubStr(l_LoopField,1,StrLen(p_Chars))=p_Chars
  633. StringTrimLeft
  634. ,l_LoopField
  635. ,l_LoopField
  636. ,% StrLen(p_Chars)
  637. }
  638.  
  639. ;-- Append to l_NewText
  640. if StrLen(l_NewText)=0
  641. l_NewText:=l_LoopField
  642. else
  643. l_NewText.="`n" . l_LoopField
  644. }
  645. }
  646. }
  647. }
  648.  
  649. ;-- Replace selected text with l_NewText
  650. HE_ReplaceSel(hEdit,l_NewText)
  651.  
  652. ;-- Reselect text
  653. if l_Reselect and StrLen(l_SelectedText)
  654. HE_SetSel(hEdit,l_StartSelPos,l_StartSelPos+StrLen(l_NewText))
  655.  
  656. return
  657. }
  658.  
  659.  
  660. ;******************
  661. ;* *
  662. ;* HE_Print *
  663. ;* *
  664. ;******************
  665. ;
  666. ;
  667. ; Description
  668. ; ===========
  669. ; Simple WYSIWYG print function for the HiEdit control.
  670. ;
  671. ;
  672. ;
  673. ; Parameters
  674. ; ==========
  675. ;
  676. ; Name Description
  677. ; ---- -----------
  678. ; hEdit Handle to the HiEdit control.
  679. ;
  680. ; p_Owner Handle to the owner window. [Optional]
  681. ;
  682. ;
  683. ; p_MarginLeft Page margins based upon the locale system of
  684. ; p_MarginTop measurement -- English or Metric. [Optional] If
  685. ; p_MarginRight English, the margin is measured in thousandths of
  686. ; p_MarginBottom inches. If metric, the margin is measured in hundredths
  687. ; of millimeters.
  688. ;
  689. ; English example: To get a 0.5 inch margin (12.7 mm), set
  690. ; the margin to 500.
  691. ;
  692. ; Metric example: To get a 25.40 mm margin (1 inch English
  693. ; equivalent), set the margin to 2540.
  694. ;
  695. ;
  696. ; Credit
  697. ; ======
  698. ; Some of the ideas/code for this function was extracted from the source code
  699. ; for the HiEditor demo program ("Print" procedure) and from the Notepad2
  700. ; source code ("Print.cpp").
  701. ;
  702. ;-------------------------------------------------------------------------------
  703. HE_Print(hEdit
  704. ,p_Owner=""
  705. ,p_MarginLeft=""
  706. ,p_MarginTop=""
  707. ,p_MarginRight=""
  708. ,p_MarginBottom="")
  709. {
  710. ;[====================]
  711. ;[ Global variables ]
  712. ;[====================]
  713. Global $LineNumbersBar
  714. ;-- Set this global variable to TRUE if the line numbers bar
  715. ; is showing, otherwise set it to FALSE
  716. ,hDevMode
  717. ,hDevNames
  718.  
  719. ;[====================]
  720. ;[ Static variables ]
  721. ;[====================]
  722. Static PD_ALLPAGES :=0x0
  723. ,PD_SELECTION :=0x1
  724. ,PD_PAGENUMS :=0x2
  725. ,PD_NOSELECTION :=0x4
  726. ,PD_NOPAGENUMS :=0x8
  727. ,PD_RETURNDC :=0x100
  728. ,PD_RETURNDEFAULT :=0x400
  729. ,PD_ENABLEPRINTHOOK :=0x1000 ;-- Not used (for now)
  730. ,PD_USEDEVMODECOPIES :=0x40000 ;-- Same as PD_USEDEVMODECOPIESANDCOLLATE
  731. ,PD_DISABLEPRINTTOFILE:=0x80000
  732. ,PD_HIDEPRINTTOFILE :=0x100000
  733.  
  734. ,LOCALE_USER_DEFAULT :=0x400
  735. ,LOCALE_IMEASURE :=0xD
  736. ,LOCALE_RETURN_NUMBER :=0x20000000
  737.  
  738. ,MM_TEXT :=0x1
  739. ,HORZRES :=0x8
  740. ,VERTRES :=0xA
  741. ,LOGPIXELSX :=0x58
  742. ,LOGPIXELSY :=0x5A
  743. ,PHYSICALWIDTH :=0x6E
  744. ,PHYSICALHEIGHT :=0x6F
  745. ,PHYSICALOFFSETX :=0x70
  746. ,PHYSICALOFFSETY :=0x71
  747.  
  748. ,WM_USER :=0x400 ;-- 1024
  749.  
  750. ,EM_EXGETSEL :=1076 ;-- WM_USER+52
  751. ,EM_FORMATRANGE :=1081 ;-- WM_uSER+57
  752. ,EM_SETTARGETDEVICE :=1096 ;-- WM_USER+72
  753. ,WM_GETTEXTLENGTH :=0xE
  754.  
  755. ;[==============]
  756. ;[ Initialize ]
  757. ;[==============]
  758. SplitPath A_ScriptName,,,,l_ScriptName
  759.  
  760. ;-- Get locale system of measurement (0=Metric, 1=English)
  761. VarSetCapacity(lpLCData,4,0)
  762. DllCall("GetLocaleInfo"
  763. ,"UInt",LOCALE_USER_DEFAULT
  764. ,"UInt",LOCALE_IMEASURE|LOCALE_RETURN_NUMBER
  765. ,"UInt",&lpLCData
  766. ,"UInt",4)
  767.  
  768. l_LOCALE_IMEASURE:=NumGet(lpLCData,0,"Unit")
  769. if l_LOCALE_IMEASURE=0 ;-- 0=HiMetric (hundredths of millimeters)
  770. l_LocaleUnits:=2540
  771. else ;-- 1=HiEnglish (thousandths of inches)
  772. l_LocaleUnits:=1000
  773.  
  774. ;[==============]
  775. ;[ Parameters ]
  776. ;[==============]
  777. if p_MarginLeft is not Integer
  778. p_MarginLeft:=l_LocaleUnits/2 ;-- (0.5 inch or 12.7 mm)
  779.  
  780. if p_MarginTop is not Integer
  781. p_MarginTop:=l_LocaleUnits/2
  782.  
  783. if p_MarginRight is not Integer
  784. p_MarginRight:=l_LocaleUnits/2
  785.  
  786. if p_MarginBottom is not Integer
  787. p_MarginBottom:=l_LocaleUnits/2
  788.  
  789. ;[================]
  790. ;[ Prep to call ]
  791. ;[ PrintDlg ]
  792. ;[================]
  793. ;-- Define/Populate the PRINTDLG structure
  794. VarSetCapacity(PRINTDLG_Structure,66,0)
  795. NumPut(66,PRINTDLG_Structure,0,"UInt") ;-- lStructSize
  796.  
  797. if p_Owner is Integer
  798. Numput(p_Owner,PRINTDLG_Structure,4,"UInt") ;-- hwndOwner
  799.  
  800. if hDevMode is Integer
  801. NumPut(hDevMode,PRINTDLG_Structure,8,"UInt") ;-- hDevMode
  802.  
  803. if hDevNames is Integer
  804. NumPut(hDevNames,PRINTDLG_Structure,12,"UInt") ;-- hDevMode
  805.  
  806. ;-- Collect start/End select positions
  807. VarSetCapacity(CHARRANGE_Structure,8,0)
  808. SendMessage EM_EXGETSEL,0,&CHARRANGE_Structure,,ahk_id %hEdit%
  809. l_StartSelPos:=NumGet(CHARRANGE_Structure,0,"Int") ;-- cpMin
  810. l_EndSelPos :=NumGet(CHARRANGE_Structure,4,"Int") ;-- cpMax
  811. ;-- Programming note: The HE_GetSel function is not used here so that
  812. ; this function can be used independent of the HiEdit library. This
  813. ; will probably be changed in the future.
  814.  
  815. ;-- Determine/Set Flags
  816. l_Flags:=PD_ALLPAGES|PD_RETURNDC|PD_USEDEVMODECOPIES
  817. if (l_StartSelPos=l_EndSelPos)
  818. l_Flags |= PD_NOSELECTION
  819. else
  820. l_Flags |= PD_SELECTION
  821.  
  822. NumPut(l_Flags,PRINTDLG_Structure,20,"UInt") ;-- Flags
  823.  
  824. ;-- Page and copies
  825. NumPut(1 ,PRINTDLG_Structure,24,"UShort") ;-- nFromPage
  826. NumPut(1 ,PRINTDLG_Structure,26,"UShort") ;-- nToPage
  827. NumPut(1 ,PRINTDLG_Structure,28,"UShort") ;-- nMinPage
  828. NumPut(-1,PRINTDLG_Structure,30,"UShort") ;-- nMaxPage
  829. NumPut(1 ,PRINTDLG_Structure,32,"UShort") ;-- nCopies
  830. ;-- Note: Use -1 to specify the maximum page number (65535).
  831. ;
  832. ; Programming note: The values that are loaded to these fields are
  833. ; critical. The Print dialog will not display (returns an error) if
  834. ; unexpected values are loaded to one or more of these fields.
  835.  
  836. ;[================]
  837. ;[ Print dialog ]
  838. ;[================]
  839. ;-- Open the Print dialog. Bounce if the user cancels.
  840. if not DllCall("comdlg32\PrintDlgA","UInt",&PRINTDLG_Structure)
  841. return
  842.  
  843. hDevMode:=NumGet(PRINTDLG_Structure,8,"UInt")
  844. ;-- Handle to a global memory object that contains a DEVMODE structure
  845.  
  846. hDevNames:=NumGet(PRINTDLG_Structure,12,"UInt")
  847. ;-- Handle to a movable global memory object that contains a DEVNAMES
  848. ; structure.
  849.  
  850. ;-- Free global structures created by PrintDlg
  851. ;
  852. ; Programming note: This function assumes that the user-selected printer
  853. ; settings will be retained in-between print requests. If this behaviour
  854. ; is not desired, the global memory objects created by the PrintDlg
  855. ; function can be released immediately by uncommenting the following code.
  856. ; However, if this behavior is desired, the global memory objects should
  857. ; be released before the script is terminated. Copy the following code
  858. ; (uncommented of course) to the appropriate "Exit" routine in your
  859. ; script.
  860. ;
  861. ;;;;; if hDevMode
  862. ;;;;; {
  863. ;;;;; DllCall("GlobalFree","UInt",hDevMode)
  864. ;;;;; hDevMode:=0
  865. ;;;;; }
  866. ;;;;;
  867. ;;;;; if hDevNames
  868. ;;;;; {
  869. ;;;;; DllCall("GlobalFree","UInt",hDevNames)
  870. ;;;;; hDevNames:=0
  871. ;;;;; }
  872.  
  873. ;-- Get the printer device context. Bounce if not defined.
  874. l_hDC:=NumGet(PRINTDLG_Structure,16,"UInt") ;-- hDC
  875. if not l_hDC
  876. {
  877. outputdebug,
  878. (ltrim join`s
  879. Function: %A_ThisFunc% - Printer device context (hDC) not defined.
  880. )
  881.  
  882. return
  883. }
  884.  
  885. ;[====================]
  886. ;[ Prepare to print ]
  887. ;[====================]
  888. ;-- Collect Flags
  889. l_Flags:=NumGet(PRINTDLG_Structure,20,"UInt") ;-- Flags
  890.  
  891. ;-- Determine From/To Page
  892. if l_Flags & PD_PAGENUMS
  893. {
  894. l_FromPage:=NumGet(PRINTDLG_Structure,24,"UShort") ;-- nFromPage
  895. l_ToPage :=NumGet(PRINTDLG_Structure,26,"UShort") ;-- nToPage
  896. }
  897. else
  898. {
  899. l_FromPage:=1
  900. l_ToPage :=65535
  901. }
  902.  
  903. ;-- Collect printer statistics
  904. l_HORZRES:=DllCall("GetDeviceCaps","UInt",l_hDC,"UInt",HORZRES)
  905. l_VERTRES:=DllCall("GetDeviceCaps","UInt",l_hDC,"UInt",VERTRES)
  906. ;-- Width and height, in pixels, of the printable area of the page
  907.  
  908. l_LOGPIXELSX:=DllCall("GetDeviceCaps","UInt",l_hDC,"UInt",LOGPIXELSX)
  909. l_LOGPIXELSY:=DllCall("GetDeviceCaps","UInt",l_hDC,"UInt",LOGPIXELSY)
  910. ;-- Number of pixels per logical inch along the page width and height
  911.  
  912. l_PHYSICALWIDTH :=DllCall("GetDeviceCaps","UInt",l_hDC,"UInt",PHYSICALWIDTH)
  913. l_PHYSICALHEIGHT:=DllCall("GetDeviceCaps","UInt",l_hDC,"UInt",PHYSICALHEIGHT)
  914. ;-- The width and height of the physical page, in device units. For
  915. ; example, a printer set to print at 600 dpi on 8.5" x 11" paper
  916. ; has a physical width value of 5100 device units. Note that the
  917. ; physical page is almost always greater than the printable area of
  918. ; the page, and never smaller.
  919.  
  920. l_PHYSICALOFFSETX:=DllCall("GetDeviceCaps","UInt",l_hDC,"UInt",PHYSICALOFFSETX)
  921. l_PHYSICALOFFSETY:=DllCall("GetDeviceCaps","UInt",l_hDC,"UInt",PHYSICALOFFSETY)
  922. ;-- The distance from the left/right edge (PHYSICALOFFSETX) and the
  923. ; top/bottom edge (PHYSICALOFFSETY) of the physical page to the edge
  924. ; of the printable area, in device units. For example, a printer set
  925. ; to print at 600 dpi on 8.5-by-11-inch paper, that cannot print on
  926. ; the leftmost 0.25-inch of paper, has a horizontal physical offset of
  927. ; 150 device units.
  928.  
  929. ;-- Define/Populate the FORMATRANGE structure
  930. VarSetCapacity(FORMATRANGE_Structure,48,0)
  931. NumPut(l_hDC,FORMATRANGE_Structure,0,"UInt") ;-- hdc
  932. NumPut(l_hDC,FORMATRANGE_Structure,4,"UInt") ;-- hdcTarget
  933.  
  934. ;-- Define FORMATRANGE.rcPage
  935. ;
  936. ; rcPage is the entire area of a page on the rendering device, measured in
  937. ; twips (1/20 point or 1/1440 of an inch)
  938. ;
  939. ; Note: rc defines the maximum printable area which does not include the
  940. ; printer's margins (the unprintable areas at the edges of the page). The
  941. ; unprintable areas are represented by PHYSICALOFFSETX and
  942. ; PHYSICALOFFSETY.
  943. ;
  944. NumPut(0,FORMATRANGE_Structure,24,"UInt") ;-- rcPage.Left
  945. NumPut(0,FORMATRANGE_Structure,28,"UInt") ;-- rcPage.Top
  946.  
  947. l_rcPage_Right:=Round((l_HORZRES/l_LOGPIXELSX)*1440)
  948. NumPut(l_rcPage_Right,FORMATRANGE_Structure,32,"UInt") ;-- rcPage.Right
  949.  
  950. l_rcPage_Bottom:=Round((l_VERTRES/l_LOGPIXELSY)*1440)
  951. NumPut(l_rcPage_Bottom,FORMATRANGE_Structure,36,"UInt") ;-- rcPage.Bottom
  952.  
  953. ;-- Define FORMATRANGE.rc
  954. ;
  955. ; rc is the area to render to (rcPage - margins), measured in twips (1/20
  956. ; point or 1/1440 of an inch).
  957. ;
  958. ; If the user-defined margins are smaller than the printer's margins (the
  959. ; unprintable areas at the edges of each page), the user margins are set
  960. ; to the printer's margins.
  961. ;
  962. ; In addition, the user-defined margins must be adjusted to account for
  963. ; the printer's margins. For example: If the user requests a 3/4 inch
  964. ; (19.05 mm) left margin but the printer's left margin is 1/4 inch
  965. ; (6.35 mm), rc.Left is set to 720 twips (0.5 inch or 12.7 mm).
  966. ;
  967. ;-- Left
  968. if (l_PHYSICALOFFSETX/l_LOGPIXELSX>p_MarginLeft/l_LocaleUnits)
  969. p_MarginLeft:=Round((l_PHYSICALOFFSETX/l_LOGPIXELSX)*l_LocaleUnits)
  970.  
  971. l_rc_Left:=Round(((p_MarginLeft/l_LocaleUnits)*1440)-((l_PHYSICALOFFSETX/l_LOGPIXELSX)*1440))
  972. NumPut(l_rc_Left,FORMATRANGE_Structure,8,"UInt") ;-- rc.Left
  973.  
  974. ;-- Top
  975. if (l_PHYSICALOFFSETY/l_LOGPIXELSY>p_MarginTop/l_LocaleUnits)
  976. p_MarginTop:=Round((l_PHYSICALOFFSETY/l_LOGPIXELSY)*l_LocaleUnits)
  977.  
  978. l_rc_Top:=Round(((p_MarginTop/l_LocaleUnits)*1440)-((l_PHYSICALOFFSETY/l_LOGPIXELSY)*1440))
  979. NumPut(l_rc_Top,FORMATRANGE_Structure,12,"UInt") ;-- rc.Top
  980.  
  981. ;-- Right
  982. if (l_PHYSICALOFFSETX/l_LOGPIXELSX>p_MarginRight/l_LocaleUnits)
  983. p_MarginRight:=Round((l_PHYSICALOFFSETX/l_LOGPIXELSX)*l_LocaleUnits)
  984.  
  985. l_rc_Right:=l_rcPage_Right-Round(((p_MarginRight/l_LocaleUnits)*1440)-((l_PHYSICALOFFSETX/l_LOGPIXELSX)*1440))
  986. NumPut(l_rc_Right,FORMATRANGE_Structure,16,"UInt") ;-- rc.Right
  987.  
  988. ;-- Bottom
  989. if (l_PHYSICALOFFSETY/l_LOGPIXELSY>p_MarginBottom/l_LocaleUnits)
  990. p_MarginBottom:=Round((l_PHYSICALOFFSETY/l_LOGPIXELSY)*l_LocaleUnits)
  991.  
  992. l_rc_Bottom:=l_rcPage_Bottom-Round(((p_MarginBottom/l_LocaleUnits)*1440)-((l_PHYSICALOFFSETY/l_LOGPIXELSY)*1440))
  993. NumPut(l_rc_Bottom,FORMATRANGE_Structure,20,"UInt") ;-- rc.Bottom
  994.  
  995. ;-- Determine print range.
  996. ;
  997. ; If "Selection" option is chosen, use selected text, otherwise use the
  998. ; entire document.
  999. ;
  1000. if l_Flags & PD_SELECTION
  1001. {
  1002. l_StartPrintPos:=l_StartSelPos
  1003. l_EndPrintPos :=l_EndSelPos
  1004. }
  1005. else
  1006. {
  1007. l_StartPrintPos:=0
  1008. l_EndPrintPos :=-1 ;-- (-1=Select All)
  1009. }
  1010.  
  1011. Numput(l_StartPrintPos,FORMATRANGE_Structure,40) ;-- cr.cpMin
  1012. NumPut(l_EndPrintPos ,FORMATRANGE_Structure,44) ;-- cr.cpMax
  1013.  
  1014. ;-- Define/Populate the DOCINFO structure
  1015. VarSetCapacity(DOCINFO_Structure,20,0)
  1016. NumPut(20 ,DOCINFO_Structure,0) ;-- cbSize
  1017. NumPut(&l_ScriptName,DOCINFO_Structure,4) ;-- lpszDocName
  1018. NumPut(0 ,DOCINFO_Structure,8) ;-- lpszOutput
  1019. ;-- Programming note: All other DOCINFO_Structure fields intentionally
  1020. ; left as null.
  1021.  
  1022. ;-- Determine l_MaxPrintIndex
  1023. if l_Flags & PD_SELECTION
  1024. l_MaxPrintIndex:=l_EndSelPos
  1025. else
  1026. {
  1027. SendMessage WM_GETTEXTLENGTH,0,0,,ahk_id %hEdit%
  1028. l_MaxPrintIndex:=ErrorLevel
  1029. ;-- Programming note: HE_GetTextLength is not used here so that this
  1030. ; function can be used independent of the HiEdit library. This
  1031. ; will probably be changed in the future.
  1032. }
  1033.  
  1034. ;-- Set LineNumbersBar to max size
  1035. ;
  1036. ; Programming note: This step is necessary because the LineNumbersBar
  1037. ; does not render correctly past the first couple of pages if the
  1038. ; "autosize" option is used. A bug perhaps, but this workaround is
  1039. ; acceptable and the fixed size may even be desirable.
  1040. ;
  1041. ; If you don't use the line numbers bar or you don't want to make any
  1042. ; changes to the line numbers bar, you can comment out this code.
  1043. ;
  1044. if $LineNumbersBar
  1045. HE_LineNumbersBar(hEdit,"automaxsize")
  1046.  
  1047. ;-- Be sure that the printer device context is in text mode
  1048. DllCall("SetMapMode","UInt",l_hDC,"UInt",MM_TEXT)
  1049.  
  1050. ;[=============]
  1051. ;[ Print it! ]
  1052. ;[=============]
  1053. ;-- Start a print job. Bounce if there is a problem.
  1054. l_PrintJob:=DllCall("StartDoc","UInt",l_hDC,"UInt",&DOCINFO_Structure,"Int")
  1055. if l_PrintJob<=0
  1056. {
  1057. outputdebug Function: %A_ThisFunc% - DLLCall of "StartDoc" failed.
  1058. return
  1059. }
  1060.  
  1061. ;-- Print page loop
  1062. l_Page:=0
  1063. l_PrintIndex:=0
  1064. While (l_PrintIndex<l_MaxPrintIndex)
  1065. {
  1066. l_Page++
  1067.  
  1068. ;-- Are we done yet?
  1069. if (l_Page>l_ToPage)
  1070. Break
  1071.  
  1072. ;-- If printing this page, do a StartPage
  1073. l_Render:=False
  1074. if l_Page between %l_FromPage% and %l_ToPage%
  1075. {
  1076. l_Render:=True
  1077.  
  1078. ;-- StartPage function. Break if there is a problem.
  1079. if DllCall("StartPage","UInt",l_hDC,"Int")<=0
  1080. {
  1081. outputdebug,
  1082. (ltrim join`s
  1083. Function: %A_ThisFunc% - DLLCall of "StartPage" failed.
  1084. )
  1085.  
  1086. Break
  1087. }
  1088. }
  1089.  
  1090. ;-- Format or measure page
  1091. SendMessage EM_FORMATRANGE,l_Render,&FORMATRANGE_Structure,,ahk_id %hEdit%
  1092. l_PrintIndex:=ErrorLevel
  1093.  
  1094. ;-- If a page was printed, do an EndPage
  1095. if l_Page between %l_FromPage% and %l_ToPage%
  1096. {
  1097. ;-- EndPage function. Break if there is a problem.
  1098. if DllCall("EndPage","UInt",l_hDC,"Int")<=0
  1099. {
  1100. outputdebug,
  1101. (ltrim join`s
  1102. Function: %A_ThisFunc% - DLLCall of "EndPage" failed.
  1103. )
  1104.  
  1105. Break
  1106. }
  1107. }
  1108.  
  1109. ;-- Update FORMATRANGE_Structure for the next page
  1110. Numput(l_PrintIndex ,FORMATRANGE_Structure,40) ;-- cr.cpMin
  1111. NumPut(l_EndPrintPos,FORMATRANGE_Structure,44) ;-- cr.cpMax
  1112. }
  1113.  
  1114. ;-- End the print job
  1115. DllCall("EndDoc","UInt",l_hDC)
  1116.  
  1117. ;-- Delete the printer device context
  1118. DllCall("DeleteDC","UInt",l_hDC)
  1119.  
  1120. ;-- Reset control (free cached information)
  1121. SendMessage EM_FORMATRANGE,0,0,,ahk_id %hEdit%
  1122.  
  1123. ;-- Reset the LineNumbersBar
  1124. ;
  1125. ; Programming note: If you don't use the line numbers bar or you don't
  1126. ; want to make any changes to the line numbers bar, you can comment out
  1127. ; this code.
  1128. ;
  1129. if $LineNumbersBar
  1130. HE_LineNumbersBar(hEdit,"autosize")
  1131.  
  1132. return
  1133. }
  1134.  
  1135.  
  1136. ;*******************************
  1137. ;* *
  1138. ;* RPBuildTable *
  1139. ;* (Build Restore table) *
  1140. ;* *
  1141. ;*******************************
  1142. RPBuildTable()
  1143. {
  1144. ;-- Global variables
  1145. Global $RPDir
  1146.  
  1147. ;-- Build it
  1148. Loop %$RPDir%\*.ahk
  1149. {
  1150. ;-- Derive restore time stamp
  1151. StringTrimRight l_RestoreTimeStamp,A_LoopFileName,4
  1152.  
  1153. ;-- Add to the restore table
  1154. if StrLen(l_RestoreTable)=0
  1155. l_RestoreTable:=l_RestoreTimeStamp
  1156. else
  1157. l_RestoreTable.="|" . l_RestoreTimeStamp
  1158. }
  1159.  
  1160. ;-- Sort it (descending order)
  1161. Sort l_RestoreTable,RD|
  1162.  
  1163. ;-- Return to sender
  1164. Return l_RestoreTable
  1165. }
  1166.  
  1167.  
  1168.  
  1169. ;********************************
  1170. ;* *
  1171. ;* RPCreate *
  1172. ;* (Create restore point) *
  1173. ;* *
  1174. ;********************************
  1175. RPCreate(p_CheckForDup=True)
  1176. {
  1177. ;[====================]
  1178. ;[ Global variables ]
  1179. ;[====================]
  1180. Global $QAHKGUI
  1181. ,$QAHKGUI_hEdit
  1182. ,$MaxRestorePoints
  1183. ,$RPDir
  1184. ,$RPViewerGUI
  1185. ,$RPViewerGUI_hWnd
  1186.  
  1187. ;[=======================]
  1188. ;[ Bounce if workspace ]
  1189. ;[ is empty ]
  1190. ;[=======================]
  1191. if HE_GetTextLength($QAHKGUI_hEdit)=0
  1192. return
  1193.  
  1194. ;[===========================]
  1195. ;[ Create "Restore" folder ]
  1196. ;[ (If it doesn't exist) ]
  1197. ;[===========================]
  1198. IfNotExist %$RPDir%\.
  1199. {
  1200. ;-- Create folder
  1201. FileCreateDir %$RPDir%
  1202. if ErrorLevel
  1203. {
  1204. gui +OwnDialogs
  1205. MsgBox
  1206. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  1207. ,Create Restore Point Error,
  1208. (ltrim join`s
  1209. Unable to create the "Restore" folder. Restore point not
  1210. created. %A_Space%
  1211. )
  1212.  
  1213. return
  1214. }
  1215. }
  1216.  
  1217. ;[========================]
  1218. ;[ Create restore point ]
  1219. ;[========================]
  1220. l_RPFile:=$RPDir . "\" . A_Now . ".ahk"
  1221.  
  1222. ;-- Bounce if restore point file already exists
  1223. IfExist %l_RPFile%
  1224. return
  1225. ;-- Note: A restore point file may already exist if the user submits
  1226. ; multiple requests within a second
  1227.  
  1228. ;-- Save current workspace to restore point file
  1229. ErrorLevel:=HE_SaveFile($QAHKGUI_hEdit,l_RPFile)
  1230. ;;;;; if ErrorLevel
  1231. ;;;;; {
  1232. ;;;;; outputdebug ErrorLevel after HE_SaveFile=%ErrorLevel%
  1233. ;;;;; gui +OwnDialogs
  1234. ;;;;; MsgBox
  1235. ;;;;; ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  1236. ;;;;; ,Create Restore Point Error,
  1237. ;;;;; (ltrim
  1238. ;;;;; Unable to create the restore point file: %A_Space%
  1239. ;;;;; %l_RPFile% %A_Space%
  1240. ;;;;; )
  1241. ;;;;;
  1242. ;;;;; return
  1243. ;;;;; }
  1244.  
  1245. ;-- Programming note: The value returned from HE_SaveFile is meaningless.
  1246. ; The function usually returns 0 regardless of whether the file was
  1247. ; successfully saved or not. On rare occasion, the function returns 1.
  1248. ; This value is also meaningless if the return value 0 does not provide
  1249. ; guidance.
  1250.  
  1251.  
  1252. ;-- Restore file created?
  1253. IfNotExist %l_RPFile%
  1254. {
  1255. gui +OwnDialogs
  1256. MsgBox
  1257. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  1258. ,Create Restore Point Error,
  1259. (ltrim
  1260. Unable to create the restore point file: %A_Space%
  1261. %l_RPFile% %A_Space%
  1262. )
  1263.  
  1264. return
  1265. }
  1266.  
  1267. ;[=======================]
  1268. ;[ Check for duplicate ]
  1269. ;[=======================]
  1270. if p_CheckForDup
  1271. RPDeleteDup()
  1272.  
  1273. ;[======================]
  1274. ;[ Update RPViewerGUI ]
  1275. ;[======================]
  1276. ;-- New restore point file retained?
  1277. IfExist %l_RPFile%
  1278. {
  1279. ;-- RPViewerGUI window open?
  1280. IfWinExist ahk_id %$RPViewerGUI_hWnd%
  1281. {
  1282. ;-- Change GUI default
  1283. gui %$RPViewerGUI%:Default
  1284.  
  1285. ;-- Extract restore time stamp
  1286. SplitPath l_RPFile,l_RPFileName
  1287. StringTrimRight $RPTimeStamp,l_RPFileName,4
  1288.  
  1289. ;-- Convert timestamp into readable date/time format
  1290. FormatTime
  1291. ,$RPDisplayField
  1292. ,%$RPTimeStamp%
  1293. ,yyyy-MM-dd HH:mm:ss
  1294.  
  1295. ;-- Get file size
  1296. FileGetSize l_FileSize,%l_RPFile%
  1297.  
  1298. ;-- Format size display
  1299. if l_FileSize<1024
  1300. $FileSize:=AddCommas(l_FileSize) . " bytes"
  1301. else
  1302. if l_FileSize<1048576
  1303. $FileSize:=AddCommas(Round(l_FileSize/1024,2)) . " KB"
  1304. else
  1305. $FileSize:=AddCommas(Round(l_FileSize/1048576,2)) . " MB"
  1306.  
  1307. $RPDisplayField:=$RPDisplayField . " " . $FileSize
  1308.  
  1309. ;-- Create new row at the top
  1310. LV_Insert(1,"",$RPDisplayField,l_RPFile)
  1311.  
  1312. ;-- Size/Sort column
  1313. LV_ModifyCol(1,"Auto SortDesc")
  1314. ;-- Programming note: This is necessary because the ListView
  1315. ; may have been empty and all columns sized to a minimum width
  1316.  
  1317. ;-- Anything selected?
  1318. if LV_GetCount("Selected")
  1319. LV_Modify(LV_GetNext(0),"+Vis") ;-- Make selected line visible
  1320.  
  1321. ;-- Reset GUI default
  1322. gui %$QAHKGUI%:Default
  1323. }
  1324. }
  1325.  
  1326. ;[================]
  1327. ;[ Housekeeping ]
  1328. ;[================]
  1329. RPTrim($MaxRestorePoints)
  1330. }
  1331.  
  1332.  
  1333. ;*********************
  1334. ;* *
  1335. ;* RPDeleteDup *
  1336. ;* *
  1337. ;*********************
  1338. RPDeleteDup()
  1339. {
  1340. ;[====================]
  1341. ;[ Global variables ]
  1342. ;[====================]
  1343. Global $RPDir
  1344.  
  1345. ;[==============]
  1346. ;[ Initialize ]
  1347. ;[==============]
  1348. l_RPTable:=RPBuildTable()
  1349.  
  1350. ;-- Bounce if there aren't at least 2 entries in the table
  1351. if l_RPTable not contains |
  1352. return
  1353.  
  1354. ;[======================]
  1355. ;[ Delete most recent ]
  1356. ;[ RP if duplicate ]
  1357. ;[======================]
  1358.  
  1359. ;-- Collect information on the first two table entries
  1360. Loop Parse,l_RPTable,|
  1361. {
  1362. ;-- First (most recent) RP file?
  1363. if A_Index=1
  1364. {
  1365. l_RPFile1:=$RPDir . "\" . A_LoopField . ".ahk"
  1366. FileGetSize l_RPFileSize1,%l_RPFile1%
  1367. Continue ;-- Go on to the next
  1368. }
  1369.  
  1370. ;-- Collect name and size of 2nd most recent RP file
  1371. l_RPFile2:=$RPDir . "\" . A_LoopField . ".ahk"
  1372. FileGetSize l_RPFileSize2,%l_RPFile2%
  1373. Break ;-- We're done with this loop
  1374. }
  1375.  
  1376. ;-- Duplicate?
  1377. ;
  1378. ; Programming note: Because of AutoHotkey's optimization techniques, the
  1379. ; FileMD5 functions are only called if the file sizes are equal.
  1380. ;
  1381. if (l_RPFileSize1=l_RPFileSize2)
  1382. and FileMD5(l_RPFile1,2)=FileMD5(l_RPFile2,2)
  1383. {
  1384. ;-- Delete most recent RP file
  1385. FileDelete %l_RPFile1%
  1386. if ErrorLevel
  1387. outputdebug,
  1388. (ltrim join`s
  1389. Function: %A_ThisLabel% -
  1390. Unable to delete "%l_RPFile1%"
  1391. )
  1392. ;-- Note: A delete failure is effectively ignored here
  1393. }
  1394.  
  1395. return
  1396. }
  1397.  
  1398.  
  1399. ;***************************************
  1400. ;* *
  1401. ;* RPTrim *
  1402. ;* (Delete superfluous RP files) *
  1403. ;* *
  1404. ;***************************************
  1405. RPTrim(p_MaxRestorePoints)
  1406. {
  1407. ;[====================]
  1408. ;[ Global variables ]
  1409. ;[====================]
  1410. Global $QAHKGUI
  1411. ,$RPDir
  1412. ,$RPViewerGUI
  1413. ,$RPViewerGUI_hEdit
  1414. ,$RPViewerGUI_hWnd
  1415.  
  1416. ;-- Initialize
  1417. l_DeleteCount:=0
  1418.  
  1419. ;[=====================]
  1420. ;[ Delete beyond-max ]
  1421. ;[ RP files ]
  1422. ;[=====================]
  1423. l_RPTable:=RPBuildTable()
  1424. Loop Parse,l_RPTable,|
  1425. {
  1426. ;-- More than max?
  1427. if (A_Index>p_MaxRestorePoints)
  1428. {
  1429. ;-- Count it
  1430. l_DeleteCount++
  1431.  
  1432. ;-- Delete restore point file
  1433. FileDelete %$RPDir%\%A_LoopField%.ahk
  1434. if ErrorLevel
  1435. outputdebug,
  1436. (ltrim join`s
  1437. Function: %A_ThisFunc% -
  1438. Unable to delete "%$RPDir%\%A_LoopField%.ahk"
  1439. )
  1440. ;-- Note: A delete failure is temporarily ignored. If
  1441. ; possible, the delinquent file is deleted the next
  1442. ; time this routine is called.
  1443. }
  1444. }
  1445.  
  1446. ;-- Anything deleted?
  1447. if l_DeleteCount
  1448. {
  1449. ;-- RPViewerGUI window open?
  1450. IfWinExist ahk_id %$RPViewerGUI_hWnd%
  1451. {
  1452. ;-- Change default GUI
  1453. gui %$RPViewerGUI%:Default
  1454.  
  1455. ;-- Redraw off
  1456. GUIControl -Redraw,$RPViewerGUI_RPList
  1457.  
  1458. ;-- Remove no-longer-valid entries from ListView
  1459. l_Row:=1
  1460. Loop % LV_GetCount()
  1461. {
  1462. LV_GetText(l_RPFIle,l_Row,2)
  1463. IfNotExist %l_RPFIle%
  1464. {
  1465. LV_Delete(l_Row)
  1466. Continue ;-- Keep the same row number
  1467. }
  1468.  
  1469. l_Row++
  1470. }
  1471.  
  1472. ;-- Redraw on
  1473. GUIControl +Redraw,$RPViewerGUI_RPList
  1474.  
  1475. ;-- Nothing selected?
  1476. if LV_GetCount("Selected")=0
  1477. {
  1478. ;-- Disable the Restore button
  1479. GUIControl Disable,$RPViewerGUI_RestoreButton
  1480.  
  1481. ;-- Close the last opened file (if any)
  1482. HE_CloseFile($RPViewerGUI_hEdit)
  1483. }
  1484.  
  1485. ;-- Reset default GUI
  1486. gui %$QAHKGUI%:Default
  1487. }
  1488. }
  1489.  
  1490. Return l_DeleteCount
  1491. }
  1492.  
  1493.  
  1494. ;********************************
  1495. ;* *
  1496. ;* RPClean *
  1497. ;* (Clean Restore folder) *
  1498. ;* *
  1499. ;********************************
  1500. ;-- This functions deletes RP files that were created before A_Now minus
  1501. ; p_NbrOfDays.
  1502. ;
  1503. RPClean(p_NbrOfDays)
  1504. {
  1505. ;[====================]
  1506. ;[ Global variables ]
  1507. ;[====================]
  1508. Global $RPDir
  1509.  
  1510. ;[==============]
  1511. ;[ Initialize ]
  1512. ;[==============]
  1513. l_DeleteCount=0
  1514.  
  1515. ;-- Identify threshold
  1516. l_ThresholdTimeStamp:=A_Now
  1517. EnvAdd l_ThresholdTimeStamp,-%p_NbrOfDays%,Days
  1518.  
  1519. ;[=========]
  1520. ;[ Clean ]
  1521. ;[=========]
  1522. Loop %$RPDir%\*.ahk
  1523. {
  1524. ;-- Derive restore time stamp
  1525. StringTrimRight l_RestoreTimeStamp,A_LoopFileName,4
  1526.  
  1527. ;-- Older than threshhold?
  1528. if (l_RestoreTimeStamp<l_ThresholdTimeStamp)
  1529. {
  1530. ;-- Delete it
  1531. FileDelete %A_LoopFileFullPath%
  1532. if ErrorLevel
  1533. outputdebug,
  1534. (ltrim join`s
  1535. Function: %A_ThisFunc% -
  1536. Unable to delete "%A_LoopFileLongPath%"
  1537. )
  1538. ;-- Note: A delete failure is temporarily ignored. If
  1539. ; possible, the delinquent file will be deleted the
  1540. ; next time this routine is called.
  1541. }
  1542.  
  1543. ;-- Count it
  1544. l_DeleteCount++
  1545. }
  1546.  
  1547. ;-- Return to sender
  1548. Return l_DeleteCount
  1549. }
  1550.  
  1551.  
  1552. ;**************************************************
  1553. ;* *
  1554. ;* Rebuild RunPIDList *
  1555. ;* (Remove processes that have been closed) *
  1556. ;* *
  1557. ;**************************************************
  1558. RebuildRunPIDList(p_RunPIDList)
  1559. {
  1560. l_RunPIDList:="" ;-- Redundant but included for clarity
  1561. Loop Parse,p_RunPIDList,`,
  1562. {
  1563. Process Exist,%A_LoopField%
  1564. if ErrorLevel
  1565. if StrLen(l_RunPIDList)=0
  1566. l_RunPIDList:=A_LoopField
  1567. else
  1568. l_RunPIDList.="," . A_LoopField
  1569. }
  1570.  
  1571. Return l_RunPIDList
  1572. }
  1573.  
  1574.  
  1575.  
  1576. ;*********************************************
  1577. ;* *
  1578. ;* *
  1579. ;* *
  1580. ;* *
  1581. ;* Subroutines *
  1582. ;* *
  1583. ;* *
  1584. ;* *
  1585. ;* *
  1586. ;*********************************************
  1587. ;****************************
  1588. ;* *
  1589. ;* Read configuration *
  1590. ;* *
  1591. ;****************************
  1592. ReadConfiguration:
  1593.  
  1594. ;[====================]
  1595. ;[ Section: General ]
  1596. ;[====================]
  1597. iniRead
  1598. ,$AlwaysOnTop
  1599. ,%$ConfigFile%
  1600. ,General
  1601. ,AlwaysOnTop
  1602. ,%False%
  1603.  
  1604. iniRead
  1605. ,$ShowMenubar
  1606. ,%$ConfigFile%
  1607. ,General
  1608. ,ShowMenubar
  1609. ,%True%
  1610.  
  1611. iniRead
  1612. ,$ShowStatusbar
  1613. ,%$ConfigFile%
  1614. ,General
  1615. ,ShowStatusbar
  1616. ,%True%
  1617.  
  1618. iniRead
  1619. ,$EscapeToExit
  1620. ,%$ConfigFile%
  1621. ,General
  1622. ,EscapeToExit
  1623. ,%True%
  1624.  
  1625. iniRead
  1626. ,$CopyFromPath
  1627. ,%$ConfigFile%
  1628. ,General
  1629. ,CopyFromPath
  1630. ,%A_Space%
  1631.  
  1632. iniRead
  1633. ,$SaveToPath
  1634. ,%$ConfigFile%
  1635. ,General
  1636. ,SaveToPath
  1637. ,%A_Space%
  1638.  
  1639. iniRead
  1640. ,$RecentFiles
  1641. ,%$ConfigFile%
  1642. ,General
  1643. ,RecentFiles
  1644. ,%A_Space%
  1645.  
  1646. ;[===================]
  1647. ;[ Section: Window ]
  1648. ;[===================]
  1649. iniRead
  1650. ,$WindowX
  1651. ,%$ConfigFile%
  1652. ,Window
  1653. ,X
  1654. ,%A_Space%
  1655.  
  1656. iniRead
  1657. ,$WindowY
  1658. ,%$ConfigFile%
  1659. ,Window
  1660. ,Y
  1661. ,%A_Space%
  1662.  
  1663. iniRead
  1664. ,$WindowW
  1665. ,%$ConfigFile%
  1666. ,Window
  1667. ,W
  1668. ,%A_Space%
  1669.  
  1670. iniRead
  1671. ,$WindowH
  1672. ,%$ConfigFile%
  1673. ,Window
  1674. ,H
  1675. ,%A_Space%
  1676.  
  1677. iniRead
  1678. ,$WindowMaximized
  1679. ,%$ConfigFile%
  1680. ,Window
  1681. ,Maximized
  1682. ,%A_Space%
  1683.  
  1684. ;-- Save original $WindowMaximized value
  1685. $Saved_WindowMaximized:=$WindowMaximized
  1686.  
  1687. ;[==================]
  1688. ;[ Section: Print ]
  1689. ;[==================]
  1690. iniRead
  1691. ,$PrintMarginLeft
  1692. ,%$ConfigFile%
  1693. ,Print
  1694. ,MarginLeft
  1695. ,%$MarginDefault%
  1696.  
  1697. iniRead
  1698. ,$PrintMarginTop
  1699. ,%$ConfigFile%
  1700. ,Print
  1701. ,MarginTop
  1702. ,%$MarginDefault%
  1703.  
  1704. iniRead
  1705. ,$PrintMarginRight
  1706. ,%$ConfigFile%
  1707. ,Print
  1708. ,MarginRight
  1709. ,%$MarginDefault%
  1710.  
  1711. iniRead
  1712. ,$PrintMarginBottom
  1713. ,%$ConfigFile%
  1714. ,Print
  1715. ,MarginBottom
  1716. ,%$MarginDefault%
  1717.  
  1718. iniRead
  1719. ,$PrintOrientation
  1720. ,%$ConfigFile%
  1721. ,Print
  1722. ,Orientation
  1723. ,%A_Space%
  1724.  
  1725. ;[===================]
  1726. ;[ Section: Editor ]
  1727. ;[===================]
  1728. ;-- Font
  1729. iniRead
  1730. ,$Font
  1731. ,%$ConfigFile%
  1732. ,Editor
  1733. ,Font
  1734. ,%$DefaultFont%
  1735.  
  1736. iniRead
  1737. ,$FontSize
  1738. ,%$ConfigFile%
  1739. ,Editor
  1740. ,FontSize
  1741. ,%$DefaultFontSize%
  1742.  
  1743. iniRead
  1744. ,$FontStyle
  1745. ,%$ConfigFile%
  1746. ,Editor
  1747. ,FontStyle
  1748. ,%A_Space%
  1749.  
  1750. iniRead
  1751. ,$AutoIndent
  1752. ,%$ConfigFile%
  1753. ,Editor
  1754. ,AutoIndent
  1755. ,%False%
  1756.  
  1757. iniRead
  1758. ,$TabWidth
  1759. ,%$ConfigFile%
  1760. ,Editor
  1761. ,TabWidth
  1762. ,4
  1763.  
  1764. iniRead
  1765. ,$RealTabs
  1766. ,%$ConfigFile%
  1767. ,Editor
  1768. ,RealTabs
  1769. ,%False%
  1770.  
  1771. iniRead
  1772. ,$LineNumbersBar
  1773. ,%$ConfigFile%
  1774. ,Editor
  1775. ,LineNumbersBar
  1776. ,%True%
  1777.  
  1778. iniRead
  1779. ,$AllowUndoAfterSave
  1780. ,%$ConfigFile%
  1781. ,Editor
  1782. ,AllowUndoAfterSave
  1783. ,%True%
  1784.  
  1785. iniRead
  1786. ,$BlockComment
  1787. ,%$ConfigFile%
  1788. ,Editor
  1789. ,BlockComment
  1790. ,%A_Space%
  1791.  
  1792. if StrLen($BlockComment)=0
  1793. $BlockComment:=";;;;;"
  1794. else
  1795. ;-- Remove borders
  1796. $BlockComment:=SubStr($BlockComment,2,-1)
  1797.  
  1798. ;[======================]
  1799. ;[ Section: ExtEditor ]
  1800. ;[======================]
  1801. iniRead
  1802. ,$ExtEditorName
  1803. ,%$ConfigFile%
  1804. ,ExtEditor
  1805. ,Name
  1806. ,%A_Space%
  1807.  
  1808. iniRead
  1809. ,$ExtEditorPath
  1810. ,%$ConfigFile%
  1811. ,ExtEditor
  1812. ,Path
  1813. ,%A_Space%
  1814.  
  1815. ;[====================]
  1816. ;[ Section: Toolbar ]
  1817. ;[====================]
  1818. iniRead
  1819. ,$ShowToolbar
  1820. ,%$ConfigFile%
  1821. ,Toolbar
  1822. ,ShowToolbar
  1823. ,%True%
  1824.  
  1825. iniRead
  1826. ,$ToolbarIconSize
  1827. ,%$ConfigFile%
  1828. ,Toolbar
  1829. ,IconSize
  1830. ,Large
  1831.  
  1832. if $ToolbarIconSize not in Large,Small
  1833. $ToolbarIconSize=Large
  1834.  
  1835. iniRead
  1836. ,$ToolbarButtons
  1837. ,%$ConfigFile%
  1838. ,Toolbar
  1839. ,Buttons
  1840. ,%A_Space%
  1841.  
  1842. if $ToolbarButtons is not Space
  1843. {
  1844. ;-- Remove borders
  1845. $ToolbarButtons:=SubStr($ToolbarButtons,2,-1)
  1846.  
  1847. ;-- Restore line feeds
  1848. StringReplace
  1849. ,$ToolbarButtons
  1850. ,$ToolbarButtons
  1851. ,%$RecordDelimiter%
  1852. ,`n
  1853. ,All
  1854. }
  1855.  
  1856. ;[================]
  1857. ;[ Section: Run ]
  1858. ;[================]
  1859. iniRead
  1860. ,$AutoHotkeyPath
  1861. ,%$ConfigFile%
  1862. ,Run
  1863. ,AutoHotkeyPath
  1864. ,%A_Space%
  1865.  
  1866. iniRead
  1867. ,$RunPrompt
  1868. ,%$ConfigFile%
  1869. ,Run
  1870. ,RunPrompt
  1871. ,%False%
  1872.  
  1873. iniRead
  1874. ,$RunDebug
  1875. ,%$ConfigFile%
  1876. ,Run
  1877. ,RunDebug
  1878. ,%False%
  1879.  
  1880. iniRead
  1881. ,$RunWait
  1882. ,%$ConfigFile%
  1883. ,Run
  1884. ,RunWait
  1885. ,%True%
  1886.  
  1887. iniRead
  1888. ,$ConfirmExitIfRunning
  1889. ,%$ConfigFile%
  1890. ,Run
  1891. ,ConfirmExitIfRunning
  1892. ,%True%
  1893.  
  1894. iniRead
  1895. ,$ClearRunWorkspaceOnRun
  1896. ,%$ConfigFile%
  1897. ,Run
  1898. ,ClearRunWorkspaceOnRun
  1899. ,%False%
  1900.  
  1901. iniRead
  1902. ,$ClearRunWorkspaceOnExit
  1903. ,%$ConfigFile%
  1904. ,Run
  1905. ,ClearRunWorkspaceOnExit
  1906. ,%False%
  1907.  
  1908. ;-- $RunParms
  1909. iniRead
  1910. ,$RunParms
  1911. ,%$ConfigFile%
  1912. ,Run
  1913. ,RunParms
  1914. ,%A_Space%
  1915.  
  1916. if StrLen($RunParms)=0
  1917. $RunParms=
  1918. (ltrim
  1919. All parameters on "one line"
  1920. Parameters
  1921. on
  1922. "separate lines"
  1923. )
  1924. else
  1925. {
  1926. ;-- Remove borders
  1927. $RunParms:=SubStr($RunParms,2,-1)
  1928.  
  1929. ;-- Restore line feeds
  1930. StringReplace
  1931. ,$RunParms
  1932. ,$RunParms
  1933. ,%$RecordDelimiter%
  1934. ,`n
  1935. ,All
  1936. }
  1937.  
  1938. ;-- $RunParmsDDL
  1939. iniRead
  1940. ,$RunParmsDDL
  1941. ,%$ConfigFile%
  1942. ,Run
  1943. ,RunParmsDDL
  1944. ,%A_Space%
  1945.  
  1946. if StrLen($RunParmsDDL)
  1947. {
  1948. ;-- Remove borders
  1949. $RunParmsDDL:=SubStr($RunParmsDDL,2,-1)
  1950.  
  1951. ;-- Restore line feeds
  1952. StringReplace
  1953. ,$RunParmsDDL
  1954. ,$RunParmsDDL
  1955. ,%$RecordDelimiter%
  1956. ,`n
  1957. ,All
  1958. }
  1959.  
  1960. ;[====================]
  1961. ;[ Section: Restore ]
  1962. ;[====================]
  1963. iniRead
  1964. ,$MaxRestorePoints
  1965. ,%$ConfigFile%
  1966. ,Restore
  1967. ,MaxRestorePoints
  1968. ,20
  1969.  
  1970. iniRead
  1971. ,$CreateRPOnCopyfromDrop
  1972. ,%$ConfigFile%
  1973. ,Restore
  1974. ,CreateRPOnCopyfromDrop
  1975. ,%False%
  1976.  
  1977. iniRead
  1978. ,$CreateRPOnRun
  1979. ,%$ConfigFile%
  1980. ,Restore
  1981. ,CreateRPOnRun
  1982. ,%False%
  1983.  
  1984. iniRead
  1985. ,$CreateRPOnSave
  1986. ,%$ConfigFile%
  1987. ,Restore
  1988. ,CreateRPOnSave
  1989. ,%False%
  1990.  
  1991. iniRead
  1992. ,$CreateRPOnExit
  1993. ,%$ConfigFile%
  1994. ,Restore
  1995. ,CreateRPOnExit
  1996. ,%True%
  1997.  
  1998. ;[=====================]
  1999. ;[ Section: RPViewer ]
  2000. ;[=====================]
  2001. iniRead
  2002. ,$RPViewerX
  2003. ,%$ConfigFile%
  2004. ,RPViewer
  2005. ,X
  2006. ,%A_Space%
  2007.  
  2008. iniRead
  2009. ,$RPViewerY
  2010. ,%$ConfigFile%
  2011. ,RPViewer
  2012. ,Y
  2013. ,%A_Space%
  2014.  
  2015. iniRead
  2016. ,$RPViewerW
  2017. ,%$ConfigFile%
  2018. ,RPViewer
  2019. ,W
  2020. ,%A_Space%
  2021.  
  2022. iniRead
  2023. ,$RPViewerH
  2024. ,%$ConfigFile%
  2025. ,RPViewer
  2026. ,H
  2027. ,%A_Space%
  2028.  
  2029. iniRead
  2030. ,$RPViewerFont
  2031. ,%$ConfigFile%
  2032. ,RPViewer
  2033. ,Font
  2034. ,%$DefaultFont%
  2035.  
  2036. iniRead
  2037. ,$RPViewerFontSize
  2038. ,%$ConfigFile%
  2039. ,RPViewer
  2040. ,FontSize
  2041. ,%$RPViewerDefaultFontSize%
  2042.  
  2043. iniRead
  2044. ,$RPViewerFontStyle
  2045. ,%$ConfigFile%
  2046. ,RPViewer
  2047. ,FontStyle
  2048. ,%A_Space%
  2049.  
  2050. iniRead
  2051. ,$RPViewerLineNumbersBar
  2052. ,%$ConfigFile%
  2053. ,RPViewer
  2054. ,LineNumbersBar
  2055. ,%False%
  2056.  
  2057. iniRead
  2058. ,$RPViewerSaveWindowPos
  2059. ,%$ConfigFile%
  2060. ,RPViewer
  2061. ,SaveWindowPos
  2062. ,%False%
  2063.  
  2064. iniRead
  2065. ,$RPViewerCloseOnRestore
  2066. ,%$ConfigFile%
  2067. ,RPViewer
  2068. ,CloseOnRestore
  2069. ,%True%
  2070.  
  2071. iniRead
  2072. ,$RPViewerEscapeToClose
  2073. ,%$ConfigFile%
  2074. ,RPViewer
  2075. ,EscapeToClose
  2076. ,%True%
  2077.  
  2078. ;[================]
  2079. ;[ Section: New ]
  2080. ;[================]
  2081. iniRead
  2082. ,$NewScriptSystemDefault
  2083. ,%$ConfigFile%
  2084. ,New
  2085. ,SystemDefault
  2086. ,%True%
  2087.  
  2088. iniRead
  2089. ,$NewScript
  2090. ,%$ConfigFile%
  2091. ,New
  2092. ,Script
  2093. ,%A_Space%
  2094.  
  2095. if StrLen($NewScript)=0
  2096. $NewScript:="; Put code for new script here"
  2097. else
  2098. {
  2099. ;-- Remove borders
  2100. $NewScript:=SubStr($NewScript,2,-1)
  2101.  
  2102. ;-- Restore line feeds
  2103. StringReplace
  2104. ,$NewScript
  2105. ,$NewScript
  2106. ,%$RecordDelimiter%
  2107. ,`n
  2108. ,All
  2109. }
  2110.  
  2111. ;[==================]
  2112. ;[ Section: Debug ]
  2113. ;[==================]
  2114. iniRead
  2115. ,$DebugScript
  2116. ,%$ConfigFile%
  2117. ,Debug
  2118. ,Script
  2119. ,%A_Space%
  2120.  
  2121. if StrLen($DebugScript)=0
  2122. $DebugScript=
  2123. (ltrim
  2124. ;-- Begin debug script ---
  2125. ExitApp ;-- Useful for "Run Selected" command
  2126.  
  2127. ;-- A few example hotkeys. Change to fit your needs
  2128. #!h::ListHotkeys
  2129. #!k::KeyHistory
  2130. #!l::ListLines
  2131. #!p::Pause ;-- Toggle
  2132. #!q::ExitApp
  2133. #!s::Suspend ;-- Toggle
  2134. #!v::ListVars
  2135. )
  2136. else
  2137. {
  2138. ;-- Remove borders
  2139. $DebugScript:=SubStr($DebugScript,2,-1)
  2140.  
  2141. ;-- Restore line feeds
  2142. StringReplace
  2143. ,$DebugScript
  2144. ,$DebugScript
  2145. ,%$RecordDelimiter%
  2146. ,`n
  2147. ,All
  2148. }
  2149.  
  2150. ;[=======================]
  2151. ;[ Section: OptionsGUI ]
  2152. ;[=======================]
  2153. iniRead
  2154. ,$OptionsGUI_Tab
  2155. ,%$ConfigFile%
  2156. ,OptionsGUI
  2157. ,Tab
  2158. ,%A_Space%
  2159.  
  2160. return
  2161.  
  2162.  
  2163. ;****************************
  2164. ;* *
  2165. ;* Save configuration *
  2166. ;* *
  2167. ;****************************
  2168. SaveConfiguration:
  2169. SetTimer %A_ThisLabel%,Off
  2170.  
  2171. ;[====================]
  2172. ;[ Section: General ]
  2173. ;[====================]
  2174. iniWrite
  2175. ,%$AlwaysOnTop%
  2176. ,%$ConfigFile%
  2177. ,General
  2178. ,AlwaysOnTop
  2179.  
  2180. iniWrite
  2181. ,%$ShowMenubar%
  2182. ,%$ConfigFile%
  2183. ,General
  2184. ,ShowMenubar
  2185.  
  2186. iniWrite
  2187. ,%$ShowStatusbar%
  2188. ,%$ConfigFile%
  2189. ,General
  2190. ,ShowStatusbar
  2191.  
  2192. iniWrite
  2193. ,%$EscapeToExit%
  2194. ,%$ConfigFile%
  2195. ,General
  2196. ,EscapeToExit
  2197.  
  2198. iniWrite
  2199. ,%$CopyFromPath%
  2200. ,%$ConfigFile%
  2201. ,General
  2202. ,CopyFromPath
  2203.  
  2204. iniWrite
  2205. ,%$SaveToPath%
  2206. ,%$ConfigFile%
  2207. ,General
  2208. ,SaveToPath
  2209.  
  2210. iniWrite
  2211. ,%$RecentFiles%
  2212. ,%$ConfigFile%
  2213. ,General
  2214. ,RecentFiles
  2215.  
  2216. ;[===================]
  2217. ;[ Section: Window ]
  2218. ;[===================]
  2219. WinGetPos
  2220. ,$WindowX
  2221. ,$WindowY
  2222. ,$WindowW
  2223. ,$WindowH
  2224. ,ahk_id %$QAHKGUI_hWnd%
  2225.  
  2226. iniWrite
  2227. ,%$WindowX%
  2228. ,%$ConfigFile%
  2229. ,Window
  2230. ,X
  2231.  
  2232. iniWrite
  2233. ,%$WindowY%
  2234. ,%$ConfigFile%
  2235. ,Window
  2236. ,Y
  2237.  
  2238. iniWrite
  2239. ,%$WindowW%
  2240. ,%$ConfigFile%
  2241. ,Window
  2242. ,W
  2243.  
  2244. iniWrite
  2245. ,%$WindowH%
  2246. ,%$ConfigFile%
  2247. ,Window
  2248. ,H
  2249.  
  2250. iniWrite
  2251. ,%$WindowMaximized%
  2252. ,%$ConfigFile%
  2253. ,Window
  2254. ,Maximized
  2255.  
  2256. ;[==================]
  2257. ;[ Section: Print ]
  2258. ;[==================]
  2259. iniWrite
  2260. ,%$PrintMarginLeft%
  2261. ,%$ConfigFile%
  2262. ,Print
  2263. ,MarginLeft
  2264.  
  2265. iniWrite
  2266. ,%$PrintMarginTop%
  2267. ,%$ConfigFile%
  2268. ,Print
  2269. ,MarginTop
  2270.  
  2271. iniWrite
  2272. ,%$PrintMarginRight%
  2273. ,%$ConfigFile%
  2274. ,Print
  2275. ,MarginRight
  2276.  
  2277. iniWrite
  2278. ,%$PrintMarginBottom%
  2279. ,%$ConfigFile%
  2280. ,Print
  2281. ,MarginBottom
  2282.  
  2283. iniWrite
  2284. ,%$PrintOrientation%
  2285. ,%$ConfigFile%
  2286. ,Print
  2287. ,Orientation
  2288.  
  2289. ;[===================]
  2290. ;[ Section: Editor ]
  2291. ;[===================]
  2292. ;-- Font
  2293. iniWrite
  2294. ,%$Font%
  2295. ,%$ConfigFile%
  2296. ,Editor
  2297. ,Font
  2298.  
  2299. iniWrite
  2300. ,%$FontSize%
  2301. ,%$ConfigFile%
  2302. ,Editor
  2303. ,FontSize
  2304.  
  2305. iniWrite
  2306. ,%$FontStyle%
  2307. ,%$ConfigFile%
  2308. ,Editor
  2309. ,FontStyle
  2310.  
  2311. iniWrite
  2312. ,%$AutoIndent%
  2313. ,%$ConfigFile%
  2314. ,Editor
  2315. ,AutoIndent
  2316.  
  2317. iniWrite
  2318. ,%$TabWidth%
  2319. ,%$ConfigFile%
  2320. ,Editor
  2321. ,TabWidth
  2322.  
  2323. iniWrite
  2324. ,%$RealTabs%
  2325. ,%$ConfigFile%
  2326. ,Editor
  2327. ,RealTabs
  2328.  
  2329. iniWrite
  2330. ,%$LineNumbersBar%
  2331. ,%$ConfigFile%
  2332. ,Editor
  2333. ,LineNumbersBar
  2334.  
  2335. iniWrite
  2336. ,%$AllowUndoAfterSave%
  2337. ,%$ConfigFile%
  2338. ,Editor
  2339. ,AllowUndoAfterSave
  2340.  
  2341. iniWrite
  2342. ,% $iniBorder . $BlockComment . $iniBorder
  2343. ,%$ConfigFile%
  2344. ,Editor
  2345. ,BlockComment
  2346. ;-- Note: Borders added to preserve leading/trailing whitespace
  2347.  
  2348. ;[======================]
  2349. ;[ Section: ExtEditor ]
  2350. ;[======================]
  2351. iniWrite
  2352. ,%$ExtEditorName%
  2353. ,%$ConfigFile%
  2354. ,ExtEditor
  2355. ,Name
  2356.  
  2357. iniWrite
  2358. ,%$ExtEditorPath%
  2359. ,%$ConfigFile%
  2360. ,ExtEditor
  2361. ,Path
  2362.  
  2363. ;[====================]
  2364. ;[ Section: Toolbar ]
  2365. ;[====================]
  2366. iniWrite
  2367. ,%$ShowToolbar%
  2368. ,%$ConfigFile%
  2369. ,Toolbar
  2370. ,ShowToolbar
  2371.  
  2372. iniWrite
  2373. ,%$ToolbarIconSize%
  2374. ,%$ConfigFile%
  2375. ,Toolbar
  2376. ,IconSize
  2377.  
  2378. ;------------------------------
  2379. ;-- Clean up $ToolbarButtons
  2380. ;-- {ToolBar_Define adds junk}
  2381. ;------------------------------
  2382. ;-- Convert all CRLF to LFs
  2383. StringReplace
  2384. ,$ToolbarButtons
  2385. ,$ToolbarButtons
  2386. ,`r`n
  2387. ,`n
  2388. ,All
  2389.  
  2390. ;-----------
  2391. ;-- Buttons
  2392. ;-----------
  2393. ;-- Assign to output variable
  2394. $ini_ToolbarButtons:=$ToolbarButtons
  2395.  
  2396. ;-- Convert LFs to record delimiters
  2397. StringReplace
  2398. ,$ini_ToolbarButtons
  2399. ,$ini_ToolbarButtons
  2400. ,`n
  2401. ,%$RecordDelimiter%
  2402. ,All
  2403.  
  2404. ;-- Add borders to preserve leading/trailing whitespace
  2405. $ini_ToolbarButtons:=$iniBorder . $ini_ToolbarButtons . $iniBorder
  2406.  
  2407. ;-- Save it
  2408. iniWrite
  2409. ,%$ini_ToolbarButtons%
  2410. ,%$ConfigFile%
  2411. ,Toolbar
  2412. ,Buttons
  2413.  
  2414. ;[================]
  2415. ;[ Section: Run ]
  2416. ;[================]
  2417. iniWrite
  2418. ,%$AutoHotkeyPath%
  2419. ,%$ConfigFile%
  2420. ,Run
  2421. ,AutoHotkeyPath
  2422.  
  2423. iniWrite
  2424. ,%$RunPrompt%
  2425. ,%$ConfigFile%
  2426. ,Run
  2427. ,RunPrompt
  2428.  
  2429. iniWrite
  2430. ,%$RunDebug%
  2431. ,%$ConfigFile%
  2432. ,Run
  2433. ,RunDebug
  2434.  
  2435. iniWrite
  2436. ,%$RunWait%
  2437. ,%$ConfigFile%
  2438. ,Run
  2439. ,RunWait
  2440.  
  2441. iniWrite
  2442. ,%$ConfirmExitIfRunning%
  2443. ,%$ConfigFile%
  2444. ,Run
  2445. ,ConfirmExitIfRunning
  2446.  
  2447. iniWrite
  2448. ,%$ClearRunWorkspaceOnRun%
  2449. ,%$ConfigFile%
  2450. ,Run
  2451. ,ClearRunWorkspaceOnRun
  2452.  
  2453. iniWrite
  2454. ,%$ClearRunWorkspaceOnExit%
  2455. ,%$ConfigFile%
  2456. ,Run
  2457. ,ClearRunWorkspaceOnExit
  2458.  
  2459. ;-------------
  2460. ;-- $RunParms
  2461. ;-------------
  2462. ;-- Assign to output variable
  2463. $ini_RunParms:=$RunParms
  2464.  
  2465. ;-- Convert newline to record delimiters
  2466. StringReplace
  2467. ,$ini_RunParms
  2468. ,$ini_RunParms
  2469. ,`n
  2470. ,%$RecordDelimiter%
  2471. ,All
  2472.  
  2473. ;-- Add borders to preserve leading/trailing whitespace
  2474. $ini_RunParms:=$iniBorder . $ini_RunParms . $iniBorder
  2475.  
  2476. ;-- Save it
  2477. iniWrite
  2478. ,%$ini_RunParms%
  2479. ,%$ConfigFile%
  2480. ,Run
  2481. ,RunParms
  2482.  
  2483. ;----------------
  2484. ;-- $RunParmsDDL
  2485. ;----------------
  2486. ;-- Assign to output variable
  2487. $ini_RunParmsDDL:=$RunParmsDDL
  2488.  
  2489. ;-- Convert newline to record delimiters
  2490. StringReplace
  2491. ,$ini_RunParmsDDL
  2492. ,$ini_RunParmsDDL
  2493. ,`n
  2494. ,%$RecordDelimiter%
  2495. ,All
  2496.  
  2497. ;-- Add borders to preserve leading/trailing whitespace
  2498. $ini_RunParmsDDL:=$iniBorder . $ini_RunParmsDDL . $iniBorder
  2499.  
  2500. ;-- Save it
  2501. iniWrite
  2502. ,%$ini_RunParmsDDL%
  2503. ,%$ConfigFile%
  2504. ,Run
  2505. ,RunParmsDDL
  2506.  
  2507. ;[====================]
  2508. ;[ Section: Restore ]
  2509. ;[====================]
  2510. iniWrite
  2511. ,%$MaxRestorePoints%
  2512. ,%$ConfigFile%
  2513. ,Restore
  2514. ,MaxRestorePoints
  2515.  
  2516. iniWrite
  2517. ,%$CreateRPOnCopyfromDrop%
  2518. ,%$ConfigFile%
  2519. ,Restore
  2520. ,CreateRPOnCopyfromDrop
  2521.  
  2522. iniWrite
  2523. ,%$CreateRPOnRun%
  2524. ,%$ConfigFile%
  2525. ,Restore
  2526. ,CreateRPOnRun
  2527.  
  2528. iniWrite
  2529. ,%$CreateRPOnSave%
  2530. ,%$ConfigFile%
  2531. ,Restore
  2532. ,CreateRPOnSave
  2533.  
  2534. iniWrite
  2535. ,%$CreateRPOnExit%
  2536. ,%$ConfigFile%
  2537. ,Restore
  2538. ,CreateRPOnExit
  2539.  
  2540. ;[=====================]
  2541. ;[ Section: RPViewer ]
  2542. ;[=====================]
  2543. iniWrite
  2544. ,%$RPViewerFont%
  2545. ,%$ConfigFile%
  2546. ,RPViewer
  2547. ,Font
  2548.  
  2549. iniWrite
  2550. ,%$RPViewerFontSize%
  2551. ,%$ConfigFile%
  2552. ,RPViewer
  2553. ,FontSize
  2554.  
  2555. iniWrite
  2556. ,%$RPViewerFontStyle%
  2557. ,%$ConfigFile%
  2558. ,RPViewer
  2559. ,FontStyle
  2560.  
  2561. iniWrite
  2562. ,%$RPViewerLineNumbersBar%
  2563. ,%$ConfigFile%
  2564. ,RPViewer
  2565. ,LineNumbersBar
  2566.  
  2567. iniWrite
  2568. ,%$RPViewerSaveWindowPos%
  2569. ,%$ConfigFile%
  2570. ,RPViewer
  2571. ,SaveWindowPos
  2572.  
  2573. iniWrite
  2574. ,%$RPViewerCloseOnRestore%
  2575. ,%$ConfigFile%
  2576. ,RPViewer
  2577. ,CloseOnRestore
  2578.  
  2579. iniWrite
  2580. ,%$RPViewerEscapeToClose%
  2581. ,%$ConfigFile%
  2582. ,RPViewer
  2583. ,EscapeToClose
  2584.  
  2585. ;[================]
  2586. ;[ Section: New ]
  2587. ;[================]
  2588. iniWrite
  2589. ,%$NewScriptSystemDefault%
  2590. ,%$ConfigFile%
  2591. ,New
  2592. ,SystemDefault
  2593.  
  2594. ;----------
  2595. ;-- Script
  2596. ;----------
  2597. ;-- Assign to output variable
  2598. $ini_NewScript:=$NewScript
  2599.  
  2600. ;-- Convert newline to record delimiters
  2601. StringReplace
  2602. ,$ini_NewScript
  2603. ,$ini_NewScript
  2604. ,`n
  2605. ,%$RecordDelimiter%
  2606. ,All
  2607.  
  2608. ;-- Add borders to preserve leading/trailing whitespace
  2609. $ini_NewScript:=$iniBorder . $ini_NewScript . $iniBorder
  2610.  
  2611. ;-- Save it
  2612. iniWrite
  2613. ,%$ini_NewScript%
  2614. ,%$ConfigFile%
  2615. ,New
  2616. ,Script
  2617.  
  2618. ;[==================]
  2619. ;[ Section: Debug ]
  2620. ;[==================]
  2621. ;-- Assign to output variable
  2622. $ini_DebugScript:=$DebugScript
  2623.  
  2624. ;-- Convert newline to record delimiters
  2625. StringReplace
  2626. ,$ini_DebugScript
  2627. ,$ini_DebugScript
  2628. ,`n
  2629. ,%$RecordDelimiter%
  2630. ,All
  2631.  
  2632. ;-- Add borders to preserve leading/trailing whitespace
  2633. $ini_DebugScript:=$iniBorder . $ini_DebugScript . $iniBorder
  2634.  
  2635. ;-- Save it
  2636. iniWrite
  2637. ,%$ini_DebugScript%
  2638. ,%$ConfigFile%
  2639. ,Debug
  2640. ,Script
  2641.  
  2642. ;[=======================]
  2643. ;[ Section: OptionsGUI ]
  2644. ;[=======================]
  2645. iniWrite
  2646. ,%$OptionsGUI_Tab%
  2647. ,%$ConfigFile%
  2648. ,OptionsGUI
  2649. ,Tab
  2650.  
  2651. return
  2652.  
  2653.  
  2654. ;***********************
  2655. ;* *
  2656. ;* Save RPViewer *
  2657. ;* configuration *
  2658. ;* *
  2659. ;***********************
  2660. SaveRPViewerConfiguration:
  2661. SetTimer %A_ThisLabel%,Off
  2662.  
  2663. ;-- Bounce if window is not open
  2664. IfWinNotExist ahk_id %$RPViewerGUI_hWnd%
  2665. return
  2666. ;-- Programming note: This test s/b redundant but remains as a fail-safe
  2667.  
  2668. WinGetPos
  2669. ,$RPViewerX
  2670. ,$RPViewerY
  2671. ,$RPViewerW
  2672. ,$RPViewerH
  2673. ,ahk_id %$RPViewerGUI_hWnd%
  2674.  
  2675. iniWrite
  2676. ,%$RPViewerX%
  2677. ,%$ConfigFile%
  2678. ,RPViewer
  2679. ,X
  2680.  
  2681. iniWrite
  2682. ,%$RPViewerY%
  2683. ,%$ConfigFile%
  2684. ,RPViewer
  2685. ,Y
  2686.  
  2687. iniWrite
  2688. ,%$RPViewerW%
  2689. ,%$ConfigFile%
  2690. ,RPViewer
  2691. ,W
  2692.  
  2693. iniWrite
  2694. ,%$RPViewerH%
  2695. ,%$ConfigFile%
  2696. ,RPViewer
  2697. ,H
  2698.  
  2699. return
  2700.  
  2701.  
  2702. ;****************************
  2703. ;* *
  2704. ;* Process parameters *
  2705. ;* *
  2706. ;****************************
  2707. ProcessParameters:
  2708.  
  2709. ;-- Bounce if no parameters
  2710. if not %0%
  2711. return
  2712.  
  2713. ;[======================]
  2714. ;[ Process parameters ]
  2715. ;[======================]
  2716. ;-- 1st parameter only (for now)
  2717. $CLParameter=%1%
  2718.  
  2719. ;-- Remove last character if a double-quote
  2720. if SubStr($CLParameter,0)=""""
  2721. StringTrimRight $CLParameter,$CLParameter,1
  2722.  
  2723. ;-- Error if file doesn't exist
  2724. IfNotExist %$CLParameter%
  2725. {
  2726. gui +OwnDialogs
  2727. MsgBox
  2728. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2729. ,File Not Found,
  2730. (ltrim
  2731. Specified file not found: %A_Space%
  2732. "%$CLParameter%" %A_Space%
  2733. `nProgram stopped. %A_Space%
  2734. )
  2735.  
  2736. ExitApp
  2737. }
  2738.  
  2739. ;-- Error if directory
  2740. if InStr(FileExist($CLParameter),"D")
  2741. {
  2742. gui +OwnDialogs
  2743. MsgBox
  2744. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2745. ,Command-line Error,
  2746. (ltrim
  2747. Command-line parameter contains a folder name: %A_Space%
  2748. "%$CLParameter%" %A_Space%
  2749. `nProgram stopped. %A_Space%
  2750. )
  2751.  
  2752. ExitApp
  2753. }
  2754.  
  2755. ;[=====================]
  2756. ;[ Prepare workspace ]
  2757. ;[=====================]
  2758. gosub PrepareWorkspace
  2759.  
  2760. ;[=============]
  2761. ;[ Copy file ]
  2762. ;[=============]
  2763. ;-- Copy specified file over workspace file
  2764. FileCopy %$CLParameter%,%$EditFile%,1 ;-- 1=overwrite
  2765. If ErrorLevel
  2766. {
  2767. gui +OwnDialogs
  2768. MsgBox
  2769. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2770. ,Copy Error,
  2771. (ltrim
  2772. Unable to copy the specified file to the workspace: %A_Space%
  2773. "%$CLParameter%" %A_Space%
  2774. `nProgram stopped. %A_Space%
  2775. )
  2776.  
  2777. ExitApp
  2778. }
  2779.  
  2780. ;-- Reset file attributes
  2781. FileSetAttrib -RSH,%$EditFile%
  2782.  
  2783. ;-- Redefine $CopyFromPath
  2784. SplitPath $CLParameter,,$CopyFromPath
  2785.  
  2786. ;-- Push to $RecentFiles and reload menu
  2787. MRUManager($RecentFiles,"Push",$CLParameter,"|",9)
  2788. gosub QAHKGUI_ReloadRecentFilesMenu
  2789.  
  2790. ;-- Update status bar
  2791. SB_SetText("Contents of " . CompressFileName($CLParameter,65) . " copied to the workspace.")
  2792. SetTimer QAHKGUI_ClearStatusBar,25000
  2793. return
  2794.  
  2795.  
  2796. ;***************************
  2797. ;* *
  2798. ;* Prepare workspace *
  2799. ;* *
  2800. ;***************************
  2801. PrepareWorkspace:
  2802.  
  2803. ;[=========================]
  2804. ;[ Create "Edit" folder ]
  2805. ;[ (If it doesn't exist) ]
  2806. ;[=========================]
  2807. IfNotExist %$EditDir%\.
  2808. {
  2809. FileCreateDir %$EditDir%
  2810. if ErrorLevel
  2811. {
  2812. gui +OwnDialogs
  2813. MsgBox
  2814. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2815. ,Prepare Workspace Error,
  2816. (ltrim
  2817. Unable to create the "Edit" folder. %A_Space%
  2818. Program stopped. %A_Space%
  2819. )
  2820.  
  2821. ExitApp
  2822. }
  2823. }
  2824.  
  2825. ;[=========================]
  2826. ;[ Create workspace file ]
  2827. ;[ (If it doesn't exist) ]
  2828. ;[=========================]
  2829. IfNotExist %$EditFile%
  2830. {
  2831. FileAppend MsgBox Enter script here,%$EditFile%
  2832. if ErrorLevel
  2833. {
  2834. gui +OwnDialogs
  2835. MsgBox
  2836. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2837. ,Prepare Workspace Error,
  2838. (ltrim join`s
  2839. Error occurred while attempting to create the initial
  2840. workspace. %A_Space%
  2841. `nProgram stopped. %A_Space%
  2842. )
  2843.  
  2844. ExitApp
  2845. }
  2846. }
  2847.  
  2848. return
  2849.  
  2850.  
  2851. ;************************
  2852. ;* *
  2853. ;* Load workspace *
  2854. ;* *
  2855. ;************************
  2856. LoadWorkspace:
  2857.  
  2858. ;-- Close current file
  2859. HE_CloseFile($QAHKGUI_hEdit)
  2860.  
  2861. ;-- Prepare workspace
  2862. gosub PrepareWorkspace
  2863.  
  2864. ;-- Open workspace file
  2865. HE_OpenFile($QAHKGUI_hEdit,$EditFile)
  2866. if not ErrorLevel
  2867. {
  2868. ;-- Notify the user
  2869. gui +OwnDialogs
  2870. MsgBox
  2871. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2872. ,Load Workspace Error,
  2873. (ltrim
  2874. Could not find/open the workspace file: %A_Space%
  2875. %$EditFile% %A_Space%
  2876.  
  2877. This file is probably locked by another program or process. %A_Space%
  2878. Program stopped. %A_Space%
  2879. )
  2880.  
  2881. ExitApp
  2882. }
  2883.  
  2884. return
  2885.  
  2886.  
  2887. ;************************
  2888. ;* *
  2889. ;* Save workspace *
  2890. ;* *
  2891. ;************************
  2892. SaveWorkspace:
  2893.  
  2894. ;-- Bounce if there are no changes
  2895. if HE_GetModify($QAHKGUI_hEdit)=0
  2896. return
  2897.  
  2898. ;-- Prep
  2899. gosub PrepareWorkspace
  2900. ;-- Note: This routine is called here to check/rebuild the workspace area
  2901. ; just in case it was destroyed during a run or other program/user action.
  2902.  
  2903. ;-- Save it
  2904. ErrorLevel :=HE_SaveFile($QAHKGUI_hEdit,$EditFile)
  2905. ;;;;;If ErrorLevel
  2906. ;;;;; {
  2907. ;;;;; gui +OwnDialogs
  2908. ;;;;; MsgBox
  2909. ;;;;; ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2910. ;;;;; ,Save Workspace Error
  2911. ;;;;; ,Unable to save the current workspace. %A_Space%
  2912. ;;;;;
  2913. ;;;;; return
  2914. ;;;;; }
  2915.  
  2916. ;-- Programming note: The value returned from HE_SaveFile is meaningless. The
  2917. ; function usually returns 0 regardless of whether the file was successfully
  2918. ; saved or not. On rare occasion, the function returns 1. This value is also
  2919. ; meaningless if the return value 0 does not provide guidance.
  2920.  
  2921. ;-- Workspace file exist?
  2922. ;
  2923. ; Programming note: For the most part, this test is meaningless but remains
  2924. ; as a fail-safe.
  2925. ;
  2926. IfNotExist %$EditFile%
  2927. {
  2928. gui +OwnDialogs
  2929. MsgBox
  2930. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2931. ,Save Workspace Error
  2932. ,Unable to save the current workspace. %A_Space%
  2933.  
  2934. return
  2935. }
  2936.  
  2937. ;-- Reset Modify flag
  2938. HE_SetModify($QAHKGUI_hEdit,False)
  2939. return
  2940.  
  2941.  
  2942. ;**************************
  2943. ;* *
  2944. ;* Backup workspace *
  2945. ;* *
  2946. ;**************************
  2947. BackupWorkspace:
  2948.  
  2949. ;-- Programming note: This routine assumes that the workspace environment
  2950. ; exists. If you're not sure that the workspace environment has been
  2951. ; prepared, run the PrepareWorkspace routine before calling this routine.
  2952.  
  2953.  
  2954. ;-- Copy workspace file over workspace backup file
  2955. FileCopy %$EditFile%,%$EditBackupFile%,1 ;-- 1=overwrite
  2956. If ErrorLevel
  2957. {
  2958. gui +OwnDialogs
  2959. MsgBox
  2960. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2961. ,Workspace Backup Error
  2962. ,Unable to create/update the workspace backup file. %A_Space%
  2963.  
  2964. return
  2965. }
  2966.  
  2967. ;-- Reset file attributes
  2968. FileSetAttrib -RSH,%$EditBackupFile%
  2969. ;-- Usually redundant but remains as a fail-safe
  2970.  
  2971. return
  2972.  
  2973.  
  2974. ;***************************
  2975. ;* *
  2976. ;* Delete Run folder *
  2977. ;* *
  2978. ;***************************
  2979. DeleteRunFolder:
  2980.  
  2981. ;-- "Run" folder exists?
  2982. IfExist %$RunDir%\.
  2983. {
  2984. ;-- Delete it
  2985. FileRemoveDir %$RunDir%,1 ;-- 1=Remove all files and subdirectories
  2986. if ErrorLevel
  2987. {
  2988. gui +OwnDialogs
  2989. MsgBox
  2990. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  2991. ,Clear Run Workspace Error,
  2992. (ltrim join`s
  2993. Unable to clear the Run workspace. It's likely that one or more
  2994. files or folders are in use. %A_Space%
  2995. )
  2996. }
  2997. }
  2998.  
  2999. return
  3000.  
  3001.  
  3002. ;*******************************
  3003. ;* *
  3004. ;* Delete Restore folder *
  3005. ;* *
  3006. ;*******************************
  3007. DeleteRestoreFolder:
  3008.  
  3009. ;-- "Restore" folder exist?
  3010. IfExist %$RPDir%\.
  3011. {
  3012. ;-- Delete it
  3013. FileRemoveDir %$RPDir%,1 ;-- 1=Remove all files and subdirectories
  3014. if ErrorLevel
  3015. {
  3016. gui +OwnDialogs
  3017. MsgBox
  3018. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  3019. ,Delete Restore Folder Error,
  3020. (ltrim join`s
  3021. Unable to clear the "Restore" folder. It's likely that one or
  3022. more files are in use. %A_Space%
  3023. )
  3024. }
  3025. }
  3026.  
  3027. return
  3028.  
  3029.  
  3030. ;*********************************
  3031. ;* *
  3032. ;* Update printer settings *
  3033. ;* *
  3034. ;*********************************
  3035. UpdatePrinterSettings:
  3036.  
  3037. ;-- Bounce if the PageSetupDlg or PrintDlg functions have been called before
  3038. if hDevMode
  3039. return
  3040.  
  3041. ;-- Load ComDlg32 library
  3042. ;
  3043. ; Programming note: Since both the PageSetup and Print routines call this
  3044. ; subroutine, the comdlg32.dll library is loaded here. It is not unloaded
  3045. ; until the script ends.
  3046. ;
  3047. if not hComDlg32
  3048. hComDlg32:=DllCall("LoadLibrary","Str","comdlg32.dll")
  3049.  
  3050. ;-- Create/Define PAGESETUPDLG Structure
  3051. VarSetCapacity(PAGESETUPDLG_Structure,84,0)
  3052. NumPut(84,PAGESETUPDLG_Structure,0,"UInt") ;-- lStructSize
  3053. NumPut($QAHKGUI_hWnd,PAGESETUPDLG_Structure,4,"UInt") ;-- hwndOwner
  3054. NumPut(PSD_RETURNDEFAULT,PAGESETUPDLG_Structure,16,"UInt") ;-- Flags
  3055.  
  3056. ;-- Call Page Setup using ReturnDefault flag. Bounce if there is an error.
  3057. if not DllCall("comdlg32\PageSetupDlgA","UInt",&PAGESETUPDLG_Structure)
  3058. {
  3059. outputdebug End Subrou: %A_ThisLabel% -- Error returned from PageSetupDlgA
  3060. return
  3061. }
  3062.  
  3063. ;-- Collect handles
  3064. hDevMode :=NumGet(PAGESETUPDLG_Structure,8,"UInt")
  3065. ;-- Handle to a global memory object that contains a DEVMODE structure
  3066.  
  3067. hDevNames :=NumGet(PAGESETUPDLG_Structure,12,"UInt")
  3068. ;-- Handle to a movable global memory object that contains a DEVNAMES
  3069. ; structure
  3070.  
  3071. ;-- Update orientation
  3072. if $PrintOrientation is Integer
  3073. {
  3074. ;-- Lock the moveable memory, retrieving a pointer to it
  3075. pDevMode:=DllCall("GlobalLock","UInt",hDevMode)
  3076.  
  3077. ;-- Orientation
  3078. NumPut($PrintOrientation,pDevMode+0,44,"Short")
  3079.  
  3080. ;-- Unlock the moveable memory
  3081. DllCall("GlobalUnlock","Uint",hDevMode)
  3082. }
  3083.  
  3084. return
  3085.  
  3086.  
  3087.  
  3088. ;-------------------------------------------------------------------------------
  3089. ;-------------------------------------------------------------------------------
  3090. ;-------------------------------------------------------------------------------
  3091. ;-------------------------------------------------------------------------------
  3092. ;-------------------------------------------------------------------------------
  3093. ;----------------------------- Begin QAHKGUI Stuff -----------------------------
  3094. ;-------------------------------------------------------------------------------
  3095. ;***************************
  3096. ;* *
  3097. ;* *
  3098. ;* Functions *
  3099. ;* (QAHKGUI) *
  3100. ;* *
  3101. ;* *
  3102. ;***************************
  3103. ;*******************
  3104. ;* *
  3105. ;* OnToolbar *
  3106. ;* (QAHKGUI) *
  3107. ;* *
  3108. ;*******************
  3109. QAHKGUI_OnToolbar(p_hToolbar,p_Event,p_Button,p_ButtonPos)
  3110. {
  3111. ;[====================]
  3112. ;[ Global variables ]
  3113. ;[====================]
  3114. Global $hToolbar
  3115. ,$ToolbarButtons
  3116.  
  3117. ;[=====================]
  3118. ;[ Clean up p_Button ]
  3119. ;[=====================]
  3120. StringReplace p_Button,p_Button,%A_Space%,,All
  3121. StringReplace p_Button,p_Button,$,,All ;-- NL delimiter. Feature doesn't work (yet)
  3122. StringReplace p_Button,p_Button,.,,All
  3123.  
  3124. ;[===============]
  3125. ;[ Event: Menu ]
  3126. ;[===============]
  3127. if p_Event=Menu
  3128. QAHKGUI_ToolbarMenu(p_Button,p_ButtonPos)
  3129. ;-- Programming note: Don't create an independent thread (SetTimer)
  3130. ; when calling a routine that shows a menu for a button. Two
  3131. ; reasons:
  3132. ;
  3133. ; 1) The right side of the button should remain in a depressed
  3134. ; state while the menu is displayed. The button remains in a
  3135. ; depressed state until the OnToolbar routine has been
  3136. ; completed.
  3137. ;
  3138. ; 2) All other OnToolbar messages should be ignored while the
  3139. ; menu is shown. The toolbar appears to locked out until the
  3140. ; user selects one of the menu options or until the menu is
  3141. ; dismissed.
  3142.  
  3143. ;[================]
  3144. ;[ Event: Click ]
  3145. ;[================]
  3146. if p_Event=Click
  3147. {
  3148. ;-- Programming note: Most (all?) Click events are initiated by creating
  3149. ; an independent thread via a SetTimer command with a 0 (start
  3150. ; immediately) period. To insure that the routine is only called
  3151. ; once, make sure that the routine turns off the timer as the first
  3152. ; step. If the routine fails to turn off the the timer, the SetTimer
  3153. ; command becomes an infinite loop.
  3154. ;
  3155. ;-- Most buttons
  3156. if IsLabel("QAHKGUI_" . p_Button)
  3157. SetTimer QAHKGUI_%p_Button%,0
  3158. else
  3159. {
  3160. ;-- Edit
  3161. if IsLabel("QAHKGUI_Edit" . p_Button)
  3162. SetTimer QAHKGUI_Edit%p_Button%,0
  3163. else
  3164. {
  3165. ;-- Exceptions
  3166. if p_Button=Options
  3167. SetTimer OptionsGUI,0
  3168. else
  3169. if p_Button=Restore
  3170. SetTimer RPViewerGUI,0
  3171. }
  3172. }
  3173. }
  3174.  
  3175. ;[===========================]
  3176. ;[ Event: Adjust or Change ]
  3177. ;[===========================]
  3178. if p_Event in Adjust,Change
  3179. {
  3180. $ToolbarButtons:=Toolbar_Define($hToolbar)
  3181. SetTimer SaveConfiguration,0
  3182. SetTimer QAHKGUI_SetToolbarButtonState,250
  3183. }
  3184.  
  3185. return
  3186. }
  3187.  
  3188.  
  3189. ;*********************
  3190. ;* *
  3191. ;* ToolbarMenu *
  3192. ;* (QAHKGUI) *
  3193. ;* *
  3194. ;*********************
  3195. ;
  3196. ; Description
  3197. ; ===========
  3198. ; This function, called by the QAHKGUI_OnToolbar function when there is a
  3199. ; "Menu" event, shows a context menu specifically designed for the toolbar.
  3200. ; The function does not end until the user has selected one of the menu
  3201. ; items or the menu is dismissed.
  3202. ;
  3203. ;
  3204. ; Programming Notes
  3205. ; ================
  3206. ; - This function will stop with an "Unable to find xxxx menu" error message
  3207. ; if a menu for the associated toolbar menu button does not exist. Be
  3208. ; sure to test all toolbar menu buttons.
  3209. ;
  3210. ; - Any routine called from a toolbar menu should either 1) finish quickly
  3211. ; or 2) should spawn an independent thread to complete the task. If a
  3212. ; new thread is not spawned, this function will not complete until the
  3213. ; request has completed. In addition, the button will remain depressed
  3214. ; until the request has completed.
  3215. ;
  3216. ;-------------------------------------------------------------------------------
  3217. QAHKGUI_ToolbarMenu(p_Button,p_ButtonPos)
  3218. {
  3219. ;[====================]
  3220. ;[ Global variables ]
  3221. ;[====================]
  3222. Global SM_CXSIZEFRAME
  3223. ,SM_CYSIZEFRAME
  3224. ,SM_CYCAPTION
  3225. ,SM_CYMENU
  3226. ,$hToolbar
  3227. ,$ScriptName
  3228. ,$ShowMenubar
  3229.  
  3230. ;-- Collect button statistics
  3231. l_ButtonStats:=Toolbar_GetRect($hToolbar,p_ButtonPos)
  3232. StringSplit l_ButtonRect,l_ButtonStats,%A_Space%
  3233.  
  3234. ;-- Show menu
  3235. Menu Tray,UseErrorLevel
  3236. Menu Toolbar_%p_Button%
  3237. ,Show
  3238. ,% SM_CXSIZEFRAME+l_ButtonRect1 ;-- The button's X (left) position
  3239. ,% SM_CYSIZEFRAME
  3240. + SM_CYCAPTION
  3241. + ($ShowMenubar ? SM_CYMENU:0)
  3242. + 2 ;-- see Note 1
  3243. + l_ButtonRect2 ;-- The button's Y (top) position
  3244. + l_ButtonRect4 ;-- The button's height
  3245.  
  3246. ;-- Note 1: +2 is needed because Toolbar_GetRect doesn't account for a
  3247. ; 2-pixel line top border.
  3248. ;
  3249. ;-- Note 2: This calculation only works if the toolbar is at the top of
  3250. ; the form. If the menubar is wrapped, the Y position will be off by
  3251. ; the size of the extra menubar line(s).
  3252.  
  3253. ;-- Menu not found?
  3254. if ErrorLevel
  3255. MsgBox
  3256. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  3257. ,%$ScriptName% - Programmer Error
  3258. ,Unable to find the "Toolbar_%p_Button%" menu. %A_Space%
  3259.  
  3260. ;-- Reset UseErrorLevel
  3261. Menu Tray,UseErrorLevel,Off
  3262. return
  3263. }
  3264.  
  3265.  
  3266. ;*******************
  3267. ;* *
  3268. ;* OnFind *
  3269. ;* (QAHKGUI) *
  3270. ;* *
  3271. ;*******************
  3272. QAHKGUI_OnFind(p_Event,p_Flags,p_FindWhat,Dummy="")
  3273. {
  3274. ;[====================]
  3275. ;[ Global variables ]
  3276. ;[====================]
  3277. Global Dlg_hWnd
  3278. ,Dlg_Flags
  3279. ,Dlg_FindWhat
  3280. ,Dlg_FindFromTheTop
  3281. ,$QAHKGUI
  3282. ,$QAHKGUI_hEdit
  3283.  
  3284. ;[==========]
  3285. ;[ Close? ]
  3286. ;[==========]
  3287. if p_Event=C
  3288. return
  3289.  
  3290. ;-- If open, manually close the Find dialog
  3291. IfWinExist ahk_id %Dlg_hWnd%
  3292. {
  3293. WinClose ahk_id %Dlg_hWnd%
  3294. Dlg_hWnd:=0
  3295. }
  3296.  
  3297. ;[==============]
  3298. ;[ Initialize ]
  3299. ;[==============]
  3300. ;-- Update Globals
  3301. Dlg_Flags :=p_Flags
  3302. Dlg_FindWhat:=p_FindWhat
  3303. ;-- These global variables are used by Find, FindNext, FindPrevious, and
  3304. ; Replace routines.
  3305.  
  3306. ;-- Convert Dlg_Find flags to HE_FindText flags
  3307. l_Flags:=""
  3308. if p_Flags contains c
  3309. l_Flags:=l_Flags . "MATCHCASE "
  3310.  
  3311. if p_Flags contains w
  3312. l_Flags:=l_Flags . "WHOLEWORD "
  3313.  
  3314. ;[===========]
  3315. ;[ Find it ]
  3316. ;[===========]
  3317. HE_GetSel($QAHKGUI_hEdit,l_StartSelPos,l_EndSelPos)
  3318.  
  3319. ;-- Which direction?
  3320. if p_Flags contains d
  3321. l_FindPos:=HE_FindText($QAHKGUI_hEdit,p_FindWhat,l_EndSelPos,-1,l_Flags)<<32>>32
  3322. else
  3323. l_FindPos:=HE_FindText($QAHKGUI_hEdit,p_FindWhat,l_StartSelPos,0,l_Flags)<<32>>32
  3324.  
  3325. ;-- Anything found?
  3326. if (l_FindPos>=0)
  3327. {
  3328. ;-- Select and scroll to it
  3329. HE_SetSel($QAHKGUI_hEdit,l_FindPos,l_FindPos+StrLen(p_FindWhat))
  3330. HE_ScrollCaret($QAHKGUI_hEdit)
  3331. }
  3332. else
  3333. {
  3334. ;-- Attach dialog to QAHKGUI window
  3335. gui %$QAHKGUI%:+OwnDialogs
  3336.  
  3337. ;-- Notify/Prompt the user
  3338. $Message=Next occurrence of "%p_FindWhat%" not found.
  3339. if Dlg_FindFromTheTop or InStr(p_Flags,"D")=0
  3340. {
  3341. MsgBox
  3342. ,64 ;-- 64 = 0 (OK button) + 64 (Info icon)
  3343. ,Find
  3344. ,%$Message% %A_Space%
  3345.  
  3346. Dlg_FindFromTheTop:=False
  3347. return
  3348. }
  3349.  
  3350. MsgBox
  3351. ,33 ;-- 33 = 1 (OK/Cancel buttons) + 32 ("?" icon)
  3352. ,Find
  3353. ,%$Message%`nContinue search from the top? %A_Space%
  3354.  
  3355. IfMsgBox Cancel
  3356. {
  3357. Dlg_FindFromTheTop:=False
  3358. return
  3359. }
  3360.  
  3361. ;[===================]
  3362. ;[ Start searching ]
  3363. ;[ from the top ]
  3364. ;[===================]
  3365. Dlg_FindFromTheTop:=True
  3366. HE_SetSel($QAHKGUI_hEdit,0,0) ;-- Move caret to the top
  3367. QAHKGUI_OnFind("F",p_Flags,p_FindWhat)
  3368. ;-- Recursive call
  3369. }
  3370.  
  3371. return
  3372. }
  3373.  
  3374.  
  3375. ;*******************
  3376. ;* *
  3377. ;* OnReplace *
  3378. ;* (QAHKGUI) *
  3379. ;* *
  3380. ;*******************
  3381. QAHKGUI_OnReplace(p_Event,p_Flags,p_FindWhat,p_ReplaceWith)
  3382. {
  3383. ;[====================]
  3384. ;[ Global variables ]
  3385. ;[====================]
  3386. Global Dlg_hWnd
  3387. ,Dlg_Flags
  3388. ,Dlg_FindWhat
  3389. ,Dlg_ReplaceWith
  3390. ,Dlg_FindFromTheTop
  3391. ,$QAHKGUI
  3392. ,$QAHKGUI_hEdit
  3393.  
  3394. ;[====================]
  3395. ;[ Static variables ]
  3396. ;[====================]
  3397. Static s_ReplaceCount:=0
  3398. ;-- Counter to track the number of standard "Replace" commands
  3399. ; that have been performed.
  3400.  
  3401. ;[==========]
  3402. ;[ Close? ]
  3403. ;[==========]
  3404. if p_Event=C
  3405. return
  3406.  
  3407. ;[==============]
  3408. ;[ Initialize ]
  3409. ;[==============]
  3410. ;-- Update Globals
  3411. Dlg_Flags :=p_Flags
  3412. Dlg_FindWhat :=p_FindWhat
  3413. Dlg_ReplaceWith:=p_ReplaceWith
  3414. ;-- These global variables are used by Find, FindNext, FindPrevious, and
  3415. ; Replace routines.
  3416.  
  3417. ;-- Convert Dlg_Find flags to HE_FindText flags
  3418. l_Flags:=""
  3419. if p_Flags contains c
  3420. l_Flags:=l_Flags . "MATCHCASE "
  3421.  
  3422. if p_Flags contains w
  3423. l_Flags:=l_Flags . "WHOLEWORD "
  3424.  
  3425. ;-- Get select positions
  3426. HE_GetSel($QAHKGUI_hEdit,l_StartSelPos,l_EndSelPos)
  3427.  
  3428. ;[=========]
  3429. ;[ Find ]
  3430. ;[=========]
  3431. if p_Event=F
  3432. {
  3433. ;-- Look for it
  3434. l_FindPos:=HE_FindText($QAHKGUI_hEdit,p_FindWhat,l_EndSelPos,-1,l_Flags)<<32>>32
  3435.  
  3436. ;-- Anything found?
  3437. if (l_FindPos>=0)
  3438. {
  3439. ;-- Select and scroll to it
  3440. HE_SetSel($QAHKGUI_hEdit,l_FindPos,l_FindPos+StrLen(p_FindWhat))
  3441. HE_ScrollCaret($QAHKGUI_hEdit)
  3442. }
  3443. else
  3444. {
  3445. ;-- Attach MsgBox dialog to QAHKGUI window
  3446. gui %$QAHKGUI%:+OwnDialogs
  3447.  
  3448. ;-- Disable dialog
  3449. WinSet Disable,,ahk_id %Dlg_hWnd%
  3450.  
  3451. ;-- Notify/Prompt the user
  3452. $Message="%p_FindWhat%" not found.
  3453. if Dlg_FindFromTheTop
  3454. {
  3455. MsgBox
  3456. ,64 ;-- 64 = 0 (OK button) + 64 (Info icon)
  3457. ,Replace
  3458. ,%$Message% %A_Space%
  3459.  
  3460. Dlg_FindFromTheTop:=False
  3461. WinSet Enable,,ahk_id %Dlg_hWnd%
  3462. return
  3463. }
  3464.  
  3465. MsgBox
  3466. ,33 ;-- 33 = 1 (OK/Cancel buttons) + 32 ("?" icon)
  3467. ,Replace
  3468. ,%$Message%`nContinue search from the top? %A_Space%
  3469.  
  3470. ;-- Enable dialog
  3471. WinSet Enable,,ahk_id %Dlg_hWnd%
  3472.  
  3473. IfMsgBox Cancel
  3474. {
  3475. Dlg_FindFromTheTop:=False
  3476. return
  3477. }
  3478.  
  3479. ;[===================]
  3480. ;[ Start searching ]
  3481. ;[ from the top ]
  3482. ;[===================]
  3483. Dlg_FindFromTheTop:=True
  3484. HE_SetSel($QAHKGUI_hEdit,0,0) ;-- Move caret to the top
  3485. QAHKGUI_OnReplace("F",p_Flags,p_FindWhat,p_ReplaceWith)
  3486. ;-- Recursive call
  3487. }
  3488. }
  3489.  
  3490. ;[===========]
  3491. ;[ Replace ]
  3492. ;[===========]
  3493. if p_Event=R
  3494. {
  3495. ;-- Anything selected and if so, is it the same length of p_FindWhat?
  3496. if (l_StartSelPos<>l_EndSelPos)
  3497. and StrLen(p_FindWhat)=l_EndSelPos-l_StartSelPos
  3498. {
  3499. ;-- Look for it within the selected area
  3500. l_FindPos:=HE_FindText($QAHKGUI_hEdit,p_FindWhat,l_StartSelPos,l_EndSelPos,l_Flags)
  3501. ;-- Programming note: The HE_FindText function is called here
  3502. ; instead of just doing a plain "If selected=p_FindWhat"
  3503. ; test because the function takes into consideration the
  3504. ; optional "Match case" and "Match Whole Word" flags.
  3505.  
  3506. ;-- If found, replace with p_ReplaceWith
  3507. if (l_FindPos=l_StartSelPos)
  3508. {
  3509. HE_ReplaceSel($QAHKGUI_hEdit,p_ReplaceWith)
  3510.  
  3511. ;-- Count it
  3512. s_ReplaceCount++
  3513. }
  3514. }
  3515. ;-- Find next
  3516. QAHKGUI_OnReplace("F",p_Flags,p_FindWhat,p_ReplaceWith)
  3517. ;-- Recursive call
  3518. }
  3519.  
  3520. ;[================]
  3521. ;[ Replace All ]
  3522. ;[================]
  3523. if p_Event=A
  3524. {
  3525. ;-- Manually close the Replace dialog
  3526. WinClose ahk_id %Dlg_hWnd%
  3527. Dlg_hWnd:=0
  3528.  
  3529.  
  3530. ;-- Set focus
  3531. ControlFocus,,ahk_id %$QAHKGUI_hEdit%
  3532. ;-- Not sure if this is necessary
  3533.  
  3534. ;-- Set to Wait (Hourglass) cursor
  3535. SetSystemCursor("IDC_Wait")
  3536.  
  3537. ;-- Position caret
  3538. if (l_StartSelPos<>l_EndSelPos)
  3539. if StrLen(p_FindWhat)=l_EndSelPos-l_StartSelPos
  3540. HE_SetSel($QAHKGUI_hEdit,l_StartSelPos,l_StartSelPos)
  3541. else
  3542. HE_SetSel($QAHKGUI_hEdit,l_EndSelPos+1,l_EndSelPos+1)
  3543.  
  3544. ;-- Replace All
  3545. l_ReplaceCount:=0
  3546. Loop
  3547. {
  3548. ;-- Get select positions
  3549. rHE_GetSel:=HE_GetSel($QAHKGUI_hEdit,Dummy,l_EndSelPos)
  3550.  
  3551. ;-- Look for next
  3552. l_FindPos:=HE_FindText($QAHKGUI_hEdit,p_FindWhat,l_EndSelPos,-1,l_Flags)<<32>>32
  3553.  
  3554. ;-- Anything found?
  3555. if (l_FindPos>=0)
  3556. {
  3557. ;-- Select and scroll to it
  3558. rHE_SetSel:=HE_SetSel($QAHKGUI_hEdit,l_FindPos,l_FindPos+StrLen(p_FindWhat))
  3559. HE_ScrollCaret($QAHKGUI_hEdit)
  3560.  
  3561. ;-- Replace with p_ReplaceWith
  3562. rHE_ReplaceSel:=HE_ReplaceSel($QAHKGUI_hEdit,p_ReplaceWith)
  3563.  
  3564. ;-- Count it
  3565. l_ReplaceCount++
  3566. }
  3567. else
  3568. Break
  3569. }
  3570.  
  3571. ;-- Restore the cursor
  3572. SetSystemCursor("restore")
  3573.  
  3574. ;-------------------
  3575. ;-- Notify the user
  3576. ;-------------------
  3577. ;-- Attach dialog to QAHKGUI window
  3578. gui %$QAHKGUI%:+OwnDialogs
  3579.  
  3580. ;-- Display message
  3581. if l_ReplaceCount=0
  3582. $Message="%p_FindWhat%" not found.
  3583. else
  3584. $Message="%p_FindWhat%" replaced %l_ReplaceCount% times.
  3585.  
  3586. MsgBox
  3587. ,64 ;-- 64 = 0 (OK button) + 64 (Info icon)
  3588. ,Replace All
  3589. ,%$Message% %A_Space%
  3590. }
  3591.  
  3592. return
  3593. }
  3594.  
  3595.  
  3596. ;*********************
  3597. ;* *
  3598. ;* ConvertCase *
  3599. ;* (QAHKGUI) *
  3600. ;* *
  3601. ;*********************
  3602. QAHKGUI_ConvertCase(hEdit,p_Case)
  3603. {
  3604. ;-- Convert p_case to format used by HE_ConvertCase
  3605. StringReplace p_Case,p_Case,case,,All
  3606.  
  3607. ;-- Get select positions
  3608. HE_GetSel(hEdit,l_StartSelPos,l_EndSelPos)
  3609.  
  3610. ;-- Bounce if nothing is selected
  3611. if (l_StartSelPos=l_EndSelPos)
  3612. return
  3613.  
  3614. ;-- Convert Case
  3615. HE_ConvertCase(hEdit,p_Case)
  3616.  
  3617. ;-- Reselect
  3618. HE_SetSel(hEdit,l_StartSelPos,l_EndSelPos)
  3619. return
  3620. }
  3621.  
  3622.  
  3623. ;**********************
  3624. ;* *
  3625. ;* Confirm Exit *
  3626. ;* (QAHKGUI) *
  3627. ;* *
  3628. ;**********************
  3629. QAHKGUI_ConfirmExit()
  3630. {
  3631. ;[====================]
  3632. ;[ Global variables ]
  3633. ;[====================]
  3634. Global $RunPIDList
  3635. ,$ScriptName
  3636.  
  3637. ;[===============]
  3638. ;[ OK to exit? ]
  3639. ;[===============]
  3640. $RunPIDList:=RebuildRunPIDList($RunPIDList)
  3641. if StrLen($RunPIDList)
  3642. {
  3643. gui +OwnDialogs
  3644. MsgBox
  3645. ,49 ;-- 49 = 1 (OK/Cancel buttons) + 48 ("!" icon)
  3646. ,Confirm Exit,
  3647. (ltrim join`s
  3648. Warning: There is at least one script started by
  3649. %$ScriptName% that is still running. %A_Space%
  3650. `n`nPlease note that scripts started by %$ScriptName% will not
  3651. be stopped when the program is closed. Also, scripts started by
  3652. this session of %$ScriptName% will not be recognized by future
  3653. sessions. %A_Space%
  3654. `n`nPress OK to exit %$ScriptName%. %A_Space%
  3655. )
  3656.  
  3657. ;-- Cancel?
  3658. IfMsgBox Cancel
  3659. Return False
  3660. }
  3661.  
  3662. ;-- It's all good
  3663. Return True
  3664. }
  3665.  
  3666.  
  3667.  
  3668. ;*****************************
  3669. ;* *
  3670. ;* *
  3671. ;* Subroutines *
  3672. ;* (QAHKGUI) *
  3673. ;* *
  3674. ;* *
  3675. ;*****************************
  3676. ;*****************
  3677. ;* *
  3678. ;* QAHKGUI *
  3679. ;* *
  3680. ;*****************
  3681. QAHKGUI:
  3682.  
  3683. ;-- Initialize
  3684. $QAHKGUI=11
  3685.  
  3686. ;-- Set GUI default
  3687. gui %$QAHKGUI%:Default
  3688.  
  3689. ;-- Identify window handle
  3690. gui %$QAHKGUI%:+LastFound
  3691. WinGet $QAHKGUI_hWnd,ID
  3692. GroupAdd $QAHKGUI_Group,ahk_id %$QAHKGUI_hWnd%
  3693.  
  3694. ;-- Build menus
  3695. gosub QAHKGUI_BuildMenus
  3696.  
  3697. ;-- Build GUI
  3698. gosub QAHKGUI_BuildGUI
  3699.  
  3700. ;-- Build $Tab variable - Used by the Tab and Shift+Tab hotkeys
  3701. $Tab=
  3702. if $RealTabs
  3703. $Tab:="`t"
  3704. else
  3705. Loop % $TabWidth
  3706. $Tab.=A_Space
  3707.  
  3708. ;-- Trap right click
  3709. OnMessage(WM_RBUTTONUP,"WM_RBUTTONUP")
  3710. return
  3711.  
  3712.  
  3713. ;*********************
  3714. ;* *
  3715. ;* Build menus *
  3716. ;* (QAHKGUI) *
  3717. ;* *
  3718. ;*********************
  3719. QAHKGUI_BuildMenus:
  3720.  
  3721. ;[========]
  3722. ;[ Menu ]
  3723. ;[========]
  3724. ;-- RecentFiles (sub-menu of File menu)
  3725. gosub QAHKGUI_BuildRecentFilesMenu
  3726.  
  3727. ;--------
  3728. ;-- File
  3729. ;--------
  3730. Menu QAHKGUI_FileMenu
  3731. ,Add
  3732. ,%s_New_MI%
  3733. ,QAHKGUI_New
  3734.  
  3735. Menu QAHKGUI_FileMenu
  3736. ,Add
  3737. ,%s_Prepend_New_MI%
  3738. ,QAHKGUI_PrependNew
  3739.  
  3740. Menu QAHKGUI_FileMenu
  3741. ,Add
  3742. ,&Copy From...`tCtrl+O
  3743. ,QAHKGUI_CopyFrom
  3744.  
  3745. Menu QAHKGUI_FileMENU
  3746. ,Add
  3747. ,Copy Recent
  3748. ,:QAHKGUI_RecentFilesMenu
  3749.  
  3750. Menu QAHKGUI_FileMenu
  3751. ,Add
  3752.  
  3753. ;-- External editor?
  3754. if $ExtEditorPath is not Space
  3755. {
  3756. if $ExtEditorName
  3757. Menu QAHKGUI_FileMenu
  3758. ,Add
  3759. ,Edit with %$ExtEditorName%`tF8
  3760. ,QAHKGUI_ExternalEditor
  3761. else
  3762. Menu QAHKGUI_FileMenu
  3763. ,Add
  3764. ,Edit with external editor`tF8
  3765. ,QAHKGUI_ExternalEditor
  3766.  
  3767. Menu QAHKGUI_FileMenu
  3768. ,Add
  3769. }
  3770.  
  3771. Menu QAHKGUI_FileMenu
  3772. ,Add
  3773. ,%s_Run_MI%
  3774. ,QAHKGUI_Run
  3775.  
  3776. Menu QAHKGUI_FileMenu
  3777. ,Add
  3778. ,%s_RunSelected_MI%
  3779. ,QAHKGUI_RunSelected
  3780.  
  3781. Menu QAHKGUI_FileMenu
  3782. ,Add
  3783. ,%s_File_Stop_MI%
  3784. ,QAHKGUI_Stop
  3785.  
  3786. Menu QAHKGUI_FileMenu
  3787. ,Disable
  3788. ,%s_File_Stop_MI%
  3789.  
  3790. Menu QAHKGUI_FileMenu
  3791. ,Add
  3792. ,Exp&lore Run Workspace`tCtrl+Shift+F9
  3793. ,QAHKGUI_ExploreRunWorkspace
  3794.  
  3795. Menu QAHKGUI_FileMenu
  3796. ,Add
  3797. ,Clear Run &Workspace`tCtrl+Alt+F9
  3798. ,QAHKGUI_ClearRunWorkspace
  3799.  
  3800. Menu QAHKGUI_FileMenu
  3801. ,Add
  3802.  
  3803. Menu QAHKGUI_FileMenu
  3804. ,Add
  3805. ,%s_Save_MI%
  3806. ,QAHKGUI_Save
  3807.  
  3808. Menu QAHKGUI_FileMenu
  3809. ,Add
  3810. ,%s_SaveTo_MI%
  3811. ,QAHKGUI_SaveTo
  3812.  
  3813. Menu QAHKGUI_FileMenu
  3814. ,Add
  3815. ,Re&vert`tCtrl+Shift+Z
  3816. ,QAHKGUI_Revert
  3817.  
  3818. Menu QAHKGUI_FileMenu
  3819. ,Add
  3820.  
  3821. Menu QAHKGUI_FileMenu
  3822. ,Add
  3823. ,Create Restore &Point`tCtrl+Shift+R
  3824. ,QAHKGUI_CreateRestorePoint
  3825.  
  3826. Menu QAHKGUI_FileMenu
  3827. ,Add
  3828. ,Rest&ore...`tF4
  3829. ,RPViewerGUI
  3830.  
  3831. Menu QAHKGUI_FileMenu
  3832. ,Add
  3833.  
  3834. Menu QAHKGUI_FileMenu
  3835. ,Add
  3836. ,%s_PageSetup_MI%
  3837. ,QAHKGUI_PageSetup
  3838.  
  3839. Menu QAHKGUI_FileMenu
  3840. ,Add
  3841. ,%s_Print_MI%
  3842. ,QAHKGUI_Print
  3843.  
  3844. Menu QAHKGUI_FileMenu
  3845. ,Add
  3846.  
  3847. Menu QAHKGUI_FileMenu
  3848. ,Add
  3849. ,E&xit`tAlt+F4
  3850. ,QAHKGUI_Close
  3851.  
  3852. ;---------------------------
  3853. ;-- Convert Case
  3854. ;-- (Sub-Menu of Edit menu)
  3855. ;---------------------------
  3856. Menu QAHKGUI_ConvertCaseMenu
  3857. ,Add
  3858. ,&Uppercase`tCtrl+Shift+U
  3859. ,QAHKGUI_Uppercase
  3860.  
  3861. Menu QAHKGUI_ConvertCaseMenu
  3862. ,Add
  3863. ,&Lowercase`tCtrl+Shift+L
  3864. ,QAHKGUI_Lowercase
  3865.  
  3866. Menu QAHKGUI_ConvertCaseMenu
  3867. ,Add
  3868. ,&Capitalize`tCtrl+Shift+C
  3869. ,QAHKGUI_Capitalize
  3870.  
  3871. Menu QAHKGUI_ConvertCaseMenu
  3872. ,Add
  3873. ,&Toggle case`tCtrl+Shift+T
  3874. ,QAHKGUI_ToggleCase
  3875.  
  3876. ;----------
  3877. ;-- Edit
  3878. ;----------
  3879. Menu QAHKGUI_EditMenu
  3880. ,Add
  3881. ,%s_Undo_MI%
  3882. ,QAHKGUI_Undo
  3883.  
  3884. Menu QAHKGUI_EditMenu
  3885. ,Add
  3886. ,%s_Redo_MI%
  3887. ,QAHKGUI_Redo
  3888.  
  3889. Menu QAHKGUI_EditMenu
  3890. ,Add
  3891.  
  3892. Menu QAHKGUI_EditMenu
  3893. ,Add
  3894. ,%s_Cut_MI%
  3895. ,QAHKGUI_EditCut
  3896.  
  3897. Menu QAHKGUI_EditMenu
  3898. ,Add
  3899. ,%s_Copy_MI%
  3900. ,QAHKGUI_EditCopy
  3901.  
  3902. Menu QAHKGUI_EditMenu
  3903. ,Add
  3904. ,%s_Paste_MI%
  3905. ,QAHKGUI_EditPaste
  3906.  
  3907. Menu QAHKGUI_EditMenu
  3908. ,Add
  3909. ,%s_PasteC_MI%
  3910. ,QAHKGUI_PasteClipboard
  3911.  
  3912. Menu QAHKGUI_EditMenu
  3913. ,Add
  3914. ,%s_Delete_MI%
  3915. ,QAHKGUI_Editclear
  3916.  
  3917. Menu QAHKGUI_EditMenu
  3918. ,Add
  3919. ,%s_SelectAll_MI%
  3920. ,QAHKGUI_EditSelectAll
  3921.  
  3922. Menu QAHKGUI_EditMenu
  3923. ,Add
  3924.  
  3925. Menu QAHKGUI_EditMenu
  3926. ,Add
  3927. ,%s_BlockComment_MI%
  3928. ,QAHKGUI_BlockComment
  3929.  
  3930. Menu QAHKGUI_EditMenu
  3931. ,Add
  3932. ,%s_BlockUncomment_MI%
  3933. ,QAHKGUI_BlockUncomment
  3934.  
  3935. Menu QAHKGUI_EditMenu
  3936. ,Add
  3937.  
  3938. Menu QAHKGUI_EditMenu
  3939. ,Add
  3940. ,%s_ConvertCase_MI%
  3941. ,:QAHKGUI_ConvertCaseMenu
  3942.  
  3943. ;----------------
  3944. ;-- Context Menu
  3945. ;----------------
  3946. Menu QAHKGUI_ContextMenu
  3947. ,Add
  3948. ,%s_Undo_MI%
  3949. ,QAHKGUI_Undo
  3950.  
  3951. Menu QAHKGUI_ContextMenu
  3952. ,Add
  3953. ,%s_Redo_MI%
  3954. ,QAHKGUI_Redo
  3955.  
  3956. Menu QAHKGUI_ContextMenu
  3957. ,Add
  3958.  
  3959. Menu QAHKGUI_ContextMenu
  3960. ,Add
  3961. ,%s_Cut_MI%
  3962. ,QAHKGUI_EditCut
  3963.  
  3964. Menu QAHKGUI_ContextMenu
  3965. ,Add
  3966. ,%s_Copy_MI%
  3967. ,QAHKGUI_EditCopy
  3968.  
  3969. Menu QAHKGUI_ContextMenu
  3970. ,Add
  3971. ,%s_Paste_MI%
  3972. ,QAHKGUI_EditPaste
  3973.  
  3974. Menu QAHKGUI_ContextMenu
  3975. ,Add
  3976. ,%s_PasteC_MI%
  3977. ,QAHKGUI_PasteClipboard
  3978.  
  3979. Menu QAHKGUI_ContextMenu
  3980. ,Add
  3981. ,%s_Delete_MI%
  3982. ,QAHKGUI_Editclear
  3983.  
  3984. Menu QAHKGUI_ContextMenu
  3985. ,Add
  3986. ,%s_SelectAll_MI%
  3987. ,QAHKGUI_EditSelectAll
  3988.  
  3989. Menu QAHKGUI_ContextMenu
  3990. ,Add
  3991.  
  3992. Menu QAHKGUI_ContextMenu
  3993. ,Add
  3994. ,%s_BlockComment_MI%
  3995. ,QAHKGUI_BlockComment
  3996.  
  3997. Menu QAHKGUI_ContextMenu
  3998. ,Add
  3999. ,%s_BlockUncomment_MI%
  4000. ,QAHKGUI_BlockUncomment
  4001.  
  4002. Menu QAHKGUI_ContextMenu
  4003. ,Add
  4004.  
  4005. Menu QAHKGUI_ContextMenu
  4006. ,Add
  4007. ,%s_ConvertCase_MI%
  4008. ,:QAHKGUI_ConvertCaseMenu
  4009.  
  4010. Menu QAHKGUI_ContextMenu
  4011. ,Add
  4012.  
  4013. Menu QAHKGUI_ContextMenu
  4014. ,Add
  4015. ,%s_RunSelected_MI%
  4016. ,QAHKGUI_ContextMenu_RunSelected
  4017.  
  4018. ;----------
  4019. ;-- Search
  4020. ;----------
  4021. Menu QAHKGUI_SearchMenu
  4022. ,Add
  4023. ,%s_Find_MI%
  4024. ,QAHKGUI_Find
  4025.  
  4026. Menu QAHKGUI_SearchMenu
  4027. ,Add
  4028. ,%s_FindNext_MI%
  4029. ,QAHKGUI_FindNext
  4030.  
  4031. Menu QAHKGUI_SearchMenu
  4032. ,Add
  4033. ,%s_FindPrevious_MI%
  4034. ,QAHKGUI_FindPrevious
  4035.  
  4036. Menu QAHKGUI_SearchMenu
  4037. ,Add
  4038. ,%s_Replace_MI%
  4039. ,QAHKGUI_Replace
  4040.  
  4041. Menu QAHKGUI_SearchMenu
  4042. ,Add
  4043. ,%s_Replace_MI%
  4044. ,QAHKGUI_Replace
  4045.  
  4046. Menu QAHKGUI_SearchMenu
  4047. ,Add
  4048.  
  4049. Menu QAHKGUI_SearchMenu
  4050. ,Add
  4051. ,%s_Goto_MI%
  4052. ,QAHKGUI_Goto
  4053.  
  4054. ;--------
  4055. ;-- View
  4056. ;--------
  4057. Menu QAHKGUI_ViewMenu
  4058. ,Add
  4059. ,%s_AlwaysOnTop_MI%
  4060. ,QAHKGUI_MenuAction
  4061.  
  4062. Menu QAHKGUI_ViewMenu
  4063. ,Add
  4064.  
  4065. Menu QAHKGUI_ViewMenu
  4066. ,Add
  4067. ,%s_MenuBar_MI%
  4068. ,QAHKGUI_MenuAction
  4069.  
  4070. Menu QAHKGUI_ViewMenu
  4071. ,Add
  4072. ,%s_ToolBar_MI%
  4073. ,QAHKGUI_MenuAction
  4074.  
  4075. Menu QAHKGUI_ViewMenu
  4076. ,Add
  4077. ,%s_LineNumbersBar_MI%
  4078. ,QAHKGUI_MenuAction
  4079.  
  4080. Menu QAHKGUI_ViewMenu
  4081. ,Add
  4082. ,%s_StatusBar_MI%
  4083. ,QAHKGUI_MenuAction
  4084.  
  4085. ;-------
  4086. ;-- Run
  4087. ;-------
  4088. Menu QAHKGUI_RunMenu
  4089. ,Add
  4090. ,%s_Run_MI%
  4091. ,QAHKGUI_Run
  4092.  
  4093. Menu QAHKGUI_RunMenu
  4094. ,Add
  4095. ,%s_RunSelected_MI%
  4096. ,QAHKGUI_RunSelected
  4097.  
  4098. Menu QAHKGUI_RunMenu
  4099. ,Add
  4100.  
  4101. Menu QAHKGUI_RunMenu
  4102. ,Add
  4103. ,%s_RunPrompt_MI%
  4104. ,QAHKGUI_MenuAction
  4105.  
  4106. Menu QAHKGUI_RunMenu
  4107. ,Add
  4108. ,%s_RunDebug_MI%
  4109. ,QAHKGUI_MenuAction
  4110.  
  4111. Menu QAHKGUI_RunMenu
  4112. ,Add
  4113. ,%s_RunWait_MI%
  4114. ,QAHKGUI_MenuAction
  4115.  
  4116. Menu QAHKGUI_RunMenu
  4117. ,Add
  4118.  
  4119. Menu QAHKGUI_RunMenu
  4120. ,Add
  4121. ,%s_ClearRunWorkspaceOnRun_MI%
  4122. ,QAHKGUI_MenuAction
  4123.  
  4124. Menu QAHKGUI_RunMenu
  4125. ,Add
  4126. ,%s_ClearRunWorkspaceOnExit_MI%
  4127. ,QAHKGUI_MenuAction
  4128.  
  4129. ;--------
  4130. ;-- Help
  4131. ;--------
  4132. Menu QAHKGUI_HelpMenu
  4133. ,Add
  4134. ,%s_Help_MI%
  4135. ,QAHKGUI_Help
  4136.  
  4137. Menu QAHKGUI_HelpMenu
  4138. ,Add
  4139. ,%s_About_MI%
  4140. ,QAHKGUI_About
  4141.  
  4142. ;-----------
  4143. ;-- Menubar
  4144. ;-----------
  4145. Menu QAHKGUI_Menubar
  4146. ,Add
  4147. ,&File
  4148. ,:QAHKGUI_FileMenu
  4149.  
  4150. Menu QAHKGUI_Menubar
  4151. ,Add
  4152. ,&Edit
  4153. ,:QAHKGUI_EditMenu
  4154.  
  4155. Menu QAHKGUI_Menubar
  4156. ,Add
  4157. ,&Search
  4158. ,:QAHKGUI_SearchMenu
  4159.  
  4160. Menu QAHKGUI_Menubar
  4161. ,Add
  4162. ,&View
  4163. ,:QAHKGUI_ViewMenu
  4164.  
  4165. Menu QAHKGUI_Menubar
  4166. ,Add
  4167. ,&Options
  4168. ,OptionsGUI
  4169.  
  4170. Menu QAHKGUI_Menubar
  4171. ,Add
  4172. ,&New
  4173. ,QAHKGUI_New
  4174.  
  4175. Menu QAHKGUI_Menubar
  4176. ,Add
  4177. ,&PasteC
  4178. ,QAHKGUI_PasteClipboard
  4179.  
  4180. Menu QAHKGUI_Menubar
  4181. ,Add
  4182. ,Run
  4183. ,:QAHKGUI_RunMenu
  4184.  
  4185. Menu QAHKGUI_Menubar
  4186. ,Add
  4187. ,%s_Menubar_Stop_MI%
  4188. ,QAHKGUI_Stop
  4189.  
  4190. Menu QAHKGUI_Menubar
  4191. ,Disable
  4192. ,%s_Menubar_Stop_MI%
  4193.  
  4194. Menu QAHKGUI_Menubar
  4195. ,Add
  4196. ,Rest&ore
  4197. ,RPViewerGUI
  4198.  
  4199. Menu QAHKGUI_Menubar
  4200. ,Add
  4201. ,&Help
  4202. ,:QAHKGUI_HelpMenu
  4203.  
  4204. ;------------------
  4205. ;-- MenubarRunWait
  4206. ;------------------
  4207. Menu QAHKGUI_MenubarRunWait
  4208. ,Add
  4209. ,%s_Menubar_Stop_MI%
  4210. ,QAHKGUI_Stop
  4211.  
  4212. ;----------------
  4213. ;-- Toolbar: New
  4214. ;----------------
  4215. Menu Toolbar_New
  4216. ,Add
  4217. ,%s_New_MI%
  4218. ,QAHKGUI_New
  4219.  
  4220. Menu Toolbar_New
  4221. ,Default
  4222. ,%s_New_MI%
  4223.  
  4224. Menu Toolbar_New
  4225. ,Add
  4226. ,%s_Prepend_New_MI%
  4227. ,QAHKGUI_PrependNew
  4228.  
  4229. ;-----------------
  4230. ;-- Toolbar: Save
  4231. ;-----------------
  4232. Menu Toolbar_Save
  4233. ,Add
  4234. ,%s_Save_MI%
  4235. ,QAHKGUI_Save
  4236.  
  4237. Menu Toolbar_Save
  4238. ,Default
  4239. ,%s_Save_MI%
  4240.  
  4241. Menu Toolbar_Save
  4242. ,Add
  4243. ,%s_SaveTo_MI%
  4244. ,QAHKGUI_Toolbar_SaveTo
  4245.  
  4246. ;------------------
  4247. ;-- Toolbar: Print
  4248. ;------------------
  4249. Menu Toolbar_Print
  4250. ,Add
  4251. ,%s_Print_MI%
  4252. ,QAHKGUI_Toolbar_Print
  4253.  
  4254. Menu Toolbar_Print
  4255. ,Default
  4256. ,%s_Print_MI%
  4257.  
  4258. Menu Toolbar_Print
  4259. ,Add
  4260. ,%s_PageSetup_MI%
  4261. ,QAHKGUI_Toolbar_PageSetup
  4262.  
  4263. ;-----------------
  4264. ;-- Toolbar: Find
  4265. ;-----------------
  4266. Menu Toolbar_Find
  4267. ,Add
  4268. ,%s_Find_MI%
  4269. ,QAHKGUI_Find
  4270.  
  4271. Menu Toolbar_Find
  4272. ,Default
  4273. ,%s_Find_MI%
  4274.  
  4275. Menu Toolbar_Find
  4276. ,Add
  4277. ,%s_FindNext_MI%
  4278. ,QAHKGUI_FindNext
  4279.  
  4280. Menu Toolbar_Find
  4281. ,Add
  4282. ,%s_FindPrevious_MI%
  4283. ,QAHKGUI_FindPrevious
  4284.  
  4285. Menu Toolbar_Find
  4286. ,Add
  4287. ,%s_Replace_MI%
  4288. ,QAHKGUI_Replace
  4289.  
  4290. Menu Toolbar_Find
  4291. ,Add
  4292.  
  4293. Menu Toolbar_Find
  4294. ,Add
  4295. ,%s_Goto_MI%
  4296. ,QAHKGUI_Toolbar_Goto
  4297.  
  4298. ;----------------
  4299. ;-- Toolbar: Run
  4300. ;----------------
  4301. Menu Toolbar_Run
  4302. ,Add
  4303. ,%s_Run_MI%
  4304. ,QAHKGUI_Toolbar_Run
  4305.  
  4306. Menu Toolbar_Run
  4307. ,Default
  4308. ,%s_Run_MI%
  4309.  
  4310. Menu Toolbar_Run
  4311. ,Add
  4312. ,%s_RunSelected_MI%
  4313. ,QAHKGUI_Toolbar_RunSelected
  4314.  
  4315. ;-----------------
  4316. ;-- Toolbar: Help
  4317. ;-----------------
  4318. Menu Toolbar_Help
  4319. ,Add
  4320. ,%s_Help_MI%
  4321. ,QAHKGUI_Help
  4322.  
  4323. Menu Toolbar_Help
  4324. ,Default
  4325. ,%s_Help_MI%
  4326.  
  4327. Menu Toolbar_Help
  4328. ,Add
  4329. ,%s_About_MI%
  4330. ,QAHKGUI_Toolbar_About
  4331.  
  4332. return
  4333.  
  4334.  
  4335. QAHKGUI_BuildRecentFilesMenu:
  4336.  
  4337. ;-- Create stub (needed for the 1st call)
  4338. Menu QAHKGUI_RecentFilesMenu,Add
  4339.  
  4340. ;-- Clear menu
  4341. Menu QAHKGUI_RecentFilesMenu,DeleteAll
  4342.  
  4343. ;-- Populate Recent Files Menu
  4344. Loop Parse,$RecentFiles,|
  4345. Menu QAHKGUI_RecentFilesMenu
  4346. ,Add
  4347. ,% A_Index . ". " . CompressFileName(A_LoopField,65)
  4348. ,QAHKGUI_RecentFilesMenu
  4349.  
  4350. if $RecentFiles is not Space
  4351. Menu QAHKGUI_RecentFilesMenu,Add
  4352.  
  4353. Menu QAHKGUI_RecentFilesMenu,Add,Clear List,QAHKGUI_ClearRecentFilesMenu
  4354.  
  4355. if $RecentFiles is Space
  4356. Menu QAHKGUI_RecentFilesMenu,Disable,Clear List
  4357.  
  4358. ;-- Update $RecentFilesMenu
  4359. $RecentFilesMenu:=$RecentFiles
  4360. ;-- Programming note: $RecentFiles and $RecentFilesMenu contain the same
  4361. ; information but $RecentFilesMenu always has the information in the order
  4362. ; defined in the menu.
  4363.  
  4364. return
  4365.  
  4366.  
  4367. ;*******************
  4368. ;* *
  4369. ;* Build GUI *
  4370. ;* (QAHKGUI) *
  4371. ;* *
  4372. ;*******************
  4373. QAHKGUI_BuildGUI:
  4374.  
  4375. ;[============]
  4376. ;[ Build it ]
  4377. ;[============]
  4378. ;-- GUI options
  4379. gui Margin,0,0
  4380.  
  4381. if $ShowMenubar
  4382. gui Menu,QAHKGUI_Menubar
  4383.  
  4384. gui +Resize
  4385. || +LabelQAHKGUI_
  4386.  
  4387. ;-- AOT
  4388. if $AlwaysOnTop
  4389. gui +AlwaysOnTop
  4390.  
  4391. ;-- Dummy fields
  4392. gui Add
  4393. ,Text
  4394. ,% "x" . $MaxGUIW . " ym w0 h0"
  4395. ,DummyX
  4396.  
  4397. gui Add
  4398. ,Text
  4399. ,xm y300 w0 h0
  4400. ,DummyY
  4401.  
  4402. ;-- The preceding two dummy controls are necessary because AutoHotkey does not
  4403. ; see the HiEdit object and therefore will not autosize the window correctly.
  4404. ; Setting a fixed size on the "gui Show" command will also work but additional
  4405. ; calculations must be performed to correctly account for the status bar and
  4406. ; the menu bar.
  4407.  
  4408. ;------------------
  4409. ;-- HiEdit control
  4410. ;------------------
  4411. $QAHKGUI_hEdit:=HE_Add($QAHKGUI_hWnd,0,0,$MaxGUIW,300,"HSCROLL VSCROLL HILIGHT",$LibDir . "\HiEdit.dll")
  4412. if not $QAHKGUI_hEdit
  4413. {
  4414. gui +OwnDialogs
  4415. MsgBox
  4416. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  4417. ,%$ScriptName% Error
  4418. ,Unable to find HiEdit.dll. Program stopped. %A_Space%
  4419.  
  4420. ExitApp
  4421. }
  4422.  
  4423. ;-- Get the default colors
  4424. $DefaultColors:=HE_GetColors($QAHKGUI_hEdit)
  4425.  
  4426. ;-- Change selected colors
  4427. $Colors=
  4428. Loop Parse,$DefaultColors,`n
  4429. {
  4430. $Key:=A_LoopField
  4431. if $Key contains InSelBack
  4432. $Key:="InSelBack=0xC56A31"
  4433. ;-- Programming note: This change allows selected text to appear
  4434. ; prominent while the main window is not in focus. This
  4435. ; modification was included to support the Replace dialog which
  4436. ; remains in focus until all changes are made.
  4437.  
  4438. if $Colors is Space
  4439. $Colors:=$Key
  4440. else
  4441. $Colors:=$Colors . "`n" . $Key
  4442. }
  4443.  
  4444. ;-- Set colors to include changes
  4445. HE_SetColors($QAHKGUI_hEdit,$Colors)
  4446.  
  4447. ;-- Font and font size
  4448. HE_SetFont($QAHKGUI_hEdit,"s" . $FontSize . A_Space . $FontStyle . "," . $Font)
  4449.  
  4450. ;-- Keywords file
  4451. HE_SetKeywordFile($LibDir . "\KeyWords.hes")
  4452.  
  4453. ;-- Tab width
  4454. if $TabWidth
  4455. HE_SetTabWidth($QAHKGUI_hEdit,$TabWidth)
  4456.  
  4457. ;-- Auto indent
  4458. if $AutoIndent
  4459. HE_AutoIndent($QAHKGUI_hEdit,True)
  4460.  
  4461. ;-- Line numbers bar
  4462. if $LineNumbersBar
  4463. HE_LineNumbersBar($QAHKGUI_hEdit,"autosize")
  4464.  
  4465. ;--------------
  4466. ;-- Status bar
  4467. ;--------------
  4468. gui Add
  4469. ,StatusBar
  4470. ,Hidden
  4471. || v$QAHKGUI_StatusBar
  4472.  
  4473. if $ShowStatusbar
  4474. GUIControl Show,$QAHKGUI_StatusBar
  4475.  
  4476. ;-- Get statusbar statistics
  4477. GUIControlGet $StatusBar,Pos,$QAHKGUI_StatusBar
  4478.  
  4479. ;-- Programming note: Status bar must be added before the toolbar so
  4480. ; that the window can be autosized... ##### need to finish this thought...
  4481.  
  4482. ;-----------
  4483. ;-- Toolbar
  4484. ;-----------
  4485. gosub QAHKGUI_AddToolbar
  4486.  
  4487.  
  4488. ;-- Collect toolbar height
  4489. $ToolbarH:=Toolbar_GetRect($hToolbar,"","h")+2
  4490. ;-- Note: +2 is added because Toolbar_GetRect doesn't account for a 2-pixel
  4491. ; line top border.
  4492. ;
  4493. ;-- Programming notes: The Toolbar_GetRect is a tiny bit faster than the
  4494. ; ControlGetPos command. Also, the values returned differs (for both
  4495. ; commands), sometimes in unexpected ways, depending on which options are
  4496. ; used when the toolbar is created.
  4497.  
  4498. ;-- Toolbar showing?
  4499. if $ShowToolbar
  4500. {
  4501. ;-- Move HiEdit control to accommodate the Toolbar
  4502. ControlGetPos X,Y,W,H,,ahk_id %$QAHKGUI_hEdit%
  4503. ControlMove,,,% Y+$ToolbarH,,% H-$ToolbarH,ahk_id %$QAHKGUI_hEdit%
  4504. }
  4505. else
  4506. Control Hide,,,ahk_id %$hToolbar%
  4507.  
  4508. ;-- Process parameters (if any)
  4509. gosub ProcessParameters
  4510.  
  4511. ;-- Load workspace
  4512. gosub LoadWorkspace
  4513.  
  4514. ;-- Backup workspace
  4515. gosub BackupWorkspace
  4516.  
  4517. ;-- Set focus
  4518. ControlFocus,,ahk_id %$QAHKGUI_hEdit%
  4519.  
  4520. ;---------------------------------------------------------- Not sure of this location
  4521. ;--- Initialize menu values
  4522. gosub QAHKGUI_MenuAction
  4523.  
  4524. ;[============]
  4525. ;[ Show it! ]
  4526. ;[============]
  4527. ;-- Set/Restore window position
  4528. DetectHiddenWindows On
  4529. if $WindowX is Space
  4530. {
  4531. $WindowW:=600
  4532. $WindowH:=400
  4533. $WindowX:=Round($MonitorWorkAreaLeft+(($MonitorWorkAreaWidth-$WindowW)/2))
  4534. $WindowY:=Round($MonitorWorkAreaTop+(($MonitorWorkAreaBottom-$WindowH)/2))
  4535. }
  4536.  
  4537. WinMove ahk_id %$QAHKGUI_hWnd%,,%$WindowX%,%$WindowY%,%$WindowW%,%$WindowH%
  4538. DetectHiddenWindows Off
  4539.  
  4540. ;-- Show it
  4541. if $Saved_WindowMaximized
  4542. gui Show,Maximize
  4543. else
  4544. gui Show
  4545.  
  4546. return
  4547.  
  4548.  
  4549.  
  4550. ;*********************
  4551. ;* *
  4552. ;* Add Toolbar *
  4553. ;* (QAHKGUI) *
  4554. ;* *
  4555. ;*********************
  4556. QAHKGUI_AddToolbar:
  4557.  
  4558. ;[=========================]
  4559. ;[ Render but don't show ]
  4560. ;[=========================]
  4561. gui Show,% "w" . $MaxGUIW . " h300 AutoSize Hide",%$ScriptName%
  4562. ;-- Programming note: The window must be rendered in order for the Toolbar
  4563. ; feature to work. The AutoSize option is necessary to make sure that the
  4564. ; status bar is taken into consideration.
  4565.  
  4566. ;[==================]
  4567. ;[ Create toolbar ]
  4568. ;[==================]
  4569. $hToolbar:=Toolbar_Add($QAHKGUI_hWnd,"QAHKGUI_OnToolbar","Adjustable Flat List ToolTips Wrapable","")
  4570. ;-- Programming note: The toolbar is created with no image list. The
  4571. ; ImageList parameter must be set to blank or the default image list (1L)
  4572. ; will be created and assigned.
  4573.  
  4574. ;[=======================]
  4575. ;[ Create and populate ]
  4576. ;[ small and large ILs ]
  4577. ;[=======================]
  4578. Loop 2
  4579. {
  4580. if A_Index=1
  4581. {
  4582. $TBIconSize:=16
  4583. $TBIconSizeA:="Small"
  4584. }
  4585. else
  4586. {
  4587. $TBIconSize:=24
  4588. $TBIconSizeA:="Large"
  4589. }
  4590.  
  4591. ;[=====================]
  4592. ;[ Create image list ]
  4593. ;[=====================]
  4594. $hToolbar%$TBIconSizeA%IL:=DllCall("ImageList_Create"
  4595. ,"Int",$TBIconSize ;-- cx (The width, in pixels, of each image)
  4596. ,"Int",$TBIconSize ;-- cy (The height, in pixels, of each image)
  4597. ,"UInt",0x21 ;-- flags
  4598. ,"Int",300 ;-- cInitial
  4599. ,"Int",10) ;-- cGrow
  4600.  
  4601. $hToolbar%$TBIconSizeA%IL2:=DllCall("ImageList_Create"
  4602. ,"Int",$TBIconSize ;-- cx (The width, in pixels, of each image)
  4603. ,"Int",$TBIconSize ;-- cy (The height, in pixels, of each image)
  4604. ,"UInt",0x21 ;-- flags
  4605. ,"Int",300 ;-- cInitial
  4606. ,"Int",10) ;-- cGrow
  4607.  
  4608. ;-- Programming note: AutoHotkey's IL_Create command can be used if
  4609. ; small (16x16) or medium (32x32) icons are used but does not work for
  4610. ; toolbar (24x24) icons.
  4611.  
  4612. ;[====================]
  4613. ;[ Attach imagelist ]
  4614. ;[ to the toolbar ]
  4615. ;[====================]
  4616. Toolbar_SetImageList($hToolbar,$hToolbar%$TBIconSizeA%IL)
  4617. ; Programming note: The toolbar is assigned an empty image list.
  4618. ; Images are added later but before buttons are added. Creating a
  4619. ; toolbar with images already loaded doesn't work if using a mix
  4620. ; of standard (catalog) icons and "other" icons.
  4621.  
  4622. ;[======================]
  4623. ;[ Add standard icons ]
  4624. ;[ to the image list ]
  4625. ;[======================]
  4626. SendMessage TB_LOADIMAGES,IDB_STD_%$TBIconSizeA%_COLOR,HINST_COMMCTRL,,ahk_id %$hToolbar%
  4627. ;-- Standard icons (Catalog 1) - 15 icons
  4628. ; Icons 1-15
  4629.  
  4630. SendMessage TB_LOADIMAGES,IDB_VIEW_%$TBIconSizeA%_COLOR,HINST_COMMCTRL,,ahk_id %$hToolbar%
  4631. ;-- View icons (Catalog 2) - 12 icons
  4632. ; Icons 16-27
  4633.  
  4634. SendMessage TB_LOADIMAGES,IDB_HIST_%$TBIconSizeA%_COLOR,HINST_COMMCTRL,,ahk_id %$hToolbar%
  4635. ;-- Windows Explorer travel buttons and favorites (Catalog 3) - 5 icons
  4636. ; Icons 28-32
  4637.  
  4638. ;-- Programming note: The standard (catalog) images are added to the IL
  4639. ; via messages to the toolbar. It would be nice if the images could be
  4640. ; added directly to the IL but I haven't figured out a way to do it.
  4641.  
  4642. ;[========================]
  4643. ;[ Selected shell icons ]
  4644. ;[========================]
  4645. ;-- Icons 33, 34, 35
  4646. $shell32List:="23,24,166"
  4647. Loop Parse,$shell32List,`,
  4648. IL_AddIcon($hToolbar%$TBIconSizeA%IL,"shell32.dll",A_LoopField,$TBIconSize)
  4649.  
  4650. ;[==================]
  4651. ;[ Resource icons ]
  4652. ;[==================]
  4653. ;-- Icons 36 thru 69
  4654. Loop 34
  4655. IL_AddIcon($hToolbar%$TBIconSizeA%IL,$LibDir . "\QuickAHK.dll",A_Index,$TBIconSize)
  4656. }
  4657.  
  4658.  
  4659. Toolbar_SetImageList($hToolbar,$hToolbar%$TBIconSizeA%IL2)
  4660. ; Programming note: The toolbar is assigned an empty image list.
  4661. ; Images are added later but before buttons are added. Creating a
  4662. ; toolbar with images already loaded doesn't work if using a mix
  4663. ; of standard (catalog) icons and "other" icons.
  4664.  
  4665. ;[======================]
  4666. ;[ Add standard icons ]
  4667. ;[ to the image list ]
  4668. ;[======================]
  4669. SendMessage TB_LOADIMAGES,IDB_STD_%$TBIconSizeA%_COLOR,HINST_COMMCTRL,,ahk_id %$hToolbar%
  4670. ;-- Standard icons (Catalog 1) - 15 icons
  4671. ; Icons 1-15
  4672.  
  4673. SendMessage TB_LOADIMAGES,IDB_VIEW_%$TBIconSizeA%_COLOR,HINST_COMMCTRL,,ahk_id %$hToolbar%
  4674. ;-- View icons (Catalog 2) - 12 icons
  4675. ; Icons 16-27
  4676. ;*********************************************
  4677. ; need an alternate method to load these 5 icons in different order
  4678. SendMessage TB_LOADIMAGES,IDB_HIST_%$TBIconSizeA%_COLOR,HINST_COMMCTRL,,ahk_id %$hToolbar%
  4679. ;-- Windows Explorer travel buttons and favorites (Catalog 3) - 5 icons
  4680. ; Icons 28-32
  4681. ;*********************************************
  4682.  
  4683. ;[========================]
  4684. ;[ Selected shell icons ]
  4685. ;[========================]
  4686. ;-- Icons 33, 34, 35
  4687. $shell32List:="23,24,166"
  4688. Loop Parse,$shell32List,`,
  4689. IL_AddIcon($hToolbar%$TBIconSizeA%IL2,"shell32.dll",A_LoopField,$TBIconSize)
  4690.  
  4691. ;[==================]
  4692. ;[ Resource icons ]
  4693. ;[==================]
  4694. ;-- Icons 36 thru 69
  4695. Loop 34 {
  4696. IL_AddIcon($hToolbar%$TBIconSizeA%IL2,$LibDir . "\QuickAHK.dll",A_Index,$TBIconSize)
  4697. }
  4698. Toolbar_SetImageList($hToolbar,$hToolbar%$TBIconSizeA%IL)
  4699.  
  4700. ;[=========================]
  4701. ;[ Build toolbar buttons ]
  4702. ;[=========================]
  4703. if $ToolbarButtons is Space
  4704. $ToolbarButtons=
  4705. (ltrim
  4706. New,7
  4707. Copy From...,8
  4708. Save,9
  4709. Create Restore Point,42
  4710. -
  4711. Print,15
  4712. -
  4713. Revert,59
  4714. Restore,58
  4715. -
  4716. Find,33,,Dropdown
  4717. -
  4718. PasteC,56
  4719. -
  4720. Undo,4
  4721. Redo,5
  4722. -
  4723. Run,61,,Dropdown
  4724. Stop,67
  4725. -
  4726. Options,35
  4727. Help,34
  4728.  
  4729. *New,7,,Dropdown
  4730. *Prepend New,57
  4731. *Save,9,,Dropdown
  4732. *Save To,65
  4733. *Page Setup,55
  4734. *Print,15,,Dropdown
  4735. *Find,33
  4736. *Find,13,,Dropdown
  4737. *Find,13
  4738. *Find Next,48
  4739. *Find Previous,49
  4740. *Replace,14
  4741. *Go To...,50
  4742. *Cut,1
  4743. *Copy,2
  4744. *Paste,3
  4745. *Clear,6
  4746. *Block Comment,38
  4747. *Block Uncomment,39
  4748. *Uppercase,69
  4749. *Lowercase,53
  4750. *Capitalize,40
  4751. *Toggle Case,68
  4752. *Increase Font Size,51
  4753. *Decrease Font Size,43
  4754. *Default Font Size,44
  4755. *Run,61
  4756. *Run Selected,60
  4757. *Explore Run Workspace,46
  4758. *Clear Run Workspace,41
  4759. *Always On Top,37
  4760. *External Editor,47
  4761. *Toggle Line Numbers Bar,52
  4762. *Toggle Menu Bar,54
  4763. *Toggle Toolbar Icon Size,16
  4764. *Toggle Status Bar,66
  4765. *Toggle RunDebug,62
  4766. *Toggle RunPrompt,63
  4767. *Toggle RunWait,64
  4768. *Help,34,,Dropdown
  4769. *About,36
  4770. *Exit,45
  4771. )
  4772.  
  4773. ; Programming notes
  4774. ; -----------------
  4775. ; The button labels have a direct relationship to routine names in this
  4776. ; script. Do not change the value of the labels without changing the
  4777. ; associated routine names.
  4778. ;
  4779. ; Buttons that may look to be duplicates are either buttons with different
  4780. ; icons and/or buttons with/without a dropdown. These additional buttons give
  4781. ; the user a few options that are different than the standard buttons.
  4782.  
  4783. ;[=========================]
  4784. ;[ Change button padding ]
  4785. ;[=========================]
  4786. ;-- Collect initial cxPad and cyPad values (padding inside the toolbar buttons)
  4787. VarSetCapacity(TBMETRICS_Structure,32,0)
  4788. NumPut(32,TBMETRICS_Structure,0,"UInt") ;-- cbSize
  4789. NumPut(TBMF_PAD,TBMETRICS_Structure,4,"Int") ;-- dwMask
  4790. SendMessage TB_GETMETRICS,0,&TBMETRICS_Structure,,ahk_id %$hToolbar%
  4791.  
  4792. cxPad :=NumGet(TBMETRICS_Structure,8,"Int")
  4793. cyPad :=NumGet(TBMETRICS_Structure,12,"Int")
  4794. ;-- Programming note: The cxPad and cYPad values collected here are reused
  4795. ; if/when the toolbar is changed.
  4796.  
  4797. ;-- Any active dropdown buttons?
  4798. Loop Parse,$ToolbarButtons,`n
  4799. {
  4800. if SubStr(A_LoopField,1,1)="-" ;-- Spacer
  4801. Continue
  4802.  
  4803. if SubStr(A_LoopField,1,1)="*" ;-- Inactive button
  4804. Continue
  4805.  
  4806. ;-- Active dropdown button?
  4807. if A_LoopField contains DropDown
  4808. {
  4809. ;-- Set cyPad (height of the padding inside the toolbar buttons) to 0
  4810. VarSetCapacity(TBMETRICS_Structure,32,0)
  4811. NumPut(32,TBMETRICS_Structure,0,"UInt") ;-- cbSize
  4812. NumPut(TBMF_PAD,TBMETRICS_Structure,4,"Int") ;-- dwMask
  4813. NumPut(cxPad,TBMETRICS_Structure,8,"Int") ;-- cxPad
  4814. NumPut(0,TBMETRICS_Structure,12,"Int") ;-- cyPad
  4815. SendMessage TB_SETMETRICS,0,&TBMETRICS_Structure,,ahk_id %$hToolbar%
  4816. ;-- Programming note: This step recovers ~6 of the 8 pixels of
  4817. ; height that is added to all buttons when at least one button
  4818. ; with dropdown style is shown on the toolbar. Without this step,
  4819. ; the buttons look too tall. I'm still looking for a better way
  4820. ; to recover this extra space but this works OK for now.
  4821. ;
  4822.  
  4823. Break ;-- We're done here
  4824. }
  4825. }
  4826.  
  4827. ;[======================]
  4828. ;[ Assign appropriate ]
  4829. ;[ IL to the toolbar ]
  4830. ;[======================]
  4831. Toolbar_SetImageList($hToolbar,$hToolbar%$ToolbarIconSize%IL)
  4832.  
  4833. ;[==================]
  4834. ;[ Add buttons to ]
  4835. ;[ the toolbar ]
  4836. ;[==================]
  4837. Toolbar_SetButtonWidth($hToolbar,40)
  4838. ;-- This option only works if the "List" style is not used
  4839.  
  4840. Toolbar_Insert($hToolbar,$ToolbarButtons)
  4841.  
  4842. ;-- Find IDs for buttons that will accessed in other routines
  4843. $Toolbar_AOTButtonID :=0
  4844. $Toolbar_RunButtonList :="" ;-- List of "Run" and "Run Selected" buttons
  4845. $Toolbar_RunPromptButtonID :=0
  4846. $Toolbar_RunDebugButtonID :=0
  4847. $Toolbar_RunWaitButtonID :=0
  4848. Loop 2
  4849. {
  4850. if A_Index=1
  4851. {
  4852. $Index=1
  4853. $Increment=1
  4854. $MaxIndex:=Toolbar_Count($hToolbar,"c") ;-- Current icons only
  4855. }
  4856. else
  4857. {
  4858. $Index=-1
  4859. $Increment=-1
  4860. $MaxIndex:=Toolbar_Count($hToolbar,"a") ;-- Available icons only
  4861. }
  4862.  
  4863. While (Abs($Index)<=$MaxIndex)
  4864. {
  4865. ;-- Aways On Top
  4866. if InStr(Toolbar_GetButton($hToolbar,$Index,"C"),"Always On Top")
  4867. $Toolbar_AOTButtonID:="." . Toolbar_GetButton($hToolbar,$Index,"ID")
  4868.  
  4869. ;-- "Run" or "Run Selected" buttons
  4870. $Pos:=InStr(Toolbar_GetButton($hToolbar,$Index,"C") . A_Space,"Run ")
  4871. if $Pos in 1,2
  4872. if not $Toolbar_RunButtonList
  4873. $Toolbar_RunButtonList:="." . Toolbar_GetButton($hToolbar,$Index,"ID")
  4874. else
  4875. $Toolbar_RunButtonList:=$Toolbar_RunButtonList
  4876. . ",."
  4877. . Toolbar_GetButton($hToolbar,$Index,"ID")
  4878.  
  4879. ;-- Run Prompt
  4880. if InStr(Toolbar_GetButton($hToolbar,$Index,"C"),"RunPrompt")
  4881. $Toolbar_RunPromptButtonID:="." . Toolbar_GetButton($hToolbar,$Index,"ID")
  4882.  
  4883. ;-- Run Debug
  4884. if InStr(Toolbar_GetButton($hToolbar,$Index,"C"),"RunDebug")
  4885. $Toolbar_RunDebugButtonID:="." . Toolbar_GetButton($hToolbar,$Index,"ID")
  4886.  
  4887. ;-- "RunWait"
  4888. if InStr(Toolbar_GetButton($hToolbar,$Index,"C"),"RunWait")
  4889. $Toolbar_RunWaitButtonID:="." . Toolbar_GetButton($hToolbar,$Index,"ID")
  4890.  
  4891. ;-- Bump index
  4892. $Index:=$Index+$Increment
  4893. }
  4894. }
  4895.  
  4896. ;-- Set initial button state
  4897. gosub QAHKGUI_SetToolbarButtonState
  4898. return
  4899.  
  4900.  
  4901. ;***************************
  4902. ;* *
  4903. ;* Set toolbar state *
  4904. ;* (QAHKGUI) *
  4905. ;* *
  4906. ;***************************
  4907. QAHKGUI_SetToolbarButtonState:
  4908. SetTimer %A_ThisLabel%,Off
  4909.  
  4910. ;-- Always On Top
  4911. if $Toolbar_AOTButtonID
  4912. if $AlwaysOnTop
  4913. Toolbar_SetButton($hToolbar,$Toolbar_AOTButtonID,"Checked")
  4914. else
  4915. Toolbar_SetButton($hToolbar,$Toolbar_AOTButtonID,"-Checked")
  4916.  
  4917. ;-- Run and Run Selected
  4918. if $Toolbar_RunButtonList
  4919. if $Running
  4920. Loop Parse,$Toolbar_RunButtonList,`,
  4921. Toolbar_SetButton($hToolbar,A_LoopField,"Disabled")
  4922. else
  4923. Loop Parse,$Toolbar_RunButtonList,`,
  4924. Toolbar_SetButton($hToolbar,A_LoopField,"-Disabled")
  4925.  
  4926. ;-- RunPrompt
  4927. if $Toolbar_RunPromptButtonID
  4928. if $RunPrompt
  4929. Toolbar_SetButton($hToolbar,$Toolbar_RunPromptButtonID,"Checked")
  4930. else
  4931. Toolbar_SetButton($hToolbar,$Toolbar_RunPromptButtonID,"-Checked")
  4932.  
  4933. ;-- RunDebug
  4934. if $Toolbar_RunDebugButtonID
  4935. if $RunDebug
  4936. Toolbar_SetButton($hToolbar,$Toolbar_RunDebugButtonID,"Checked")
  4937. else
  4938. Toolbar_SetButton($hToolbar,$Toolbar_RunDebugButtonID,"-Checked")
  4939.  
  4940. ;-- RunWait
  4941. if $Toolbar_RunWaitButtonID
  4942. if $RunWait
  4943. Toolbar_SetButton($hToolbar,$Toolbar_RunWaitButtonID,"Checked")
  4944. else
  4945. Toolbar_SetButton($hToolbar,$Toolbar_RunWaitButtonID,"-Checked")
  4946.  
  4947. return
  4948. ;-- Programming note: This routine is called once on startup and again
  4949. ; if/when the toolbar buttons change.
  4950.  
  4951.  
  4952.  
  4953. ;------------------------------------------------------------ Temporary location
  4954. ;-- Some code for this function extracted from the MI_ExtractIcon
  4955. ; function. Author: Lexikos
  4956. ExtractIcon(p_lpszFile,p_nIconIndex,p_cxIcon,p_cyIcon=0)
  4957. {
  4958. ;-- Static variables
  4959. Static SM_CXSMICON
  4960.  
  4961. ;-- Initialize
  4962. if not SM_CXSMICON
  4963. SysGet SM_CXSMICON,49
  4964.  
  4965. ;-- Parameters
  4966. if p_cyIcon=0
  4967. p_cyIcon:=p_cxIcon
  4968.  
  4969. ;-- If possible, use PrivateExtractIcons (only available for W2K+)
  4970. if A_OSVersion not in WIN_95,WIN_98,WIN_ME,WIN_NT4
  4971. {
  4972. l_Return:=DllCall("PrivateExtractIcons"
  4973. ,"Str",p_lpszFile ;-- lpszFile
  4974. ,"Int",p_nIconIndex-1 ;-- nIconIndex
  4975. ,"Int",p_cxIcon ;-- cxIcon
  4976. ,"Int",p_cyIcon ;-- cyIcon
  4977. ,"UInt*",l_hIcon ;-- *phicon
  4978. ,"UInt*",0 ;-- *piconid
  4979. ,"UInt",1 ;-- nIcons
  4980. ,"UInt",0 ;-- flags
  4981. ,"Int") ;-- Return type
  4982.  
  4983. if (l_Return=-1) or ErrorLevel
  4984. {
  4985. outputdebug,
  4986. (ltrim join
  4987. Function: %A_ThisFunc%: PrivateExtractIcons DllCall
  4988. failure. Return=%l_Return%, ErrorLevel=%ErrorLevel%
  4989. )
  4990.  
  4991. Return 0
  4992. }
  4993.  
  4994. ;-- Return *icon
  4995. Return l_hIcon
  4996. }
  4997.  
  4998. ;---------------------------
  4999. ;-- Begin code for older OS
  5000. ;---------------------------
  5001. ;-- Extract icons
  5002. l_Return:=DllCall("shell32.dll\ExtractIconExA"
  5003. ,"Str",p_lpszFile ;-- lpszFile
  5004. ,"Int",p_nIconIndex-1 ;-- nIconIndex
  5005. ,"UInt*",l_hIconLarge ;-- *phiconLarge
  5006. ,"UInt*",l_hIconSmall ;-- *phiconSmall
  5007. ,"UInt",1) ;-- nIcons (Number of icons to extract)
  5008.  
  5009. ;-- Anything found?
  5010. if not l_Return
  5011. Return 0
  5012.  
  5013. ;-- Decide which icon to use. Destroy the other.
  5014. if (p_cxIcon<=SM_CXSMICON)
  5015. {
  5016. l_hIcon:=l_hIconSmall
  5017. DllCall("DeStroyIcon","UInt",l_hIconLarge)
  5018. }
  5019. else
  5020. {
  5021. l_hIcon:=l_hIconLarge
  5022. DllCall("DeStroyIcon","UInt",l_hIconSmall)
  5023. }
  5024.  
  5025. ;-- Convert icon to the desired size
  5026. if l_hIcon and p_cxIcon
  5027. l_hIcon:=DllCall("CopyImage"
  5028. ,"UInt",l_hIcon ;-- hImage
  5029. ,"UInt",0x1 ;-- uType (0x1=IMAGE_ICON)
  5030. ,"Int",p_cxIcon ;-- cxDesired
  5031. ,"Int",p_cyIcon ;-- cyDesired
  5032. ,"UInt",0x4|0x8) ;-- fuFlags
  5033. ;-- 0x4=LR_COPYDELETEORG - Delete original after copy.
  5034. ;-- 0x8=LR_COPYRETURNORG - Returns original if size matches the
  5035. ; requested size.
  5036.  
  5037. ;-- Return to sender
  5038. Return l_hIcon ? l_hIcon:0
  5039. }
  5040.  
  5041. IL_AddIcon(p_hIL,p_lpszFile,p_nIconIndex,p_cxIcon,p_cyIcon=0)
  5042. {
  5043. ;-- Initialize
  5044. if p_cyIcon=0
  5045. p_cyIcon:=p_cxIcon
  5046.  
  5047. ;-- Extract icon
  5048. l_hIcon:=ExtractIcon(p_lpszFile,p_nIconIndex,p_cxIcon,p_cyIcon=0)
  5049.  
  5050. ;-- Icon not found?
  5051. if not l_hIcon
  5052. Return False
  5053.  
  5054. ;-- Add icon to the IL
  5055. DllCall("ImageList_ReplaceIcon"
  5056. ,"UInt",p_hIL ;-- himl
  5057. ,"Int",-1 ;-- i (if -1, image appended to the end)
  5058. ,"UInt",l_hIcon) ;-- hicon
  5059.  
  5060. ;-- Destroy icon
  5061. DllCall("DeStroyIcon","UInt",l_hIcon)
  5062.  
  5063. ;-- Return icon # added to the image list
  5064. Return DllCall("ImageList_GetImageCount","UInt",p_hIL)
  5065. }
  5066. ;-------------------------------------------------------- End Temporary location
  5067.  
  5068.  
  5069. ;*******************
  5070. ;* *
  5071. ;* Resize *
  5072. ;* (QAHKGUI) *
  5073. ;* *
  5074. ;*******************
  5075. QAHKGUI_Size:
  5076.  
  5077. ;-- Bounce?
  5078. if not $Resize
  5079. return
  5080.  
  5081. ;-- Minimize?
  5082. $WindowMinimized:=False
  5083. if A_EventInfo=1
  5084. {
  5085. $WindowMinimized:=True
  5086. return ;-- Nothing else to do here
  5087. }
  5088.  
  5089. ;-- Maximize?
  5090. $WindowMaximized:=False
  5091. if A_EventInfo=2
  5092. {
  5093. $WindowMaximized:=True
  5094. Sleep 75 ;-- Give the window a chance to render
  5095. }
  5096.  
  5097. ;-- Move it!
  5098. ControlMove,,,,%A_GuiWidth%,% A_GuiHeight-(($ShowToolbar) ? $ToolBarH:0)-(($ShowStatusbar) ? $StatusBarH:0),ahk_id %$QAHKGUI_hEdit%
  5099. return
  5100.  
  5101.  
  5102. ;*********************
  5103. ;* *
  5104. ;* Drag & Drop *
  5105. ;* (QAHKGUI) *
  5106. ;* *
  5107. ;*********************
  5108. QAHKGUI_DropFiles:
  5109.  
  5110. ;-- Create resore point?
  5111. if $CreateRPOnCopyfromDrop
  5112. RPCreate()
  5113.  
  5114. ;-- Get the first file
  5115. Loop Parse,A_GuiControlEvent,`n,`r
  5116. {
  5117. $DropFile=%A_LoopField% ;-- Assign and AutoTrim
  5118. Break
  5119. }
  5120.  
  5121. ;-- Copy dropped file over workspace file
  5122. FileCopy %$DropFile%,%$EditFile%,1 ;-- 1=overwrite
  5123. If ErrorLevel
  5124. {
  5125. ;-- Notify the user
  5126. gui +OwnDialogs
  5127. MsgBox
  5128. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  5129. ,Drop File Error
  5130. ,Unable to copy the dropped file to the workspace. %A_Space%
  5131.  
  5132. return
  5133. }
  5134.  
  5135. ;-- Reset file attributes
  5136. FileSetAttrib -RSH,%$EditFile%
  5137.  
  5138. ;-- Reload workspace
  5139. gosub LoadWorkspace
  5140.  
  5141. ;-- Push to $RecentFiles and reload menu
  5142. MRUManager($RecentFiles,"Push",$DropFile,"|",9)
  5143. gosub QAHKGUI_ReloadRecentFilesMenu
  5144.  
  5145. ;-- Update status bar
  5146. SB_SetText("Contents of " . CompressFileName($DropFile,65) . " copied to the workspace.")
  5147. SetTimer QAHKGUI_ClearStatusBar,25000
  5148. return
  5149.  
  5150.  
  5151. ;;;;;QAHKGUI_ContextMenu:
  5152. ;-- This label is not used because it only fires when the mouse is not over
  5153. ; the HiEdit control (Ex: toolbar)
  5154.  
  5155. QAHKGUI_ContextMenu2: ;---------- Better name than ...Menu2?
  5156. SetTimer %A_ThisLabel%,Off
  5157.  
  5158. ;-- Mouse over the HiEdit control?
  5159. MouseGetPos,,,,$MousePos_ControlhWnd,2
  5160. if ($MousePos_ControlhWnd=$QAHKGUI_hEdit)
  5161. {
  5162. ;-- Update and show menu
  5163. gosub QAHKGUI_UpdateContextMenu
  5164. Menu QAHKGUI_ContextMenu,Show,%A_GuiX%,%A_GuiY%
  5165. }
  5166.  
  5167.  
  5168. return
  5169.  
  5170.  
  5171. ;*****************************
  5172. ;* *
  5173. ;* Update Context Menu *
  5174. ;* (QAHKGUI) *
  5175. ;* *
  5176. ;*****************************
  5177. QAHKGUI_UpdateContextMenu:
  5178.  
  5179. ;-- Undo
  5180. if HE_CanUndo($QAHKGUI_hEdit)
  5181. Menu QAHKGUI_ContextMenu,Enable,%s_Undo_MI%
  5182. else
  5183. Menu QAHKGUI_ContextMenu,Disable,%s_Undo_MI%
  5184.  
  5185. ;-- Redo
  5186. if HE_CanRedo($QAHKGUI_hEdit)
  5187. Menu QAHKGUI_ContextMenu,Enable,%s_Redo_MI%
  5188. else
  5189. Menu QAHKGUI_ContextMenu,Disable,%s_Redo_MI%
  5190.  
  5191. ;-- Get select positions
  5192. HE_GetSel($QAHKGUI_hEdit,$StartSelPos,$EndSelPos)
  5193.  
  5194. ;-- Cut, Copy, Delete, Convert Case, and Run Selected
  5195. if ($StartSelPos<>$EndSelPos)
  5196. {
  5197. Menu QAHKGUI_ContextMenu,Enable,%s_Cut_MI%
  5198. Menu QAHKGUI_ContextMenu,Enable,%s_Copy_MI%
  5199. Menu QAHKGUI_ContextMenu,Enable,%s_Delete_MI%
  5200. Menu QAHKGUI_ContextMenu,Enable,%s_ConvertCase_MI%
  5201. Menu QAHKGUI_ContextMenu,Enable,%s_RunSelected_MI%
  5202. }
  5203. else
  5204. {
  5205. Menu QAHKGUI_ContextMenu,Disable,%s_Cut_MI%
  5206. Menu QAHKGUI_ContextMenu,Disable,%s_Copy_MI%
  5207. Menu QAHKGUI_ContextMenu,Disable,%s_Delete_MI%
  5208. Menu QAHKGUI_ContextMenu,Disable,%s_ConvertCase_MI%
  5209. Menu QAHKGUI_ContextMenu,Disable,%s_RunSelected_MI%
  5210. }
  5211.  
  5212. ;-- Paste
  5213. if HE_CanPaste($QAHKGUI_hEdit)
  5214. {
  5215. Menu QAHKGUI_ContextMenu,Enable,%s_Paste_MI%
  5216. Menu QAHKGUI_ContextMenu,Enable,%s_PasteC_MI%
  5217. }
  5218. else
  5219. {
  5220. Menu QAHKGUI_ContextMenu,Disable,%s_Paste_MI%
  5221. Menu QAHKGUI_ContextMenu,Disable,%s_PasteC_MI%
  5222. }
  5223.  
  5224. return
  5225.  
  5226.  
  5227. ;*********************
  5228. ;* *
  5229. ;* Menu Action *
  5230. ;* (QAHKGUI) *
  5231. ;* *
  5232. ;*********************
  5233. QAHKGUI_MenuAction:
  5234.  
  5235. if A_ThisMenu is Space
  5236. {
  5237. ;-- Initial View menu values
  5238. if $AlwaysOnTop
  5239. Menu QAHKGUI_ViewMenu,Check,%s_AlwaysOnTop_MI%
  5240.  
  5241. if $ShowMenuBar
  5242. Menu QAHKGUI_ViewMenu,Check,%s_MenuBar_MI%
  5243.  
  5244. if $ShowToolBar
  5245. Menu QAHKGUI_ViewMenu,Check,%s_ToolBar_MI%
  5246.  
  5247. if $LineNumbersBar
  5248. Menu QAHKGUI_ViewMenu,Check,%s_LineNumbersBar_MI%
  5249.  
  5250. if $ShowStatusBar
  5251. Menu QAHKGUI_ViewMenu,Check,%s_StatusBar_MI%
  5252.  
  5253.  
  5254. ;-- Initial Run menu values
  5255. if $RunPrompt
  5256. Menu QAHKGUI_RunMenu,Check,%s_RunPrompt_MI%
  5257.  
  5258. if $RunDebug
  5259. Menu QAHKGUI_RunMenu,Check,%s_RunDebug_MI%
  5260.  
  5261. if $RunWait
  5262. Menu QAHKGUI_RunMenu,Check,%s_RunWait_MI%
  5263.  
  5264. if $ClearRunWorkspaceOnRun
  5265. Menu QAHKGUI_RunMenu,Check,%s_ClearRunWorkspaceOnRun_MI%
  5266.  
  5267. if $ClearRunWorkspaceOnExit
  5268. Menu QAHKGUI_RunMenu,Check,%s_ClearRunWorkspaceOnExit_MI%
  5269. }
  5270. else
  5271. {
  5272. ;-- Toggle
  5273. if A_ThisMenu=QAHKGUI_ViewMenu
  5274. {
  5275. if (A_ThisMenuItem=s_AlwaysOnTop_MI)
  5276. gosub QAHKGUI_ToggleAlwaysOnTop
  5277.  
  5278. if (A_ThisMenuItem=s_MenuBar_MI)
  5279. gosub QAHKGUI_ToggleMenuBar
  5280.  
  5281. if (A_ThisMenuItem=s_ToolBar_MI)
  5282. gosub QAHKGUI_ToggleToolbar
  5283.  
  5284. if (A_ThisMenuItem=s_LineNumbersBar_MI)
  5285. gosub QAHKGUI_ToggleLineNumbersBar
  5286.  
  5287. if (A_ThisMenuItem=s_StatusBar_MI)
  5288. gosub QAHKGUI_ToggleStatusBar
  5289. }
  5290. else
  5291. {
  5292. if (A_ThisMenuItem=s_RunPrompt_MI)
  5293. gosub QAHKGUI_ToggleRunPrompt
  5294.  
  5295. if (A_ThisMenuItem=s_RunDebug_MI)
  5296. gosub QAHKGUI_ToggleRunDebug
  5297.  
  5298. if (A_ThisMenuItem=s_RunWait_MI)
  5299. gosub QAHKGUI_ToggleRunWait
  5300.  
  5301. if (A_ThisMenuItem=s_ClearRunWorkspaceOnRun_MI)
  5302. {
  5303. $ClearRunWorkspaceOnRun:=$ClearRunWorkspaceOnRun ? False:True
  5304. Menu QAHKGUI_RunMenu,ToggleCheck,%A_ThisMenuItem%
  5305. }
  5306.  
  5307. if (A_ThisMenuItem=s_ClearRunWorkspaceOnExit_MI)
  5308. {
  5309. $ClearRunWorkspaceOnExit:=$ClearRunWorkspaceOnExit ? False:True
  5310. Menu QAHKGUI_RunMenu,ToggleCheck,%A_ThisMenuItem%
  5311. }
  5312. }
  5313. }
  5314.  
  5315. return
  5316.  
  5317.  
  5318. ;***************************
  5319. ;* *
  5320. ;* Default font size *
  5321. ;* (QAHKGUI) *
  5322. ;* *
  5323. ;***************************
  5324. QAHKGUI_DefaultFontSize:
  5325. SetTimer %A_ThisLabel%,Off
  5326.  
  5327. ;-- Running?
  5328. if $Running
  5329. {
  5330. SoundPlay *-1 ;-- System default sound
  5331. return
  5332. }
  5333.  
  5334. ;-- Set GUI default
  5335. gui %$QAHKGUI%:Default
  5336.  
  5337. ;-- Default font size
  5338. $FontSize:=$DefaultFontSize
  5339. HE_SetFont($QAHKGUI_hEdit,"s" . $FontSize . A_Space . $FontStyle . "," . $Font)
  5340.  
  5341. ;-- Update status bar
  5342. SB_SetText("Default font size set. Font=" . $Font . " Size=" . $FontSize)
  5343. SetTimer QAHKGUI_ClearStatusBar,15000
  5344. return
  5345.  
  5346.  
  5347. ;****************************
  5348. ;* *
  5349. ;* Decrease font size *
  5350. ;* (QAHKGUI) *
  5351. ;* *
  5352. ;****************************
  5353. QAHKGUI_DecreaseFontSize:
  5354. SetTimer %A_ThisLabel%,Off
  5355.  
  5356. ;-- Running?
  5357. if $Running
  5358. {
  5359. SoundPlay *-1 ;-- System default sound
  5360. return
  5361. }
  5362.  
  5363. ;-- Set GUI default
  5364. gui %$QAHKGUI%:Default
  5365.  
  5366. ;-- Decrease font szie
  5367. if ($FontSize>$MinimumFontSize)
  5368. {
  5369. $FontSize--
  5370. HE_SetFont($QAHKGUI_hEdit,"s" . $FontSize . A_Space . $FontStyle . "," . $Font)
  5371.  
  5372. ;-- Update status bar
  5373. SB_SetText("Font size changed. Font=" . $Font . " Size=" . $FontSize)
  5374. SetTimer QAHKGUI_ClearStatusBar,15000
  5375. }
  5376. else
  5377. SoundPlay *-1 ;-- System default sound
  5378.  
  5379. return
  5380.  
  5381.  
  5382. ;****************************
  5383. ;* *
  5384. ;* Increase font size *
  5385. ;* (QAHKGUI) *
  5386. ;* *
  5387. ;****************************
  5388. QAHKGUI_IncreaseFontSize:
  5389. SetTimer %A_ThisLabel%,Off
  5390.  
  5391. ;-- Running?
  5392. if $Running
  5393. {
  5394. SoundPlay *-1 ;-- System default sound
  5395. return
  5396. }
  5397.  
  5398. ;-- Set GUI default
  5399. gui %$QAHKGUI%:Default
  5400.  
  5401. ;-- Increase font size
  5402. if ($FontSize<$MaximumFontSize)
  5403. {
  5404. $FontSize++
  5405. HE_SetFont($QAHKGUI_hEdit,"s" . $FontSize . A_Space . $FontStyle . "," . $Font)
  5406.  
  5407. ;-- Update status bar
  5408. SB_SetText("Font size changed. Font=" . $Font . " Size=" . $FontSize)
  5409. SetTimer QAHKGUI_ClearStatusBar,15000
  5410. }
  5411. else
  5412. SoundPlay *-1 ;-- System default sound
  5413.  
  5414. return
  5415.  
  5416.  
  5417. ;******************************
  5418. ;* *
  5419. ;* Toggle Always On Top *
  5420. ;* (QAHKGUI) *
  5421. ;* *
  5422. ;******************************
  5423. QAHKGUI_AlwaysOnTop:
  5424. QAHKGUI_ToggleAlwaysOnTop:
  5425. SetTimer %A_ThisLabel%,Off
  5426.  
  5427. ;-- Set GUI default
  5428. gui %$QAHKGUI%:Default
  5429.  
  5430. ;-- Toggle
  5431. if $AlwaysOnTop
  5432. {
  5433. gui -AlwaysOnTop
  5434. $AlwaysOnTop:=False
  5435. if $Toolbar_AOTButtonID
  5436. Toolbar_SetButton($hToolbar,$Toolbar_AOTButtonID,"-Checked")
  5437. }
  5438. else
  5439. {
  5440. gui +AlwaysOnTop
  5441. $AlwaysOnTop:=True
  5442. if $Toolbar_AOTButtonID
  5443. Toolbar_SetButton($hToolbar,$Toolbar_AOTButtonID,"Checked")
  5444. }
  5445.  
  5446. ;-- Update menu
  5447. Menu QAHKGUI_ViewMenu
  5448. ,ToggleCheck
  5449. ,%s_AlwaysOnTop_MI%
  5450.  
  5451. ;-- Update status bar
  5452. if not $Running
  5453. {
  5454. SB_SetText("Always On Top " . ($AlwaysOnTop ? "enabled.":"disabled."))
  5455. SetTimer QAHKGUI_ClearStatusBar,8000
  5456. }
  5457.  
  5458. return
  5459.  
  5460.  
  5461. ;*********************************
  5462. ;* *
  5463. ;* Toggle line numbers bar *
  5464. ;* (QAHKGUI) *
  5465. ;* *
  5466. ;*********************************
  5467. QAHKGUI_ToggleLineNumbersBar:
  5468. SetTimer %A_ThisLabel%,Off
  5469.  
  5470. ;-- Running?
  5471. if $Running
  5472. {
  5473. SoundPlay *-1 ;-- System default sound
  5474. return
  5475. }
  5476.  
  5477. ;-- Toggle
  5478. if $LineNumbersBar
  5479. {
  5480. HE_LineNumbersBar($QAHKGUI_hEdit,"hide",0,0)
  5481. $LineNumbersBar:=False
  5482. }
  5483. else
  5484. {
  5485. HE_LineNumbersBar($QAHKGUI_hEdit,"autosize")
  5486. $LineNumbersBar:=True
  5487. }
  5488.  
  5489. ;-- Update menu
  5490. Menu QAHKGUI_ViewMenu
  5491. ,ToggleCheck
  5492. ,%s_LineNumbersBar_MI%
  5493.  
  5494. return
  5495.  
  5496.  
  5497. ;************************
  5498. ;* *
  5499. ;* Toggle Menubar *
  5500. ;* (QAHKGUI) *
  5501. ;* *
  5502. ;************************
  5503. QAHKGUI_ToggleMenubar:
  5504. SetTimer %A_ThisLabel%,Off
  5505.  
  5506. ;-- Toggle
  5507. if $ShowMenubar
  5508. {
  5509. gui %$QAHKGUI%:Menu
  5510. $ShowMenubar:=False
  5511. }
  5512. else
  5513. {
  5514. if $Running
  5515. gui %$QAHKGUI%:Menu,QAHKGUI_MenubarRunWait
  5516. else
  5517. gui %$QAHKGUI%:Menu,QAHKGUI_Menubar
  5518.  
  5519. $ShowMenubar:=True
  5520. }
  5521.  
  5522. ;-- Update menu
  5523. Menu QAHKGUI_ViewMenu
  5524. ,ToggleCheck
  5525. ,%s_MenuBar_MI%
  5526.  
  5527. return
  5528.  
  5529.  
  5530. ;************************
  5531. ;* *
  5532. ;* Toggle Toolbar *
  5533. ;* (QAHKGUI) *
  5534. ;* *
  5535. ;************************
  5536. QAHKGUI_ToggleToolbar:
  5537. SetTimer %A_ThisLabel%,Off
  5538.  
  5539. ;-- Toggle
  5540. if $ShowToolbar
  5541. {
  5542. ;-- Hide it
  5543. Control Hide,,,ahk_id %$hToolbar%
  5544. $ShowToolbar:=False
  5545.  
  5546. ;-- Toolbar gone. Move HiEdit control to compensate.
  5547. ControlGetPos X,Y,W,H,,ahk_id %$QAHKGUI_hEdit%
  5548. ControlMove,,,% Y-$ToolbarH,,% H+$ToolbarH,ahk_id %$QAHKGUI_hEdit%
  5549. }
  5550. else
  5551. {
  5552. ;-- Show it
  5553. Control Show,,,ahk_id %$hToolbar%
  5554. $ShowToolbar:=True
  5555.  
  5556. ;-- Toolbar is back! Move HiEdit control to compensate.
  5557. ControlGetPos X,Y,W,H,,ahk_id %$QAHKGUI_hEdit%
  5558. ControlMove,,,% Y+$ToolbarH,,% H-$ToolbarH,ahk_id %$QAHKGUI_hEdit%
  5559. WinSet Redraw,,ahk_id %$QAHKGUI_hEdit%
  5560. }
  5561.  
  5562. ;-- Update menu
  5563. Menu QAHKGUI_ViewMenu
  5564. ,ToggleCheck
  5565. ,%s_ToolBar_MI%
  5566.  
  5567. return
  5568.  
  5569.  
  5570. ;**********************************
  5571. ;* *
  5572. ;* Toggle Toolbar Icon Size *
  5573. ;* (QAHKGUI) *
  5574. ;* *
  5575. ;**********************************
  5576. QAHKGUI_ToggleToolbarIconSize:
  5577. SetTimer %A_ThisLabel%,Off
  5578.  
  5579. ;-- Turn off sizing during this exercise
  5580. $Resize:=False
  5581.  
  5582. ;-- If toolbar is showing, move HiEdit control
  5583. if $ShowToolBar
  5584. {
  5585. ;-- Move HiEdit control to assume there is no toolbar
  5586. ControlGetPos X,Y,W,H,,ahk_id %$QAHKGUI_hEdit%
  5587. ControlMove,,,% Y-$ToolbarH,,% H+$ToolbarH,ahk_id %$QAHKGUI_hEdit%
  5588. ;-- Programming note: It's easier to that assume that the current toolbar
  5589. ; doesn't exist ##### need to finish my thought here.
  5590. }
  5591.  
  5592. ;-- Get Current window statistics
  5593. WinGetPos,$WindowX,$WindowY,$WindowW,$WindowH,ahk_id %$QAHKGUI_hWnd%
  5594.  
  5595. ;-- Set to window to max width
  5596. WinMove ahk_id %$QAHKGUI_hWnd%,,%$MonitorWorkAreaLeft%,,% $MaxGUIW+12
  5597. ;-- Haven't figured out why the window can be 12 pixels bigger that the
  5598. ; $MonitorWorkAreaWidth but there you go...
  5599.  
  5600. ;-- Toggle icon size
  5601. if $ToolbarIconSize=Large
  5602. $ToolbarIconSize=Small
  5603. else
  5604. $ToolbarIconSize=Large
  5605.  
  5606. ;-- Set cyPad & cyPad (padding inside the toolbar buttons) to initial values
  5607. VarSetCapacity(TBMETRICS_Structure,32,0)
  5608. NumPut(32,TBMETRICS_Structure,0,"UInt") ;-- cbSize
  5609. NumPut(TBMF_PAD,TBMETRICS_Structure,4,"Int") ;-- dwMask
  5610. NumPut(cxPad,TBMETRICS_Structure,8,"Int") ;-- cxPad
  5611. NumPut(cyPad,TBMETRICS_Structure,12,"Int") ;-- cyPad
  5612. SendMessage TB_SETMETRICS,0,&TBMETRICS_Structure,,ahk_id %$hToolbar%
  5613.  
  5614. ;-- Any active dropdown buttons?
  5615. Loop Parse,$ToolbarButtons,`n
  5616. {
  5617. if SubStr(A_LoopField,1,1)="-" ;-- Spacer
  5618. or SubStr(A_LoopField,1,1)="*" ;-- Inactive button
  5619. Continue
  5620.  
  5621. ;-- Active dropdown button?
  5622. if A_LoopField contains DropDown
  5623. {
  5624. ;-- Set cyPad (height of the padding inside the toolbar buttons) to 0
  5625. VarSetCapacity(TBMETRICS_Structure,32,0)
  5626. NumPut(32,TBMETRICS_Structure,0,"UInt") ;-- cbSize
  5627. NumPut(TBMF_PAD,TBMETRICS_Structure,4,"Int") ;-- dwMask
  5628. NumPut(cxPad,TBMETRICS_Structure,8,"Int") ;-- cxPad
  5629. NumPut(0,TBMETRICS_Structure,12,"Int") ;-- cyPad
  5630. SendMessage TB_SETMETRICS,0,&TBMETRICS_Structure,,ahk_id %$hToolbar%
  5631. ;-- Programming note: This step recovers ~6 of the 8 pixels of
  5632. ; height that is added to all buttons when at least 1 button with
  5633. ; dropdown style is shown on the toolbar. Without this step, the
  5634. ; buttons look too tall. I'm still looking for a better way to
  5635. ; recover this extra space but this works OK for now.
  5636. ;
  5637.  
  5638. Break ;-- We're done here
  5639. }
  5640. }
  5641.  
  5642. ;-- Set to new icon list
  5643. Toolbar_SetImageList($hToolbar,$hToolbar%$ToolbarIconSize%IL)
  5644.  
  5645. ;-- Set button size to smallest possible size. Let AutoSize figure it out.
  5646. Toolbar_SetButtonSize($hToolbar,1,1)
  5647.  
  5648. ;-- Reset window to original width
  5649. WinMove ahk_id %$QAHKGUI_hWnd%,,%$WindowX%,,%$WindowW%
  5650.  
  5651. ;-- Collect new toolbar statistics
  5652. $ToolbarH:=Toolbar_GetRect($hToolbar,"","h")+2
  5653. ;-- Note: +2 is needed because Toolbar_GetRect doesn't account for a 2-pixel
  5654. ; line top border
  5655.  
  5656. ;-- If toolbar is showing, move HiEdit control
  5657. if $ShowToolBar
  5658. {
  5659. ;-- Move HiEdit control to accommodate the new toolbar size
  5660. ControlGetPos X,Y,W,H,,ahk_id %$QAHKGUI_hEdit%
  5661. ControlMove,,,% Y+$ToolbarH,,% H-$ToolbarH,ahk_id %$QAHKGUI_hEdit%
  5662. WinSet Redraw,,ahk_id %$QAHKGUI_hEdit%
  5663. }
  5664.  
  5665. ;-- Restore sizing
  5666. $Resize:=True
  5667. return
  5668.  
  5669.  
  5670. ;**************************
  5671. ;* *
  5672. ;* Toggle Statusbar *
  5673. ;* (QAHKGUI) *
  5674. ;* *
  5675. ;**************************
  5676. QAHKGUI_ToggleStatusbar:
  5677. SetTimer %A_ThisLabel%,Off
  5678.  
  5679. ;-- Toggle
  5680. if $ShowStatusbar
  5681. {
  5682. GUIControl %$QAHKGUI%:Hide,$QAHKGUI_StatusBar
  5683. $ShowStatusbar:=False
  5684.  
  5685. ;-- Move HiEdit control to accommodate the Statusbar
  5686. ControlGetPos X,Y,W,H,,ahk_id %$QAHKGUI_hEdit%
  5687. ControlMove,,,,,% H+$StatusBarH,ahk_id %$QAHKGUI_hEdit%
  5688. }
  5689. else
  5690. {
  5691. GUIControl %$QAHKGUI%:Show,$QAHKGUI_StatusBar
  5692. $ShowStatusbar:=True
  5693.  
  5694. ;-- Move HiEdit control to accommodate the Statusbar
  5695. ControlGetPos X,Y,W,H,,ahk_id %$QAHKGUI_hEdit%
  5696. ControlMove,,,,,% H-$StatusBarH,ahk_id %$QAHKGUI_hEdit%
  5697. }
  5698.  
  5699. ;-- Update menu
  5700. Menu QAHKGUI_ViewMenu
  5701. ,ToggleCheck
  5702. ,%s_StatusBar_MI%
  5703.  
  5704. return
  5705.  
  5706.  
  5707. ;**************************
  5708. ;* *
  5709. ;* Toggle RunPrompt *
  5710. ;* (QAHKGUI) *
  5711. ;* *
  5712. ;**************************
  5713. QAHKGUI_ToggleRunPrompt:
  5714. SetTimer %A_ThisLabel%,Off
  5715.  
  5716. ;-- Running?
  5717. if $Running
  5718. {
  5719. SoundPlay *-1 ;-- System default sound
  5720. return
  5721. }
  5722.  
  5723. ;-- Toggle
  5724. if $RunPrompt
  5725. {
  5726. $RunPrompt:=False
  5727. if $Toolbar_RunPromptButtonID
  5728. Toolbar_SetButton($hToolbar,$Toolbar_RunPromptButtonID,"-Checked")
  5729. }
  5730. else
  5731. {
  5732. $RunPrompt:=True
  5733. if $Toolbar_RunPromptButtonID
  5734. Toolbar_SetButton($hToolbar,$Toolbar_RunPromptButtonID,"Checked")
  5735. }
  5736.  
  5737. ;-- Update menu
  5738. Menu QAHKGUI_RunMenu
  5739. ,ToggleCheck
  5740. ,%s_RunPrompt_MI%
  5741.  
  5742. return
  5743.  
  5744.  
  5745. ;*************************
  5746. ;* *
  5747. ;* Toggle RunDebug *
  5748. ;* (QAHKGUI) *
  5749. ;* *
  5750. ;*************************
  5751. QAHKGUI_ToggleRunDebug:
  5752. SetTimer %A_ThisLabel%,Off
  5753.  
  5754. ;-- Running?
  5755. if $Running
  5756. {
  5757. SoundPlay *-1 ;-- System default sound
  5758. return
  5759. }
  5760.  
  5761. ;-- Toggle
  5762. if $RunDebug
  5763. {
  5764. $RunDebug:=False
  5765. if $Toolbar_RunDebugButtonID
  5766. Toolbar_SetButton($hToolbar,$Toolbar_RunDebugButtonID,"-Checked")
  5767. }
  5768. else
  5769. {
  5770. $RunDebug:=True
  5771. if $Toolbar_RunDebugButtonID
  5772. Toolbar_SetButton($hToolbar,$Toolbar_RunDebugButtonID,"Checked")
  5773. }
  5774.  
  5775. ;-- Update menu
  5776. Menu QAHKGUI_RunMenu
  5777. ,ToggleCheck
  5778. ,%s_RunDebug_MI%
  5779.  
  5780. return
  5781.  
  5782.  
  5783. ;************************
  5784. ;* *
  5785. ;* Toggle RunWait *
  5786. ;* (QAHKGUI) *
  5787. ;* *
  5788. ;************************
  5789. QAHKGUI_ToggleRunWait:
  5790. SetTimer %A_ThisLabel%,Off
  5791.  
  5792. ;-- Running?
  5793. if $Running
  5794. {
  5795. SoundPlay *-1 ;-- System default sound
  5796. return
  5797. }
  5798.  
  5799. ;-- Toggle
  5800. if $RunWait
  5801. {
  5802. $RunWait:=False
  5803. if $Toolbar_RunWaitButtonID
  5804. Toolbar_SetButton($hToolbar,$Toolbar_RunWaitButtonID,"-Checked")
  5805. }
  5806. else
  5807. {
  5808. $RunWait:=True
  5809. if $Toolbar_RunWaitButtonID
  5810. Toolbar_SetButton($hToolbar,$Toolbar_RunWaitButtonID,"Checked")
  5811. }
  5812.  
  5813. ;-- Update menu
  5814. Menu QAHKGUI_RunMenu
  5815. ,ToggleCheck
  5816. ,%s_RunWait_MI%
  5817.  
  5818. return
  5819.  
  5820.  
  5821. ;*******************
  5822. ;* *
  5823. ;* Find *
  5824. ;* (QAHKGUI) *
  5825. ;* *
  5826. ;*******************
  5827. QAHKGUI_Find:
  5828. SetTimer %A_ThisLabel%,Off
  5829.  
  5830. ;-- Running?
  5831. if $Running
  5832. {
  5833. SoundPlay *-1 ;-- System default sound
  5834. return
  5835. }
  5836.  
  5837. ;-- Bounce if Find or Replace dialog is already showing
  5838. IfWinExist ahk_id %Dlg_hWnd%
  5839. return
  5840.  
  5841. ;-- Where are we starting from?
  5842. HE_GetSel($QAHKGUI_hEdit,Dummy,$EndSelectPos)
  5843. if $EndSelectPos=0
  5844. Dlg_FindFromTheTop:=True
  5845. else
  5846. Dlg_FindFromTheTop:=False
  5847.  
  5848. ;-- Anything selected?
  5849. $Selected:=HE_GetSelText($QAHKGUI_hEdit)
  5850. if StrLen($Selected)
  5851. {
  5852. ;-- Ignore if multiple lines are selected
  5853. if InStr($Selected,"`n")=0
  5854. Dlg_FindWhat:=$Selected
  5855. }
  5856.  
  5857. ;-- Show the Find dialog
  5858. Dlg_hWnd :=Dlg_Find($QAHKGUI_hWnd,"QAHKGUI_OnFind",Dlg_Flags,Dlg_FindWhat)
  5859. return
  5860.  
  5861.  
  5862.  
  5863. ;*******************
  5864. ;* *
  5865. ;* Find Next *
  5866. ;* (QAHKGUI) *
  5867. ;* *
  5868. ;*******************
  5869. QAHKGUI_FindNext:
  5870. SetTimer %A_ThisLabel%,Off
  5871.  
  5872. ;-- Running?
  5873. if $Running
  5874. {
  5875. SoundPlay *-1 ;-- System default sound
  5876. return
  5877. }
  5878.  
  5879. ;-- Bounce if Find was never called
  5880. if StrLen(Dlg_FindWhat)=0
  5881. return
  5882.  
  5883. ;-- Save Dlg_Flags
  5884. $Saved_Dlg_Flags:=Dlg_Flags
  5885.  
  5886. ;-- If necessary, update Dlg_Flags
  5887. if Dlg_Flags not contains d
  5888. Dlg_Flags:="d" . Dlg_Flags
  5889.  
  5890. ;-- Find next
  5891. QAHKGUI_OnFind("F",Dlg_Flags,Dlg_FindWhat)
  5892.  
  5893. ;-- Restore Dlg_Flags
  5894. Dlg_Flags :=$Saved_Dlg_Flags
  5895. return
  5896.  
  5897.  
  5898. ;***********************
  5899. ;* *
  5900. ;* Find Previous *
  5901. ;* (QAHKGUI) *
  5902. ;* *
  5903. ;***********************
  5904. QAHKGUI_FindPrevious:
  5905. SetTimer %A_ThisLabel%,Off
  5906.  
  5907. ;-- Running?
  5908. if $Running
  5909. {
  5910. SoundPlay *-1 ;-- System default sound
  5911. return
  5912. }
  5913.  
  5914. ;-- Bounce if Find was never called
  5915. if StrLen(Dlg_FindWhat)=0
  5916. return
  5917.  
  5918. ;-- Save Dlg_Flags
  5919. $Saved_Dlg_Flags:=Dlg_Flags
  5920.  
  5921. ;-- If necessary, update Dlg_Flags
  5922. if Dlg_Flags contains d
  5923. StringReplace Dlg_Flags,Dlg_Flags,d
  5924.  
  5925. ;-- Find previous
  5926. QAHKGUI_OnFind("F",Dlg_Flags,Dlg_FindWhat)
  5927.  
  5928. ;-- Restore Dlg_Flags
  5929. Dlg_Flags :=$Saved_Dlg_Flags
  5930. return
  5931.  
  5932.  
  5933. ;*******************
  5934. ;* *
  5935. ;* Goto *
  5936. ;* (QAHKGUI) *
  5937. ;* *
  5938. ;*******************
  5939. QAHKGUI_Toolbar_Goto:
  5940. SetTimer %A_ThisLabel%,Off
  5941. SetTimer QAHKGUI_GoTo,0
  5942. return
  5943.  
  5944.  
  5945.  
  5946. QAHKGUI_GoTo:
  5947. SetTimer %A_ThisLabel%,Off
  5948.  
  5949. ;-- Running?
  5950. if $Running
  5951. {
  5952. SoundPlay *-1 ;-- System default sound
  5953. return
  5954. }
  5955.  
  5956. ;[===================]
  5957. ;[ Prompt the user ]
  5958. ;[===================]
  5959. gui %$QAHKGUI%:+OwnDialogs
  5960. InputBox $GoToLine,Go To,Line Number:, ,130,130
  5961. if ErrorLevel
  5962. return
  5963.  
  5964. ;-- Adjust GoTo line for zero-based index
  5965. $MaxLineNumber:=HE_GetLineCount($QAHKGUI_hEdit)
  5966. if ($GoToLine>$MaxLineNumber)
  5967. $GoToLine:=$MaxLineNumber-1
  5968. else
  5969. $GotoLine--
  5970.  
  5971.  
  5972. ;[========]
  5973. ;[ GoTo ]
  5974. ;[========]
  5975. ;-- Collect first visible line
  5976. $FirstVisibleLine:=HE_GetFirstVisibleLine($QAHKGUI_hEdit)
  5977.  
  5978. ;-- Collect the line index for the requested line and select it
  5979. $LineIndex:=HE_LineIndex($QAHKGUI_hEdit,$GoToLine)
  5980. HE_SetSel($QAHKGUI_hEdit,$LineIndex,$LineIndex)
  5981.  
  5982. ;-- Scroll to make the caret visible
  5983. HE_ScrollCaret($QAHKGUI_hEdit)
  5984.  
  5985. ;[====================]
  5986. ;[ Scroll to center ]
  5987. ;[====================]
  5988. $FirstVisibleLine2:=HE_GetFirstVisibleLine($QAHKGUI_hEdit)
  5989.  
  5990. ;-- If no movement, bounce because the requested line is already visible
  5991. if ($FirstVisibleLine=$FirstVisibleLine2)
  5992. return
  5993.  
  5994. ;-- Reset 1st visible line, collect last visible line
  5995. $FirstVisibleLine:=$FirstVisibleLine2
  5996. $LastVisibleLine :=HE_GetLastVisibleLine($QAHKGUI_hEdit)-1
  5997. ;-- Subtract 1 because there is significant chance (90%+ depending on the
  5998. ; font size) that the last visible line is only a partially displayed
  5999. ; line.
  6000.  
  6001. ;-- On the first visible line?
  6002. if ($GoToLine=$FirstVisibleLine)
  6003. HE_LineScroll($QAHKGUI_hEdit,0,Round((($LastVisibleLine-$FirstVisibleLine+1)/2)-1)*-1)
  6004. else
  6005. ;-- On or very near the last visible line?
  6006. if ($GoToLine>=$LastVisibleLine-1)
  6007. {
  6008. if ($LastVisibleLine>$GoToLine)
  6009. $LastVisibleLine:=$LastVisibleLine-2
  6010. ;-- Rarely needed adjustment but allows for consistent results
  6011.  
  6012. HE_LineScroll($QAHKGUI_hEdit,0,Floor(($LastVisibleLine-$FirstVisibleLine+1)/2))
  6013. }
  6014.  
  6015. ;-- Programming notes: This routine uses the HE_ScrollCaret function to move
  6016. ; the selected "go to" line number within view. If the caret is anywhere in
  6017. ; the middle of the control, the user either requested to go to a line number
  6018. ; that was already visible or the "go to" line number is near the top of the
  6019. ; the control. If the caret is on the first visible line of the control, the
  6020. ; user requested to go to a line number earlier in the control. If the caret
  6021. ; is on the last (full) visible line on the control, the user requested to go
  6022. ; to a line number further down in the control. After the HE_ScrollCaret
  6023. ; brings the caret into view, this routine attempts to scroll the control so
  6024. ; that the caret is in the middle of the control.
  6025. ;
  6026. ; The calculation for deteriming how many lines to scroll up when the caret is
  6027. ; at the top of the control (go to an earlier line number) is fairly
  6028. ; straightforward -- Round(VisibleLineCount/2)-1.
  6029. ;
  6030. ; The calculation for determining how many lines to scroll down when the carat
  6031. ; is at the bottom of the control (go to a later line number) is a bit tenuous
  6032. ; because the caret is not always on the very last fully visible line. The
  6033. ; reason: If the last visible line fits exactly (to the pixel) at the bottom
  6034. ; of the control, the HE_ScrollCaret function will scroll the control up 1
  6035. ; additional line because the caret is actually 2 pixels larger (1 at the top,
  6036. ; 1 at the bottom) larger than an individual line.
  6037.  
  6038.  
  6039. return
  6040.  
  6041.  
  6042. ;*******************
  6043. ;* *
  6044. ;* Replace *
  6045. ;* (QAHKGUI) *
  6046. ;* *
  6047. ;*******************
  6048. QAHKGUI_Replace:
  6049. SetTimer %A_ThisLabel%,Off
  6050.  
  6051. ;-- Running?
  6052. if $Running
  6053. {
  6054. SoundPlay *-1 ;-- System default sound
  6055. return
  6056. }
  6057.  
  6058. ;-- Bounce if Find or Replace dialog is already showing
  6059. IfWinExist ahk_id %Dlg_hWnd%
  6060. return
  6061.  
  6062. ;-- Where are we starting from?
  6063. HE_GetSel($QAHKGUI_hEdit,Dummy,$EndSelectPos)
  6064. if $EndSelectPos=0
  6065. Dlg_FindFromTheTop:=True
  6066. else
  6067. Dlg_FindFromTheTop:=False
  6068.  
  6069. ;-- Anything selected?
  6070. $Selected:=HE_GetSelText($QAHKGUI_hEdit)
  6071. if StrLen($Selected)
  6072. {
  6073. ;-- Ignore if multiple lines are selected
  6074. if InStr($Selected,"`n")=0
  6075. Dlg_FindWhat:=$Selected
  6076. }
  6077.  
  6078. ;-- Set direction
  6079. if Dlg_Flags not contains d
  6080. Dlg_Flags:=Dlg_Flags . "d"
  6081.  
  6082. ;-- Show Replace dialog
  6083. Dlg_hWnd :=Dlg_Replace($QAHKGUI_hWnd,"QAHKGUI_OnReplace",Dlg_Flags,Dlg_FindWhat,Dlg_ReplaceWith)
  6084. return
  6085.  
  6086.  
  6087. ;*******************************
  6088. ;* *
  6089. ;* Explore Run workspace *
  6090. ;* (QAHKGUI) *
  6091. ;* *
  6092. ;*******************************
  6093. QAHKGUI_ExploreRunFolder:
  6094. QAHKGUI_ExploreRunWorkspace:
  6095. SetTimer %A_ThisLabel%,Off
  6096.  
  6097. ;-- Set GUI default
  6098. gui %$QAHKGUI%:Default
  6099.  
  6100. ;-- Attach messages to the current GUI
  6101. gui +OwnDialogs
  6102.  
  6103. ;-- Run workspace exists?
  6104. IfNotExist %$RunDir%\.
  6105. {
  6106. $Message=The Run Workspace has been cleared. There is nothing to explore.
  6107.  
  6108. ;-- Status bar showing?
  6109. if $ShowStatusBar
  6110. {
  6111. ;-- Update status bar
  6112. SB_SetText($Message)
  6113. SetTimer QAHKGUI_ClearStatusBar,8000
  6114.  
  6115. ;-- Make a "not gonna happen" noise
  6116. SoundPlay *16 ;-- System error sound
  6117. }
  6118. else
  6119. MsgBox
  6120. ,48 ;-- 48 = 0 (OK button) + 48 ('!" icon)
  6121. ,Explore Run Workspace
  6122. ,%$Message% %A_Space%
  6123.  
  6124. ;-- Bounce
  6125. return
  6126. }
  6127.  
  6128. ;-- Open Windows Explorer to the "Run" folder
  6129. Run explorer.exe /e`,"%$RunDir%",,UseErrorLevel
  6130. if ErrorLevel
  6131. MsgBox
  6132. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6133. ,Explore Error
  6134. ,% SystemMessage(A_LastError)
  6135.  
  6136. return
  6137.  
  6138.  
  6139. ;*****************************
  6140. ;* *
  6141. ;* Clear Run workspace *
  6142. ;* (QAHKGUI) *
  6143. ;* *
  6144. ;*****************************
  6145. QAHKGUI_ClearRunWorkspace:
  6146. SetTimer %A_ThisLabel%,Off
  6147.  
  6148. ;-- Running?
  6149. if $Running
  6150. {
  6151. SoundPlay *-1 ;-- System default sound
  6152. return
  6153. }
  6154.  
  6155. ;-- Set GUI default
  6156. gui %$QAHKGUI%:Default
  6157.  
  6158. ;-- Attach messages to the current GUI
  6159. gui +OwnDialogs
  6160.  
  6161. ;-- Anything to clear?
  6162. IfNotExist %$RunDir%\.
  6163. {
  6164. $Message=The Run workspace has already been cleared.
  6165.  
  6166. ;-- Status bar showing?
  6167. if $ShowStatusBar
  6168. {
  6169. ;-- Update status bar
  6170. SB_SetText($Message)
  6171. SetTimer QAHKGUI_ClearStatusBar,8000
  6172.  
  6173. ;-- Make a "not gonna happen" noise
  6174. SoundPlay *16 ;-- System error sound
  6175. }
  6176. else
  6177. MsgBox
  6178. ,48 ;-- 49 = 1 (OK buttons) + 48 ("!" icon)
  6179. ,No Run Workspace
  6180. ,%$Message% %A_Space%
  6181.  
  6182.  
  6183. ;-- Bounce
  6184. return
  6185. }
  6186.  
  6187. ;-- Script(s) running?
  6188. $RunPIDList:=RebuildRunPIDList($RunPIDList)
  6189. if StrLen($RunPIDList)
  6190. {
  6191. MsgBox
  6192. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6193. ,Clear Run Workspace Error,
  6194. (ltrim join`s
  6195. One or more scripts are still running. Please stop all running
  6196. scripts before attempting to clear the Run workspace. %A_Space%
  6197. )
  6198.  
  6199. ;-- Bounce
  6200. return
  6201. }
  6202.  
  6203.  
  6204. ;-- Confirm
  6205. MsgBox
  6206. ,49 ;-- 49 = 1 (OK/Cancel buttons) + 48 ("!" icon)
  6207. ,Clear Run Workspace,
  6208. (ltrim join`s
  6209. All files and folders in the Run workspace will be deleted. Press OK to
  6210. proceed. %A_Space%
  6211. )
  6212.  
  6213. ;-- Bounce if Cancel
  6214. IfMsgBox Cancel
  6215. return
  6216.  
  6217. ;-- Delete "Run" Folder
  6218. gosub DeleteRunFolder
  6219.  
  6220. ;-- Update status bar
  6221. SB_SetText("Run workspace cleared.")
  6222. SetTimer QAHKGUI_ClearStatusBar,10000
  6223.  
  6224. ;-- Make a "OK, I did it" noise
  6225. SoundPlay *64 ;-- System info sound
  6226. return
  6227.  
  6228.  
  6229. ;*********************
  6230. ;* *
  6231. ;* New *
  6232. ;* Prepend New *
  6233. ;* (QAHKGUI) *
  6234. ;* *
  6235. ;*********************
  6236. QAHKGUI_New:
  6237. QAHKGUI_PrependNew:
  6238. SetTimer %A_ThisLabel%,Off
  6239.  
  6240. ;-- Running?
  6241. if $Running
  6242. {
  6243. SoundPlay *-1 ;-- System default sound
  6244. return
  6245. }
  6246.  
  6247. ;-- Set GUI default
  6248. gui %$QAHKGUI%:Default
  6249.  
  6250. ;-- Attach messages to the current GUI
  6251. gui +OwnDialogs
  6252.  
  6253. ;[===================]
  6254. ;[ Find new script ]
  6255. ;[===================]
  6256. ;-- System default?
  6257. if $NewScriptSystemDefault
  6258. {
  6259. ;-- Not found?
  6260. IfNotExist %A_Windir%\ShellNew\Template.ahk
  6261. {
  6262. MsgBox
  6263. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  6264. ,New Script Error,
  6265. (ltrim
  6266. Cannot find the AutoHotkey new script template: %A_Space%
  6267. %A_Windir%\ShellNew\Template.ahk %A_Space%
  6268. )
  6269.  
  6270. return
  6271. }
  6272.  
  6273. ;-- Read into t_NewScript
  6274. FileRead t_NewScript,%A_Windir%\ShellNew\Template.ahk
  6275. if ErrorLevel
  6276. {
  6277. outputdebug A_LastError=%A_LastError%
  6278. MsgBox
  6279. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6280. ,New Script Error,
  6281. (ltrim
  6282. Cannot read the AutoHotkey new script template: %A_Space%
  6283. %A_Windir%\ShellNew\Template.ahk %A_Space%
  6284. )
  6285.  
  6286. return
  6287. }
  6288. }
  6289. else
  6290. {
  6291. ;-- Program "new script" not defined?
  6292. if StrLen($NewScript)=0
  6293. {
  6294. MsgBox
  6295. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  6296. ,New Script Error,
  6297. (ltrim join`s
  6298. No "New Script" has been defined. Check Options for more
  6299. information. %A_Space%
  6300. )
  6301.  
  6302. return
  6303. }
  6304.  
  6305. ;-- Assign to t_NewScript. Convert NL chars to CRNL chars
  6306. t_NewScript:=$NewScript
  6307. StringReplace t_NewScript,t_NewScript,`n,`r`n,All
  6308. }
  6309.  
  6310. ;-- Update workspace
  6311. if A_ThisLabel contains Prepend
  6312. HE_SetSel($QAHKGUI_hEdit,0,0)
  6313. else
  6314. HE_SetSel($QAHKGUI_hEdit,0,-1)
  6315.  
  6316. HE_ReplaceSel($QAHKGUI_hEdit,t_NewScript)
  6317. ;-- Note: This method is a bit choppy but it does allow for undo
  6318.  
  6319. ;-- Scroll to the top/left
  6320. HE_LineScroll($QAHKGUI_hEdit,-999999,-999999)
  6321.  
  6322. ;-- Update status bar
  6323. if A_ThisLabel contains Prepend
  6324. $Message=
  6325. (ltrim join`s
  6326. "New" script template prepended to the current script. Use Ctrl+Z to
  6327. undo.
  6328. )
  6329. else
  6330. $Message="New" script template copied to the workspace. Use Ctrl+Z to undo.
  6331.  
  6332. SB_SetText($Message)
  6333. SetTimer QAHKGUI_ClearStatusBar,20000
  6334. return
  6335.  
  6336.  
  6337. ;*******************
  6338. ;* *
  6339. ;* Copy From *
  6340. ;* (QAHKGUI) *
  6341. ;* *
  6342. ;*******************
  6343. QAHKGUI_CopyFrom:
  6344. SetTimer %A_ThisLabel%,Off
  6345.  
  6346. ;-- Running?
  6347. if $Running
  6348. {
  6349. SoundPlay *-1 ;-- System default sound
  6350. return
  6351. }
  6352.  
  6353. ;-- Set GUI default
  6354. gui %$QAHKGUI%:Default
  6355.  
  6356. ;-- Attach messages and dialogs to the current GUI
  6357. gui +OwnDialogs
  6358.  
  6359. ;-- Initialize $CopyFromPath
  6360. if $CopyFromPath is Space
  6361. if $SaveToPath is not Space
  6362. $CopyFromPath:=$SaveToPath
  6363. else
  6364. $CopyFromPath:=A_MyDocuments
  6365.  
  6366. ;[=================]
  6367. ;[ Browse for it ]
  6368. ;[=================]
  6369. FileSelectFile
  6370. ,$QAHKGUI_CopyFromFileName ;-- OutputVar
  6371. ,1 ;-- Options. 1=File must exist
  6372. ,%$CopyFromPath% ;-- Starting path
  6373. ,Copy From ;-- Prompt
  6374. ,*.ahk;*.ini;*.txt ;-- Filter
  6375.  
  6376. ;-- Cancel?
  6377. If ErrorLevel
  6378. return
  6379.  
  6380. ;-- Create restore point?
  6381. if $CreateRPOnCopyfromDrop
  6382. RPCreate()
  6383.  
  6384. ;[===========]
  6385. ;[ Copy it ]
  6386. ;[===========]
  6387. ;-- Copy selected file over workspace file
  6388. FileCopy %$QAHKGUI_CopyFromFileName%,%$EditFile%,1 ;-- 1=overwrite
  6389. If ErrorLevel
  6390. {
  6391. ;-- Notify the user
  6392. gui +OwnDialogs
  6393. MsgBox
  6394. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6395. ,Copy From Error
  6396. ,Unable to copy the selected file to the workspace. %A_Space%
  6397.  
  6398. return
  6399. }
  6400.  
  6401. ;-- Reset file attributes
  6402. FileSetAttrib -RSH,%$EditFile%
  6403.  
  6404. ;-- Reload workspace
  6405. gosub LoadWorkspace
  6406.  
  6407. ;-- Redefine $CopyFromPath
  6408. SplitPath $QAHKGUI_CopyFromFileName,,$CopyFromPath
  6409.  
  6410. ;-- Push to $RecentFiles and reload menu
  6411. MRUManager($RecentFiles,"Push",$QAHKGUI_CopyFromFileName,"|",9)
  6412. gosub QAHKGUI_ReloadRecentFilesMenu
  6413.  
  6414. ;-- Update status bar
  6415. SB_SetText("Contents of " . CompressFileName($QAHKGUI_CopyFromFileName,65) . " copied to the workspace.")
  6416. SetTimer QAHKGUI_ClearStatusBar,25000
  6417. return
  6418.  
  6419.  
  6420. ;**********************
  6421. ;* *
  6422. ;* Recent Files *
  6423. ;* (QAHKGUI) *
  6424. ;* *
  6425. ;**********************
  6426. QAHKGUI_RecentFilesMenu:
  6427. SetTimer %A_ThisLabel%,Off
  6428.  
  6429. ;-- Running?
  6430. if $Running
  6431. {
  6432. SoundPlay *-1 ;-- System default sound
  6433. return
  6434. }
  6435.  
  6436. ;-- Set GUI default
  6437. gui %$QAHKGUI%:Default
  6438.  
  6439. ;-- Attach messages and dialogs to the current GUI
  6440. gui +OwnDialogs
  6441.  
  6442. ;-- Determine file name
  6443. $QAHKGUI_CopyFromFileName :=""
  6444. Loop Parse,$RecentFilesMenu,|
  6445. if (A_ThisMenuItemPos=A_Index)
  6446. {
  6447. $QAHKGUI_CopyFromFileName:=A_LoopField
  6448. Break
  6449. }
  6450.  
  6451. ;-- File exists?
  6452. IfNotExist %$QAHKGUI_CopyFromFileName%
  6453. {
  6454. MsgBox
  6455. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6456. ,File Not Found,
  6457. (ltrim
  6458. Selected file not found: %A_Space%
  6459. %$QAHKGUI_CopyFromFileName% %A_Space%
  6460. )
  6461.  
  6462. return
  6463. }
  6464.  
  6465. ;-- Create restore point?
  6466. if $CreateRPOnCopyfromDrop
  6467. RPCreate()
  6468.  
  6469. ;-- Copy selected file over workspace file
  6470. FileCopy %$QAHKGUI_CopyFromFileName%,%$EditFile%,1 ;-- 1=overwrite
  6471. If ErrorLevel
  6472. {
  6473. ;-- Notify the user
  6474. gui +OwnDialogs
  6475. MsgBox
  6476. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6477. ,Copy From Error
  6478. ,Unable to copy the selected file to the workspace. %A_Space%
  6479.  
  6480. return
  6481. }
  6482.  
  6483. ;-- Reset file attributes
  6484. FileSetAttrib -RSH,%$EditFile%
  6485.  
  6486. ;-- Reload workspace
  6487. gosub LoadWorkspace
  6488.  
  6489. ;-- Redefine $CopyFromPath
  6490. SplitPath $QAHKGUI_CopyFromFileName,,$CopyFromPath
  6491.  
  6492. ;-- Push to $RecentFiles
  6493. MRUManager($RecentFiles,"Push",$QAHKGUI_CopyFromFileName,"|",9)
  6494. ;-- Note: Although $QAHKGUI_CopyFromFileName is pushed to $RecentFiles, the
  6495. ; Recent Files menu is not reloaded here. This allows the user to copy
  6496. ; only recent files without having to see a resequenced (LIFO) list
  6497. ; every time. However, the recent files list will automatically be
  6498. ; resequenced if other methods to load the workspace are used.
  6499.  
  6500. ;-- Update status bar
  6501. SB_SetText("Contents of " . CompressFileName($QAHKGUI_CopyFromFileName,65) . " copied to the workspace.")
  6502. SetTimer QAHKGUI_ClearStatusBar,25000
  6503. return
  6504.  
  6505.  
  6506. QAHKGUI_ClearRecentFilesMenu:
  6507. MRUManager($RecentFiles,"Clear")
  6508. gosub QAHKGUI_ReloadRecentFilesMenu
  6509. return
  6510.  
  6511.  
  6512. QAHKGUI_ReloadRecentFilesMenu:
  6513.  
  6514. if $ShowMenubar
  6515. {
  6516. ;-- Temporarily turn off sizing
  6517. $Resize:=False
  6518.  
  6519. ;-- Hide menu bar
  6520. gui %$QAHKGUI%:Menu
  6521. }
  6522.  
  6523. ;-- Rebuild RecentFiles menu
  6524. gosub QAHKGUI_BuildRecentFilesMenu
  6525.  
  6526. if $ShowMenubar
  6527. {
  6528. ;-- Show menu
  6529. gui %$QAHKGUI%:Menu,QAHKGUI_Menubar
  6530.  
  6531. ;-- Allow resizing to occur
  6532. Sleep 1
  6533.  
  6534. ;-- Restore sizing
  6535. $Resize:=True
  6536. }
  6537.  
  6538. return
  6539.  
  6540.  
  6541. ;*************************
  6542. ;* *
  6543. ;* External Editor *
  6544. ;* (QAHKGUI) *
  6545. ;* *
  6546. ;*************************
  6547. QAHKGUI_ExternalEditor:
  6548. SetTimer %A_ThisLabel%,Off
  6549.  
  6550. ;-- Running?
  6551. if $Running
  6552. {
  6553. SoundPlay *-1 ;-- System default sound
  6554. return
  6555. }
  6556.  
  6557. ;-- Set GUI default
  6558. gui %$QAHKGUI%:Default
  6559.  
  6560. ;-- Attach messages to the current GUI
  6561. gui +OwnDialogs
  6562.  
  6563. ;-- External editor defined?
  6564. if $ExtEditorPath is Space
  6565. {
  6566. MsgBox
  6567. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  6568. ,External Editor Error
  6569. ,No external editor has been defined. %A_Space%
  6570.  
  6571. return
  6572. }
  6573.  
  6574. ;-- Format editor name
  6575. t_EditorName :=""
  6576. if StrLen($ExtEditorName)
  6577. StringReplace t_EditorName,$ExtEditorName,&,,All
  6578.  
  6579. t_EditorName2 :=t_EditorName
  6580. if t_EditorName is Space
  6581. {
  6582. t_EditorName :="An external editor"
  6583. t_EditorName2:="the external editor"
  6584. }
  6585.  
  6586. ;-- Instructions/Confirm
  6587. MsgBox
  6588. ,49 ;-- 49 = 1 (OK/Cancel buttons) + 48 ("!" icon)
  6589. ,External Editor,
  6590. (ltrim join`s
  6591. %t_EditorName% will be called to edit the current workspace. When
  6592. you have finished making changes, save the file, close %t_EditorName2%,
  6593. and restart %$ScriptName%. `n`nPress OK to continue. %A_Space%
  6594. )
  6595.  
  6596. IfMsgBox Cancel
  6597. return
  6598.  
  6599. ;-- OK to exit?
  6600. if $ConfirmExitIfRunning
  6601. if not QAHKGUI_ConfirmExit()
  6602. return
  6603.  
  6604. ;-- Close RPViewerGUI?
  6605. IfWinExist ahk_id %$RPViewerGUI_hWnd%
  6606. gosub RPViewerGUI_Close
  6607.  
  6608. ;-- Save workspace
  6609. gosub SaveWorkspace
  6610.  
  6611. ;-- Create resore point?
  6612. if $CreateRPOnExit
  6613. RPCreate()
  6614.  
  6615. ;-- Clear run workspace?
  6616. if $ClearRunWorkspaceOnExit
  6617. gosub DeleteRunFolder
  6618.  
  6619. ;-- Save configuration
  6620. gosub SaveConfiguration
  6621.  
  6622. ;-- Destroy GUI to ensure that there is no confict with the editor
  6623. gui Destroy
  6624.  
  6625. ;-- Run it!
  6626. Run "%$ExtEditorPath%" "%$EditFile%",,UseErrorLevel
  6627. if ErrorLevel
  6628. {
  6629. if A_LastError=2
  6630. MsgBox
  6631. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6632. ,Run External Editor Error,
  6633. (ltrim join`s
  6634. Unable to find and/or run the external editor
  6635. program: %A_Space%`n"%$ExtEditorPath%" %A_Space%
  6636. )
  6637. else
  6638. MsgBox
  6639. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6640. ,Run External Editor Error
  6641. ,% SystemMessage(A_LastError)
  6642.  
  6643. ExitApp
  6644. }
  6645.  
  6646. ;-- Shut it down
  6647. ExitApp
  6648. return
  6649.  
  6650.  
  6651.  
  6652. ;*******************
  6653. ;* *
  6654. ;* Save *
  6655. ;* (QAHKGUI) *
  6656. ;* *
  6657. ;*******************
  6658. QAHKGUI_Save:
  6659. SetTimer %A_ThisLabel%,Off
  6660.  
  6661. ;-- Running?
  6662. if $Running
  6663. {
  6664. SoundPlay *-1 ;-- System default sound
  6665. return
  6666. }
  6667.  
  6668. ;-- Set GUI default
  6669. gui %$QAHKGUI%:Default
  6670.  
  6671. ;-- Save and backup workspace
  6672. gosub SaveWorkspace
  6673. gosub BackupWorkspace
  6674.  
  6675. ;-- Flush Undo buffer?
  6676. if not $AllowUndoAfterSave
  6677. HE_EmptyUndoBuffer($QAHKGUI_hEdit)
  6678.  
  6679. ;-- Programming note: The Undo buffer is only flushed (if requested) when the
  6680. ; the user requests a manual save.
  6681.  
  6682. ;-- Create restore point?
  6683. if $CreateRPOnSave
  6684. RPCreate()
  6685.  
  6686. ;-- Update status bar
  6687. SB_SetText("Workspace saved.")
  6688. SetTimer QAHKGUI_ClearStatusBar,15000
  6689. return
  6690.  
  6691.  
  6692. ;*******************
  6693. ;* *
  6694. ;* Save To *
  6695. ;* (QAHKGUI) *
  6696. ;* *
  6697. ;*******************
  6698. QAHKGUI_Toolbar_SaveTo:
  6699. SetTimer %A_ThisLabel%,Off
  6700. SetTimer QAHKGUI_SaveTo,0
  6701. return
  6702.  
  6703.  
  6704. QAHKGUI_SaveTo:
  6705. SetTimer %A_ThisLabel%,Off
  6706.  
  6707. ;-- Running?
  6708. if $Running
  6709. {
  6710. SoundPlay *-1 ;-- System default sound
  6711. return
  6712. }
  6713.  
  6714. ;-- Set GUI default
  6715. gui %$QAHKGUI%:Default
  6716.  
  6717. ;-- Attach dialogs and messages to current GUI
  6718. gui +OwnDialogs
  6719.  
  6720. ;-- Initialize $SaveToPath
  6721. if $SaveToPath is Space
  6722. if $CopyFromPath is not Space
  6723. $SaveToPath:=$CopyFromPath
  6724. else
  6725. $SaveToPath:=A_MyDocuments
  6726.  
  6727. ;[=================]
  6728. ;[ Browse for it ]
  6729. ;[=================]
  6730. FileSelectFile
  6731. ,$QAHKGUI_SaveToFileName ;-- OutputVar
  6732. ,S16 ;-- Options. 16=Prompt to overWrite file
  6733. ,%$SaveToPath% ;-- Starting path
  6734. ,Save To ;-- Prompt
  6735. ,*.ahk;*.txt;*.ini ;-- Filter
  6736.  
  6737. ;-- Cancel?
  6738. if ErrorLevel
  6739. return
  6740.  
  6741. ;-- Redefine $SaveToPath
  6742. SplitPath $QAHKGUI_SaveToFileName,,$SaveToPath
  6743.  
  6744. ;[=============]
  6745. ;[ Save file ]
  6746. ;[=============]
  6747. HE_SaveFile($QAHKGUI_hEdit,$QAHKGUI_SaveToFileName)
  6748. ;;;;;If ErrorLevel
  6749. ;;;;; {
  6750. ;;;;; MsgBox
  6751. ;;;;; ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6752. ;;;;; ,Save To Error
  6753. ;;;;; ,Unable to save the workspace to: `n%$QAHKGUI_SaveToFileName% %A_Space%
  6754. ;;;;;
  6755. ;;;;; return
  6756. ;;;;; }
  6757.  
  6758. ;-- Programming note: The value returned from HE_SaveFile is meaningless. The
  6759. ; function usually returns 0 regardless of whether the file was successfully
  6760. ; saved or not. On rare occasion, the function returns 1. This value is also
  6761. ; meaningless if the return value 0 does not provide guidance.
  6762.  
  6763. ;-- SaveToFile created?
  6764. IfNotExist %$QAHKGUI_SaveToFileName%
  6765. {
  6766. MsgBox
  6767. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6768. ,Save To Error
  6769. ,Unable to save the workspace to: `n%$QAHKGUI_SaveToFileName% %A_Space%
  6770.  
  6771. return
  6772. }
  6773.  
  6774. ;-- Push to $RecentFiles and reload menu
  6775. MRUManager($RecentFiles,"Push",$QAHKGUI_SaveToFileName,"|",9)
  6776. gosub QAHKGUI_ReloadRecentFilesMenu
  6777.  
  6778. ;-- Update status bar
  6779. SB_SetText("Workspace saved to " . CompressFileName($QAHKGUI_SaveToFileName,65))
  6780. SetTimer QAHKGUI_ClearStatusBar,25000
  6781. return
  6782.  
  6783.  
  6784. ;*******************
  6785. ;* *
  6786. ;* Revert *
  6787. ;* (QAHKGUI) *
  6788. ;* *
  6789. ;*******************
  6790. QAHKGUI_Revert:
  6791. SetTimer %A_ThisLabel%,Off
  6792.  
  6793. ;-- Running?
  6794. if $Running
  6795. {
  6796. SoundPlay *-1 ;-- System default sound
  6797. return
  6798. }
  6799.  
  6800. ;-- Set GUI default
  6801. gui %$QAHKGUI%:Default
  6802.  
  6803. ;-- Attach messages to the current GUI
  6804. gui +OwnDialogs
  6805.  
  6806. ;-- Save workspace
  6807. gosub SaveWorkspace
  6808. ;-- A little ironic I know, but we need to compare the current workspace
  6809. ; against the workspace backup file.
  6810.  
  6811. ;-- Collect file sizes
  6812. FileGetSize $EditFileSize,%$EditFile%
  6813. FileGetSize $EditBackupFileSize,%$EditBackupFile%
  6814.  
  6815. ;-- Bounce if there is nothing to revert to
  6816. ;
  6817. ; Programming note: Because of AutoHotkey's optimization techniques, the
  6818. ; FileMD5 functions are only called if the file sizes are equal.
  6819. ;
  6820. if ($EditFileSize=$EditBackupFileSize)
  6821. and FileMD5($EditFile,2)=FileMD5($EditBackupFile,2)
  6822. {
  6823. ;-- Status bar showing?
  6824. if $ShowStatusBar
  6825. {
  6826. ;-- Update status bar
  6827. SB_SetText("There are no changes to revert.")
  6828. SetTimer QAHKGUI_ClearStatusBar,8000
  6829.  
  6830. ;-- Make a "not gonna happen" noise
  6831. SoundPlay *16 ;-- System error sound
  6832. }
  6833. else
  6834. {
  6835. gui +OwnDialogs
  6836. MsgBox
  6837. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  6838. ,Revert
  6839. ,There are no changes to revert. %A_Space%
  6840. }
  6841.  
  6842. ;-- Bounce
  6843. return
  6844. }
  6845.  
  6846. ;-- Confirm
  6847. MsgBox
  6848. ,33 ;-- 32 = 1 (OK/Cancel buttons) + 32 ("?" icon)
  6849. ,Revert
  6850. ,Revert to the last saved version? %A_Space%
  6851.  
  6852. IfMsgBox Cancel
  6853. return
  6854.  
  6855.  
  6856. ;-- Copy backup file over workspace file
  6857. FileCopy %$EditBackupFile%,%$EditFile%,1 ;-- 1=overwrite
  6858. If ErrorLevel
  6859. {
  6860. gui +OwnDialogs
  6861. MsgBox
  6862. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6863. ,Revert Error
  6864. ,Unable to copy the backup file to the workspace. %A_Space%
  6865.  
  6866. return
  6867. }
  6868.  
  6869. ;-- Reset file attributes
  6870. FileSetAttrib -RSH,%$EditFile%
  6871. ;-- Probably redundant but remains as a fail-safe
  6872.  
  6873. ;-- Reload workspace
  6874. gosub LoadWorkspace
  6875.  
  6876. ;-- Update status bar
  6877. SB_SetText("Workspace reverted to the last saved version.")
  6878. SetTimer QAHKGUI_ClearStatusBar,10000
  6879. return
  6880.  
  6881.  
  6882. ;*************************
  6883. ;* *
  6884. ;* Paste clipboard *
  6885. ;* (QAHKGUI) *
  6886. ;* *
  6887. ;*************************
  6888. QAHKGUI_PasteC:
  6889. QAHKGUI_PasteClipboard:
  6890. SetTimer %A_ThisLabel%,Off
  6891.  
  6892. ;-- Running?
  6893. if $Running
  6894. {
  6895. SoundPlay *-1 ;-- System default sound
  6896. return
  6897. }
  6898.  
  6899. ;-- Set GUI default
  6900. gui %$QAHKGUI%:Default
  6901.  
  6902. ;-- Empty clipboard?
  6903. if StrLen(Clipboard)=0
  6904. {
  6905. gui +OwnDialogs
  6906. MsgBox
  6907. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  6908. ,Clipboard Empty
  6909. ,The clipboard is empty. Command aborted. %A_Space%
  6910.  
  6911. return
  6912. }
  6913.  
  6914. ;-- Autotrim/Convert to text
  6915. Clipboard=%Clipboard%
  6916.  
  6917. ;-- Replace workspace
  6918. HE_SetSel($QAHKGUI_hEdit,0,-1)
  6919. HE_ReplaceSel($QAHKGUI_hEdit,Clipboard)
  6920.  
  6921. ;-- Update status bar
  6922. $Message=
  6923. (ltrim join`s
  6924. Contents of the clipboard copied to the workspace. Use Ctrl+Z to undo.
  6925. )
  6926.  
  6927. SB_SetText($Message)
  6928. SetTimer QAHKGUI_ClearStatusBar,12000
  6929. return
  6930.  
  6931.  
  6932. ;*******************
  6933. ;* *
  6934. ;* Run *
  6935. ;* (QAHKGUI) *
  6936. ;* *
  6937. ;*******************
  6938. QAHKGUI_ContextMenu_RunSelected:
  6939. QAHKGUI_Toolbar_Run:
  6940. QAHKGUI_Toolbar_RunSelected:
  6941. SetTimer %A_ThisLabel%,Off
  6942.  
  6943. if A_ThisLabel contains Selected
  6944. SetTimer QAHKGUI_RunSelected,0
  6945. else
  6946. SetTimer QAHKGUI_Run,0
  6947.  
  6948. return
  6949.  
  6950.  
  6951. QAHKGUI_Run:
  6952. QAHKGUI_RunSelected:
  6953.  
  6954.  
  6955. ;-- Already running?
  6956. if $Running
  6957. {
  6958. gosub QAHKGUI_Stop
  6959. SoundPlay *-1 ;-- System default sound
  6960. return
  6961. }
  6962. SetTimer %A_ThisLabel%,Off
  6963. ;-- Set GUI default
  6964. gui %$QAHKGUI%:Default
  6965.  
  6966. ;-- Attach messages to the current GUI
  6967. gui +OwnDialogs
  6968.  
  6969.  
  6970. ;[==============]
  6971. ;[ Initialize ]
  6972. ;[==============]
  6973. $RunSelected:=False
  6974. $CLParms:=""
  6975.  
  6976. ;[====================]
  6977. ;[ Anything to run? ]
  6978. ;[====================]
  6979. if A_ThisLabel contains Selected
  6980. {
  6981. $RunSelected:=True
  6982. if StrLen(HE_GetSelText($QAHKGUI_hEdit))=0
  6983. {
  6984. ;-- Status bar showing?
  6985. if $ShowStatusBar
  6986. {
  6987. ;-- Update status bar
  6988. SB_SetText("Nothing selected. Script not run.")
  6989. SetTimer QAHKGUI_ClearStatusBar,10000
  6990.  
  6991. ;-- Make a "I couldn't do it" noise
  6992. SoundPlay *16 ;-- System error sound
  6993. }
  6994. else
  6995. {
  6996. gui +OwnDialogs
  6997. MsgBox
  6998. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  6999. ,Run Error
  7000. ,Nothing selected. Script not run. %A_Space%
  7001. }
  7002.  
  7003. ;-- Bounce
  7004. return
  7005. }
  7006. }
  7007. else
  7008. {
  7009. if HE_GetTextLength($QAHKGUI_hEdit)=0
  7010. {
  7011. ;-- Status bar showing?
  7012. if $ShowStatusBar
  7013. {
  7014. ;-- Update status bar
  7015. SB_SetText("Workspace is empty. Script not run.")
  7016. SetTimer QAHKGUI_ClearStatusBar,10000
  7017.  
  7018. ;-- Make a "I couldn't do it" noise
  7019. SoundPlay *16 ;-- System error sound
  7020. }
  7021. else
  7022. {
  7023. gui +OwnDialogs
  7024. MsgBox
  7025. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  7026. ,Run Error
  7027. ,Workspace is empty. Script not run. %A_Space%
  7028. }
  7029.  
  7030. return
  7031. }
  7032. }
  7033.  
  7034. if $RunPrompt
  7035. {
  7036. gosub RunPromptGUI
  7037. return
  7038. }
  7039.  
  7040.  
  7041. QAHKGUI_Run_AfterPrompt:
  7042. SetTimer %A_ThisLabel%,Off
  7043.  
  7044. ;-- Reset GUI default
  7045. gui %$QAHKGUI%:Default
  7046.  
  7047. ;-- Attach messages to the current GUI
  7048. gui +OwnDialogs
  7049.  
  7050. ;[===============]
  7051. ;[ Preliminary ]
  7052. ;[===============]
  7053. ;-- Save workspace
  7054. gosub SaveWorkspace
  7055.  
  7056. ;-- Create resore point?
  7057. if $CreateRPOnRun
  7058. RPCreate()
  7059.  
  7060. ;-- Clear Run workspace?
  7061. if $ClearRunWorkspaceOnRun
  7062. gosub DeleteRunFolder
  7063.  
  7064. ;-- Save configuration
  7065. gosub SaveConfiguration
  7066.  
  7067. ;[=========================]
  7068. ;[ Create "Run" folder ]
  7069. ;[ (If it doesn't exist) ]
  7070. ;[=========================]
  7071. IfNotExist %$RunDir%\.
  7072. {
  7073. ;-- Create folder
  7074. FileCreateDir %$RunDir%
  7075. if ErrorLevel
  7076. {
  7077. MsgBox
  7078. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  7079. ,Run Error
  7080. ,Unable to create the Run workspace. Script not run. %A_Space%
  7081.  
  7082. return
  7083. }
  7084. }
  7085.  
  7086. ;[===================]
  7087. ;[ Copy script ]
  7088. ;[ to "Run" folder ]
  7089. ;[===================]
  7090. if $RunSelected
  7091. {
  7092. ;-- Delete Run file (if it exists)
  7093. IfExist %$RunFile%
  7094. {
  7095. FileDelete %$RunFile%
  7096. if ErrorLevel
  7097. {
  7098. MsgBox
  7099. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  7100. ,Run Error,
  7101. (ltrim
  7102. Unable to delete the Run file: %A_Space%
  7103. %$RunFile% %A_Space%
  7104. `nThis file may be in use by another program. %A_Space%
  7105. )
  7106.  
  7107. outputdebug End Subrou: %A_ThisLabel% - Unable to delete Run file
  7108. return
  7109. }
  7110. }
  7111.  
  7112. ;-- Write selected text to Run file
  7113. FileAppend % HE_GetSelText($QAHKGUI_hEdit),%$RunFile%
  7114. If ErrorLevel
  7115. {
  7116. MsgBox
  7117. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  7118. ,Run Error,
  7119. (ltrim join`s
  7120. Unable to copy the selected text to the Run workspace. Script
  7121. not run. %A_Space%
  7122. )
  7123.  
  7124. outputdebug,
  7125. (ltrim join`s
  7126. End Subrou: %A_ThisLabel% - Unable to write selected text to the Run
  7127. file
  7128. )
  7129.  
  7130. return
  7131. }
  7132. }
  7133. else
  7134. {
  7135. ;-- Create/Overwrite the Run file
  7136. FileCopy %$EditFile%,%$RunFile%,1 ;-- 1=Overwrite existing file(s)
  7137. If ErrorLevel
  7138. {
  7139. MsgBox
  7140. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  7141. ,Run Error,
  7142. (ltrim join`s
  7143. Unable to copy the workspace script to the Run
  7144. workspace. Script not run. %A_Space%
  7145. )
  7146.  
  7147. outputdebug,
  7148. (ltrim join`s
  7149. End Subrou: %A_ThisLabel% - Unable to copy workspace script to the
  7150. "Run" folder
  7151. )
  7152. return
  7153. }
  7154. }
  7155.  
  7156. ;[================]
  7157. ;[ Debug script ]
  7158. ;[================]
  7159. if $RunDebug
  7160. {
  7161. ;-- Append debug script to Run file
  7162. FileAppend % "`n" . $DebugScript,%$RunFile%
  7163. If ErrorLevel
  7164. {
  7165. MsgBox
  7166. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  7167. ,Run Error,
  7168. (ltrim join`s
  7169. Unable to append the debug script to the Run script. Script not
  7170. run. %A_Space%
  7171. )
  7172.  
  7173. outputdebug,
  7174. (ltrim join`s
  7175. End Subrou: %A_ThisLabel% - Unable to append the debug script to the
  7176. Run file
  7177. )
  7178.  
  7179. return
  7180. }
  7181. }
  7182.  
  7183. ;[=============================]
  7184. ;[ Determine Autohotkey path ]
  7185. ;[=============================]
  7186. ;-- Set to blank
  7187. $AHKRunPath=
  7188.  
  7189. ;-- First, try user-defined path
  7190. if $AutoHotkeyPath is not Space
  7191. {
  7192. $AHKRunPath:=$AutoHotkeyPath
  7193.  
  7194. ;-- Blank if not found
  7195. IfNotExist %$AHKRunPath%
  7196. $AHKRunPath=
  7197. }
  7198.  
  7199. ;-- If blank, try A_AhkPath
  7200. if $AHKRunPath is Space
  7201. {
  7202. $AHKRunPath:=A_AhkPath
  7203.  
  7204. ;-- Blank if not found
  7205. if $AHKRunPath is not Space
  7206. IfNotExist %$AHKRunPath%
  7207. $AHKRunPath=
  7208. }
  7209.  
  7210. ;-- Still blank, error
  7211. if $AHKRunPath is Space
  7212. {
  7213. MsgBox
  7214. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  7215. ,Run Error,
  7216. (ltrim join`s
  7217. Cannot find the AutoHotkey program. The AutoHotkey path has not
  7218. been defined (Options window, "Run" tab) or is invalid, or
  7219. AutoHotkey has not been installed on this computer.
  7220. )
  7221.  
  7222. return
  7223. }
  7224.  
  7225. ;[======================]
  7226. ;[ Run but don't wait ]
  7227. ;[======================]
  7228. if not $RunWait
  7229. {
  7230. ;-- Enable menu and toolbar items
  7231. Menu QAHKGUI_FileMenu
  7232. ,Enable
  7233. ,%s_File_Stop_MI%
  7234.  
  7235. Menu QAHKGUI_Menubar
  7236. ,Enable
  7237. ,%s_Menubar_Stop_MI%
  7238.  
  7239. ;----------
  7240. ;-- Run it
  7241. ;----------
  7242. $RunPID=0
  7243. Run
  7244. ,"%$AHKRunPath%" "%$RunFile%" %$CLParms%
  7245. ,%$RunDir%
  7246. ,UseErrorLevel
  7247. ,$RunPID
  7248.  
  7249. ;-- Run error?
  7250. if A_LastError
  7251. {
  7252. MsgBox
  7253. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  7254. ,Run Error
  7255. ,% SystemMessage(A_LastError)
  7256.  
  7257. return
  7258. }
  7259.  
  7260. ;-- Add $RunPID to $RunPIDList
  7261. gosub QAHKGUI_AddRunPID
  7262.  
  7263. ;-- Update status bar
  7264. SB_SetText("Script run without waiting to complete.")
  7265. SetTimer QAHKGUI_ClearStatusBar,10000
  7266. return
  7267. }
  7268.  
  7269. ;[================]
  7270. ;[ Run and wait ]
  7271. ;[================]
  7272. ;-- Update status bar
  7273. if $RunDebug
  7274. $Message:="Running script with appended debug script..."
  7275. else
  7276. $Message:="Running script..."
  7277.  
  7278. SB_SetText($Message)
  7279. SetTimer QAHKGUI_ClearStatusBar,Off
  7280.  
  7281. ;-- Update menu, toolbar, and GUI objects
  7282. ;if $ShowMenubar
  7283. ; gui Menu,QAHKGUI_MenubarRunWait
  7284.  
  7285. Toolbar_SetImageList($hToolbar,$hToolbar%$TBIconSizeA%IL2)
  7286.  
  7287. ;if $Toolbar_RunButtonList
  7288. ; Loop Parse,$Toolbar_RunButtonList,`,
  7289. ; Toolbar_SetButton($hToolbar,A_LoopField,"Disabled")
  7290.  
  7291. Control Disable,,,ahk_id %$QAHKGUI_hEdit%
  7292.  
  7293. ;-- Run and wait
  7294. $Running:=True
  7295. $StartTime:=A_TickCount
  7296.  
  7297. $RunPID=0
  7298. SetTimer QAHKGUI_AddRunPID,250
  7299. RunWait
  7300. ,"%$AHKRunPath%" "%$RunFile%" %$CLParms%
  7301. ,%$RunDir%
  7302. ,UseErrorLevel
  7303. ,$RunPID
  7304.  
  7305. ;-- Run error?
  7306. if A_LastError
  7307. {
  7308. MsgBox
  7309. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  7310. ,Run Error
  7311. ,% SystemMessage(A_LastError)
  7312.  
  7313. return
  7314. }
  7315.  
  7316. ;[==================]
  7317. ;[ Post-Run stuff ]
  7318. ;[==================]
  7319. SetTimer QAHKGUI_AddRunPID,Off
  7320.  
  7321. $Running :=False
  7322. $RunPID :=0
  7323. $RunErrorLevel:=ErrorLevel
  7324. $RunTime :=(A_TickCount-$StartTime)/1000
  7325.  
  7326.  
  7327. ;-- Format run time
  7328. $FormattedRunTime:=SecondsToHHMMSS(floor($RunTime),5) . SubStr($RunTime,-6,4)
  7329. ;-- Programming note: This statement assumes that the script is using the
  7330. ; default AutoHotkey format: Float 0.6. This statement will produce
  7331. ; different results if the default format is changed.
  7332.  
  7333. ;-- Update status bar
  7334. $Message=
  7335. (ltrim join`s
  7336. Run complete. ErrorLevel:
  7337. %$RunErrorLevel% Run time:
  7338. %$FormattedRunTime%
  7339. )
  7340.  
  7341. SB_SetText($Message)
  7342.  
  7343. ;-- Update menus, toolbars, and GUI objects
  7344. ;if $ShowMenubar
  7345. ; gui Menu,QAHKGUI_Menubar
  7346.  
  7347. ;Toolbar_SetImageList($hToolbar,$hToolbar%$TBIconSizeA%IL)
  7348.  
  7349. ;if $Toolbar_RunButtonList
  7350. ;Loop Parse,$Toolbar_RunButtonList,`,
  7351. ; Toolbar_SetButton($hToolbar,A_LoopField,"-Disabled")
  7352.  
  7353. Control Enable,,,ahk_id %$QAHKGUI_hEdit%
  7354.  
  7355. ;-- If there are no running scripts, disable "Stop" menu and toolbar items
  7356. $RunPIDList:=RebuildRunPIDList($RunPIDList)
  7357. if StrLen($RunPIDList)=0
  7358. {
  7359. Menu QAHKGUI_FileMenu
  7360. ,Disable
  7361. ,%s_File_Stop_MI%
  7362.  
  7363. Menu QAHKGUI_Menubar
  7364. ,Disable
  7365. ,%s_Menubar_Stop_MI%
  7366. }
  7367.  
  7368. ;-- Reset focus
  7369. ControlFocus,,ahk_id %$QAHKGUI_hEdit%
  7370. return
  7371.  
  7372.  
  7373.  
  7374. ;*********************
  7375. ;* *
  7376. ;* Add Run PID *
  7377. ;* (QAHKGUI) *
  7378. ;* *
  7379. ;*********************
  7380. QAHKGUI_AddRunPID:
  7381. SetTimer %A_ThisLabel%,Off
  7382.  
  7383. if $RunPID
  7384. if StrLen($RunPIDList)=0
  7385. $RunPIDList:=$RunPID
  7386. else
  7387. $RunPIDList:=$RunPIDList . "," . $RunPID
  7388.  
  7389. return
  7390.  
  7391.  
  7392. ;******************************
  7393. ;* *
  7394. ;* Stop running scripts *
  7395. ;* (QAHKGUI) *
  7396. ;* *
  7397. ;******************************
  7398. QAHKGUI_Stop:
  7399. run=0
  7400. SetTimer %A_ThisLabel%,Off
  7401.  
  7402. ;-- Set GUI default
  7403. gui %$QAHKGUI%:Default
  7404.  
  7405. ;-- Attach messages to the current GUI
  7406. gui +OwnDialogs
  7407.  
  7408. ;[======================]
  7409. ;[ Anything to close? ]
  7410. ;[======================]
  7411. $RunPIDList:=RebuildRunPIDList($RunPIDList)
  7412. if StrLen($RunPIDList)=0
  7413. {
  7414. ;-- Status bar showing?
  7415. if $ShowStatusBar
  7416. {
  7417. ;-- Update status bar
  7418. SB_SetText("There are no running scripts.")
  7419. SetTimer QAHKGUI_ClearStatusBar,8000
  7420.  
  7421. ;-- Make a "There is nothing to do" noise
  7422. SoundPlay *16 ;-- System error sound
  7423. }
  7424. else
  7425. MsgBox
  7426. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  7427. ,Stop Error
  7428. ,There are no running scripts. %A_Space%
  7429.  
  7430. ;-- Bounce
  7431. return
  7432. }
  7433.  
  7434. ;[===========]
  7435. ;[ Confirm ]
  7436. ;[===========]
  7437. ;-- Create display list
  7438. $RunPIDListDisplay:=" " . $RunPIDList
  7439. StringReplace $RunPIDListDisplay,$RunPIDListDisplay,`,,`n %A_Space%,All
  7440.  
  7441. ;-- Prompt
  7442. if (ConfirmExitIfRunning)
  7443. {
  7444. if InStr($RunPIDList,",")=0
  7445. MsgBox
  7446. ,49 ;-- 49 = 1 (OK/Cancel buttons) + 48 ("!" icon)
  7447. ,Confirm Stop,
  7448. (ltrim join`s
  7449. This request will terminate the script that is currently
  7450. running. Press OK to proceed. %A_Space%
  7451. )
  7452. else
  7453. MsgBox
  7454. ,49 ;-- 49 = 1 (OK/Cancel buttons) + 48 ("!" icon)
  7455. ,Confirm Stop,
  7456. (ltrim join`s
  7457. The following %$ScriptName% processes will be terminated: %A_Space%
  7458. `n`n%$RunPIDListDisplay%
  7459. `n`nPress OK to proceed. %A_Space%
  7460. )
  7461. }
  7462. IfMsgBox Cancel
  7463. return
  7464.  
  7465. ;[=============]
  7466. ;[ Close 'em ]
  7467. ;[=============]
  7468. $CloseCount=0
  7469. $ErrorCount=0
  7470. Loop Parse,$RunPIDList,`,
  7471. {
  7472. ;-- Ignore if already closed
  7473. Process Exist,%A_LoopField%
  7474. if not ErrorLevel
  7475. Continue
  7476.  
  7477.  
  7478. ;-- Close it
  7479. Process Close,%A_LoopField%
  7480. if ErrorLevel
  7481. $CloseCount++
  7482. else
  7483. $ErrorCount++
  7484. }
  7485.  
  7486. ;-- Errors?
  7487. if $ErrorCount
  7488. MsgBox
  7489. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  7490. ,Stop Error,
  7491. (ltrim join`s
  7492. %$ErrorCount% %$ScriptName% process(es) could not be
  7493. terminated. %A_Space%
  7494. )
  7495. else
  7496. if $CloseCount
  7497. {
  7498. if (ConfirmExitIfRunning)
  7499. {
  7500. if InStr($RunPIDList,",")=0
  7501. MsgBox
  7502. ,64 ;-- 64 = 0 (OK button) + 64 (Info icon)
  7503. ,Stop
  7504. ,Script terminated. %A_Space%
  7505. ,20 ;-- Timeout
  7506. else
  7507. MsgBox
  7508. ,64 ;-- 64 = 0 (OK button) + 64 (Info icon)
  7509. ,Stop
  7510. ,%$CloseCount% %$ScriptName% processes terminated. %A_Space%
  7511. }
  7512. }
  7513. else
  7514. MsgBox
  7515. ,48 ;-- 48 = 0 (OK button) + 48 ("!" icon)
  7516. ,Nothing to Stop
  7517. ,All active scripts already stopped. %A_Space%
  7518.  
  7519. ;-- Clear $RunPIDList
  7520. $RunPIDList:=""
  7521.  
  7522. ;-- Disable "Stop" menu and toolbar items
  7523. Menu QAHKGUI_FileMenu
  7524. ,Disable
  7525. ,%s_File_Stop_MI%
  7526.  
  7527. Menu QAHKGUI_Menubar
  7528. ,Disable
  7529. ,%s_Menubar_Stop_MI%
  7530.  
  7531. return
  7532.  
  7533.  
  7534. ;******************************
  7535. ;* *
  7536. ;* Create restore point *
  7537. ;* (QAHKGUI) *
  7538. ;* *
  7539. ;******************************
  7540. QAHKGUI_CreateRestorePoint:
  7541. SetTimer %A_ThisLabel%,Off
  7542.  
  7543. ;-- Running?
  7544. if $Running
  7545. {
  7546. SoundPlay *-1 ;-- System default sound
  7547. return
  7548. }
  7549.  
  7550. ;-- Set GUI default
  7551. gui %$QAHKGUI%:Default
  7552.  
  7553.  
  7554. ;-- Workspace empty?
  7555. if HE_GetTextLength($QAHKGUI_hEdit)=0
  7556. {
  7557. ;-- Update status bar
  7558. SB_SetText("Workspace empty. Restore point NOT created.")
  7559. SetTimer QAHKGUI_ClearStatusBar,8000
  7560.  
  7561. ;-- Make a "Didn't happen" noise
  7562. SoundPlay *16 ;-- System error sound
  7563. }
  7564. else
  7565. {
  7566. ;-- Create restore point
  7567. RPCreate(False)
  7568.  
  7569. ;-- Update status bar
  7570. SB_SetText("Restore point created.")
  7571. SetTimer QAHKGUI_ClearStatusBar,10000
  7572.  
  7573. ;-- Make a "OK, I did it" noise
  7574. SoundPlay *64: ;-- System Info sound
  7575. }
  7576.  
  7577. return
  7578.  
  7579.  
  7580. ;***********************
  7581. ;* *
  7582. ;* Edit commands *
  7583. ;* (QAHKGUI) *
  7584. ;* *
  7585. ;***********************
  7586. QAHKGUI_EditCopy:
  7587. SetTimer %A_ThisLabel%,Off
  7588.  
  7589. ;-- Running?
  7590. if $Running
  7591. {
  7592. SoundPlay *-1 ;-- System default sound
  7593. return
  7594. }
  7595.  
  7596. HE_Copy($QAHKGUI_hEdit)
  7597. return
  7598.  
  7599.  
  7600. QAHKGUI_EditCut:
  7601. SetTimer %A_ThisLabel%,Off
  7602.  
  7603. ;-- Running?
  7604. if $Running
  7605. {
  7606. SoundPlay *-1 ;-- System default sound
  7607. return
  7608. }
  7609.  
  7610. HE_Cut($QAHKGUI_hEdit)
  7611. return
  7612.  
  7613.  
  7614. QAHKGUI_EditPaste:
  7615. SetTimer %A_ThisLabel%,Off
  7616.  
  7617. ;-- Running?
  7618. if $Running
  7619. {
  7620. SoundPlay *-1 ;-- System default sound
  7621. return
  7622. }
  7623.  
  7624. HE_Paste($QAHKGUI_hEdit)
  7625. return
  7626.  
  7627.  
  7628. QAHKGUI_Editclear:
  7629. SetTimer %A_ThisLabel%,Off
  7630.  
  7631. ;-- Running?
  7632. if $Running
  7633. {
  7634. SoundPlay *-1 ;-- System default sound
  7635. return
  7636. }
  7637.  
  7638. HE_Clear($QAHKGUI_hEdit)
  7639. return
  7640.  
  7641.  
  7642. QAHKGUI_EditSelectAll:
  7643. SetTimer %A_ThisLabel%,Off
  7644.  
  7645. ;-- Running?
  7646. if $Running
  7647. {
  7648. SoundPlay *-1 ;-- System default sound
  7649. return
  7650. }
  7651.  
  7652. HE_SetSel($QAHKGUI_hEdit,0,-1)
  7653. return
  7654.  
  7655.  
  7656. QAHKGUI_Redo:
  7657. SetTimer %A_ThisLabel%,Off
  7658.  
  7659. ;-- Running?
  7660. if $Running
  7661. {
  7662. SoundPlay *-1 ;-- System default sound
  7663. return
  7664. }
  7665.  
  7666.  
  7667. ;-- Reset GUI default
  7668. gui %$QAHKGUI%:Default
  7669.  
  7670.  
  7671. ;-- Redo
  7672. if HE_Redo($QAHKGUI_hEdit)
  7673. SB_SetText("Redo requested.")
  7674. else
  7675. {
  7676. SB_SetText("Nothing to redo.")
  7677. SoundPlay *-1 ;-- System default sound
  7678. }
  7679.  
  7680. SetTimer QAHKGUI_ClearStatusBar,6000
  7681. return
  7682.  
  7683.  
  7684.  
  7685. QAHKGUI_Undo:
  7686. SetTimer %A_ThisLabel%,Off
  7687.  
  7688. ;-- Running?
  7689. if $Running
  7690. {
  7691. SoundPlay *-1 ;-- System default sound
  7692. return
  7693. }
  7694.  
  7695.  
  7696. ;-- Reset GUI default
  7697. gui %$QAHKGUI%:Default
  7698.  
  7699. ;-- Undo
  7700. if HE_Undo($QAHKGUI_hEdit)
  7701. SB_SetText("Undo requested.")
  7702. else
  7703. {
  7704. SB_SetText("Nothing to undo.")
  7705. SoundPlay *-1 ;-- System default sound
  7706. }
  7707.  
  7708. SetTimer QAHKGUI_ClearStatusBar,6000
  7709. return
  7710.  
  7711.  
  7712. ;********************
  7713. ;* *
  7714. ;* Capitalize *
  7715. ;* Lowercase *
  7716. ;* ToggleCase *
  7717. ;* Uppercase *
  7718. ;* *
  7719. ;* (QAHKGUI) *
  7720. ;* *
  7721. ;********************
  7722. QAHKGUI_Capitalize:
  7723. QAHKGUI_Lowercase:
  7724. QAHKGUI_InvertCase:
  7725. QAHKGUI_ToggleCase:
  7726. QAHKGUI_Uppercase:
  7727. SetTimer %A_ThisLabel%,Off
  7728.  
  7729. ;-- Running?
  7730. if $Running
  7731. {
  7732. SoundPlay *-1 ;-- System default sound
  7733. return
  7734. }
  7735.  
  7736. ;-- Convert
  7737. QAHKGUI_ConvertCase($QAHKGUI_hEdit,SubStr(A_ThisLabel,9))
  7738. return
  7739.  
  7740.  
  7741. ;***********************
  7742. ;* *
  7743. ;* Block Comment *
  7744. ;* (QAHKGUI) *
  7745. ;* *
  7746. ;***********************
  7747. QAHKGUI_BlockComment:
  7748. SetTimer %A_ThisLabel%,Off
  7749.  
  7750. ;-- Running?
  7751. if $Running
  7752. {
  7753. SoundPlay *-1 ;-- System default sound
  7754. return
  7755. }
  7756.  
  7757. ;-- Block comment
  7758. Critical
  7759. HE_BlockComment($QAHKGUI_hEdit,"Insert",$BlockComment)
  7760. Critical Off
  7761. return
  7762.  
  7763.  
  7764. ;*************************
  7765. ;* *
  7766. ;* Block Uncomment *
  7767. ;* (QAHKGUI) *
  7768. ;* *
  7769. ;*************************
  7770. QAHKGUI_BlockUncomment:
  7771. SetTimer %A_ThisLabel%,Off
  7772.  
  7773. ;-- Running?
  7774. if $Running
  7775. {
  7776. SoundPlay *-1 ;-- System default sound
  7777. return
  7778. }
  7779.  
  7780. ;-- Block uncomment
  7781. Critical
  7782. HE_BlockComment($QAHKGUI_hEdit,"Delete",$BlockComment)
  7783. Critical Off
  7784. return
  7785.  
  7786.  
  7787. ;********************
  7788. ;* *
  7789. ;* Page Setup *
  7790. ;* (QAHKGUI) *
  7791. ;* *
  7792. ;********************
  7793. QAHKGUI_Toolbar_PageSetup:
  7794. SetTimer %A_ThisLabel%,Off
  7795. SetTimer QAHKGUI_PageSetup,0
  7796. return
  7797.  
  7798.  
  7799. QAHKGUI_PageSetup:
  7800. SetTimer %A_ThisLabel%,Off
  7801.  
  7802. ;-- Running?
  7803. if $Running
  7804. {
  7805. SoundPlay *-1 ;-- System default sound
  7806. return
  7807. }
  7808.  
  7809. ;-- Update printer settings to user defaults
  7810. gosub UpdatePrinterSettings
  7811.  
  7812. ;[==============]
  7813. ;[ Page setup ]
  7814. ;[==============]
  7815. ;-- Create/Define PAGESETUPDLG Structure
  7816. VarSetCapacity(PAGESETUPDLG_Structure,84,0)
  7817. NumPut(84,PAGESETUPDLG_Structure,0,"UInt") ;-- lStructSize
  7818. NumPut($QAHKGUI_hWnd,PAGESETUPDLG_Structure,4,"UInt") ;-- hwndOwner
  7819.  
  7820. if hDevMode is Integer
  7821. NumPut(hDevMode,PAGESETUPDLG_Structure,8,"UInt") ;-- hDevMode
  7822.  
  7823. if hDevNames is Integer
  7824. NumPut(hDevNames,PAGESETUPDLG_Structure,12,"UInt") ;-- hDevMode
  7825.  
  7826. ;-- Flags
  7827. NumPut(PSD_MARGINS,PAGESETUPDLG_Structure,16,"UInt")
  7828.  
  7829. ;-- Set default margins
  7830. NumPut($PrintMarginLeft ,PAGESETUPDLG_Structure,44,"UInt") ;-- rtMargin.left
  7831. NumPut($PrintMarginTop ,PAGESETUPDLG_Structure,48,"UInt") ;-- rtMargin.top
  7832. NumPut($PrintMarginRight ,PAGESETUPDLG_Structure,52,"UInt") ;-- rtMargin.right
  7833. NumPut($PrintMarginBottom,PAGESETUPDLG_Structure,56,"UInt") ;-- rtMargin.bottom
  7834.  
  7835.  
  7836. ;-- Show Page Setup dialog. Bounce if user cancels.
  7837. if not DllCall("comdlg32\PageSetupDlgA","UInt",&PAGESETUPDLG_Structure)
  7838. return
  7839.  
  7840. ;-- Collect handles
  7841. hDevMode :=NumGet(PAGESETUPDLG_Structure,8,"UInt")
  7842. ;-- Handle to a global memory object that contains a DEVMODE structure
  7843.  
  7844. hDevNames :=NumGet(PAGESETUPDLG_Structure,12,"UInt")
  7845. ;-- Handle to a movable global memory object that contains a DEVNAMES
  7846. ; structure
  7847.  
  7848. ;[===========================]
  7849. ;[ Collect user selections ]
  7850. ;[===========================]
  7851. ;-- Margins
  7852. $PrintMarginLeft :=NumGet(PAGESETUPDLG_Structure,44,"UInt") ;-- rtMargin.left
  7853. $PrintMarginTop :=NumGet(PAGESETUPDLG_Structure,48,"UInt") ;-- rtMargin.top
  7854. $PrintMarginRight :=NumGet(PAGESETUPDLG_Structure,52,"UInt") ;-- rtMargin.right
  7855. $PrintMarginBottom:=NumGet(PAGESETUPDLG_Structure,56,"UInt") ;-- rtMargin.bottom
  7856.  
  7857. ;-- Lock the moveable memory, retrieving a pointer to it
  7858. pDevMode :=DllCall("GlobalLock","UInt",hDevMode)
  7859.  
  7860. ;-- Collet orientation
  7861. $PrintOrientation:=NumGet(pDevMode+0,44,"Short")
  7862.  
  7863. ;-- Save configuration
  7864. gosub SaveConfiguration
  7865. return
  7866.  
  7867.  
  7868.  
  7869. ;*******************
  7870. ;* *
  7871. ;* Print *
  7872. ;* (QAHKGUI) *
  7873. ;* *
  7874. ;*******************
  7875. QAHKGUI_Toolbar_Print:
  7876. SetTimer %A_ThisLabel%,Off
  7877. SetTimer QAHKGUI_Print,0
  7878. return
  7879.  
  7880.  
  7881. QAHKGUI_Print:
  7882. SetTimer %A_ThisLabel%,Off
  7883.  
  7884. ;-- Running?
  7885. if $Running
  7886. {
  7887. SoundPlay *-1 ;-- System default sound
  7888. return
  7889. }
  7890.  
  7891.  
  7892. ;-- Anything to print?
  7893. if HE_GetTextLength($QAHKGUI_hEdit)=0
  7894. {
  7895. gui +OwnDialogs
  7896. MsgBox
  7897. ,48 ;-- 16 = 0 (OK button) + 48 ("!" icon)
  7898. ,Print Error
  7899. ,The workspace is empty. There is nothing to print. %A_Space%
  7900.  
  7901. return
  7902. }
  7903.  
  7904. ;-- Update printer setting to user defaults
  7905. gosub UpdatePrinterSettings
  7906.  
  7907. ;-- Print it
  7908. HE_Print($QAHKGUI_hEdit
  7909. ,$QAHKGUI_hWnd
  7910. ,$PrintMarginLeft
  7911. ,$PrintMarginTop
  7912. ,$PrintMarginRight
  7913. ,$PrintMarginBottom)
  7914.  
  7915. return
  7916.  
  7917.  
  7918. ;*******************
  7919. ;* *
  7920. ;* Help *
  7921. ;* (QAHKGUI) *
  7922. ;* *
  7923. ;*******************
  7924. QAHKGUI_Help:
  7925. SetTimer %A_ThisLabel%,Off
  7926.  
  7927. ;-- Help file already open?
  7928. IfWinExist %$ScriptName% Help
  7929. WinActivate
  7930. else
  7931. {
  7932. ;-- Open Help file
  7933. Run %$HelpFile%,,UseErrorLevel
  7934. if ErrorLevel
  7935. {
  7936. gui +OwnDialogs
  7937. MsgBox
  7938. ,16 ;-- 16=0 (OK button) + 16 (Stop icon)
  7939. ,Help Error
  7940. ,Unable to find the Help file. %A_Space%
  7941. }
  7942. }
  7943.  
  7944. return
  7945.  
  7946.  
  7947. ;*******************
  7948. ;* *
  7949. ;* About *
  7950. ;* (QAHKGUI) *
  7951. ;* *
  7952. ;*******************
  7953. QAHKGUI_Toolbar_About:
  7954. SetTimer %A_ThisLabel%,Off
  7955. SetTimer QAHKGUI_About,0
  7956. return
  7957.  
  7958.  
  7959. QAHKGUI_About:
  7960. SetTimer %A_ThisLabel%,Off
  7961.  
  7962. ;-- Running?
  7963. if $Running
  7964. {
  7965. SoundPlay *-1 ;-- System default sound
  7966. return
  7967. }
  7968.  
  7969. ;-- Collect current HiEdit version
  7970. FileGetVersion,$HiEditVersion,%$LibDir%\HiEdit.dll
  7971.  
  7972. ;-- Build display text
  7973. $Text:="`n" . $ScriptName . "`nv" . $Version . "`n`nHiEdit v" . $HiEditVersion
  7974.  
  7975. ;-- About window
  7976. InfoGUI($QAHKGUI ;-- Owner
  7977. ,$Text ;-- Text
  7978. ,"About..." ;-- Title
  7979. ,"" ;-- GUI options
  7980. ,"Text" ;-- Object type
  7981. ,"r6 w200 Center" ;-- Object options
  7982. ,"Black" ;-- Background color
  7983. ,"Arial" ;-- Font
  7984. ,"cLime s16") ;-- Font options
  7985.  
  7986. return
  7987.  
  7988.  
  7989. ;**************************
  7990. ;* *
  7991. ;* Clear status bar *
  7992. ;* (QAHKGUI) *
  7993. ;* *
  7994. ;**************************
  7995. QAHKGUI_ClearStatusBar:
  7996.  
  7997. ;-- Set GUI default
  7998. gui %$QAHKGUI%:Default
  7999.  
  8000. SetTimer QAHKGUI_ClearStatusBar,Off
  8001. SB_SetText("")
  8002. return
  8003.  
  8004.  
  8005. ;***********************
  8006. ;* *
  8007. ;* Close up shop *
  8008. ;* (QAHKGUI) *
  8009. ;* *
  8010. ;***********************
  8011. ;;; QAHKGUI_Escape:
  8012. ;-- Programming note: The Escape key trap that this label provides cannot be
  8013. ; used because of the HiEdit control. If the HiEdit control is in focus,
  8014. ; any Escape key from any pop-up window will pass control to this label.
  8015. ; To get around this bug, a context-sensitive Escape hotkey has been added
  8016. ; to emulate the function that this label provided.
  8017.  
  8018.  
  8019. QAHKGUI_Close:
  8020. QAHKGUI_Exit:
  8021. SetTimer %A_ThisLabel%,Off
  8022.  
  8023. ;-- Set GUI default
  8024. gui %$QAHKGUI%:Default
  8025.  
  8026. ;-- OK to exit?
  8027. if $ConfirmExitIfRunning
  8028. if not QAHKGUI_ConfirmExit()
  8029. return
  8030.  
  8031. ;-- Close RPViewerGUI?
  8032. IfWinExist ahk_id %$RPViewerGUI_hWnd%
  8033. gosub RPViewerGUI_Close
  8034.  
  8035. ;-- Save workspace
  8036. gosub SaveWorkspace
  8037.  
  8038. ;-- Create resore point?
  8039. if $CreateRPOnExit
  8040. RPCreate()
  8041.  
  8042. ;-- Clear run workspace?
  8043. if $ClearRunWorkspaceOnExit
  8044. gosub DeleteRunFolder
  8045.  
  8046. ;-- Minimized or maximized?
  8047. if $WindowMinimized or $WindowMaximized
  8048. {
  8049. ;-- Turn off sizing
  8050. $Resize:=False
  8051.  
  8052. ;-- Make the window invisible
  8053. DetectHiddenWindows On
  8054. WinSet Transparent,0,ahk_id %$QAHKGUI_hWnd%
  8055. DetectHiddenWindows Off
  8056.  
  8057. ;-- Restore the window so that the final X/Y/W/H can be captured
  8058. if $WindowMinimized
  8059. gui Show,Restore ;-- Un-minimize
  8060. ;-- Note: This action can restore the window into a maximized window
  8061.  
  8062. if $WindowMaximized
  8063. {
  8064. gui Show,Restore
  8065. $WindowMaximized:=True ;-- Restore $WindowMaximized flag
  8066. }
  8067. }
  8068.  
  8069. ;-- Save configuration
  8070. gosub SaveConfiguration
  8071.  
  8072. ;-- Destroy toolbar ILs
  8073. IL_Destroy($hToolbarSmallIL)
  8074. IL_Destroy($hToolbarLargeIL)
  8075.  
  8076. ;-- Free global structures created by PageSetupDlg or PrintDlg
  8077. if hDevMode
  8078. DllCall("GlobalFree","UInt",hDevMode)
  8079.  
  8080. if hDevNames
  8081. DllCall("GlobalFree","UInt",hDevNames)
  8082.  
  8083. ;-- Shut it down
  8084. ExitApp
  8085. return
  8086.  
  8087.  
  8088. ;***************************
  8089. ;* *
  8090. ;* *
  8091. ;* Hotkeys *
  8092. ;* (QAHKGUI) *
  8093. ;* *
  8094. ;* *
  8095. ;***************************
  8096.  
  8097.  
  8098. ;-- Begin #IfWinActive directive
  8099.  
  8100. #IfWinActive ahk_group $QAHKGUI_Group
  8101.  
  8102. ;[==========]
  8103. ;[ Ctrl+R ]
  8104. ;[==========]
  8105.  
  8106.  
  8107.  
  8108.  
  8109. ;[=======]
  8110. ;[ F10 ]
  8111. ;[=======]
  8112. F10::
  8113. ^r::
  8114. if $running
  8115. settimer QAHKGUI_Stop, -1
  8116. else
  8117. settimer QAHKGUI_Run, -1
  8118. return
  8119.  
  8120.  
  8121. ;[==========]
  8122. ;[ Escape ]
  8123. ;[==========]
  8124. ~Escape::
  8125. if $EscapeToExit
  8126. {
  8127. ;-- Bounce if Find or Replace dialog is showing
  8128. IfWinExist ahk_id %Dlg_hWnd%
  8129. {
  8130. SoundPlay *-1 ;-- System default sound
  8131. return
  8132. }
  8133.  
  8134. ;-- We're outta here!
  8135. gosub QAHKGUI_Exit
  8136. }
  8137.  
  8138. return
  8139.  
  8140. ;[===========]
  8141. ;[ AppsKey ]
  8142. ;[===========]
  8143. AppsKey::
  8144.  
  8145. ;-- Get coordinates of end selection position
  8146. HE_GetSel($QAHKGUI_hEdit,$StartSelPos,$EndSelPos)
  8147. HE_PosFromChar($QAHKGUI_hEdit,$EndSelPos,$EndSelX,$EndSelY)
  8148.  
  8149.  
  8150. ;-- Show context menu
  8151. Menu QAHKGUI_ContextMenu
  8152. ,Show
  8153. ,% $EndSelX+10
  8154. ,% $EndSelY+SM_CYSIZEFRAME+SM_CYCAPTION+($ShowMenuBar ? SM_CYMENU:0)+($ShowToolBar ? $ToolbarH:0)
  8155. ;-- Programming note: Additions to the X and Y positions are to allow
  8156. ; the caret to be visible (X) and to account for the height of the
  8157. ; horizontal border, title bar, menu bar, and toolbar. (Y). These
  8158. ; calculations are only accurate if menu bar and the toolbar are not
  8159. ; wrapped.
  8160.  
  8161. return
  8162.  
  8163.  
  8164. ;[================]
  8165. ;[ Ctrl+WheelUp ]
  8166. ;[================]
  8167. ^WheelUp::
  8168. gosub QAHKGUI_IncreaseFontSize
  8169. return
  8170.  
  8171.  
  8172. ;[==================]
  8173. ;[ Ctrl+WheelDown ]
  8174. ;[==================]
  8175. ^WheelDown::
  8176. gosub QAHKGUI_DecreaseFontSize
  8177. return
  8178.  
  8179.  
  8180. ;[=======]
  8181. ;[ Tab ]
  8182. ;[=======]
  8183. Tab::
  8184.  
  8185. ;-- Running?
  8186. if $Running
  8187. {
  8188. SoundPlay *-1 ;-- System default sound
  8189. return
  8190. }
  8191.  
  8192. ;-- Shift right
  8193. Critical
  8194. HE_ShiftLine($QAHKGUI_hEdit,"Insert",$Tab)
  8195. return
  8196.  
  8197.  
  8198. ;[=============]
  8199. ;[ Shift+Tab ]
  8200. ;[=============]
  8201. +Tab::
  8202.  
  8203. ;-- Running?
  8204. if $Running
  8205. {
  8206. SoundPlay *-1 ;-- System default sound
  8207. return
  8208. }
  8209.  
  8210. ;-- Shift left
  8211. Critical
  8212. HE_ShiftLine($QAHKGUI_hEdit,"Delete",$Tab)
  8213. return
  8214.  
  8215.  
  8216. ;[==========]
  8217. ;[ Ctrl+[ ]
  8218. ;[==========]
  8219. ^[::
  8220. gosub QAHKGUI_DecreaseFontSize
  8221. return
  8222.  
  8223.  
  8224. ;[==========]
  8225. ;[ Ctrl+] ]
  8226. ;[==========]
  8227. ^]::
  8228. gosub QAHKGUI_IncreaseFontSize
  8229. return
  8230.  
  8231.  
  8232. ;[==================]
  8233. ;[ Ctrl+NumpadAdd ]
  8234. ;[==================]
  8235. ^NumpadAdd::
  8236. gosub QAHKGUI_IncreaseFontSize
  8237. return
  8238.  
  8239.  
  8240. ;[==================]
  8241. ;[ Ctrl+NumpadSub ]
  8242. ;[==================]
  8243. ^NumpadSub::
  8244. gosub QAHKGUI_DecreaseFontSize
  8245. return
  8246.  
  8247.  
  8248. ;[==================]
  8249. ;[ Ctrl+Numpad0 ]
  8250. ;[ Ctrl+NumpadIns ]
  8251. ;[==================]
  8252. ^Numpad0::
  8253. ^NumpadIns::
  8254. ^NumpadDiv::
  8255. gosub QAHKGUI_DefaultFontSize
  8256. return
  8257.  
  8258.  
  8259. ;[======]
  8260. ;[ F1 ]
  8261. ;[======]
  8262. F1::
  8263. gosub QAHKGUI_Help
  8264. return
  8265.  
  8266.  
  8267. ;[======]
  8268. ;[ F2 ]
  8269. ;[======]
  8270. F2::
  8271. gosub OptionsGUI
  8272. return
  8273.  
  8274.  
  8275. ;[======]
  8276. ;[ F3 ]
  8277. ;[======]
  8278. F3::
  8279. gosub QAHKGUI_FindNext
  8280. return
  8281.  
  8282.  
  8283. ;[============]
  8284. ;[ Shift+F3 ]
  8285. ;[============]
  8286. +F3::
  8287. gosub QAHKGUI_FindPrevious
  8288. return
  8289.  
  8290.  
  8291. ;[======]
  8292. ;[ F4 ]
  8293. ;[======]
  8294. F4::
  8295. gosub RPViewerGUI ;-- Restore
  8296. return
  8297.  
  8298.  
  8299. ;[======]
  8300. ;[ F5 ]
  8301. ;[======]
  8302. F5::
  8303. gosub QAHKGUI_PasteClipboard ;-- PasteC
  8304. return
  8305.  
  8306.  
  8307. ;[======]
  8308. ;[ F8 ]
  8309. ;[======]
  8310. F8::
  8311. gosub QAHKGUI_ExternalEditor
  8312. return
  8313.  
  8314.  
  8315. ;[======]
  8316. ;[ F9 ]
  8317. ;[======]
  8318. F9::
  8319. gosub QAHKGUI_Run
  8320. return
  8321.  
  8322.  
  8323. ;[===========]
  8324. ;[ Ctrl+F9 ]
  8325. ;[===========]
  8326. ^F9::
  8327. gosub QAHKGUI_RunSelected
  8328. return
  8329.  
  8330.  
  8331. ;[=================]
  8332. ;[ Ctrl+Shift+F9 ]
  8333. ;[=================]
  8334. ^+F9::
  8335. gosub QAHKGUI_ExploreRunWorkspace
  8336. return
  8337.  
  8338.  
  8339. ;[===============]
  8340. ;[ Ctrl+Alt+F9 ]
  8341. ;[===============]
  8342. ^!F9::
  8343. gosub QAHKGUI_ClearRunWorkspace
  8344. return
  8345.  
  8346.  
  8347. ;[=======]
  8348. ;[ F12 ]
  8349. ;[=======]
  8350. F12::
  8351. gosub QAHKGUI_SaveTo
  8352. return
  8353.  
  8354.  
  8355. ;[================]
  8356. ;[ Ctrl+Shift+A ]
  8357. ;[================]
  8358. ^+a::
  8359. gosub QAHKGUI_ToggleAlwaysOnTop
  8360. return
  8361.  
  8362.  
  8363. ;[================]
  8364. ;[ Ctrl+Shift+C ]
  8365. ;[================]
  8366. ^+c::
  8367. gosub QAHKGUI_Capitalize
  8368. return
  8369.  
  8370.  
  8371. ;[==========]
  8372. ;[ Ctrl+F ]
  8373. ;[==========]
  8374. ^f::
  8375. gosub QAHKGUI_Find
  8376. return
  8377.  
  8378.  
  8379. ;[==========]
  8380. ;[ Ctrl+G ]
  8381. ;[==========]
  8382. ^g::
  8383. gosub QAHKGUI_Goto
  8384. return
  8385.  
  8386.  
  8387. ;[==========]
  8388. ;[ Ctrl+H ]
  8389. ;[==========]
  8390. ^h::
  8391. gosub QAHKGUI_Replace
  8392. return
  8393.  
  8394.  
  8395. ;[==========]
  8396. ;[ Ctrl+Shift+I ]
  8397. ;[==========]
  8398. ^+i::
  8399. gosub QAHKGUI_ToggleToolbarIconSize
  8400. return
  8401.  
  8402.  
  8403. ;[==========]
  8404. ;[ Ctrl+L ]
  8405. ;[==========]
  8406. ^l::
  8407. gosub QAHKGUI_ToggleLineNumbersBar
  8408. return
  8409.  
  8410.  
  8411. ;[================]
  8412. ;[ Ctrl+Shift+L ]
  8413. ;[================]
  8414. ^+l::
  8415. gosub QAHKGUI_Lowercase
  8416. return
  8417.  
  8418.  
  8419. ;[================]
  8420. ;[ Ctrl+Shift+M ]
  8421. ;[================]
  8422. ^+m::
  8423. gosub QAHKGUI_ToggleMenubar
  8424. return
  8425.  
  8426.  
  8427. ;[==========]
  8428. ;[ Ctrl+N ]
  8429. ;[==========]
  8430. ^n::
  8431. gosub QAHKGUI_New
  8432. return
  8433.  
  8434.  
  8435. ;[================]
  8436. ;[ Ctrl+Shift+N ]
  8437. ;[================]
  8438. ^+n::
  8439. gosub QAHKGUI_PrependNew
  8440. return
  8441.  
  8442.  
  8443. ;[==========]
  8444. ;[ Ctrl+O ]
  8445. ;[==========]
  8446. ^o::
  8447. gosub QAHKGUI_CopyFrom
  8448. return
  8449.  
  8450.  
  8451. ;[==========]
  8452. ;[ Ctrl+P ]
  8453. ;[==========]
  8454. ^p::
  8455. gosub QAHKGUI_Print
  8456. return
  8457.  
  8458.  
  8459. ;[================]
  8460. ;[ Ctrl+Shift+P ]
  8461. ;[================]
  8462. ^+p::
  8463. gosub QAHKGUI_PageSetup
  8464. return
  8465.  
  8466.  
  8467. ;[==========]
  8468. ;[ Ctrl+Q ]
  8469. ;[==========]
  8470. ^q::
  8471. gosub QAHKGUI_BlockComment
  8472. return
  8473.  
  8474.  
  8475. ;[================]
  8476. ;[ Ctrl+Shift+Q ]
  8477. ;[================]
  8478. ^+q::
  8479. gosub QAHKGUI_BlockUncomment
  8480. return
  8481.  
  8482.  
  8483.  
  8484.  
  8485.  
  8486. ;[================]
  8487. ;[ Ctrl+Shift+R ]
  8488. ;[================]
  8489. ^+r::
  8490. gosub QAHKGUI_CreateRestorePoint
  8491. return
  8492.  
  8493.  
  8494. ;[==========]
  8495. ;[ Ctrl+S ]
  8496. ;[==========]
  8497. ^s::
  8498. gosub QAHKGUI_Save
  8499. return
  8500.  
  8501.  
  8502. ;[================]
  8503. ;[ Ctrl+Shift+S ]
  8504. ;[================]
  8505. ^+s::
  8506. gosub QAHKGUI_ToggleStatusbar
  8507. return
  8508.  
  8509.  
  8510. ;[==========]
  8511. ;[ Ctrl+T ]
  8512. ;[==========]
  8513. ^t::
  8514. gosub QAHKGUI_ToggleToolbar
  8515. return
  8516.  
  8517.  
  8518. ;[================]
  8519. ;[ Ctrl+Shift+T ]
  8520. ;[================]
  8521. ^+t::
  8522. gosub QAHKGUI_ToggleCase
  8523. return
  8524.  
  8525.  
  8526. ;[================]
  8527. ;[ Ctrl+Shift+U ]
  8528. ;[================]
  8529. ^+u::
  8530. gosub QAHKGUI_Uppercase
  8531. return
  8532.  
  8533.  
  8534. ;[==========]
  8535. ;[ Ctrl+Y ]
  8536. ;[==========]
  8537. ^y:: ;-- Note: Native is not used for this hotkey
  8538. gosub QAHKGUI_Redo
  8539. return
  8540.  
  8541.  
  8542. ;[==========]
  8543. ;[ Ctrl+Z ]
  8544. ;[==========]
  8545. ^z:: ;-- Note: Native is not used for this hotkey
  8546. gosub QAHKGUI_Undo
  8547. return
  8548.  
  8549.  
  8550. ;[================]
  8551. ;[ Ctrl+Shift+Z ]
  8552. ;[================]
  8553. ^+z::
  8554. gosub QAHKGUI_Revert
  8555. return
  8556.  
  8557. ;-- End #IfWinActive directive
  8558. #IfWinActive
  8559.  
  8560.  
  8561. ;-------------------------------------------------------------------------------
  8562. ;------------------------------ End QAHKGUI Stuff ------------------------------
  8563. ;-------------------------------------------------------------------------------
  8564. ;-------------------------------------------------------------------------------
  8565. ;-------------------------------------------------------------------------------
  8566. ;-------------------------------------------------------------------------------
  8567. ;-------------------------------------------------------------------------------
  8568.  
  8569.  
  8570.  
  8571.  
  8572.  
  8573. ;-------------------------------------------------------------------------------
  8574. ;-------------------------------------------------------------------------------
  8575. ;-------------------------------------------------------------------------------
  8576. ;-------------------------------------------------------------------------------
  8577. ;-------------------------------------------------------------------------------
  8578. ;---------------------------- Begin OptionsGUI Stuff ---------------------------
  8579. ;-------------------------------------------------------------------------------
  8580. ;*****************************
  8581. ;* *
  8582. ;* *
  8583. ;* Options GUI *
  8584. ;* *
  8585. ;* *
  8586. ;*****************************
  8587. OptionsGUI:
  8588. SetTimer OptionsGUI,Off
  8589.  
  8590. ;-- Running?
  8591. if $Running
  8592. {
  8593. SoundPlay *-1 ;-- System default sound
  8594. return
  8595. }
  8596.  
  8597. ;[==============]
  8598. ;[ Initialize ]
  8599. ;[==============]
  8600. $OptionsGUI:=21
  8601.  
  8602. ;---------------------
  8603. ;-- Toolbar icon size
  8604. ;---------------------
  8605. $OptionsGUI_ToolbarLargeIcons:=False
  8606. $OptionsGUI_ToolbarSmallIcons:=False
  8607. if $ToolbarIconSize=Large
  8608. $OptionsGUI_ToolbarLargeIcons:=True
  8609. else
  8610. $OptionsGUI_ToolbarSmallIcons:=True
  8611.  
  8612. ;----------------------
  8613. ;-- Shell context menu
  8614. ;----------------------
  8615. $OptionsGUI_ShellContextMenu:=False
  8616.  
  8617. ;-- Compiled?
  8618. if A_IsCompiled
  8619. {
  8620. ;-- Is .ahk registered?
  8621. RegRead
  8622. ,$DocumentType
  8623. ,HKEY_CLASSES_ROOT
  8624. ,.ahk\
  8625.  
  8626. if not ErrorLevel
  8627. {
  8628. ;-- Look for custom command
  8629. RegRead
  8630. ,$Dummy
  8631. ,HKEY_CLASSES_ROOT
  8632. ,%$DocumentType%\shell\Open with %$ScriptName%\command
  8633.  
  8634. if not ErrorLevel
  8635. $OptionsGUI_ShellContextMenu:=True
  8636. }
  8637. }
  8638.  
  8639. ;[=============]
  8640. ;[ Build GUI ]
  8641. ;[=============]
  8642. ;-- Set GUI default
  8643. gui %$OptionsGUI%:Default
  8644.  
  8645. ;-- Disable parent GUI, give ownership to parent GUI
  8646. gui %$QAHKGUI%:+Disabled
  8647. gui +Owner%$QAHKGUI%
  8648. ;-- Note: Ownership assignment must be be performed before any other GUI
  8649. ; commands.
  8650.  
  8651. ;-- Identify window handle
  8652. gui %$OptionsGUI%:+LastFound
  8653. WinGet $OptionsGUI_hWnd,ID
  8654.  
  8655. ;-- GUI options
  8656. gui Margin,6,6
  8657. gui +LabelOptionsGUI_
  8658. || +Resize
  8659. || -MinimizeBox
  8660. || -MaximizeBox
  8661. || +MinSize
  8662.  
  8663. ;-- Tab
  8664. gui Add
  8665. ,Tab2
  8666. ,xm y10 w420 h440
  8667. || hWnd$OptionsGUI_Tab_hWnd
  8668. || v$OptionsGUI_Tab
  8669. || gOptionsGUI_Tab
  8670. ,General|Editor|Run|Restore|New|Debug
  8671.  
  8672. ;----------------
  8673. ;-- Tab: General
  8674. ;----------------
  8675. gui Tab,General
  8676. gui Add
  8677. ,GroupBox
  8678. ,xm+10 y40 w400 h10
  8679. || hWnd$OptionsGUI_GeneralGB_hWnd
  8680. || v$OptionsGUI_GeneralGB
  8681. ,General
  8682.  
  8683. gui Add
  8684. ,Edit
  8685. ,xp+10 yp+20
  8686. || Hidden
  8687. ,Dummy
  8688. ;-- Used to establish height for the rest of the controls on group box
  8689.  
  8690. gui Add
  8691. ,CheckBox
  8692. ,xp hp
  8693. || Checked%$OptionsGUI_ShellContextMenu%
  8694. || v$OptionsGUI_ShellContextMenu
  8695. ,Integrate %$ScriptName% Into Shell Context Menu
  8696.  
  8697. ;-- Disable if running script
  8698. if not A_IsCompiled
  8699. GUIControl Disable,$OptionsGUI_ShellContextMenu
  8700.  
  8701. gui Add
  8702. ,CheckBox
  8703. ,y+0 hp
  8704. || Checked%$AlwaysOnTop%
  8705. || v$OptionsGUI_AlwaysOnTop
  8706. ,Always On Top
  8707.  
  8708. gui Add
  8709. ,CheckBox
  8710. ,y+0 hp
  8711. || Section
  8712. || Checked%$ShowMenubar%
  8713. || v$OptionsGUI_ShowMenubar
  8714. ,Show Menu Bar
  8715.  
  8716. gui Add
  8717. ,CheckBox
  8718. ,y+0 hp
  8719. || Checked%$ShowToolbar%
  8720. || v$OptionsGUI_ShowToolbar
  8721. ,Show Toolbar. Icons:%A_Space%
  8722.  
  8723. gui Add
  8724. ,Radio
  8725. ,x+0 hp
  8726. || Checked%$OptionsGUI_ToolbarLargeIcons%
  8727. || v$OptionsGUI_ToolbarLargeIcons
  8728. ,Large %A_Space%
  8729.  
  8730. gui Add
  8731. ,Radio
  8732. ,x+0 hp
  8733. || Checked%$OptionsGUI_ToolbarSmallIcons%
  8734. || v$OptionsGUI_ToolbarSmallIcons
  8735. ,Small
  8736.  
  8737. gui Add
  8738. ,CheckBox
  8739. ,xs y+0 hp
  8740. || Checked%$ShowStatusbar%
  8741. || v$OptionsGUI_ShowStatusbar
  8742. ,Show Status Bar
  8743.  
  8744. gui Add
  8745. ,CheckBox
  8746. ,y+0 hp
  8747. || Checked%$EscapeToExit%
  8748. || v$OptionsGUI_EscapeToExit
  8749. ,Escape to Exit
  8750.  
  8751. ;-- Resize the General group box
  8752. GUIControlGet $Group1Pos,Pos,$OptionsGUI_GeneralGB
  8753. GUIControlGet $Group2Pos,Pos,$OptionsGUI_EscapeToExit
  8754. outputdebug $Group2PosY=%$Group2PosY%, $Group2PosH=%$Group2PosH%
  8755. GUIControl
  8756. ,Move
  8757. ,$OptionsGUI_GeneralGB
  8758. ,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
  8759.  
  8760. ;---------------
  8761. ;-- Tab: Editor
  8762. ;---------------
  8763. gui Tab,Editor
  8764. gui Add
  8765. ,GroupBox
  8766. ,xm+10 y40 w400 h10
  8767. || hWnd$OptionsGUI_EditorGB_hWnd
  8768. || v$OptionsGUI_EditorGB
  8769. ,Editor
  8770.  
  8771. gui Add
  8772. ,Edit
  8773. ,xp+10 yp+20
  8774. || Section
  8775. || Hidden
  8776. ,Dummy
  8777. ;-- Used to establish height for the rest of the controls on group box
  8778.  
  8779. gui Add
  8780. ,Text
  8781. ,xp w100 hp
  8782. ,Font:
  8783.  
  8784. gui Add
  8785. ,Edit
  8786. ,x+0 w250 r1
  8787. || +ReadOnly
  8788. || v$OptionsGUI_Font
  8789. ,%$Font%
  8790.  
  8791. gui Add
  8792. ,Button
  8793. ,x+0 hp
  8794. || v$OptionsGUI_SelectFont
  8795. || gOptionsGUI_SelectFont
  8796. ,...
  8797.  
  8798. gui Add
  8799. ,Text
  8800. ,xs y+0 w100 hp
  8801. ,Font Size:
  8802.  
  8803. gui Add
  8804. ,Edit
  8805. ,x+0 w50 hp
  8806. || v$OptionsGUI_FontSize
  8807.  
  8808. gui Add
  8809. ,UpDown
  8810. ,Range%$MinimumFontSize%-%$MaximumFontSize%
  8811. ,%$FontSize%
  8812.  
  8813. gui Add
  8814. ,Text
  8815. ,xs y+0 w100 hp
  8816. ,Tab Width:
  8817.  
  8818. gui Add
  8819. ,Edit
  8820. ,x+0 w50 hp
  8821. || v$OptionsGUI_TabWidth
  8822.  
  8823. gui Add
  8824. ,UpDown
  8825. ,Range1-50
  8826. ,%$TabWidth%
  8827.  
  8828.  
  8829. gui Add
  8830. ,CheckBox
  8831. ,x+10 hp
  8832. || Checked%$RealTabs%
  8833. || v$OptionsGUI_RealTabs
  8834. ,Real Tabs
  8835.  
  8836. gui Add
  8837. ,Text
  8838. ,xs y+0 w100 hp
  8839. ,Blk Comment:
  8840.  
  8841. gui Add
  8842. ,Edit
  8843. ,x+0 w100 hp
  8844. || v$OptionsGUI_BlockComment
  8845. ,%$BlockComment%
  8846.  
  8847. gui Add
  8848. ,CheckBox
  8849. ,xs y+2 hp
  8850. || Checked%$AutoIndent%
  8851. || v$OptionsGUI_AutoIndent
  8852. ,Auto Indent
  8853.  
  8854. gui Add
  8855. ,CheckBox
  8856. ,y+0 hp
  8857. || Checked%$LineNumbersBar%
  8858. || v$OptionsGUI_LineNumbersBar
  8859. ,Line Numbers Bar
  8860.  
  8861. gui Add
  8862. ,CheckBox
  8863. ,y+0 hp
  8864. || Checked%$AllowUndoAfterSave%
  8865. || v$OptionsGUI_AllowUndoAfterSave
  8866. ,Allow Undo After Save
  8867.  
  8868. ;-- Resize the Editor group box
  8869. GUIControlGet $Group1Pos,Pos,$OptionsGUI_EditorGB
  8870. GUIControlGet $Group2Pos,Pos,$OptionsGUI_AllowUndoAfterSave
  8871. GUIControl
  8872. ,Move
  8873. ,$OptionsGUI_EditorGB
  8874. ,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
  8875.  
  8876. ;-- External Editor
  8877. gui Add
  8878. ,GroupBox
  8879. ,xm+10 y+10 w400 h10
  8880. || hWnd$OptionsGUI_ExtEditorGB_hWnd
  8881. || v$OptionsGUI_ExtEditorGB
  8882. ,External Editor
  8883.  
  8884. gui Add
  8885. ,Edit
  8886. ,xp+10 yp+20
  8887. || Section
  8888. || Hidden
  8889. ,Dummy
  8890. ;-- Used to establish height for the rest of the controls on group box
  8891.  
  8892. gui Add
  8893. ,Text
  8894. ,xp w50 hp
  8895. ,Name:
  8896.  
  8897. gui Add
  8898. ,Edit
  8899. ,x+0 w300 hp
  8900. || hWnd$OptionsGUI_ExtEditorName_hWnd
  8901. || v$OptionsGUI_ExtEditorName
  8902. ,%$ExtEditorName%
  8903.  
  8904. gui Add
  8905. ,Text
  8906. ,xs y+0 w50 hp
  8907. ,Path:
  8908.  
  8909. gui Add
  8910. ,Edit
  8911. ,x+0 w300 hp
  8912. || hWnd$OptionsGUI_ExtEditorPath_hWnd
  8913. || v$OptionsGUI_ExtEditorPath
  8914. ,%$ExtEditorPath%
  8915.  
  8916. gui Add
  8917. ,Button
  8918. ,x+0 hp
  8919. || hWnd$OptionsGUI_BrowseEditorPath_hWnd
  8920. || v$OptionsGUI_BrowseEditorPath
  8921. || gOptionsGUI_BrowseEditorPath
  8922. ,...
  8923.  
  8924. ;-- Resize the External Editor group box
  8925. GUIControlGet $Group1Pos,Pos,$OptionsGUI_ExtEditorGB
  8926. GUIControlGet $Group2Pos,Pos,$OptionsGUI_BrowseEditorPath
  8927. GUIControl
  8928. ,Move
  8929. ,$OptionsGUI_ExtEditorGB
  8930. ,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
  8931.  
  8932. ;------------
  8933. ;-- Tab: Run
  8934. ;------------
  8935. gui Tab,Run
  8936. gui Add
  8937. ,GroupBox
  8938. ,xm+10 y40 w400 h10
  8939. || hWnd$OptionsGUI_RunGB_hWnd
  8940. || v$OptionsGUI_RunGB
  8941. ,Run
  8942.  
  8943. gui Add
  8944. ,Text
  8945. ,xp+10 yp+20
  8946. ,AutoHotkey Path`n(Leave blank to use registered path)
  8947.  
  8948. gui Add
  8949. ,Edit
  8950. ,xm+20 y+0 w350
  8951. || Section
  8952. || hWnd$OptionsGUI_AutoHotkeyPath_hWnd
  8953. || v$OptionsGUI_AutoHotkeyPath
  8954. ,%$AutoHotkeyPath%
  8955. ;-- This control is used to establish height for the rest of the
  8956. ; controls on group box
  8957.  
  8958. gui Add
  8959. ,Button
  8960. ,x+0 hp
  8961. || hWnd$OptionsGUI_BrowseAutoHotkeyPath_hWnd
  8962. || v$OptionsGUI_BrowseAutoHotkeyPath
  8963. || gOptionsGUI_BrowseAutoHotkeyPath
  8964. ,...
  8965.  
  8966. gui Add
  8967. ,CheckBox
  8968. ,xs y+0 hp
  8969. || Checked%$RunPrompt%
  8970. || v$OptionsGUI_RunPrompt
  8971. ,%s_RunPrompt_MI%
  8972.  
  8973. gui Add
  8974. ,CheckBox
  8975. ,y+0 hp
  8976. || Checked%$RunDebug%
  8977. || v$OptionsGUI_RunDebug
  8978. ,%s_RunDebug_MI%
  8979.  
  8980. gui Add
  8981. ,CheckBox
  8982. ,y+0 hp
  8983. || Checked%$RunWait%
  8984. || v$OptionsGUI_RunWait
  8985. ,%s_RunWait_MI%
  8986.  
  8987. gui Add
  8988. ,CheckBox
  8989. ,y+0 hp
  8990. || Checked%$ConfirmExitIfRunning%
  8991. || v$OptionsGUI_ConfirmExitIfRunning
  8992. ,Confirm Exit if Script(s) Are Still Running
  8993.  
  8994. ;-- Resize the group box
  8995. GUIControlGet $Group1Pos,Pos,$OptionsGUI_RunGB
  8996. GUIControlGet $Group2Pos,Pos,$OptionsGUI_ConfirmExitIfRunning
  8997. GUIControl
  8998. ,Move
  8999. ,$OptionsGUI_RunGB
  9000. ,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
  9001.  
  9002. gui Add
  9003. ,GroupBox
  9004. ,xs-10 y+10 w400 h10
  9005. || hWnd$OptionsGUI_RunFolderGB_hWnd
  9006. || v$OptionsGUI_RunFolderGB
  9007. ,Run Workspace
  9008.  
  9009. gui Add
  9010. ,Edit
  9011. ,xp+10 yp+20
  9012. || Section
  9013. || Hidden
  9014. ,Dummy
  9015. ;-- Used to establish height for the rest of the controls on group box
  9016.  
  9017. gui Add
  9018. ,CheckBox
  9019. ,xp hp
  9020. || Checked%$ClearRunWorkspaceOnRun%
  9021. || v$OptionsGUI_ClearRunWorkspaceOnRun
  9022. ,Clear Run Workspace Before Every Run
  9023.  
  9024. gui Add
  9025. ,CheckBox
  9026. ,y+0 hp
  9027. || Checked%$ClearRunWorkspaceOnExit%
  9028. || v$OptionsGUI_ClearRunWorkspaceOnExit
  9029. ,Clear Run Workspace on Exit
  9030.  
  9031. gui Add
  9032. ,Button
  9033. ,y+5 w90 hp
  9034. || Disabled
  9035. || v$OptionsGUI_ClearRunWorkspace
  9036. || gOptionsGUI_ClearRunWorkspace
  9037. ,Clear Now
  9038.  
  9039. gui Add
  9040. ,Button
  9041. ,x+5 wp hp
  9042. || Disabled
  9043. || v$OptionsGUI_ExploreRunFolder
  9044. || gOptionsGUI_ExploreRunFolder
  9045. ,Explore
  9046.  
  9047. ;-- Enable if "Run" folder exists
  9048. IfExist %$RunDir%\.
  9049. {
  9050. GUIControl Enable,$OptionsGUI_ClearRunWorkspace
  9051. GUIControl Enable,$OptionsGUI_ExploreRunFolder
  9052. }
  9053.  
  9054. ;-- Resize the Run Folder group box
  9055. GUIControlGet $Group1Pos,Pos,$OptionsGUI_RunFolderGB
  9056. GUIControlGet $Group2Pos,Pos,$OptionsGUI_ExploreRunFolder
  9057. GUIControl
  9058. ,Move
  9059. ,$OptionsGUI_RunFolderGB
  9060. ,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
  9061.  
  9062. ;----------------
  9063. ;-- Tab: Restore
  9064. ;----------------
  9065. gui Tab,Restore
  9066. gui Add
  9067. ,GroupBox
  9068. ,xm+10 y40 w400 h10
  9069. || hWnd$OptionsGUI_RPViewerGB_hWnd
  9070. || v$OptionsGUI_RPViewerGB
  9071. ,Restore Point Viewer
  9072.  
  9073. gui Add
  9074. ,Edit
  9075. ,xp+10 yp+20
  9076. || Section
  9077. || Hidden
  9078. ,Dummy
  9079. ;-- Used to establish height for the rest of the controls on group box
  9080.  
  9081. gui Add
  9082. ,Text
  9083. ,xp w80 hp
  9084. ,Font:
  9085.  
  9086. gui Add
  9087. ,Edit
  9088. ,x+0 w250 hp
  9089. || +ReadOnly
  9090. || v$OptionsGUI_RPViewerFont
  9091. ,%$RPViewerFont%
  9092.  
  9093. gui Add
  9094. ,Button
  9095. ,x+0 hp
  9096. || v$OptionsGUI_SelectRPViewerFont
  9097. || gOptionsGUI_SelectRPViewerFont
  9098. ,...
  9099.  
  9100. gui Add
  9101. ,Text
  9102. ,xs y+0 w80 hp
  9103. ,Font size:
  9104.  
  9105. gui Add
  9106. ,Edit
  9107. ,x+0 w50 hp
  9108. || v$OptionsGUI_RPViewerFontSize
  9109.  
  9110. gui Add
  9111. ,UpDown
  9112. ,Range%$MinimumFontSize%-%$MaximumFontSize%
  9113. ,%$RPViewerFontSize%
  9114.  
  9115. gui Add
  9116. ,CheckBox
  9117. ,xs y+0 hp
  9118. || Checked%$RPViewerLineNumbersBar%
  9119. || v$OptionsGUI_RPViewerLineNumbersBar
  9120. ,Line Numbers Bar
  9121.  
  9122. gui Add
  9123. ,Checkbox
  9124. ,xs y+0 hp
  9125. || Checked%$RPViewerSaveWindowPos%
  9126. || v$OptionsGUI_RPViewerSaveWindowPos
  9127. ,Save Window Position
  9128.  
  9129. gui Add
  9130. ,Checkbox
  9131. ,xs y+0 hp
  9132. || Checked%$RPViewerCloseOnRestore%
  9133. || v$OptionsGUI_RPViewerCloseOnRestore
  9134. ,Close Window on Restore
  9135.  
  9136. gui Add
  9137. ,Checkbox
  9138. ,xs y+0 hp
  9139. || Checked%$RPViewerEscapeToClose%
  9140. || v$OptionsGUI_RPViewerEscapeToClose
  9141. ,Escape to Close
  9142.  
  9143. ;-- Resize the RPViewer group box
  9144. GUIControlGet $Group1Pos,Pos,$OptionsGUI_RPViewerGB
  9145. GUIControlGet $Group2Pos,Pos,$OptionsGUI_RPViewerEscapeToClose
  9146. GUIControl
  9147. ,Move
  9148. ,$OptionsGUI_RPViewerGB
  9149. ,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
  9150.  
  9151. gui Add
  9152. ,GroupBox
  9153. ,xs-10 y+10 w400 h10
  9154. || hWnd$OptionsGUI_RestoreGB_hWnd
  9155. || v$OptionsGUI_RestoreGB
  9156. ,Restore Options
  9157.  
  9158. gui Add
  9159. ,Edit
  9160. ,xp+10 yp+20
  9161. || Section
  9162. || Hidden
  9163. ,Dummy
  9164. ;-- Used to establish height for the rest of the controls on group box
  9165.  
  9166. gui Add
  9167. ,Text
  9168. ,xp hp
  9169. ,Maximum restore points:
  9170.  
  9171. gui Add
  9172. ,Edit
  9173. ,x+5 w50 hp ; r5
  9174. || v$OptionsGUI_MaxRestorePoints
  9175. gui Add
  9176. ,UpDown
  9177. ,Range1-999
  9178. ,%$MaxRestorePoints%
  9179.  
  9180. $RPCount:=0
  9181. Loop %$RPDir%\*.ahk
  9182. $RPCount++
  9183.  
  9184. gui Add
  9185. ,Text
  9186. ,x+5 w50 hp
  9187. ,%$RPCount%
  9188.  
  9189. gui Add
  9190. ,CheckBox
  9191. ,xs y+0 hp
  9192. || Checked%$CreateRPOnCopyfromDrop%
  9193. || v$OptionsGUI_CreateRPOnCopyfromDrop
  9194. ,Create Restore Point on "Copy From..." or Drop File
  9195.  
  9196. gui Add
  9197. ,CheckBox
  9198. ,y+0 hp
  9199. || Checked%$CreateRPOnRun%
  9200. || v$OptionsGUI_CreateRPOnRun
  9201. ,Create Restore Point on Run
  9202.  
  9203. gui Add
  9204. ,CheckBox
  9205. ,y+0 hp
  9206. || Checked%$CreateRPOnSave%
  9207. || v$OptionsGUI_CreateRPOnSave
  9208. ,Create Restore Point on Save
  9209.  
  9210. gui Add
  9211. ,CheckBox
  9212. ,y+0 hp
  9213. || Checked%$CreateRPOnExit%
  9214. || v$OptionsGUI_CreateRPOnExit
  9215. ,Create Restore Point on Exit
  9216.  
  9217. gui Add
  9218. ,Button
  9219. ,y+5 w90 hp
  9220. || v$OptionsGUI_ClearRestoreFolder
  9221. || gOptionsGUI_ClearRestoreFolder
  9222. ,Clear Now
  9223.  
  9224. gui Add
  9225. ,Button
  9226. ,x+5 wp hp
  9227. || v$OptionsGUI_ExploreRestoreFolder
  9228. || gOptionsGUI_ExploreRestoreFolder
  9229. ,Explore
  9230.  
  9231.  
  9232. ;-- Disable buttons if "Restore" folder does not exist
  9233. IfNotExist %$RPDir%\.
  9234. {
  9235. GUIControl Disable,$OptionsGUI_ClearRestoreFolder
  9236. GUIControl Disable,$OptionsGUI_ExploreRestoreFolder
  9237. }
  9238.  
  9239. ;-- Resize the Restore group box
  9240. GUIControlGet $Group1Pos,Pos,$OptionsGUI_RestoreGB
  9241. GUIControlGet $Group2Pos,Pos,$OptionsGUI_ExploreRestoreFolder
  9242. GUIControl
  9243. ,Move
  9244. ,$OptionsGUI_RestoreGB
  9245. ,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
  9246.  
  9247. ;------------
  9248. ;-- Tab: New
  9249. ;------------
  9250. gui Tab,New
  9251. gui Add
  9252. ,CheckBox
  9253. ,xm+10 y40
  9254. || Checked%$NewScriptSystemDefault%
  9255. || v$OptionsGUI_NewScriptSystemDefault
  9256. || gOptionsGUI_NewScriptSystemDefault_Action
  9257. ,Use System Default (Template.ahk)
  9258.  
  9259. gui Add
  9260. ,GroupBox
  9261. ,xm+10 y70 w400 h370
  9262. || hWnd$OptionsGUI_NewScriptGB_hWnd
  9263. || v$OptionsGUI_NewScriptGB
  9264. ,New Script
  9265.  
  9266. ;-- Set font/size
  9267. if $Font
  9268. gui Font,,%$Font%
  9269.  
  9270. if $FontSize
  9271. gui Font,s%$FontSize%
  9272.  
  9273. ;-- Edit field
  9274. gui Add
  9275. ,Edit
  9276. ,xp+10 yp+20 w380 h340
  9277. || +0x100000 ;-- WS_HSCROLL
  9278. || -Wrap
  9279. || hWnd$OptionsGUI_NewScript_hWnd
  9280. || v$OptionsGUI_NewScript
  9281. ,%$NewScript%
  9282.  
  9283. ;-- Reset font/size
  9284. gui Font
  9285.  
  9286. ;-- Disable new script?
  9287. if $NewScriptSystemDefault
  9288. GUIControl Disable,$OptionsGUI_NewScript
  9289.  
  9290. ;--------------
  9291. ;-- Tab: Debug
  9292. ;--------------
  9293. gui Tab,Debug
  9294. gui Add
  9295. ,GroupBox
  9296. ,xm+10 y40 w400 h400
  9297. || hWnd$OptionsGUI_DebugScriptGB_hWnd
  9298. || v$OptionsGUI_DebugScriptGB
  9299. ,Debug Script
  9300.  
  9301. ;-- Set font/size
  9302. if $Font
  9303. gui Font,,%$Font%
  9304.  
  9305. if $FontSize
  9306. gui Font,s%$FontSize%
  9307.  
  9308. ;-- Edit field
  9309. gui Add
  9310. ,Edit
  9311. ,xp+10 yp+20 w380 h370
  9312. || +0x100000 ;-- WS_HSCROLL
  9313. || -Wrap
  9314. || hWnd$OptionsGUI_DebugScript_hWnd
  9315. || v$OptionsGUI_DebugScript
  9316. ,%$DebugScript%
  9317.  
  9318. ;-- Reset font/size
  9319. gui Font
  9320.  
  9321. ;-- End of tabs
  9322. gui Tab
  9323.  
  9324. ;-- Select last-used tab
  9325. if $OptionsGUI_Tab is not Space
  9326. GUIControl Choose,$OptionsGUI_Tab,%$OptionsGUI_Tab%
  9327.  
  9328. ;-----------
  9329. ;-- Buttons
  9330. ;-----------
  9331. gui Add
  9332. ,Button
  9333. ,xm y460 w70 h30
  9334. || hWnd$OptionsGUI_SaveButton_hWnd
  9335. || v$OptionsGUI_SaveButton
  9336. || gOptionsGUI_SaveButton
  9337. ,&Save
  9338.  
  9339. gui Add
  9340. ,Button
  9341. ,x+05 wp hp
  9342. || hWnd$OptionsGUI_CancelButton_hWnd
  9343. || v$OptionsGUI_CancelButton
  9344. || gOptionsGUI_Close
  9345. ,Cancel
  9346.  
  9347. ;-- Set focus
  9348. GUIControl Focus,$OptionsGUI_CancelButton
  9349.  
  9350. ;[==========]
  9351. ;[ Attach ]
  9352. ;[==========]
  9353. Attach($OptionsGUI_Tab_hWnd ,"w h")
  9354. Attach($OptionsGUI_GeneralGB_hWnd ,"w h")
  9355. Attach($OptionsGUI_EditorGB_hWnd ,"w")
  9356. Attach($OptionsGUI_ExtEditorGB_hWnd ,"w")
  9357. Attach($OptionsGUI_ExtEditorName_hWnd ,"w")
  9358. Attach($OptionsGUI_ExtEditorPath_hWnd ,"w")
  9359. Attach($OptionsGUI_BrowseEditorPath_hWnd ,"x")
  9360. Attach($OptionsGUI_RunGB_hWnd ,"w")
  9361. Attach($OptionsGUI_AutoHotkeyPath_hWnd ,"w")
  9362. Attach($OptionsGUI_BrowseAutoHotkeyPath_hWnd,"x")
  9363. Attach($OptionsGUI_RunFolderGB_hWnd ,"w")
  9364. Attach($OptionsGUI_RPViewerGB_hWnd ,"w")
  9365. Attach($OptionsGUI_RestoreGB_hWnd ,"w")
  9366. Attach($OptionsGUI_SaveButton_hWnd ,"y")
  9367. Attach($OptionsGUI_CancelButton_hWnd ,"y")
  9368. Attach($OptionsGUI_NewScriptGB_hWnd ,"w h")
  9369. Attach($OptionsGUI_NewScript_hWnd ,"w h")
  9370. Attach($OptionsGUI_DebugScriptGB_hWnd ,"w h")
  9371. Attach($OptionsGUI_DebugScript_hWnd ,"w h")
  9372.  
  9373. ;[============]
  9374. ;[ Show it! ]
  9375. ;[============]
  9376. ;-- Render but don't display
  9377. gui Show,Hide,Options
  9378.  
  9379. ;-- Calculate X/Y and Show it
  9380. PopupXY($QAHKGUI,$OptionsGUI,$PosX,$PosY)
  9381. gui Show,x%$PosX% y%$PosY%
  9382. return
  9383.  
  9384.  
  9385. ;**********************
  9386. ;* *
  9387. ;* Tab *
  9388. ;* (OptionsGUI) *
  9389. ;* *
  9390. ;**********************
  9391. OptionsGUI_Tab:
  9392. GUIControlGet $OptionsGUI_Tab,,$OptionsGUI_Tab ;-- Collect the current tab
  9393. return
  9394.  
  9395.  
  9396. ;**********************
  9397. ;* *
  9398. ;* Select font *
  9399. ;* (OptionsGUI) *
  9400. ;* *
  9401. ;**********************
  9402. OptionsGUI_SelectFont:
  9403.  
  9404. ;-- Collect form data
  9405. gui Submit,NoHide
  9406.  
  9407. ;[==============]
  9408. ;[ Initialize ]
  9409. ;[==============]
  9410. $OptionsGUI_FontStyle:="s" . $OptionsGUI_FontSize . A_Space . $FontStyle
  9411.  
  9412. ;[==========]
  9413. ;[ Select ]
  9414. ;[==========]
  9415. if not Dlg_Font($OptionsGUI_Font,$OptionsGUI_FontStyle,Dummy,False,$OptionsGUI_hWnd)
  9416. return
  9417.  
  9418. ;-- Extract font size, rebuild $OptionsGUI_FontStyle
  9419. t_FontStyle :=""
  9420. Loop Parse,$OptionsGUI_FontStyle,%A_Space%
  9421. {
  9422. if A_LoopField is Space
  9423. Continue
  9424.  
  9425. ;-- Font size
  9426. if SubStr(A_LoopField,1,1)="s"
  9427. {
  9428. StringTrimLeft $OptionsGUI_FontSize,A_LoopField,1
  9429. Continue
  9430. }
  9431.  
  9432. if t_FontStyle is Space
  9433. t_FontStyle:=A_LoopField
  9434. else
  9435. t_FontStyle:=t_FontStyle . A_Space . A_LoopField
  9436. }
  9437.  
  9438. $OptionsGUI_FontStyle:=t_FontStyle
  9439.  
  9440. ;[========================]
  9441. ;[ Refresh GUI controls ]
  9442. ;[========================]
  9443. GUIControl,,$OptionsGUI_Font,%$OptionsGUI_Font%
  9444. GUIControl,,$OptionsGUI_FontSize,%$OptionsGUI_FontSize%
  9445. return
  9446.  
  9447.  
  9448. ;****************************
  9449. ;* *
  9450. ;* Browse editor path *
  9451. ;* (OptionsGUI) *
  9452. ;* *
  9453. ;****************************
  9454. OptionsGUI_BrowseEditorPath:
  9455.  
  9456. ;-- Attach dialogs and messages to the current GUI
  9457. gui +OwnDialogs
  9458.  
  9459. ;-- Collect form data
  9460. gui Submit,NoHide
  9461.  
  9462. ;[==============]
  9463. ;[ Initialize ]
  9464. ;[==============]
  9465. ;-- AutoTrim
  9466. $OptionsGUI_ExtEditorPath=%$OptionsGUI_ExtEditorPath%
  9467.  
  9468.  
  9469. ;-- Remove leading and trailing double quotes (if they both exist)
  9470. if SubStr($OptionsGUI_ExtEditorPath,1,1)=""""
  9471. and SubStr($OptionsGUI_ExtEditorPath,0)=""""
  9472. $OptionsGUI_ExtEditorPath:=SubStr($OptionsGUI_ExtEditorPath,2,-1)
  9473.  
  9474. ;-- If empty, set to A_ProgramFiles
  9475. if $OptionsGUI_ExtEditorPath is Space
  9476. $OptionsGUI_ExtEditorPath:=A_ProgramFiles . "\"
  9477. else
  9478. {
  9479. ;-- Else if the program doesn't exist, set to A_ProgramFiles
  9480. IfNotExist %$OptionsGUI_ExtEditorPath%
  9481. $OptionsGUI_ExtEditorPath:=A_ProgramFiles . "\"
  9482. }
  9483.  
  9484. ;[=================]
  9485. ;[ Browse for it ]
  9486. ;[=================]
  9487. FileSelectFile
  9488. ,$OptionsGUI_ExtEditorPath ;-- OutputVar
  9489. ,1 ;-- Options. 1=File Must Exist
  9490. ,%$OptionsGUI_ExtEditorPath% ;-- RootDir\Filename
  9491. ,Select Editor Program: ;-- Prompt
  9492. ,Program (*.exe) ;-- Filter
  9493.  
  9494. ;-- Anything selected?
  9495. if ErrorLevel
  9496. return
  9497.  
  9498. ;[=======================]
  9499. ;[ Refresh GUI control ]
  9500. ;[=======================]
  9501. GUIControl,,$OptionsGUI_ExtEditorPath,%$OptionsGUI_ExtEditorPath%
  9502. return
  9503.  
  9504.  
  9505. ;***************************************
  9506. ;* *
  9507. ;* NewScriptSystemDefault action *
  9508. ;* (OptionsGUI) *
  9509. ;* *
  9510. ;***************************************
  9511. OptionsGUI_NewScriptSystemDefault_Action:
  9512.  
  9513. ;-- Get current value
  9514. GUIControlGet
  9515. ,$OptionsGUI_NewScriptSystemDefault
  9516. ,
  9517. ,$OptionsGUI_NewScriptSystemDefault
  9518.  
  9519.  
  9520. ;-- Enable/Disable "New Script" control
  9521. if $OptionsGUI_NewScriptSystemDefault
  9522. GUIControl Disable,$OptionsGUI_NewScript
  9523. else
  9524. GUIControl Enable,$OptionsGUI_NewScript
  9525.  
  9526. return
  9527.  
  9528.  
  9529. ;********************************
  9530. ;* *
  9531. ;* Browse AutoHotkey path *
  9532. ;* (OptionsGUI) *
  9533. ;* *
  9534. ;********************************
  9535. OptionsGUI_BrowseAutoHotkeyPath:
  9536.  
  9537. ;-- Attach dialogs and messages to the current GUI
  9538. gui +OwnDialogs
  9539.  
  9540. ;-- Collect form data
  9541. gui Submit,NoHide
  9542.  
  9543. ;[==============]
  9544. ;[ Initialize ]
  9545. ;[==============]
  9546. ;-- AutoTrim
  9547. $OptionsGUI_AutoHotkeyPath=%$OptionsGUI_AutoHotkeyPath%
  9548.  
  9549. ;-- Remove leading and trailing double quotes (if they both exist)
  9550. if SubStr($OptionsGUI_AutoHotkeyPath,1,1)=""""
  9551. and SubStr($OptionsGUI_AutoHotkeyPath,0)=""""
  9552. $OptionsGUI_AutoHotkeyPath:=SubStr($OptionsGUI_AutoHotkeyPath,2,-1)
  9553.  
  9554. ;-- If empty, set to A_ProgramFiles
  9555. if $OptionsGUI_AutoHotkeyPath is Space
  9556. $OptionsGUI_AutoHotkeyPath:=A_ProgramFiles . "\"
  9557. else
  9558. {
  9559. ;-- Else if the program doesn't exist, set to A_ProgramFiles
  9560. IfNotExist %$OptionsGUI_AutoHotkeyPath%
  9561. $OptionsGUI_AutoHotkeyPath:=A_ProgramFiles . "\"
  9562. }
  9563.  
  9564. ;[=================]
  9565. ;[ Browse for it ]
  9566. ;[=================]
  9567. FileSelectFile
  9568. ,$OptionsGUI_AutoHotkeyPath ;-- OutputVar
  9569. ,1 ;-- Options. 1=File Must Exist
  9570. ,%$OptionsGUI_AutoHotkeyPath% ;-- RootDir\Filename
  9571. ,Select AutoHotkey Program: ;-- Prompt
  9572. ,Program (*.exe) ;-- Filter
  9573.  
  9574. ;-- Anything selected?
  9575. if ErrorLevel
  9576. return
  9577.  
  9578. ;[=======================]
  9579. ;[ Refresh GUI control ]
  9580. ;[=======================]
  9581. GUIControl,,$OptionsGUI_AutoHotkeyPath,%$OptionsGUI_AutoHotkeyPath%
  9582. return
  9583.  
  9584.  
  9585. ;*****************************
  9586. ;* *
  9587. ;* Clear Run workspace *
  9588. ;* (OptionsGUI) *
  9589. ;* *
  9590. ;*****************************
  9591. OptionsGUI_ClearRunWorkspace:
  9592.  
  9593. ;-- Attach messages to the current GUI
  9594. gui +OwnDialogs
  9595.  
  9596. ;-- Script(s) running?
  9597. $RunPIDList:=RebuildRunPIDList($RunPIDList)
  9598. if StrLen($RunPIDList)
  9599. {
  9600. MsgBox
  9601. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  9602. ,Clear Run Workspace Error,
  9603. (ltrim join`s
  9604. One or more scripts are still running. Please stop all running
  9605. scripts before attempting to clear the Run workspace. %A_Space%
  9606. )
  9607.  
  9608. ;-- Bounce
  9609. return
  9610. }
  9611.  
  9612. ;-- Confirm
  9613. MsgBox
  9614. ,49 ;-- 49 = 1 (OK/Cancel buttons) + 48 ("!" icon)
  9615. ,Clear Run Workspace,
  9616. (ltrim join`s
  9617. All files and folders in the Run workspace will be deleted. Press OK to
  9618. proceed. %A_Space%
  9619. )
  9620.  
  9621. IfMsgBox Cancel
  9622. return
  9623.  
  9624. ;-- Delete "Run" Folder
  9625. gosub DeleteRunFolder
  9626.  
  9627. ;-- Disable buttons if "Run" folder has been deleted
  9628. IfNotExist %$RunDir%\.
  9629. {
  9630. GUIControl Disable,$OptionsGUI_ClearRunWorkspace
  9631. GUIControl Disable,$OptionsGUI_ExploreRunFolder
  9632. }
  9633.  
  9634. return
  9635.  
  9636.  
  9637. ;****************************
  9638. ;* *
  9639. ;* Explore Run folder *
  9640. ;* (OptionsGUI) *
  9641. ;* *
  9642. ;****************************
  9643. OptionsGUI_ExploreRunFolder:
  9644.  
  9645. ;-- Attach messages to current GUI
  9646. gui +OwnDialogs
  9647.  
  9648. ;-- Run folder exists?
  9649. IfNotExist %$RunDir%\. ;-- Test s/b redundant but remains as a fail-safe.
  9650. {
  9651. MsgBox
  9652. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  9653. ,Explore Error
  9654. ,The Run workspace does not exist: `n%$RunDir%\ %A_Space%
  9655.  
  9656. return
  9657. }
  9658.  
  9659. ;-- Open Windows Explorer to the "Run" folder
  9660. Run explorer.exe /e`,"%$RunDir%",,UseErrorLevel
  9661. if ErrorLevel
  9662. MsgBox
  9663. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  9664. ,Explore Error
  9665. ,% SystemMessage(A_LastError)
  9666.  
  9667. return
  9668.  
  9669.  
  9670. ;************************************
  9671. ;* *
  9672. ;* Select Restore Viewer font *
  9673. ;* (OptionsGUI) *
  9674. ;* *
  9675. ;************************************
  9676. OptionsGUI_SelectRPViewerFont:
  9677.  
  9678. ;-- Collect form data
  9679. gui Submit,NoHide
  9680.  
  9681. ;[==============]
  9682. ;[ Initialize ]
  9683. ;[==============]
  9684. $OptionsGUI_RPViewerFontStyle:="s" . $OptionsGUI_RPViewerFontSize . A_Space . $RPViewerFontStyle
  9685.  
  9686. ;[==========]
  9687. ;[ Select ]
  9688. ;[==========]
  9689. if not Dlg_Font($OptionsGUI_RPViewerFont,$OptionsGUI_RPViewerFontStyle,Dummy,0,$OptionsGUI_hWnd)
  9690. return
  9691.  
  9692. ;-- Extract font size, rebuild $OptionsGUI_RPViewerFontStyle
  9693. t_FontStyle :=""
  9694. Loop Parse,$OptionsGUI_RPViewerFontStyle,%A_Space%
  9695. {
  9696. if A_LoopField is Space
  9697. Continue
  9698.  
  9699. ;-- Font size
  9700. if SubStr(A_LoopField,1,1)="s"
  9701. {
  9702. StringTrimLeft $OptionsGUI_RPViewerFontSize,A_LoopField,1
  9703. Continue
  9704. }
  9705.  
  9706. if t_FontStyle is Space
  9707. t_FontStyle:=A_LoopField
  9708. else
  9709. t_FontStyle:=t_FontStyle . A_Space . A_LoopField
  9710. }
  9711.  
  9712. $OptionsGUI_RPViewerFontStyle:=t_FontStyle
  9713.  
  9714. ;[========================]
  9715. ;[ Refresh GUI controls ]
  9716. ;[========================]
  9717. GUIControl,,$OptionsGUI_RPViewerFont,%$OptionsGUI_RPViewerFont%
  9718. GUIControl,,$OptionsGUI_RPViewerFontSize,%$OptionsGUI_RPViewerFontSize%
  9719. return
  9720.  
  9721.  
  9722. ;******************************
  9723. ;* *
  9724. ;* Clear Restore folder *
  9725. ;* (OptionsGUI) *
  9726. ;* *
  9727. ;******************************
  9728. OptionsGUI_ClearRestoreFolder:
  9729.  
  9730. ;-- Attach messages to current GUI
  9731. gui +OwnDialogs
  9732.  
  9733. ;-- Confirm
  9734. MsgBox
  9735. ,49 ;-- 49 = 1 (OK/Cancel buttons) + 48 ("!" icon)
  9736. ,Confirm Delete
  9737. ,All restore points will be deleted. Press OK to proceed. %A_Space%
  9738.  
  9739. IfMsgBox Cancel
  9740. return
  9741.  
  9742. ;-- Delete "Restore" folder
  9743. gosub DeleteRestoreFolder
  9744.  
  9745. ;-- Disable buttons if "Restore" folder has been deleted
  9746. IfNotExist %$RPDir%\.
  9747. {
  9748. GUIControl Disable,$OptionsGUI_ClearRestoreFolder
  9749. GUIControl Disable,$OptionsGUI_ExploreRestoreFolder
  9750. }
  9751.  
  9752. ;-- RPViewerGUI window open?
  9753. IfWinExist ahk_id %$RPViewerGUI_hWnd%
  9754. {
  9755. ;-- Change default GUI
  9756. gui %$RPViewerGUI%:Default
  9757.  
  9758. ;-- Update RPViewerGUI
  9759. LV_Delete() ;-- Clear ListView
  9760. GUIControl Disable,$RPViewerGUI_RestoreButton ;-- Disable Restore button
  9761. HE_CloseFile($RPViewerGUI_hEdit) ;-- Close last opened file
  9762.  
  9763. ;-- Reset default GUI
  9764. gui %$OptionsGUI%:Default
  9765. }
  9766.  
  9767. return
  9768.  
  9769.  
  9770. ;********************************
  9771. ;* *
  9772. ;* Explore Restore folder *
  9773. ;* (OptionsGUI) *
  9774. ;* *
  9775. ;*********************************
  9776. OptionsGUI_ExploreRestoreFolder:
  9777.  
  9778. ;-- Attach messages to current GUI
  9779. gui +OwnDialogs
  9780.  
  9781. ;-- Restore folder exists?
  9782. IfNotExist %$RPDir%\. ;-- Test s/b redundant but remains as a fail-safe.
  9783. {
  9784. MsgBox
  9785. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  9786. ,Explore Error
  9787. ,The "Restore" folder does not exist: `n%$RPDir%\ %A_Space%
  9788.  
  9789. return
  9790. }
  9791.  
  9792. ;-- Open Windows Explorer to the "Restore" folder
  9793. Run explorer.exe /e`,"%$RPDir%",,UseErrorLevel
  9794. if ErrorLevel
  9795. MsgBox
  9796. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  9797. ,Explore Error
  9798. ,% SystemMessage(A_LastError)
  9799.  
  9800. return
  9801.  
  9802.  
  9803. ;**********************
  9804. ;* *
  9805. ;* Save button *
  9806. ;* (OptionsGUI) *
  9807. ;* *
  9808. ;**********************
  9809. OptionsGUI_SaveButton:
  9810.  
  9811. ;-- Attach any messages to the current GUI
  9812. gui +OwnDialogs
  9813.  
  9814. ;-- Collect form variables
  9815. gui Submit,NoHide
  9816. ConfirmExitIfRunning:= $OptionsGUI_ConfirmExitIfRunning
  9817. ;[====================]
  9818. ;[ Check for errors ]
  9819. ;[====================]
  9820. ;-- Editor path
  9821. $OptionsGUI_ExtEditorPath=%$OptionsGUI_ExtEditorPath% ;-- AutoTrim
  9822. if $OptionsGUI_ExtEditorPath is not Space
  9823. {
  9824. ;-- Remove leading and trailing double quotes (if they both exist)
  9825. if SubStr($OptionsGUI_ExtEditorPath,1,1)=""""
  9826. and SubStr($OptionsGUI_ExtEditorPath,0)=""""
  9827. $OptionsGUI_ExtEditorPath:=SubStr($OptionsGUI_ExtEditorPath,2,-1)
  9828.  
  9829. ;-- Program exist?
  9830. IfNotExist %$OptionsGUI_ExtEditorPath%
  9831. {
  9832. ;-- Set to Editor tab
  9833. GUIControl Choose,$OptionsGUI_Tab,Editor
  9834.  
  9835. ;-- Error message
  9836. MsgBox
  9837. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  9838. ,Options Error
  9839. ,External editor program not found. Please redefine. %A_Space%
  9840.  
  9841. return
  9842. }
  9843. }
  9844.  
  9845. ;-- AutoHotkey path
  9846. $OptionsGUI_AutoHotkeyPath=%$OptionsGUI_AutoHotkeyPath% ;-- AutoTrim
  9847. if $OptionsGUI_AutoHotkeyPath is not Space
  9848. {
  9849. ;-- Remove leading and trailing double quotes (if they both exist)
  9850. if SubStr($OptionsGUI_AutoHotkeyPath,1,1)=""""
  9851. and SubStr($OptionsGUI_AutoHotkeyPath,0)=""""
  9852. $OptionsGUI_AutoHotkeyPath:=SubStr($OptionsGUI_AutoHotkeyPath,2,-1)
  9853.  
  9854. ;-- Program exist?
  9855. IfNotExist %$OptionsGUI_AutoHotkeyPath%
  9856. {
  9857. ;-- Set to Run tab
  9858. GUIControl Choose,$OptionsGUI_Tab,Run
  9859.  
  9860. ;-- Error message
  9861. MsgBox
  9862. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  9863. ,Options Error
  9864. ,Autohotkey program not found. %A_Space%
  9865.  
  9866. return
  9867. }
  9868. }
  9869.  
  9870. ;[======================]
  9871. ;[ Shell context menu ]
  9872. ;[======================]
  9873. if A_IsCompiled
  9874. {
  9875. ;-- Only proceed if .ahk is registered
  9876. RegRead
  9877. ,$DocumentType
  9878. ,HKEY_CLASSES_ROOT
  9879. ,.ahk
  9880.  
  9881. if not ErrorLevel
  9882. {
  9883. ;-- Create shell context menu item if it doesn't already exist
  9884. if $OptionsGUI_ShellContextMenu
  9885. {
  9886. ;-- Look for custom command
  9887. RegRead
  9888. ,$Dummy
  9889. ,HKEY_CLASSES_ROOT
  9890. ,%$DocumentType%\shell\Open with %$ScriptName%\command
  9891.  
  9892. ;-- Does not exist: Create it!
  9893. if ErrorLevel
  9894. {
  9895. ;-- Parent key
  9896. RegWrite
  9897. ,REG_SZ
  9898. ,HKEY_CLASSES_ROOT
  9899. ,%$DocumentType%\shell\Open with %$ScriptName%
  9900. ,
  9901. ,Open with %$ScriptName%...
  9902.  
  9903. ;-- Command
  9904. RegWrite
  9905. ,REG_SZ
  9906. ,HKEY_CLASSES_ROOT
  9907. ,%$DocumentType%\shell\Open with %$ScriptName%\command
  9908. ,
  9909. ,"%A_ScriptFullPath%" "`%1"
  9910.  
  9911. if ErrorLevel
  9912. {
  9913. MsgBox
  9914. ,262160
  9915. ;-- 262208=0 (OK button) + 16 (Error icon) + 262144 (AOT)
  9916. ,Shell Context Menu Error
  9917. ,Shell context menu NOT created. %A_Space%
  9918. }
  9919. }
  9920. }
  9921. else
  9922. {
  9923. ;-- Exists?
  9924. RegRead
  9925. ,$Dummy
  9926. ,HKEY_CLASSES_ROOT
  9927. ,%$DocumentType%\shell\Open with %$ScriptName%
  9928.  
  9929. if not ErrorLevel
  9930. {
  9931. ;-- Remove custom command (only need to delete parent key)
  9932. RegDelete
  9933. ,HKEY_CLASSES_ROOT
  9934. ,%$DocumentType%\shell\Open with %$ScriptName%
  9935.  
  9936. if ErrorLevel
  9937. MsgBox
  9938. ,262160
  9939. ;-- 262208=0 (OK button) + 16 (Error icon) + 262144 (AOT)
  9940. ,Shell Context Menu Error
  9941. ,Shell context menu NOT deleted. %A_Space%
  9942. }
  9943. }
  9944. }
  9945. }
  9946.  
  9947. ;[===========================]
  9948. ;[ Update general settings ]
  9949. ;[===========================]
  9950. ;-- AOT
  9951. if ($OptionsGUI_AlwaysOnTop<>$AlwaysOnTop)
  9952. {
  9953. gosub QAHKGUI_ToggleAlwaysOnTop
  9954.  
  9955. ;-- Reset GUI default
  9956. gui %$OptionsGUI%:Default
  9957. ;-- Programming note: Resetting the GUI default is necessary because
  9958. ; the QAHKGUI_ToggleAlwaysOnTop routine sets the GUI default to the
  9959. ; primary GUI so that the status bar for the primary GUI can be
  9960. ; updated.
  9961. }
  9962.  
  9963. ;-- Menu bar
  9964. if ($OptionsGUI_ShowMenubar<>$ShowMenuBar)
  9965. gosub QAHKGUI_ToggleMenubar
  9966.  
  9967. ;-- Toolbar
  9968. if ($OptionsGUI_ShowToolbar<>$ShowToolbar)
  9969. gosub QAHKGUI_ToggleToolbar
  9970.  
  9971. ;-- Menu
  9972. if ($OptionsGUI_ClearRunWorkspaceOnRun<>$ClearRunWorkspaceOnRun)
  9973. Menu QAHKGUI_RunMenu,ToggleCheck,%s_ClearRunWorkspaceOnRun_MI%
  9974.  
  9975. if ($OptionsGUI_ClearRunWorkspaceOnExit<>$ClearRunWorkspaceOnExit)
  9976. Menu QAHKGUI_RunMenu,ToggleCheck,%s_ClearRunWorkspaceOnExit_MI%
  9977.  
  9978. ;-- Toolbar icon size
  9979. if $OptionsGUI_ToolbarLargeIcons
  9980. $OptionsGUI_ToolbarIconSize=Large
  9981. else
  9982. $OptionsGUI_ToolbarIconSize=Small
  9983.  
  9984. if ($OptionsGUI_ToolbarIconSize<>$ToolbarIconSize)
  9985. gosub QAHKGUI_ToggleToolbarIconSize
  9986.  
  9987. ;-- Status bar
  9988. if ($OptionsGUI_ShowStatusbar<>$ShowStatusbar)
  9989. gosub QAHKGUI_ToggleStatusbar
  9990.  
  9991. ;-- Line numbers bar
  9992. if ($OptionsGUI_LineNumbersBar<>$LineNumbersBar)
  9993. gosub QAHKGUI_ToggleLineNumbersBar
  9994.  
  9995. ;-- RunPrompt
  9996. if ($OptionsGUI_RunPrompt<>$RunPrompt)
  9997. gosub QAHKGUI_ToggleRunPrompt
  9998.  
  9999. ;-- RunDebug
  10000. if ($OptionsGUI_RunDebug<>$RunDebug)
  10001. gosub QAHKGUI_ToggleRunDebug
  10002.  
  10003. ;-- RunWait
  10004. if ($OptionsGUI_RunWait<>$RunWait)
  10005. gosub QAHKGUI_ToggleRunWait
  10006.  
  10007. ;[==========================]
  10008. ;[ Update window settings ]
  10009. ;[==========================]
  10010. ;--------
  10011. ;-- Font
  10012. ;--------
  10013. if ($OptionsGUI_Font<>$Font
  10014. or $OptionsGUI_FontSize<>$FontSize
  10015. or $OptionsGUI_FontStyle<>$FontStyle)
  10016. HE_SetFont($QAHKGUI_hEdit,"s" . $OptionsGUI_FontSize . A_Space . $OptionsGUI_FontStyle . "," . $OptionsGUI_Font)
  10017.  
  10018. ;-------------
  10019. ;-- Tab width
  10020. ;-------------
  10021. if ($OptionsGUI_TabWidth<>$TabWidth)
  10022. HE_SetTabWidth($QAHKGUI_hEdit,$OptionsGUI_TabWidth)
  10023.  
  10024. ;---------------
  10025. ;-- Auto indent
  10026. ;---------------
  10027. if ($OptionsGUI_AutoIndent<>$AutoIndent)
  10028. HE_AutoIndent($QAHKGUI_hEdit,$OptionsGUI_AutoIndent)
  10029.  
  10030. ;------------------------------
  10031. ;-- RPViewer: Line numbers bar
  10032. ;------------------------------
  10033. if ($OptionsGUI_RPViewerLineNumbersBar<>$RPViewerLineNumbersBar)
  10034. IfWinExist ahk_id %$RPViewerGUI_hWnd% ;-- RPViewerGUI window open?
  10035. gosub RPViewerGUI_ToggleLineNumbersBar
  10036.  
  10037. ;----------------------
  10038. ;-- Max Restore Points
  10039. ;----------------------
  10040. ;;;;;if ($OptionsGUI_MaxRestorePoints<>$MaxRestorePoints)
  10041. ;;;;; RPTrim($OptionsGUI_MaxRestorePoints)
  10042.  
  10043. ;-- Programming note: The request to cleanup the RP files here is commented out
  10044. ; for now. This allows to user to make a change, save the change, and then
  10045. ; change their mind and change it back. Superfluous RP files will
  10046. ; automatically be purged when a new RP is requested.
  10047.  
  10048. ;[===========================]
  10049. ;[ Update global variables ]
  10050. ;[===========================]
  10051. ;-- General
  10052. $AlwaysOnTop :=$OptionsGUI_AlwaysOnTop
  10053. $ShowMenubar :=$OptionsGUI_ShowMenubar
  10054. $ShowToolbar :=$OptionsGUI_ShowToolbar
  10055. $ShowStatusbar :=$OptionsGUI_Showstatusbar
  10056.  
  10057. if $OptionsGUI_ToolbarLargeIcons
  10058. $ToolbarIconSize=Large
  10059. else
  10060. $ToolbarIconSize=Small
  10061.  
  10062. $EscapeToExit :=$OptionsGUI_EscapeToExit
  10063.  
  10064. ;-- Editor
  10065. $Font :=$OptionsGUI_Font
  10066. $FontSize :=$OptionsGUI_FontSize
  10067. $FontStyle :=$OptionsGUI_FontStyle
  10068. $TabWidth :=$OptionsGUI_TabWidth
  10069. $RealTabs :=$OptionsGUI_RealTabs
  10070. $BlockComment :=$OptionsGUI_BlockComment
  10071. $AutoIndent :=$OptionsGUI_AutoIndent
  10072. $LineNumbersBar :=$OptionsGUI_LineNumbersBar
  10073. $AllowUndoAfterSave :=$OptionsGUI_AllowUndoAfterSave
  10074. $ExtEditorName :=$OptionsGUI_ExtEditorName
  10075. $ExtEditorPath :=$OptionsGUI_ExtEditorPath
  10076.  
  10077. ;-- Run
  10078. $AutoHotkeyPath :=$OptionsGUI_AutoHotkeyPath
  10079. $RunPrompt :=$OptionsGUI_RunPrompt
  10080. $RunDebug :=$OptionsGUI_RunDebug
  10081. $RunWait :=$OptionsGUI_RunWait
  10082. $ConfirmExitIfRunning :=$OptionsGUI_ConfirmExitIfRunning
  10083. $ClearRunWorkspaceOnRun :=$OptionsGUI_ClearRunWorkspaceOnRun
  10084. $ClearRunWorkspaceOnExit :=$OptionsGUI_ClearRunWorkspaceOnExit
  10085.  
  10086. ;-- Restore
  10087. $RPViewerFont :=$OptionsGUI_RPViewerFont
  10088. $RPViewerFontSize :=$OptionsGUI_RPViewerFontSize
  10089. $RPViewerFontStyle :=$OptionsGUI_RPViewerFontStyle
  10090. $RPViewerLineNumbersBar :=$OptionsGUI_RPViewerLineNumbersBar
  10091. $RPViewerSaveWindowPos :=$OptionsGUI_RPViewerSaveWindowPos
  10092. $RPViewerCloseOnRestore :=$OptionsGUI_RPViewerCloseOnRestore
  10093. $RPViewerEscapeToClose :=$OptionsGUI_RPViewerEscapeToClose
  10094. $MaxRestorePoints :=$OptionsGUI_MaxRestorePoints
  10095. $CreateRPOnCopyfromDrop :=$OptionsGUI_CreateRPOnCopyfromDrop
  10096. $CreateRPOnRun :=$OptionsGUI_CreateRPOnRun
  10097. $CreateRPOnSave :=$OptionsGUI_CreateRPOnSave
  10098. $CreateRPOnExit :=$OptionsGUI_CreateRPOnExit
  10099.  
  10100. ;-- New
  10101. $NewScriptSystemDefault :=$OptionsGUI_NewScriptSystemDefault
  10102. $NewScript :=$OptionsGUI_NewScript
  10103.  
  10104. ;-- Debug
  10105. $DebugScript :=$OptionsGUI_DebugScript
  10106.  
  10107. ;-- Rebuild $Tab variable
  10108. $Tab=
  10109. if $RealTabs
  10110. $Tab:="`t"
  10111. else
  10112. Loop % $TabWidth
  10113. $Tab.=A_Space
  10114.  
  10115. ;-- Return to sender
  10116. gosub OptionsGUI_Exit
  10117. return
  10118.  
  10119.  
  10120. ;***********************
  10121. ;* *
  10122. ;* Close up shop *
  10123. ;* (OptionsGUI) *
  10124. ;* *
  10125. ;***********************
  10126. OptionsGUI_Escape:
  10127. OptionsGUI_Close:
  10128. OptionsGUI_Exit:
  10129.  
  10130. ;-- Enable parent window
  10131. gui %$QAHKGUI%:-Disabled
  10132.  
  10133. ;-- Destroy window so that it can be used again
  10134. gui Destroy
  10135. return
  10136.  
  10137. ;-------------------------------------------------------------------------------
  10138. ;-------------------------------------------------------------------------------
  10139. ;-------------------------------------------------------------------------------
  10140. ;-------------------------------------------------------------------------------
  10141. ;-------------------------------------------------------------------------------
  10142. ;----------------------------- End OptionsGUI Stuff ----------------------------
  10143. ;-------------------------------------------------------------------------------
  10144.  
  10145.  
  10146.  
  10147.  
  10148.  
  10149. ;-------------------------------------------------------------------------------
  10150. ;-------------------------------------------------------------------------------
  10151. ;-------------------------------------------------------------------------------
  10152. ;-------------------------------------------------------------------------------
  10153. ;-------------------------------------------------------------------------------
  10154. ;--------------------------- Begin RPViewerGUI stuff ---------------------------
  10155. ;-------------------------------------------------------------------------------
  10156. ;*****************************
  10157. ;* *
  10158. ;* *
  10159. ;* RPViewerGUI *
  10160. ;* *
  10161. ;* *
  10162. ;*****************************
  10163. RPViewerGUI:
  10164. SetTimer %A_ThisLabel%,Off
  10165.  
  10166. ;-- Initialize
  10167. $RPViewerGUI:=22
  10168.  
  10169. ;-- Already open?
  10170. IfWinExist ahk_id %$RPViewerGUI_hWnd%
  10171. {
  10172. gui %$RPViewerGUI%:Show
  10173. return
  10174. }
  10175.  
  10176. ;-- Set to full speed just to get started
  10177. SetBatchLines -1
  10178.  
  10179. ;[=============]
  10180. ;[ Build GUI ]
  10181. ;[=============]
  10182. ;-- Set GUI default
  10183. gui %$RPViewerGUI%:Default
  10184.  
  10185. ;-- Give ownership to parent GUI
  10186. gui +Owner%$QAHKGUI%
  10187. ;-- Programming note: Ownership assignment must be be performed before any
  10188. ; other GUI commands.
  10189.  
  10190. ;-- Identify window handle
  10191. gui %$RPViewerGUI%:+LastFound
  10192. WinGet $RPViewerGUI_hWnd,ID
  10193. GroupAdd $RPViewerGUI_Group,ahk_id %$RPViewerGUI_hWnd%
  10194.  
  10195. ;-- GUI options
  10196. gui Margin,6,6
  10197. gui +LabelRPViewerGUI_
  10198. || +Resize
  10199. || -MinimizeBox
  10200. || -MaximizeBox
  10201.  
  10202. ;-------------------
  10203. ;-- Primary objects
  10204. ;-------------------
  10205. gui Add
  10206. ,GroupBox
  10207. ,xm ym w290 h170
  10208. || hWnd$RPViewerGUI_RPListGB_hWnd
  10209. || v$RPViewerGUI_RPListGB
  10210. ,Restore Point
  10211.  
  10212. gui Add
  10213. ,Edit
  10214. ,xp+10 yp+20
  10215. || Section
  10216. || Hidden
  10217. ,8888-88-88 88:88:88 8,888.88 KBXXXX
  10218. ;-- Template used to establish the width of the ListView control
  10219.  
  10220. gui Add
  10221. ,ListView
  10222. ,xp wp h140
  10223. || Section
  10224. || +AltSubmit
  10225. || Count999 ;-- 999=Maximum number of restore points
  10226. || -Hdr
  10227. || -Multi
  10228. || hWnd$RPViewerGUI_RPList_hWnd
  10229. || v$RPViewerGUI_RPList
  10230. || gRPViewerGUI_RPList
  10231. ,Display Name|Path
  10232.  
  10233. ;-- Initialize column size
  10234. LV_ModifyCol(1,0)
  10235. LV_ModifyCol(2,0)
  10236.  
  10237. ;-- Resize the RPList group box
  10238. GUIControlGet $Group1Pos,Pos,$RPViewerGUI_RPListGB
  10239. GUIControlGet $Group2Pos,Pos,$RPViewerGUI_RPList
  10240. GUIControl
  10241. ,Move
  10242. ,$RPViewerGUI_RPListGB
  10243. ,% "w" . $Group2PosW+20
  10244.  
  10245. gui Add
  10246. ,GroupBox
  10247. ,ym w330 h200
  10248. || hWnd$RPViewerGUI_ViewerGB_hWnd
  10249. || v$RPViewerGUI_ViewerGB
  10250. ,Viewer
  10251.  
  10252. ;-- Move the Viewer group box
  10253. GUIControlGet $Group1Pos,Pos,$RPViewerGUI_RPListGB
  10254. GUIControl
  10255. ,Move
  10256. ,$RPViewerGUI_ViewerGB
  10257. ,% "x" . $Group1PosX+$Group1PosW
  10258.  
  10259. ;-- HiEdit control
  10260. $RPViewerGUI_hEdit:=HE_Add($RPViewerGUI_hWnd,0,0,310,170,"HSCROLL VSCROLL HILIGHT",$LibDir . "\HiEdit.dll")
  10261.  
  10262. ;-- Font, font size, font style
  10263. HE_SetFont($RPViewerGUI_hEdit,"s" . $RPViewerFontSize . A_Space . $RPViewerFontStyle . "," . $RPViewerFont)
  10264.  
  10265. ;-- Line numbers bar?
  10266. if $RPViewerLineNumbersBar
  10267. HE_LineNumbersBar($RPViewerGUI_hEdit,"autosize",30,10)
  10268.  
  10269. ;-- Move the HiEdit control to the Viewer group box
  10270. ControlGetPos $Group1PosX, $Group1PosY,,,,ahk_id %$RPViewerGUI_ViewerGB_hWnd%
  10271. ControlMove,,% $Group1PosX+10,% $Group1PosY+20,,,ahk_id %$RPViewerGUI_hEdit%
  10272.  
  10273. ;-----------
  10274. ;-- Buttons
  10275. ;-----------
  10276. gui Add
  10277. ,Button
  10278. ,xm y180 w80 h30
  10279. || +Disabled
  10280. || hWnd$RPViewerGUI_RestoreButton_hWnd
  10281. || v$RPViewerGUI_RestoreButton
  10282. || gRPViewerGUI_RestoreButton
  10283. ,&Restore
  10284.  
  10285. gui Add
  10286. ,Button
  10287. ,x+5 wp hp
  10288. || hWnd$RPViewerGUI_CloseButton_hWnd
  10289. || v$RPViewerGUI_CloseButton
  10290. || gRPViewerGUI_Close
  10291. ,Close
  10292.  
  10293. ;[=================]
  10294. ;[ Load ListView ]
  10295. ;[=================]
  10296. Loop %$RPDir%\*.ahk
  10297. {
  10298. ;-- Derive restore time stamp
  10299. StringTrimRight $RPTimeStamp,A_LoopFileName,4
  10300.  
  10301. ;-- Convert timestamp into readable date/time format
  10302. FormatTime
  10303. ,$RPDisplayField
  10304. ,%$RPTimeStamp%
  10305. ,yyyy-MM-dd HH:mm:ss
  10306.  
  10307. ;-- Format size display
  10308. if A_LoopFileSize<1024
  10309. $FileSize:=AddCommas(A_LoopFileSize) . " bytes"
  10310. else
  10311. if A_LoopFileSize<1048576
  10312. $FileSize:=AddCommas(Round(A_LoopFileSize/1024,2)) . " KB"
  10313. else
  10314. $FileSize:=AddCommas(Round(A_LoopFileSize/1048576,2)) . " MB"
  10315.  
  10316. $RPDisplayField:=$RPDisplayField . " " . $FileSize
  10317. LV_Add("",$RPDisplayField,A_LoopFileFullPath)
  10318. }
  10319.  
  10320. ;-- Size/Sort column
  10321. LV_ModifyCol(1,"Auto SortDesc")
  10322.  
  10323. ;-- Attach GUI objects
  10324. Attach($RPViewerGUI_RPListGB_hWnd ,"h")
  10325. Attach($RPViewerGUI_RPList_hWnd ,"h")
  10326. Attach($RPViewerGUI_ViewerGB_hWnd ,"w h")
  10327. Attach($RPViewerGUI_hEdit ,"w h")
  10328. Attach($RPViewerGUI_RestoreButton_hWnd,"y")
  10329. Attach($RPViewerGUI_CloseButton_hWnd ,"y")
  10330.  
  10331. ;[============]
  10332. ;[ Show it! ]
  10333. ;[============]
  10334. ;-- Render but don't display
  10335. gui Show,Hide AutoSize,Restore
  10336.  
  10337. ;-- Set/Restore window position
  10338. if $RPViewerSaveWindowPos and $RPViewerX
  10339. {
  10340. DetectHiddenWindows On
  10341. WinMove
  10342. ,ahk_id %$RPViewerGUI_hWnd%
  10343. ,
  10344. ,%$RPViewerX%
  10345. ,%$RPViewerY%
  10346. ,%$RPViewerW%
  10347. ,%$RPViewerH%
  10348.  
  10349. DetectHiddenWindows Off
  10350. gui Show
  10351. }
  10352. else
  10353. {
  10354. ;-- Calculate X/Y and Show it
  10355. PopupXY($QAHKGUI,$RPViewerGUI,$PosX,$PosY)
  10356. gui Show,x%$PosX% y%$PosY%
  10357. }
  10358.  
  10359. ;-- Reset speed to program default
  10360. SetBatchLines %$BatchLines%
  10361. return
  10362.  
  10363.  
  10364. ;***************************
  10365. ;* *
  10366. ;* Default font size *
  10367. ;* (RPViewerGUI) *
  10368. ;* *
  10369. ;***************************
  10370. RPViewerGUI_DefaultFontSize:
  10371. $RPViewerFontSize:=$RPViewerDefaultFontSize
  10372. HE_SetFont($RPViewerGUI_hEdit,"s" . $RPViewerFontSize . A_Space . $RPViewerFontStyle . "," . $RPViewerFont)
  10373. return
  10374.  
  10375.  
  10376. ;****************************
  10377. ;* *
  10378. ;* Decrease font size *
  10379. ;* (RPViewerGUI) *
  10380. ;* *
  10381. ;****************************
  10382. RPViewerGUI_DecreaseFontSize:
  10383. if ($RPViewerFontSize>$MinimumFontSize)
  10384. {
  10385. $RPViewerFontSize--
  10386. HE_SetFont($RPViewerGUI_hEdit,"s" . $RPViewerFontSize . A_Space . $RPViewerFontStyle . "," . $RPViewerFont)
  10387. }
  10388. else
  10389. SoundPlay *-1 ;-- System default sound
  10390.  
  10391. return
  10392.  
  10393.  
  10394. ;****************************
  10395. ;* *
  10396. ;* Increase font size *
  10397. ;* (RPViewerGUI) *
  10398. ;* *
  10399. ;****************************
  10400. RPViewerGUI_IncreaseFontSize:
  10401. if ($RPViewerFontSize<$MaximumFontSize)
  10402. {
  10403. $RPViewerFontSize++
  10404. HE_SetFont($RPViewerGUI_hEdit,"s" . $RPViewerFontSize . A_Space . $RPViewerFontStyle . "," . $RPViewerFont)
  10405. }
  10406. else
  10407. SoundPlay *-1 ;-- System default sound
  10408.  
  10409. return
  10410.  
  10411.  
  10412. ;*********************************
  10413. ;* *
  10414. ;* Toggle line numbers bar *
  10415. ;* (RPViewerGUI) *
  10416. ;* *
  10417. ;*********************************
  10418. RPViewerGUI_ToggleLineNumbersBar:
  10419. if $RPViewerLineNumbersBar
  10420. {
  10421. HE_LineNumbersBar($RPViewerGUI_hEdit,"hide",0,0)
  10422. $RPViewerLineNumbersBar:=False
  10423. }
  10424. else
  10425. {
  10426. HE_LineNumbersBar($RPViewerGUI_hEdit,"autosize")
  10427. $RPViewerLineNumbersBar:=True
  10428. }
  10429.  
  10430. return
  10431.  
  10432.  
  10433. ;***********************
  10434. ;* *
  10435. ;* RPList *
  10436. ;* (RPViewerGUI) *
  10437. ;* *
  10438. ;***********************
  10439. RPViewerGUI_RPList:
  10440. Critical ;-- Added because routine was dropping critical codes on occasion
  10441.  
  10442. ;-- Doubleclick?
  10443. if A_GuiEvent=DoubleClick
  10444. {
  10445. ;-- Anything selected? (Seems redundant for a double-click, but it's not)
  10446. if LV_GetCount("Selected")
  10447. gosub RPViewerGUI_RestoreButton
  10448.  
  10449. return
  10450. }
  10451.  
  10452. ;-- Bounce if not selecting a new item
  10453. if (A_GUIEvent<>"I") or InStr(ErrorLevel,"S",True)=0
  10454. return
  10455.  
  10456. ;-- Enable Restore button
  10457. GUIControl Enable,$RPViewerGUI_RestoreButton
  10458.  
  10459. ;-- Collect RP file name
  10460. LV_GetText($RPFile,A_EventInfo,2)
  10461.  
  10462. ;-- Close current file
  10463. HE_CloseFile($RPViewerGUI_hEdit)
  10464.  
  10465. ;-- Get file size
  10466. FileGetSize $FileSize,%$RPFile%
  10467.  
  10468. ;-- Open/Display file
  10469. if $FileSize<=10485760 ;-- 10 MB
  10470. {
  10471. HE_OpenFile($RPViewerGUI_hEdit,$RPFile)
  10472. if not ErrorLevel
  10473. {
  10474. ;-- Disable Restore button
  10475. GUIControl Disable,$RPViewerGUI_RestoreButton
  10476.  
  10477. ;-- Notify the user
  10478. gui +OwnDialogs
  10479. MsgBox
  10480. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  10481. ,Select Restore Point Error
  10482. ,Could not find/open: `n%$RPFile% %A_Space%
  10483.  
  10484. return
  10485. }
  10486. }
  10487. else
  10488. {
  10489. ;-- Read RPFile
  10490. FileRead $RPViewerGUI_Viewer,*m524288 %$RPFile% ;-- 524288=512K
  10491. if ErrorLevel
  10492. {
  10493. ;-- Disable Restore button
  10494. GUIControl Disable,$RPViewerGUI_RestoreButton
  10495.  
  10496. ;-- Notify the user
  10497. gui +OwnDialogs
  10498. MsgBox
  10499. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  10500. ,Select Restore Point Error
  10501. ,Could not find/open: `n%$RPFile% %A_Space%
  10502.  
  10503. return
  10504. }
  10505.  
  10506. ;-- Load to Viewer
  10507. HE_SetSel($RPViewerGUI_hEdit,0,-1)
  10508. HE_ReplaceSel($RPViewerGUI_hEdit,$RPViewerGUI_Viewer)
  10509.  
  10510. ;-- Empty undo buffer
  10511. HE_EmptyUndoBuffer($RPViewerGUI_hEdit)
  10512.  
  10513. ;-- Scroll to the top/left
  10514. HE_LineScroll($RPViewerGUI_hEdit,-9999999,-9999999)
  10515. }
  10516.  
  10517. return
  10518.  
  10519.  
  10520. ;************************
  10521. ;* *
  10522. ;* Restore button *
  10523. ;* (RPViewerGUI) *
  10524. ;* *
  10525. ;************************
  10526. RPViewerGUI_RestoreButton:
  10527.  
  10528. ;-- Running?
  10529. if $Running
  10530. {
  10531. SoundPlay *-1 ;-- System default sound
  10532. return
  10533. }
  10534.  
  10535. ;-- Anything selected?
  10536. if LV_GetCount("Selected")=0 ;-- Test s/b redundant but remains as a fail-safe
  10537. return
  10538.  
  10539. ;-- Collect full restore file name
  10540. LV_GetText($RPFile,LV_GetNext(0),2)
  10541.  
  10542. ;-- Close RPViewerGUI?
  10543. if $RPViewerCloseOnRestore
  10544. gosub RPViewerGUI_Close
  10545.  
  10546. ;-- Reset GUI default
  10547. gui %$QAHKGUI%:Default
  10548.  
  10549. ;-- Copy selected restore point file over workspace file
  10550. FileCopy %$RPFile%,%$EditFile%,1 ;-- 1=overwrite
  10551. If ErrorLevel
  10552. {
  10553. ;-- Notify the user
  10554. gui +OwnDialogs
  10555. MsgBox
  10556. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  10557. ,Restore Error
  10558. ,Unable to copy the selected restore point to the workspace. %A_Space%
  10559.  
  10560. return
  10561. }
  10562.  
  10563. ;-- Reset file attributes
  10564. FileSetAttrib -RSH,%$EditFile%
  10565.  
  10566. ;-- Reload workspace
  10567. gosub LoadWorkspace
  10568.  
  10569. ;-- Update status bar
  10570. SB_SetText("Workspace restored from " . CompressFileName($RPFile,40))
  10571. SetTimer QAHKGUI_ClearStatusBar,25000
  10572. return
  10573.  
  10574.  
  10575. ;***********************
  10576. ;* *
  10577. ;* Delete *
  10578. ;* (RPViewerGUI) *
  10579. ;* *
  10580. ;***********************
  10581. RPViewerGUI_Delete:
  10582.  
  10583. ;-- Anything selected?
  10584. if LV_GetCount("Selected")=0
  10585. return
  10586.  
  10587. ;-- Attach messages to the current GUI
  10588. gui +OwnDialogs
  10589.  
  10590. ;[===========]
  10591. ;[ Confirm ]
  10592. ;[===========]
  10593. MsgBox
  10594. ,49 ;-- 49 = 1 (OK/Cancel buttons) + 48 ("!" icon)
  10595. ,Confirm Delete,
  10596. (ltrim join`s
  10597. The selected restore point file will be deleted. Press OK to
  10598. proceed. %A_Space%
  10599. )
  10600.  
  10601. IfMsgBox Cancel
  10602. return
  10603.  
  10604. ;[==========]
  10605. ;[ Delete ]
  10606. ;[==========]
  10607. ;-- Identify selected row
  10608. $Row:=LV_GetNext(0)
  10609.  
  10610. ;-- Collect full restore file name
  10611. LV_GetText($RPFile,$Row,2)
  10612.  
  10613. ;-- Delete it
  10614. FileDelete %$RPFile%
  10615. if ErrorLevel
  10616. {
  10617. MsgBox
  10618. ,16 ;-- 16 = 0 (OK button) + 16 (Error icon)
  10619. ,Delete Error,
  10620. (ltrim
  10621. Unable to delete the selected restore point file: %A_Space%
  10622. %$RPFile% %A_Space%
  10623. `nThis file may be in use by another program. %A_Space%
  10624. )
  10625.  
  10626. return
  10627. }
  10628.  
  10629. ;-- Delete row
  10630. LV_Delete($Row)
  10631.  
  10632. ;-- Anything left?
  10633. if LV_GetCount()
  10634. {
  10635. if ($Row>LV_GetCount())
  10636. $Row:=LV_GetCount()
  10637.  
  10638. ;-- Select next logical row
  10639. LV_Modify($Row,"+Select +Vis")
  10640. ;-- Programming note: This statement will automatically trigger the
  10641. ; RPViewerGUI_RPList routine which will populate the RP viewer with
  10642. ; the contents of the selected restore point.
  10643. }
  10644. else
  10645. {
  10646. ;-- Disable Restore button
  10647. GUIControl Disable,$RPViewerGUI_RestoreButton
  10648.  
  10649. ;-- Close last opened file
  10650. HE_CloseFile($RPViewerGUI_hEdit)
  10651. }
  10652.  
  10653. return
  10654.  
  10655.  
  10656. ;***********************
  10657. ;* *
  10658. ;* Close up shop *
  10659. ;* (RPViewerGUI) *
  10660. ;* *
  10661. ;***********************
  10662. RPViewerGUI_Escape:
  10663. if not $RPViewerEscapeToClose
  10664. return
  10665.  
  10666.  
  10667. RPViewerGUI_Close:
  10668. ;-- Save window statistics
  10669. gosub SaveRPViewerConfiguration
  10670.  
  10671. ;-- Destroy window so that it can be used again
  10672. gui %$RPViewerGUI%:Destroy
  10673. ;-- Programming note: The GUI is specified here because this routine is
  10674. ; sometimes called from the main GUI.
  10675.  
  10676. return
  10677.  
  10678.  
  10679. ;*******************************
  10680. ;* *
  10681. ;* *
  10682. ;* Hotkeys *
  10683. ;* (RPViewerGUI) *
  10684. ;* *
  10685. ;* *
  10686. ;*******************************
  10687. ;-- Begin #IfWinActive directive
  10688. #IfWinActive ahk_group $RPViewerGUI_Group
  10689.  
  10690. ;[==========]
  10691. ;[ Delete ]
  10692. ;[==========]
  10693. ~Delete::
  10694.  
  10695. ;-- Set GUI default
  10696. gui %$RPViewerGUI%:Default
  10697.  
  10698. ;-- Ignore if Listview is not in focus
  10699. GUIControlGet $Control,FocusV
  10700. if $Control<>$RPViewerGUI_RPList
  10701. return
  10702.  
  10703. ;-- Delete it
  10704. gosub RPViewerGUI_Delete
  10705. return
  10706.  
  10707.  
  10708. ;[================]
  10709. ;[ Ctrl+WheelUp ]
  10710. ;[================]
  10711. ^WheelUp::
  10712.  
  10713. ;-- Increase font size
  10714. gosub RPViewerGUI_IncreaseFontSize
  10715. return
  10716.  
  10717.  
  10718. ;[==================]
  10719. ;[ Ctrl+WheelDown ]
  10720. ;[==================]
  10721. ^WheelDown::
  10722.  
  10723. ;-- Increase font size
  10724. gosub RPViewerGUI_DecreaseFontSize
  10725. return
  10726.  
  10727.  
  10728. ;[==========]
  10729. ;[ Ctrl+[ ]
  10730. ;[==========]
  10731. ^[::
  10732.  
  10733. ;-- Decrease font size
  10734. gosub RPViewerGUI_DecreaseFontSize
  10735. return
  10736.  
  10737.  
  10738. ;[==========]
  10739. ;[ Ctrl+] ]
  10740. ;[==========]
  10741. ^]::
  10742. ;-- Increase font size
  10743. gosub RPViewerGUI_IncreaseFontSize
  10744. return
  10745.  
  10746.  
  10747. ;[==================]
  10748. ;[ Ctrl+NumpadAdd ]
  10749. ;[==================]
  10750. ^NumpadAdd::
  10751.  
  10752. ;-- Increase font size
  10753. gosub RPViewerGUI_IncreaseFontSize
  10754. return
  10755.  
  10756.  
  10757. ;[==================]
  10758. ;[ Ctrl+NumpadSub ]
  10759. ;[==================]
  10760. ^NumpadSub::
  10761.  
  10762. ;-- Decrease font size
  10763. gosub RPViewerGUI_DecreaseFontSize
  10764. return
  10765.  
  10766.  
  10767. ;[==================]
  10768. ;[ Ctrl+Numpad0 ]
  10769. ;[ Ctrl+NumpadIns ]
  10770. ;[==================]
  10771. ^Numpad0::
  10772. ^NumpadIns::
  10773. ;-- Default font size
  10774. gosub RPViewerGUI_DefaultFontSize
  10775. return
  10776.  
  10777.  
  10778. ;[==========]
  10779. ;[ Ctrl+L ]
  10780. ;[==========]
  10781. ^l::
  10782. ;-- Toggle
  10783. gosub RPViewerGUI_ToggleLineNumbersBar
  10784. return
  10785.  
  10786.  
  10787. ;-- End #IfWinActive directive
  10788. #IfWinActive
  10789.  
  10790. ;-------------------------------------------------------------------------------
  10791. ;-------------------------------------------------------------------------------
  10792. ;-------------------------------------------------------------------------------
  10793. ;-------------------------------------------------------------------------------
  10794. ;-------------------------------------------------------------------------------
  10795. ;---------------------------- End RPViewerGUI Stuff ----------------------------
  10796. ;-------------------------------------------------------------------------------
  10797.  
  10798.  
  10799.  
  10800.  
  10801.  
  10802. ;-------------------------------------------------------------------------------
  10803. ;-------------------------------------------------------------------------------
  10804. ;-------------------------------------------------------------------------------
  10805. ;-------------------------------------------------------------------------------
  10806. ;-------------------------------------------------------------------------------
  10807. ;---------------------------- Begin RunPrompt stuff ----------------------------
  10808. ;-------------------------------------------------------------------------------
  10809. ;*******************************
  10810. ;* *
  10811. ;* *
  10812. ;* RunPrompt GUI *
  10813. ;* *
  10814. ;* *
  10815. ;*******************************
  10816. RunPromptGUI:
  10817. SetTimer %A_ThisLabel%,Off
  10818.  
  10819.  
  10820. ;[==============]
  10821. ;[ Initialize ]
  10822. ;[==============]
  10823. $RunPromptGUI:=23
  10824. $CLParms :=""
  10825.  
  10826. ;[=============]
  10827. ;[ Build GUI ]
  10828. ;[=============]
  10829. ;-- Set GUI default
  10830. gui %$RunPromptGUI%:Default
  10831.  
  10832. ;-- Disable parent GUI, give ownership to parent GUI
  10833. gui %$QAHKGUI%:+Disabled
  10834. gui +Owner%$QAHKGUI%
  10835. ;-- Note: Ownership assignment must be be performed before any other GUI
  10836. ; commands.
  10837.  
  10838. ;-- Identify window handle
  10839. gui %$RunPromptGUI%:+LastFound
  10840. WinGet $RunPromptGUI_hWnd,ID
  10841. GroupAdd $RunPromptGUI_Group,ahk_id %$RunPromptGUI_hWnd%
  10842.  
  10843. ;---------------
  10844. ;-- GUI options
  10845. ;---------------
  10846. gui Margin,6,6
  10847. gui +LabelRunPromptGUI_
  10848. || +Delimiter`n
  10849. || +Resize
  10850. || -MinimizeBox
  10851. || -MaximizeBox
  10852. || +MinSize
  10853.  
  10854. ;-------------------
  10855. ;-- Primary objects
  10856. ;-------------------
  10857. gui Add
  10858. ,GroupBox
  10859. ,xm y10 w370 h170
  10860. || hWnd$RunPromptGUI_RunParmsGB_hWnd
  10861. ,Parameters (separated by space and/or by line)
  10862.  
  10863. gui Add
  10864. ,Edit
  10865. ,xp+10 yp+20 w350 h140
  10866. || +0x100000 ;-- Horizontal scroll bar
  10867. || -Wrap
  10868. || hWnd$RunPromptGUI_RunParms_hWnd
  10869. || v$RunPromptGUI_RunParms
  10870. ,%$RunParms%
  10871.  
  10872. gui Add
  10873. ,GroupBox
  10874. ,xm y+10 w370 h50
  10875. || hWnd$RunPromptGUI_RUSelectGB_hWnd
  10876. ,Recently-used parameters
  10877.  
  10878. gui Add
  10879. ,DropDownList
  10880. ,xp+10 yp+20 w310 r7 Choose1
  10881. || hWnd$RunPromptGUI_RUSelect_hWnd
  10882. || v$RunPromptGUI_RUSelect
  10883. ,%$RunParmsDDL%
  10884.  
  10885. gui Add
  10886. ,Button
  10887. ,x+1 hp
  10888. || hWnd$RunPromptGUI_AddButton_hWnd
  10889. || v$RunPromptGUI_AddButton
  10890. || gRunPromptGUI_Add
  10891. ,&Add
  10892.  
  10893. if $RunParmsDDL is Space
  10894. {
  10895. GUIControl Disable,$RunPromptGUI_RUSelect
  10896. GUIControl Disable,$RunPromptGUI_AddButton
  10897. }
  10898.  
  10899. ;-----------
  10900. ;-- Buttons
  10901. ;-----------
  10902. gui Add
  10903. ,Button
  10904. ,xm y+15 w70 h30
  10905. || hWnd$RunPromptGUI_SubmitButton_hWnd
  10906. || v$RunPromptGUI_SubmitButton
  10907. || gRunPromptGUI_Submit
  10908. ,&Submit
  10909.  
  10910. gui Add
  10911. ,Button
  10912. ,x+5 wp hp
  10913. || hWnd$RunPromptGUI_SkipButton_hWnd
  10914. || gRunPromptGUI_Skip
  10915. ,S&kip
  10916.  
  10917. gui Add,Button
  10918. ,x+5 wp hp
  10919. || hWnd$RunPromptGUI_CancelButton_hWnd
  10920. || gRunPromptGUI_Close
  10921. ,Cancel
  10922.  
  10923. ;-- Set focus
  10924. GUIControl Focus,$RunPromptGUI_SubmitButton
  10925.  
  10926. ;[==========]
  10927. ;[ Attach ]
  10928. ;[==========]
  10929. Attach($RunPromptGUI_RunParmsGB_hWnd ,"w h")
  10930. Attach($RunPromptGUI_RunParms_hWnd ,"w h")
  10931. Attach($RunPromptGUI_RUSelectGB_hWnd ,"y w")
  10932. Attach($RunPromptGUI_RUSelect_hWnd ,"y w")
  10933. Attach($RunPromptGUI_AddButton_hWnd ,"x y r")
  10934. Attach($RunPromptGUI_SubmitButton_hWnd,"y r")
  10935. Attach($RunPromptGUI_SkipButton_hWnd ,"y r")
  10936. Attach($RunPromptGUI_CancelButton_hWnd,"y r")
  10937.  
  10938. ;[============]
  10939. ;[ Show it! ]
  10940. ;[============]
  10941. ;-- Render but don't display
  10942. gui Show,Hide,Script Parameters
  10943.  
  10944. ;-- Calculate X/Y and Show it
  10945. PopupXY($QAHKGUI,$RunPromptGUI,$PosX,$PosY)
  10946. gui Show,x%$PosX% y%$PosY%
  10947.  
  10948. ;-- Prompt sound
  10949. SoundPlay *32 ;-- System "Question" sound
  10950. return
  10951.  
  10952.  
  10953. ;************************
  10954. ;* *
  10955. ;* Add *
  10956. ;* (RunPromptGUI) *
  10957. ;* *
  10958. ;************************
  10959. RunPromptGUI_Add:
  10960.  
  10961. ;-- Collect form variables
  10962. gui Submit,NoHide
  10963.  
  10964. ;-- Update/Refresh Parameters field
  10965. if $RunPromptGUI_RunParms is Space
  10966. $RunPromptGUI_RunParms:=$RunPromptGUI_RUSelect
  10967. else
  10968. $RunPromptGUI_RunParms:=$RunPromptGUI_RunParms . "`n" . $RunPromptGUI_RUSelect
  10969.  
  10970. GUIControl,,$RunPromptGUI_RunParms,%$RunPromptGUI_RunParms%
  10971.  
  10972. ;-- Scroll to the bottom
  10973. SendMessage
  10974. ,EM_LINESCROLL
  10975. ,0 ;-- Number of characters to scroll horizontally
  10976. ,999999999 ;-- Number of characters to scroll vertically
  10977. ,Edit1
  10978. ,ahk_id %$RunPromptGUI_hWnd%
  10979.  
  10980. return
  10981.  
  10982.  
  10983. ;************************
  10984. ;* *
  10985. ;* Submit *
  10986. ;* (RunPromptGUI) *
  10987. ;* *
  10988. ;************************
  10989. RunPromptGUI_Submit:
  10990.  
  10991. ;-- Set GUI default
  10992. gui %$RunPromptGUI%:Default
  10993. ;-- Needed to support hotkeys
  10994.  
  10995. ;-- Collect form variables
  10996. gui Submit,NoHide
  10997.  
  10998. ;-- Update $RunParms (Leave intact. Pimples and all)
  10999. $RunParms:=$RunPromptGUI_RunParms
  11000.  
  11001. ;-- Build parameters list
  11002. t_RunParms :=""
  11003. Loop Parse,$RunPromptGUI_RunParms,`n
  11004. {
  11005. ;-- Skip empty
  11006. if A_LoopField is Space
  11007. Continue
  11008.  
  11009. ;-- AutoTrim
  11010. l_LoopField=%A_LoopField%
  11011.  
  11012. ;-- Populate $CLParms and t_RunParms
  11013. if StrLen($CLParms)=0
  11014. {
  11015. $CLParms:=l_LoopField
  11016. t_RunParms:=A_LoopField
  11017. }
  11018. else
  11019. {
  11020. $CLParms:=$CLParms . A_Space . l_LoopField ;-- FIFO (left to right)
  11021. t_RunParms:=l_LoopField . "`n" . t_RunParms ;-- LIFO (reverse) order
  11022. }
  11023. }
  11024.  
  11025. ;-- Push parameters to $RunParmsDDL
  11026. Loop Parse,t_RunParms,`n
  11027. DDLManager("Push",1,$RunParmsDDL,"`n",A_LoopField,30)
  11028.  
  11029.  
  11030. RunPromptGUI_Skip:
  11031.  
  11032. ;-- Shut down GUI
  11033. gosub RunPromptGUI_Close
  11034. Sleep 50 ;-- Allow for the GUI to respond
  11035.  
  11036. ;-- Continue running
  11037. gosub QAHKGUI_Run_AfterPrompt
  11038. return
  11039.  
  11040.  
  11041. ;************************
  11042. ;* *
  11043. ;* Close up shop *
  11044. ;* (RunPromptGUI) *
  11045. ;* *
  11046. ;************************
  11047. RunPromptGUI_Escape:
  11048. RunPromptGUI_Close:
  11049. RunPromptGUI_Exit:
  11050.  
  11051. ;-- Enable parent window
  11052. gui %$QAHKGUI%:-Disabled
  11053.  
  11054. ;-- Destroy window so that it can be used again
  11055. gui Destroy
  11056. return
  11057.  
  11058.  
  11059. ;********************************
  11060. ;* *
  11061. ;* *
  11062. ;* Hotkeys *
  11063. ;* (RunPromptGUI) *
  11064. ;* *
  11065. ;* *
  11066. ;********************************
  11067. ;-- Begin #IfWinActive directive
  11068. #IfWinActive ahk_group $RunPromptGUI_Group
  11069.  
  11070. ;[==========]
  11071. ;[ F9 ]
  11072. ;[ Ctrl+S ]
  11073. ;[==========]
  11074. F9::
  11075. ^s::
  11076. gosub RunPromptGUI_Submit
  11077. return
  11078.  
  11079.  
  11080. ;-- End #IfWinActive directive
  11081. #IfWinActive
  11082.  
  11083. ~^S::
  11084. sleep 300
  11085. reload
  11086.  
  11087.  
  11088.  
  11089. ;-------------------------------------------------------------------------------
  11090. ;-------------------------------------------------------------------------------
  11091. ;-------------------------------------------------------------------------------
  11092. ;-------------------------------------------------------------------------------
  11093. ;-------------------------------------------------------------------------------
  11094. ;--------------------------- End RunPromptGUI Stuff ----------------------------
  11095. ;-------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement