/Releases/0.5/texter.ahk

https://github.com/darnyte/texter · AutoHotKey · 1374 lines · 1217 code · 84 blank · 73 comment · 85 complexity · 6dbb25a9badd4e4c973e7226caf824a2 MD5 · raw file

  1. ; Texter
  2. ; Author: Adam Pash <adam@lifehacker.com>
  3. ; Gratefully adapted several ideas from AutoClip by Skrommel:
  4. ; http://www.donationcoder.com/Software/Skrommel/index.html#AutoClip
  5. ; Huge thanks to Dustin Luck for his contributions
  6. ; Script Function:
  7. ; Designed to implement simple, on-the-fly creation and managment
  8. ; of auto-replacing hotstrings for repetitive text
  9. ; http://lifehacker.com/software//lifehacker-code-texter-windows-238306.php
  10. SetWorkingDir %A_ScriptDir%
  11. #SingleInstance,Force
  12. #NoEnv
  13. StringCaseSense On
  14. AutoTrim,off
  15. SetKeyDelay,-1
  16. SetWinDelay,0
  17. Gosub,UpdateCheck
  18. Gosub,ASSIGNVARS
  19. Gosub,READINI
  20. EnableTriggers(true)
  21. Gosub,RESOURCES
  22. Gosub,TRAYMENU
  23. Gosub,BuildActive
  24. ;Gosub,AUTOCLOSE
  25. FileRead, EnterKeys, %EnterCSV%
  26. FileRead, TabKeys, %TabCSV%
  27. FileRead, SpaceKeys, %SpaceCSV%
  28. ;Gosub,GetFileList
  29. Goto Start
  30. START:
  31. EnableTriggers(true)
  32. hotkey =
  33. executed = false
  34. Input,input,V L99,{SC77}
  35. input:=hexify(input)
  36. IfInString,ActiveList,%input%|
  37. { ;input matches a hotstring -- see if hotkey matches a trigger for hotstring
  38. if hotkey in %ignore%
  39. {
  40. StringTrimLeft,Bank,hotkey,1
  41. StringTrimRight,Bank,Bank,1
  42. Bank = %Bank%Keys
  43. Bank := %Bank%
  44. if input in %Bank%
  45. {
  46. GoSub, EXECUTE
  47. executed = true
  48. }
  49. }
  50. }
  51. if executed = false
  52. {
  53. SendInput,%hotkey%
  54. }
  55. Goto,START
  56. return
  57. EXECUTE:
  58. WinGetActiveTitle,thisWindow ; this variable ensures that the active Window is receiving the text, activated before send
  59. ;; below added b/c SendMode Play appears not to be supported in Vista
  60. EnableTriggers(false)
  61. if (A_OSVersion = "WIN_VISTA") or (Synergy = 1) ;;; need to implement this in the preferences - should work, though
  62. SendMode Input
  63. else
  64. SendMode Play ; Set an option in Preferences to enable for use with Synergy - Use SendMode Input to work with Synergy
  65. if (ExSound = 1)
  66. SoundPlay, %ReplaceWAV%
  67. ReturnTo := 0
  68. hexInput:=Dehexify(input)
  69. StringLen,BSlength,hexInput
  70. Send, {BS %BSlength%}
  71. FileRead, ReplacementText, %A_ScriptDir%\Active\replacements\%input%.txt
  72. StringLen,ClipLength,ReplacementText
  73. IfInString,ReplacementText,::scr::
  74. {
  75. ;To fix double spacing issue, replace `r`n (return + new line) as AHK sends a new line for each character
  76. StringReplace,ReplacementText,ReplacementText,`r`n,`n, All
  77. StringReplace,ReplacementText,ReplacementText,::scr::,,
  78. IfInString,ReplacementText,`%p
  79. {
  80. textPrompt(ReplacementText)
  81. }
  82. IfInString,ReplacementText,`%s
  83. {
  84. StringReplace, ReplacementText, ReplacementText,`%s(, ˘, All
  85. Loop,Parse,ReplacementText,˘
  86. {
  87. if (A_Index != 1)
  88. {
  89. StringGetPos,len,A_LoopField,)
  90. StringTrimRight,sleepTime,A_LoopField,%len%
  91. StringMid,thisScript,A_LoopField,(len + 2),
  92. Sleep,%sleepTime%
  93. ;WinActivate,%thisWindow% The assumption must be made that in script mode
  94. ; the user can intend to enter text in other windows
  95. SendInput,%thisScript%
  96. }
  97. else
  98. {
  99. ;WinActivate,%thisWindow% The assumption must be made that in script mode
  100. ; the user can intend to enter text in other windows
  101. SendInput,%A_LoopField%
  102. }
  103. }
  104. }
  105. else
  106. SendInput,%ReplacementText%
  107. return
  108. }
  109. else
  110. {
  111. ;To fix double spacing issue, replace `r`n (return + new line) as AHK sends a new line for each character
  112. ;(but only in compatibility mode)
  113. if MODE = 0
  114. {
  115. StringReplace,ReplacementText,ReplacementText,`r`n,`n, All
  116. }
  117. IfInString,ReplacementText,`%c
  118. {
  119. StringReplace, ReplacementText, ReplacementText, `%c, %Clipboard%, All
  120. }
  121. IfInString,ReplacementText,`%t
  122. {
  123. FormatTime, CurrTime, , Time
  124. StringReplace, ReplacementText, ReplacementText, `%t, %CurrTime%, All
  125. }
  126. IfInString,ReplacementText,`%ds
  127. {
  128. FormatTime, SDate, , ShortDate
  129. StringReplace, ReplacementText, ReplacementText, `%ds, %SDate%, All
  130. }
  131. IfInString,ReplacementText,`%dl
  132. {
  133. FormatTime, LDate, , LongDate
  134. StringReplace, ReplacementText, ReplacementText, `%dl, %LDate%, All
  135. }
  136. IfInString,ReplacementText,`%p
  137. {
  138. textPrompt(ReplacementText)
  139. }
  140. IfInString,ReplacementText,`%|
  141. {
  142. ;in clipboard mode, CursorPoint & ClipLength need to be calculated after replacing `r`n
  143. if MODE = 0
  144. {
  145. MeasurementText := ReplacementText
  146. }
  147. else
  148. {
  149. StringReplace,MeasurementText,ReplacementText,`r`n,`n, All
  150. }
  151. StringGetPos,CursorPoint,MeasurementText,`%|
  152. StringReplace, ReplacementText, ReplacementText, `%|,, All
  153. StringReplace, MeasurementText, MeasurementText, `%|,, All
  154. StringLen,ClipLength,MeasurementText
  155. ReturnTo := ClipLength - CursorPoint
  156. }
  157. if MODE = 0
  158. {
  159. if ReturnTo > 0
  160. {
  161. if ReplacementText contains !,#,^,+,{
  162. {
  163. WinActivate,%thisWindow%
  164. SendRaw, %ReplacementText%
  165. Send,{Left %ReturnTo%}
  166. }
  167. else
  168. {
  169. WinActivate,%thisWindow%
  170. Send,%ReplacementText%{Left %ReturnTo%}
  171. }
  172. }
  173. else
  174. {
  175. WinActivate,%thisWindow%
  176. SendRaw,%ReplacementText%
  177. }
  178. }
  179. else
  180. {
  181. oldClip = %Clipboard%
  182. Clipboard = %ReplacementText%
  183. if ReturnTo > 0
  184. {
  185. WinActivate,%thisWindow%
  186. Send,^v{Left %ReturnTo%}
  187. }
  188. else
  189. {
  190. WinActivate,%thisWindow%
  191. Send,^v
  192. }
  193. Clipboard = %oldClip%
  194. }
  195. ; if ReturnTo > 0
  196. ; Send, {Left %ReturnTo%}
  197. }
  198. SendMode Event
  199. IniRead,expanded,texter.ini,Stats,Expanded
  200. IniRead,chars_saved,texter.ini,Stats,Characters
  201. expanded += 1
  202. chars_saved += ClipLength
  203. IniWrite,%expanded%,texter.ini,Stats,Expanded
  204. IniWrite,%chars_saved%,texter.ini,Stats,Characters
  205. Return
  206. HOTKEYS:
  207. StringTrimLeft,hotkey,A_ThisHotkey,1
  208. StringLen,hotkeyl,hotkey
  209. If hotkeyl>1
  210. hotkey=`{%hotkey%`}
  211. Send,{SC77}
  212. Return
  213. ASSIGNVARS:
  214. Version = 0.5
  215. EnterCSV = %A_ScriptDir%\Active\bank\enter.csv
  216. TabCSV = %A_ScriptDir%\Active\bank\tab.csv
  217. SpaceCSV = %A_ScriptDir%\Active\bank\space.csv
  218. ReplaceWAV = %A_ScriptDir%\resources\replace.wav
  219. TexterPNG = %A_ScriptDir%\resources\texter.png
  220. TexterICO = %A_ScriptDir%\resources\texter.ico
  221. StyleCSS = %A_ScriptDir%\resources\style.css
  222. return
  223. READINI:
  224. IfNotExist bank
  225. FileCreateDir, bank
  226. IfNotExist replacements
  227. FileCreateDir, replacements
  228. else
  229. {
  230. IniRead,hexified,texter.ini,Settings,Hexified
  231. if hexified = ERROR
  232. Gosub,HexAll
  233. }
  234. IfNotExist resources
  235. FileCreateDir, resources
  236. IfNotExist bundles
  237. FileCreateDir, bundles
  238. IfNotExist Active
  239. {
  240. FileCreateDir, Active
  241. FileCreateDir, Active\replacements
  242. FileCreateDir, Active\bank
  243. }
  244. IniWrite,%Version%,texter.ini,Preferences,Version
  245. cancel := GetValFromIni("Cancel","Keys","{Escape}") ;keys to stop completion, remember {}
  246. ignore := GetValFromIni("Ignore","Keys","{Tab}`,{Enter}`,{Space}") ;keys not to send after completion
  247. IniWrite,{Escape}`,{Tab}`,{Enter}`,{Space}`,{Left}`,{Right}`,{Up}`,{Down},texter.ini,Autocomplete,Keys
  248. keys := GetValFromIni("Autocomplete","Keys","{Escape}`,{Tab}`,{Enter}`,{Space}`,{Left}`,{Right}`,{Esc}`,{Up}`,{Down}")
  249. otfhotkey := GetValFromIni("Hotkey","OntheFly","^+H")
  250. managehotkey := GetValFromIni("Hotkey","Management","^+M")
  251. MODE := GetValFromIni("Settings","Mode",0)
  252. EnterBox := GetValFromIni("Triggers","Enter",0)
  253. TabBox := GetValFromIni("Triggers","Tab",0)
  254. SpaceBox := GetValFromIni("Triggers","Space",0)
  255. ExSound := GetValFromIni("Preferences","ExSound",1)
  256. Synergy := GetValFromIni("Preferences","Synergy",0)
  257. ;; Enable hotkeys for creating new keys and managing replacements
  258. if otfhotkey <>
  259. {
  260. Hotkey,IfWinNotActive,Texter Preferences
  261. Hotkey,%otfhotkey%,NEWKEY
  262. Hotkey,IfWinActive
  263. }
  264. if managehotkey <>
  265. {
  266. Hotkey,IfWinNotActive,Texter Preferences
  267. Hotkey,%managehotkey%,MANAGE
  268. Hotkey,IfWinActive
  269. }
  270. ;; This section is intended to exit the input in the Start thread whenever the mouse is clicked or
  271. ;; the user Alt-Tabs to another window so that Texter is prepared
  272. ~LButton::Send,{SC77}
  273. $!Tab::
  274. {
  275. GetKeyState,capsL,Capslock,T
  276. SetCapsLockState,Off
  277. pressed = 0
  278. Loop {
  279. Sleep,10
  280. GetKeyState,altKey,Alt,P
  281. GetKeyState,tabKey,Tab,P
  282. if (altKey = "D") and (tabKey = "D")
  283. {
  284. if pressed = 0
  285. {
  286. pressed = 1
  287. Send,{Alt down}{Tab}
  288. continue
  289. }
  290. else
  291. {
  292. continue
  293. }
  294. }
  295. else if (altKey = "D")
  296. {
  297. pressed = 0
  298. continue
  299. }
  300. else
  301. {
  302. Send,{Alt up}
  303. break
  304. }
  305. }
  306. Send,{SC77}
  307. if (capsL = "D")
  308. SetCapsLockState,On
  309. }
  310. $!+Tab::
  311. {
  312. GetKeyState,capsL,Capslock,T
  313. SetCapsLockState,Off
  314. pressed = 0
  315. Loop {
  316. Sleep,10
  317. GetKeyState,altKey,Alt,P
  318. GetKeyState,tabKey,Tab,P
  319. GetKeyState,shiftKey,Shift,P
  320. if (altKey = "D") and (tabKey = "D") and (shiftKey = "D")
  321. {
  322. if pressed = 0
  323. {
  324. pressed = 1
  325. Send,{Alt down}{Shift down}{Tab}
  326. ;Send,{Shift up}
  327. continue
  328. }
  329. else
  330. {
  331. continue
  332. }
  333. }
  334. else if (altKey = "D") and (shiftKey != "D")
  335. {
  336. pressed = 0
  337. Send,{Shift up}
  338. break
  339. }
  340. else if (altKey = "D") and (shiftKey = "D")
  341. {
  342. pressed = 0
  343. continue
  344. }
  345. else
  346. {
  347. Send,{Alt up}{Shift up}
  348. break
  349. }
  350. }
  351. ; Send,{SC77}
  352. if (capsL = "D")
  353. SetCapsLockState,On
  354. }
  355. Return
  356. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Implementation and GUI for on-the-fly creation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  357. NEWKEY:
  358. if A_GuiControl = + ;;;; MAYBE CHANGE THIS TO IfWinExist,Texter Management
  359. GuiControlGet,CurrentBundle,,BundleTabs
  360. else
  361. CurrentBundle =
  362. if (CurrentBundle != "") and (CurrentBundle != "Default")
  363. AddToDir = Bundles\%CurrentBundle%\
  364. else
  365. AddToDir =
  366. Gui,1: Destroy
  367. IniRead,EnterBox,texter.ini,Triggers,Enter
  368. IniRead,TabBox,texter.ini,Triggers,Tab
  369. IniRead,SpaceBox,texter.ini,Triggers,Space
  370. Gui,1: font, s12, Arial
  371. Gui,1: +owner2 +AlwaysOnTop -SysMenu +ToolWindow ;suppresses taskbar button, always on top, removes minimize/close
  372. Gui,1: Add, Text,x10 y20, Hotstring:
  373. Gui,1: Add, Edit, x13 y45 r1 W65 vRString,
  374. Gui,1: Add, Edit, x100 y45 r4 W395 vFullText, Enter your replacement text here...
  375. Gui,1: Add, Text,x115,Trigger:
  376. Gui,1: Add, Checkbox, vEnterCbox yp x175 Checked%EnterBox%, Enter
  377. Gui,1: Add, Checkbox, vTabCbox yp x242 Checked%TabBox%, Tab
  378. Gui,1: Add, Checkbox, vSpaceCbox yp x305 Checked%SpaceBox%, Space
  379. Gui,1: font, s8, Arial
  380. Gui,1: Add, Button,w80 x320 default,&OK
  381. Gui,1: Add, Button,w80 xp+90 GButtonCancel,&Cancel
  382. Gui,1: font, s12, Arial
  383. Gui,1: Add,DropDownList,x100 y15 vTextOrScript, Text||Script
  384. Gui,1: Add,Picture,x0 y105,%TexterPNG%
  385. Gui 2:+Disabled
  386. Gui,1: Show, W500 H200,Add new hotstring...
  387. return
  388. GuiEscape:
  389. ButtonCancel:
  390. Gui 2:-Disabled
  391. Gui,1: Destroy
  392. return
  393. ButtonOK:
  394. Gui,1: Submit, NoHide
  395. Gui 1:+OwnDialogs
  396. hexRString:=hexify(RString)
  397. IfExist, %A_ScriptDir%\%AddToDir%replacements\%hexRString%.txt
  398. {
  399. MsgBox,262144,Hotstring already exists, A replacement with the text %RString% already exists. Would you like to try again?
  400. return
  401. }
  402. IsScript := (TextOrScript == "Script")
  403. if SaveHotstring(RString, FullText, IsScript, AddToDir, SpaceCbox, TabCbox, EnterCbox)
  404. {
  405. Gui 2:-Disabled
  406. Gui,1: Submit
  407. }
  408. Gosub,GetFileList
  409. return
  410. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; End Implementation and GUI for on-the-fly creation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  411. TRAYMENU:
  412. Menu,TRAY,NoStandard
  413. Menu,TRAY,DeleteAll
  414. Menu,TRAY,Add,&Manage hotstrings,MANAGE
  415. Menu,TRAY,Add,&Create new hotstring,NEWKEY
  416. Menu,TRAY,Add
  417. Menu,TRAY,Add,P&references...,PREFERENCES
  418. Menu,TRAY,Add,&Import bundle,IMPORT
  419. Menu,TRAY,Add,&Help,HELP
  420. Menu,TRAY,Add
  421. Menu,TRAY,Add,&About...,ABOUT
  422. Menu,TRAY,Add,&Disable,DISABLE
  423. if disable = 1
  424. Menu,Tray,Check,&Disable
  425. Menu,TRAY,Add,E&xit,EXIT
  426. Menu,TRAY,Default,&Manage hotstrings
  427. Menu,Tray,Tip,Texter
  428. Menu,TRAY,Icon,resources\texter.ico
  429. Return
  430. ABOUT:
  431. Gui,4: Destroy
  432. Gui,4: +owner2
  433. Gui,4: Add,Picture,x200 y0,%TexterPNG%
  434. Gui,4: font, s36, Courier New
  435. Gui,4: Add, Text,x10 y35,Texter
  436. Gui,4: font, s8, Courier New
  437. Gui,4: Add, Text,x171 y77,%Version%
  438. Gui,4: font, s9, Arial
  439. Gui,4: Add,Text,x10 y110 Center,Texter is a text replacement utility designed to save`nyou countless keystrokes on repetitive text entry by`nreplacing user-defined abbreviations (or hotstrings)`nwith your frequently-used text snippets.`n`nTexter is written by Adam Pash and distributed`nby Lifehacker under the GNU Public License.`nFor details on how to use Texter, check out the
  440. Gui,4:Font,underline bold
  441. Gui,4:Add,Text,cBlue gHomepage Center x110 y230,Texter homepage
  442. Gui,4: Color,F8FAF0
  443. Gui 2:+Disabled
  444. Gui,4: Show,auto,About Texter
  445. Return
  446. DISABLE:
  447. IniRead,disable,texter.ini,Settings,Disable
  448. if disable = 0
  449. {
  450. IniWrite,1,texter.ini,Settings,Disable
  451. EnableTriggers(false)
  452. Menu,Tray,Check,&Disable
  453. }
  454. else
  455. {
  456. IniWrite,0,texter.ini,Settings,Disable
  457. EnableTriggers(true)
  458. Menu,Tray,Uncheck,&Disable
  459. }
  460. return
  461. Homepage:
  462. Run http://lifehacker.com/software//lifehacker-code-texter-windows-238306.php
  463. return
  464. BasicUse:
  465. Run http://lifehacker.com/software//lifehacker-code-texter-windows-238306.php#basic
  466. return
  467. Scripting:
  468. Run http://lifehacker.com/software//lifehacker-code-texter-windows-238306.php#advanced
  469. return
  470. 4GuiClose:
  471. 4GuiEscape:
  472. DismissAbout:
  473. Gui 2:-Disabled
  474. Gui,4: Destroy
  475. return
  476. HELP:
  477. Gui,5: Destroy
  478. Gui,5: Add,Picture,x200 y5,%TexterPNG%
  479. Gui,5: font, s36, Courier New
  480. Gui,5: Add, Text,x20 y40,Texter
  481. Gui,5: font, s9, Arial
  482. Gui,5: Add,Text,x19 y285 w300 center,All of Texter's documentation can be found online at the
  483. Gui,5:Font,underline bold
  484. Gui,5:Add,Text,cBlue gHomepage Center x125 y305,Texter homepage
  485. Gui,5: font, s9 norm, Arial
  486. Gui,5: Add,Text,x10 y100 w300,For help by topic, click on one of the following:
  487. Gui,5:Font,underline bold
  488. Gui,5:Add,Text,x30 y120 cBlue gBasicUse,Basic Use:
  489. Gui,5:Font,norm
  490. Gui,5:Add,Text,x50 y140 w280, Covers how to create basic text replacement hotstrings.
  491. Gui,5:Font,underline bold
  492. Gui,5:Add,Text,x30 y180 cBlue gScripting,Sending advanced keystrokes:
  493. Gui,5:Font,norm
  494. Gui,5:Add,Text,x50 y200 w280, Texter is capable of sending advanced keystrokes, like keyboard combinations. This section lists all of the special characters used in script creation, and offers a few examples of how you might use scripts.
  495. Gui,5: Color,F8FAF0
  496. Gui,5: Show,auto,Texter Help
  497. Return
  498. 5GuiEscape:
  499. DismissHelp:
  500. Gui,5: Destroy
  501. return
  502. GetFileList:
  503. FileList =
  504. Loop, %A_ScriptDir%\replacements\*.txt
  505. {
  506. thisFile:=Dehexify(A_LoopFileName)
  507. FileList = %FileList%%thisFile%|
  508. }
  509. StringReplace, FileList, FileList, .txt,,All
  510. return
  511. PREFERENCES:
  512. Gui,3: Destroy
  513. Gui,3: +owner2
  514. Gui,3: Add, Tab,x5 y5 w306 h230,General|Print|Stats ;|Import|Export Add these later
  515. Gui,3: Add,Button,x150 y240 w75 GSETTINGSOK Default,&OK
  516. IniRead,otfhotkey,texter.ini,Hotkey,OntheFly
  517. Gui,3: Add,Text,x10 y40,On-the-Fly shortcut:
  518. Gui,3: Add,Hotkey,xp+10 yp+20 w100 vsotfhotkey, %otfhotkey%
  519. Gui,3: Add,Text,x150 y40,Hotstring Management shortcut:
  520. Gui,3: Add,Hotkey,xp+10 yp+20 w100 vsmanagehotkey, %managehotkey%
  521. ;code optimization -- use mode value to set in initial radio values
  522. CompatMode := NOT MODE
  523. Gui,3: Add,Radio,x10 y100 vModeGroup Checked%CompatMode%,Compatibility mode (Default)
  524. Gui,3: Add,Radio,Checked%MODE%,Clipboard mode (Faster, but less compatible)
  525. OnStartup := GetValFromIni(Settings, Startup, false)
  526. Gui,3: Add,Checkbox, vStartup x20 yp+30 Checked%OnStartup%,Run Texter at start up
  527. IniRead,Update,texter.ini,Preferences,UpdateCheck
  528. Gui,3: Add,Checkbox, vUpdate x20 yp+20 Checked%Update%,Check for updates at launch?
  529. IniRead,ExSound,texter.ini,Preferences,ExSound
  530. Gui,3: Add,Checkbox, vExSound x20 yp+20 gToggle Checked%ExSound%,Play sound when replacement triggered?
  531. IniRead,Synergy,texter.ini,Preferences,Synergy
  532. Gui,3: Add,Checkbox, vSynergy x20 yp+20 gToggle Checked%Synergy%,Make Texter compatible across computers with Synergy?
  533. ;Gui,3: Add,Button,x150 y200 w75 GSETTINGSOK Default,&OK
  534. Gui,3: Add,Button,x230 y240 w75 GSETTINGSCANCEL,&Cancel
  535. Gui,3: Tab,2
  536. Gui,3: Add,Button,w150 h150 gPrintableList,Create Printable Texter Cheatsheet
  537. Gui,3: Add,Text,xp+160 y50 w125 Wrap,Click the big button to export a printable cheatsheet of all your Texter hotstrings, replacements, and triggers.
  538. Gui,3: Tab,3
  539. Gui,3: Add,Text,x10 y40,Your Texter stats:
  540. IniRead,expanded,texter.ini,Stats,Expanded
  541. Gui,3: Add,Text,x25 y60,Snippets expanded: %expanded%
  542. IniRead,chars_saved,texter.ini,Stats,Characters
  543. Gui,3: Add,Text,x25 y80,Characters saved: %chars_saved%
  544. SetFormat,FLOAT,0.2
  545. time_saved := chars_saved/24000
  546. Gui,3: Add,Text,x25 y100,Hours saved: %time_saved% (assuming 400 chars/minute)
  547. ;Gui,3: Add,Button,x150 y200 w75 GSETTINGSOK Default,&OK
  548. ;Gui,3: Add,Button,x230 y200 w75 GSETTINGSCANCEL,&Cancel
  549. Gui 2:+Disabled
  550. Gui,3: Show,AutoSize,Texter Preferences
  551. Return
  552. SETTINGSOK:
  553. Gui,3: Submit, NoHide
  554. If (sotfhotkey != otfhotkey)
  555. {
  556. otfhotkey:=sotfhotkey
  557. If otfhotkey<>
  558. {
  559. Hotkey,IfWinNotActive,Texter Preferences
  560. Hotkey,%otfhotkey%,Newkey
  561. HotKey,%otfhotkey%,On
  562. Hotkey,IfWinActive
  563. }
  564. IniWrite,%otfhotkey%,texter.ini,Hotkey,OntheFly
  565. }
  566. If (smanagehotkey != managehotkey)
  567. {
  568. managehotkey:=smanagehotkey
  569. If managehotkey<>
  570. {
  571. Hotkey,IfWinNotActive,Texter Preferences
  572. Hotkey,%managehotkey%,Manage
  573. HotKey,%managehotkey%,On
  574. Hotkey,IfWinActive
  575. }
  576. IniWrite,%managehotkey%,texter.ini,Hotkey,Management
  577. }
  578. ;code optimization -- calculate MODE from ModeGroup
  579. MODE := ModeGroup - 1
  580. IniWrite,%MODE%,texter.ini,Settings,Mode
  581. IniWrite,%Update%,texter.ini,Preferences,UpdateCheck
  582. If Startup = 1
  583. {
  584. IfNotExist %A_StartMenu%\Programs\Startup\Texter.lnk
  585. ;Get icon for shortcut link:
  586. ;1st from compiled EXE
  587. if %A_IsCompiled%
  588. {
  589. IconLocation=%A_ScriptFullPath%
  590. }
  591. ;2nd from icon in resources folder
  592. else IfExist %TexterICO%
  593. {
  594. IconLocation=%TexterICO%
  595. }
  596. ;3rd from the AutoHotkey application itself
  597. else
  598. {
  599. IconLocation=%A_AhkPath%
  600. }
  601. ;use %A_ScriptFullPath% instead of texter.exe
  602. ;to allow compatibility with source version
  603. FileCreateShortcut,%A_ScriptFullPath%,%A_StartMenu%\Programs\Startup\Texter.lnk,%A_ScriptDir%,,Text replacement system tray application,%IconLocation%
  604. }
  605. else
  606. {
  607. IfExist %A_StartMenu%\Programs\Startup\Texter.lnk
  608. {
  609. FileDelete %A_StartMenu%\Programs\Startup\Texter.lnk
  610. }
  611. }
  612. IniWrite,%Startup%,texter.ini,Settings,Startup
  613. 3GuiClose:
  614. 3GuiEscape:
  615. SETTINGSCANCEL:
  616. Gui 2:-Disabled
  617. Gui,3: Destroy
  618. Return
  619. TOGGLE:
  620. GuiControlGet,ToggleValue,,%A_GuiControl%
  621. IniWrite,%ToggleValue%,texter.ini,Preferences,%A_GuiControl%
  622. return
  623. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Implementation and GUI for management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  624. MANAGE:
  625. GoSub,GetFileList
  626. Bundles =
  627. Loop,bundles\*,2
  628. {
  629. Bundles = %Bundles%|%A_LoopFileName%
  630. thisBundle = %A_LoopFileName%
  631. ; Loop,bundles\%A_LoopFileName%\replacements\*.txt
  632. ; {
  633. ; thisReplacement:=Dehexify(A_LoopFileName)
  634. ; thisBundle = %thisBundle%%thisReplacement%|
  635. ; }
  636. StringReplace, thisBundle, thisBundle, .txt,,All
  637. StringReplace, thisBundle, thisBundle, %A_LoopFileName%,,
  638. %A_LoopFileName% = %thisBundle%
  639. }
  640. StringReplace, FileList, FileList, .txt,,All
  641. StringTrimLeft,Bundles,Bundles,1
  642. Gui,2: Destroy
  643. Gui,2: Default
  644. Gui,2: Font, s12, Arial
  645. Gui,2: Add,Tab,x5 y5 h390 w597 vBundleTabs gListBundle,Default|%Bundles% ;;;;;; START ADDING BUNDLES
  646. Gui,2: Add, Text, Section,
  647. Gui,2: Tab ;;; Every control after this point belongs to no individual tab
  648. Gui,2: Add, Text,ys xs,Hotstring:
  649. Gui,2: Add, ListBox, xs r15 W100 vChoice gShowString Sort, %FileList%
  650. Gui,2: Add, Button, w35 xs+10 GAdd,+
  651. Gui,2: Add, Button, w35 xp+40 GDelete,-
  652. Gui,2: Add, DropDownList, Section ys vTextOrScript, Text||Script
  653. Gui,2: Font, s12, Arial
  654. Gui,2: Add, Edit, r12 W460 xs vFullText
  655. Gui,2: Add, Text, xs,Trigger:
  656. Gui,2: Add, Checkbox, vEnterCbox yp xp+65, Enter
  657. Gui,2: Add, Checkbox, vTabCbox yp xp+65, Tab
  658. Gui,2: Add, Checkbox, vSpaceCbox yp xp+60, Space
  659. Gui,2: Font, s8, Arial
  660. Gui,2: Add,Button, w80 GPButtonSave xs+375 yp, &Save
  661. IniRead,bundleCheck,texter.ini,Bundles,Default
  662. Gui,2: Add, Checkbox, Checked%bundleCheck% vbundleCheck gToggleBundle xs+400 yp+50,Enabled
  663. Gui,2: Add, Button, w80 Default GPButtonOK xs+290 yp+30,&OK
  664. Gui,2: Add, Button, w80 xp+90 GPButtonCancel, &Cancel
  665. Menu, ToolsMenu, Add, P&references..., Preferences
  666. Menu, MgmtMenuBar, Add, &Tools, :ToolsMenu
  667. Menu, BundlesMenu, Add, &Export, Export
  668. Menu, BundlesMenu, Add, &Import, Import
  669. Menu, BundlesMenu, Add, &Add, AddBundle
  670. Menu, BundlesMenu, Add, &Remove, DeleteBundle
  671. Menu, MgmtMenuBar, Add, &Bundles, :BundlesMenu
  672. Menu, HelpMenu, Add, &Basic Use, BasicUse
  673. Menu, HelpMenu, Add, Ad&vanced Use, Scripting
  674. Menu, HelpMenu, Add, &Homepage, Homepage
  675. Menu, HelpMenu, Add, &About..., About
  676. Menu, MgmtMenuBar, Add, &Help, :HelpMenu
  677. Gui,2: Menu, MgmtMenuBar
  678. Gui,2: Show, , Texter Management
  679. Hotkey,IfWinActive, Texter Management
  680. Hotkey,!p,Preferences
  681. Hotkey,delete,Delete
  682. Hotkey,IfWinActive
  683. return
  684. ListBundle:
  685. if A_GuiControl = BundleTabs
  686. GuiControlGet,CurrentBundle,2:,BundleTabs
  687. IniRead,bundleCheck,texter.ini,Bundles,%CurrentBundle%
  688. GuiControl,2:,Choice,|
  689. Loop,bundles\*,2
  690. {
  691. Bundles = %Bundles%|%A_LoopFileName%
  692. thisBundle = %A_LoopFileName%
  693. Loop,bundles\%A_LoopFileName%\replacements\*.txt
  694. {
  695. thisReplacement:=Dehexify(A_LoopFileName)
  696. thisBundle = %thisBundle%%thisReplacement%|
  697. }
  698. ; StringReplace, thisBundle, thisBundle, .txt,,All
  699. StringReplace, thisBundle, thisBundle, %A_LoopFileName%,,
  700. %A_LoopFileName% = %thisBundle%
  701. }
  702. ;if A_GuiControl = Tab
  703. ; GuiControl,,Choice,|
  704. ;else
  705. ; GuiControl,,Choice,%RString%||
  706. GuiControl,2:,FullText,
  707. GuiControl,2:,EnterCbox,0
  708. GuiControl,2:,TabCbox,0
  709. GuiControl,2:,SpaceCbox,0
  710. GuiControl,2:,bundleCheck,%bundleCheck%
  711. if CurrentBundle = Default
  712. {
  713. Gosub,GetFileList
  714. CurrentBundle = %FileList%
  715. GuiControl,,Choice,%CurrentBundle%
  716. }
  717. else
  718. {
  719. StringTrimLeft,CurrentBundle,%CurrentBundle%,0
  720. GuiControl,2:,Choice,%CurrentBundle%
  721. }
  722. return
  723. ToggleBundle:
  724. GuiControlGet,CurrentBundle,,BundleTabs
  725. GuiControlGet,bundleCheck,,bundleCheck
  726. IniWrite,%bundleCheck%,texter.ini,Bundles,%CurrentBundle%
  727. Gosub,BuildActive
  728. return
  729. BuildActive:
  730. activeBundles =
  731. FileDelete,Active\replacements\*
  732. FileDelete,Active\bank\*
  733. Loop,bundles\*,2
  734. {
  735. IniRead,activeCheck,texter.ini,Bundles,%A_LoopFileName%
  736. if activeCheck = 1
  737. activeBundles = %activeBundles%%A_LoopFileName%,
  738. }
  739. IniRead,activeCheck,texter.ini,Bundles,Default
  740. if activeCheck = 1
  741. activeBundles = %activeBundles%Default
  742. Loop,Parse,activeBundles,CSV
  743. {
  744. ; MsgBox,%A_LoopField%
  745. if A_LoopField = Default
  746. {
  747. FileCopy,replacements\*.txt,Active\replacements
  748. FileRead,tab,bank\tab.csv
  749. FileAppend,%tab%,Active\bank\tab.csv
  750. FileRead,space,bank\space.csv
  751. FileAppend,%space%,Active\bank\space.csv
  752. FileRead,enter,bank\enter.csv
  753. FileAppend,%enter%,Active\bank\enter.csv
  754. }
  755. else
  756. {
  757. FileCopy,Bundles\%A_LoopField%\replacements\*.txt,active\replacements
  758. FileRead,tab,Bundles\%A_LoopField%\bank\tab.csv
  759. FileAppend,%tab%,active\bank\tab.csv
  760. FileRead,space,Bundles\%A_LoopField%\bank\space.csv
  761. FileAppend,%space%,active\bank\space.csv
  762. FileRead,enter,Bundles\%A_LoopField%\bank\enter.csv
  763. FileAppend,%enter%,active\bank\enter.csv
  764. }
  765. ; IfExist active\replacements\wc.txt
  766. ; MsgBox,%A_LoopFileName% put me here
  767. }
  768. FileRead, EnterKeys, %A_WorkingDir%\Active\bank\enter.csv
  769. FileRead, TabKeys, %A_WorkingDir%\Active\bank\tab.csv
  770. FileRead, SpaceKeys, %A_WorkingDir%\Active\bank\space.csv
  771. ActiveList =
  772. Loop, Active\replacements\*.txt
  773. {
  774. ActiveList = %ActiveList%%A_LoopFileName%|
  775. }
  776. StringReplace, ActiveList, ActiveList, .txt,,All
  777. return
  778. ADD:
  779. EnableTriggers(false)
  780. GoSub,Newkey
  781. IfWinExist,Add new hotstring...
  782. {
  783. WinWaitClose,Add new hotstring...,,
  784. }
  785. ;GoSub,GetFileList
  786. GoSub,ListBundle
  787. StringReplace, CurrentBundle, CurrentBundle,|%RString%|,|%RString%||
  788. GuiControl,,Choice,|%CurrentBundle%
  789. EnableTriggers(true)
  790. GoSub,ShowString
  791. return
  792. DELETE:
  793. Gui 2:+OwnDialogs
  794. GuiControlGet,ActiveChoice,,Choice
  795. GuiControlGet,CurrentBundle,,BundleTabs
  796. if (CurrentBundle != "") and (CurrentBundle != "Default")
  797. RemoveFromDir = Bundles\%CurrentBundle%\
  798. else
  799. RemoveFromDir =
  800. MsgBox,1,Confirm Delete,Are you sure you want to delete this hotstring: %ActiveChoice%
  801. IfMsgBox, OK
  802. {
  803. ActiveChoice:=Hexify(ActiveChoice)
  804. FileDelete,%A_ScriptDir%\%RemoveFromDir%replacements\%ActiveChoice%.txt
  805. DelFromBank(ActiveChoice, RemoveFromDir, "enter")
  806. DelFromBank(ActiveChoice, RemoveFromDir, "tab")
  807. DelFromBank(ActiveChoice, RemoveFromDir, "space")
  808. GoSub,ListBundle
  809. Gosub,BuildActive
  810. GuiControl,,Choice,|%CurrentBundle%
  811. GuiControl,,FullText,
  812. GuiControl,,EnterCbox,0
  813. GuiControl,,TabCbox,0
  814. GuiControl,,SpaceCbox,0
  815. }
  816. return
  817. ShowString:
  818. GuiControlGet,ActiveChoice,,Choice
  819. ActiveChoice:=Hexify(ActiveChoice)
  820. GuiControlGet,CurrentBundle,,BundleTabs
  821. if CurrentBundle = Default
  822. ReadFrom =
  823. else
  824. ReadFrom = bundles\%CurrentBundle%\
  825. FileRead,enter,%ReadFrom%bank\enter.csv
  826. FileRead,tab,%ReadFrom%bank\tab.csv
  827. FileRead,space,%ReadFrom%bank\space.csv
  828. if ActiveChoice in %enter%
  829. {
  830. GuiControl,,EnterCbox,1
  831. }
  832. else
  833. GuiControl,,EnterCbox,0
  834. if ActiveChoice in %tab%
  835. {
  836. GuiControl,,TabCbox,1
  837. }
  838. else
  839. GuiControl,,TabCbox,0
  840. if ActiveChoice in %space%
  841. {
  842. GuiControl,,SpaceCbox,1
  843. }
  844. else
  845. GuiControl,,SpaceCbox,0
  846. FileRead, Text, %ReadFrom%replacements\%ActiveChoice%.txt
  847. IfInString,Text,::scr::
  848. {
  849. GuiControl,,TextOrScript,|Text|Script||
  850. StringReplace,Text,Text,::scr::,,
  851. }
  852. else
  853. GuiControl,,TextOrScript,|Text||Script
  854. GuiControl,,FullText,%Text%
  855. return
  856. PButtonSave:
  857. Gui,2: Submit, NoHide
  858. IsScript := (TextOrScript == "Script")
  859. If Choice <>
  860. {
  861. if (CurrentBundle != "") and (CurrentBundle != "Default")
  862. SaveToDir = Bundles\%CurrentBundle%\
  863. else
  864. SaveToDir =
  865. PSaveSuccessful := SaveHotstring(Choice, FullText, IsScript, SaveToDir, SpaceCbox, TabCbox, EnterCbox)
  866. }
  867. else
  868. {
  869. PSaveSuccessful = true
  870. }
  871. return
  872. 2GuiEscape:
  873. PButtonCancel:
  874. Gui,2: Destroy
  875. return
  876. PButtonOK:
  877. Gosub,PButtonSave
  878. if PSaveSuccessful
  879. Gui,2: Submit
  880. return
  881. AddBundle:
  882. EnableTriggers(false)
  883. Hotkey,IfWinActive,New Bundle
  884. Hotkey,Space,NOSPACE
  885. Hotkey,IfWinActive
  886. InputBox,BundleName,New Bundle,What would you like to call your bundle? (no spaces),,160,150,,,
  887. if ErrorLevel
  888. {
  889. EnableTriggers(true)
  890. return
  891. }
  892. else
  893. {
  894. IfExist bundles\%BundleName%
  895. MsgBox,,Bundle already in use,%BundleName% bundle already exists.`nChoose another name or delete the current %BundleName% bundle.
  896. else
  897. {
  898. FileCreateDir,bundles\%BundleName%
  899. FileCreateDir,bundles\%BundleName%\replacements
  900. FileCreateDir,bundles\%BundleName%\bank
  901. IniWrite,1,texter.ini,Bundles,%BundleName%
  902. Bundles =
  903. Loop,bundles\*,2
  904. {
  905. Bundles = %Bundles%|%A_LoopFileName%
  906. ;thisBundle = %A_LoopFileName%
  907. if BundleName = %A_LoopFileName%
  908. Bundles = %Bundles%|
  909. }
  910. GuiControl,,BundleTabs,|Default|%Bundles%
  911. GuiControl,,Choice,|
  912. }
  913. }
  914. EnableTriggers(true)
  915. return
  916. NOSPACE:
  917. Msgbox,0,Oops...,Whoops... Bundle names must not have any spaces.
  918. return
  919. DeleteBundle:
  920. GuiControlGet,CurrentBundle,,BundleTabs
  921. if CurrentBundle = Default
  922. {
  923. MsgBox,You can't remove the Default bundle.
  924. return
  925. }
  926. MsgBox,4,Confirm bundle delete,Are you sure you want to remove the %CurrentBundle% bundle?
  927. IfMsgBox, Yes
  928. {
  929. FileRemoveDir,bundles\%CurrentBundle%,1
  930. Bundles =
  931. Loop,bundles\*,2
  932. {
  933. Bundles = %Bundles%|%A_LoopFileName%
  934. }
  935. GuiControl,,BundleTabs,|Default|%Bundles%
  936. Gosub,GetFileList
  937. GuiControl,,Choice,%FileList%
  938. }
  939. return
  940. EXPORT:
  941. GuiControlGet,CurrentBundle,,BundleTabs
  942. MsgBox,4,Confirm Bundle Export,Are you sure you want to export the %CurrentBundle% bundle?
  943. IfMsgBox, Yes
  944. {
  945. IfNotExist %A_WorkingDir%\Texter Export
  946. FileCreateDir,%A_WorkingDir%\Texter Exports
  947. FileDelete,Texter Exports\%CurrentBundle%.texter
  948. IniWrite,%CurrentBundle%,Texter Exports\%CurrentBundle%.texter,Info,Name
  949. if (CurrentBundle = "Default")
  950. BundleDir =
  951. else
  952. BundleDir = bundles\%CurrentBundle%\
  953. Loop,%BundleDir%replacements\*,0
  954. {
  955. FileRead,replacement,%A_LoopFileFullPath%
  956. IfInString,replacement,`r`n
  957. StringReplace,replacement,replacement,`r`n,`%bundlebreak,All
  958. IniWrite,%A_LoopFileName%,Texter Exports\%CurrentBundle%.texter,%A_Index%,Hotstring
  959. IniWrite,%replacement%,Texter Exports\%CurrentBundle%.texter,%A_Index%,Replacement
  960. }
  961. MsgBox,4,Your bundle was successfully created!,Congratulations, your bundle was successfully exported!`nYou can now share your bundle with the world by sending them the %CurrentBundle%.texter file.`nThey can add it to Texter through the import feature. `n`nWould you like to see the %CurrentBundle% bundle?
  962. IfMsgBox, Yes
  963. Run,Texter Exports\
  964. }
  965. return
  966. IMPORT:
  967. FileSelectFile, ImportBundle,,, Import Texter bundle, *.texter
  968. if ErrorLevel = 0
  969. {
  970. IniRead,BundleName,%ImportBundle%,Info,Name
  971. IfExist bundles\%BundleName%
  972. {
  973. MsgBox,4,%BundleName% bundle already installed,%BundleName% bundle already installed.`nWould you like to overwrite previous %BundleName% bundle?
  974. IfMsgBox, No
  975. return
  976. else
  977. {
  978. FileRemoveDir,bundles\%BundleName%,1
  979. }
  980. }
  981. FileCreateDir,bundles\%BundleName%
  982. FileCreateDir,bundles\%BundleName%\replacements
  983. FileCreateDir,bundles\%BundleName%\bank
  984. Loop
  985. {
  986. IniRead,file,%ImportBundle%,%A_Index%,Hotstring
  987. IniRead,replacement,%ImportBundle%,%A_Index%,Replacement
  988. StringReplace, hotstring, file, .txt
  989. StringReplace,replacement,replacement,`%bundlebreak,`r`n,All
  990. bundleCollection = %hotstring%,%bundleCollection%
  991. if file = ERROR
  992. break
  993. else
  994. FileAppend,%replacement%,bundles\%BundleName%\replacements\%file%
  995. }
  996. Gui, 8: Add, Text, Section x10 y10,What triggers would you like to use with the %BundleName% bundle?
  997. Gui,8: Add, Checkbox, vEnterCbox x30, Enter
  998. Gui,8: Add, Checkbox, vTabCbox yp xp+65, Tab
  999. Gui,8: Add, Checkbox, vSpaceCbox yp xp+60, Space
  1000. Gui,8: Add,Button, x180 Default w80 GCreateBank,&OK
  1001. Gui, 8: Show,,Set default triggers
  1002. }
  1003. return
  1004. CreateBank:
  1005. Gui,8: Submit
  1006. Gui,8: Destroy
  1007. if EnterCbox = 1
  1008. FileAppend,%bundleCollection%,bundles\%BundleName%\bank\enter.csv
  1009. if TabCbox = 1
  1010. FileAppend,%bundleCollection%,bundles\%BundleName%\bank\tab.csv
  1011. if SpaceCbox = 1
  1012. FileAppend,%bundleCollection%,bundles\%BundleName%\bank\space.csv
  1013. MsgBox,4,Enable %BundleName% bundle?,Would you like to enable the %BundleName% bundle?
  1014. IfMsgBox,Yes
  1015. {
  1016. IniWrite,1,texter.ini,Bundles,%BundleName%
  1017. Gosub,BuildActive
  1018. }
  1019. else
  1020. IniWrite,0,texter.ini,Bundles,%BundleName%
  1021. Bundles =
  1022. Loop,bundles\*,2
  1023. {
  1024. Bundles = %Bundles%%A_LoopFileName%|
  1025. ;thisBundle = %A_LoopFileName%
  1026. if BundleName = %A_LoopFileName%
  1027. Bundles = %Bundles%|
  1028. }
  1029. GuiControl,2:,BundleTabs,|Default|%Bundles%
  1030. Gosub,ListBundle
  1031. return
  1032. ;; method written by Dustin Luck for writing to ini
  1033. GetValFromIni(section, key, default)
  1034. {
  1035. IniRead,IniVal,texter.ini,%section%,%key%
  1036. if IniVal = ERROR
  1037. {
  1038. IniWrite,%default%,texter.ini,%section%,%key%
  1039. IniVal := default
  1040. }
  1041. return IniVal
  1042. }
  1043. SaveHotstring(HotString, Replacement, IsScript, Bundle, SpaceIsTrigger, TabIsTrigger, EnterIsTrigger)
  1044. {
  1045. global EnterCSV
  1046. global TabCSV
  1047. global SpaceCSV
  1048. global EnterKeys
  1049. global TabKeys
  1050. global SpaceKeys
  1051. HotString:=Hexify(HotString)
  1052. successful := false
  1053. if (!EnterIsTrigger AND !TabIsTrigger AND !SpaceIsTrigger)
  1054. {
  1055. MsgBox,262144,Choose a trigger,You need to choose a trigger in order to save a hotstring replacement.
  1056. }
  1057. else if (HotString <> "" AND Replacement <> "")
  1058. {
  1059. successful := true
  1060. if IsScript
  1061. {
  1062. Replacement = ::scr::%Replacement%
  1063. }
  1064. IniWrite,%SpaceIsTrigger%,texter.ini,Triggers,Space
  1065. IniWrite,%TabIsTrigger%,texter.ini,Triggers,Tab
  1066. IniWrite,%EnterIsTrigger%,texter.ini,Triggers,Enter
  1067. FileDelete, %A_ScriptDir%\%Bundle%replacements\%HotString%.txt
  1068. FileAppend,%Replacement%,%A_ScriptDir%\%Bundle%replacements\%HotString%.txt
  1069. if EnterIsTrigger
  1070. {
  1071. AddToBank(HotString, Bundle, "enter")
  1072. }
  1073. else
  1074. {
  1075. DelFromBank(HotString, Bundle, "enter")
  1076. }
  1077. if TabIsTrigger
  1078. {
  1079. AddToBank(HotString, Bundle, "tab")
  1080. }
  1081. else
  1082. {
  1083. DelFromBank(HotString, Bundle, "tab")
  1084. }
  1085. if SpaceIsTrigger
  1086. {
  1087. AddToBank(HotString, Bundle, "space")
  1088. }
  1089. else
  1090. {
  1091. DelFromBank(HotString, Bundle, "space")
  1092. }
  1093. }
  1094. GoSub,BuildActive
  1095. return successful
  1096. }
  1097. AddToBank(HotString, Bundle, Trigger)
  1098. {
  1099. ;HotString:=Dehexify(HotString)
  1100. BankFile = %Bundle%bank\%trigger%.csv
  1101. FileRead, Bank, %BankFile%
  1102. if HotString not in %Bank%
  1103. {
  1104. FileAppend,%HotString%`,, %BankFile%
  1105. FileRead, Bank, %BankFile%
  1106. }
  1107. }
  1108. DelFromBank(HotString, Bundle, Trigger)
  1109. {
  1110. BankFile = %Bundle%bank\%trigger%.csv
  1111. FileRead, Bank, %BankFile%
  1112. ;HotString:=Dehexify(HotString)
  1113. if HotString in %Bank%
  1114. {
  1115. StringReplace, Bank, Bank, %HotString%`,,,All
  1116. FileDelete, %BankFile%
  1117. FileAppend,%Bank%, %BankFile%
  1118. }
  1119. }
  1120. EnableTriggers(doEnable)
  1121. {
  1122. global keys
  1123. StringReplace,tempKeys,keys,`}`,`{,`n,All
  1124. Loop,Parse,TempKeys,`n,`{`}
  1125. {
  1126. if (doEnable)
  1127. {
  1128. Hotkey,IfWinNotActive,Enter desired text
  1129. Hotkey,$%A_LoopField%,HOTKEYS
  1130. Hotkey,$%A_LoopField%,On
  1131. Hotkey,IfWinActive
  1132. }
  1133. else
  1134. {
  1135. Hotkey,IfWinNotActive,Enter desired text
  1136. Hotkey,$%A_LoopField%,Off
  1137. Hotkey,IfWinActive
  1138. }
  1139. }
  1140. }
  1141. RESOURCES:
  1142. ;code optimization -- removed IfNotExist tests
  1143. ;redundant when final arg to FileInstall is 0
  1144. FileInstall,resources\texter.ico,%TexterICO%,1
  1145. FileInstall,resources\replace.wav,%ReplaceWAV%,0
  1146. FileInstall,resources\texter.png,%TexterPNG%,1
  1147. FileInstall,resources\style.css,%StyleCSS%,0
  1148. return
  1149. ;AUTOCLOSE:
  1150. ;:*?B0:(::){Left}
  1151. ;:*?B0:[::]{Left}
  1152. ;:*?B0:{::{}}{Left}
  1153. ;return
  1154. PrintableList:
  1155. alt := 0
  1156. List = <html xmlns="http://www.w3.org/1999/xhtml"><head><link type="text/css" href="style.css" rel="stylesheet"><title>Texter Hotstrings and Replacement Text Cheatsheet</title></head><body><h2>Texter Hostrings and Replacement Text Cheatsheet</h2><span class="hotstring" style="border:none`; color:black`;"><h3>Hotstring</h3></span><span class="replacement" style="border:none`;"><h3>Replacement Text</h3></span><span class="trigger" style="border:none`;"><h3>Trigger(s)</h3></span>
  1157. Loop, replacements\*.txt
  1158. {
  1159. alt := 1 - alt
  1160. trig =
  1161. hs = %A_LoopFileName%
  1162. StringReplace, hs, hs, .txt
  1163. FileRead, rp, replacements\%hs%.txt
  1164. If hs in %EnterKeys%
  1165. trig = Enter
  1166. If hs in %TabKeys%
  1167. trig = %trig% Tab
  1168. If hs in %SpaceKeys%
  1169. trig = %trig% Space
  1170. StringReplace, rp, rp, <,&lt;,All
  1171. StringReplace, rp, rp, >,&gt;,All
  1172. List = %List%<div class="row%alt%"><span class="hotstring">%hs%</span><span class="replacement">%rp%</span><span class="trigger">%trig%</span></div><br />
  1173. }
  1174. List = %List%</body></html>
  1175. IfExist resources\Texter Replacement Guide.html
  1176. FileDelete,resources\Texter Replacement Guide.html
  1177. FileAppend,%List%, resources\Texter Replacement Guide.html
  1178. Run,resources\Texter Replacement Guide.html
  1179. return
  1180. UpdateCheck: ;;;;;;; Update the version number on each new release ;;;;;;;;;;;;;
  1181. IfNotExist texter.ini
  1182. {
  1183. MsgBox,4,Check for Updates?,Would you like to automatically check for updates when on startup?
  1184. IfMsgBox,Yes
  1185. updatereply = 1
  1186. else
  1187. updatereply = 0
  1188. }
  1189. update := GetValFromIni("Preferences","UpdateCheck",updatereply)
  1190. IniWrite,%Version%,texter.ini,Preferences,Version
  1191. if (update = 1)
  1192. SetTimer,RunUpdateCheck,10000
  1193. return
  1194. RunUpdateCheck:
  1195. update("texter")
  1196. return
  1197. update(program) {
  1198. SetTimer, RunUpdateCheck, Off
  1199. UrlDownloadToFile,http://svn.adampash.com/%program%/CurrentVersion.txt,VersionCheck.txt
  1200. if ErrorLevel = 0
  1201. {
  1202. FileReadLine, Latest, VersionCheck.txt,1
  1203. IniRead,Current,%program%.ini,Preferences,Version
  1204. ;MsgBox,Latest: %Latest% `n Current: %Current%
  1205. if (Latest > Current)
  1206. {
  1207. MsgBox,4,A new version of %program% is available!,Would you like to visit the %program% homepage and download the latest version?
  1208. IfMsgBox,Yes
  1209. Goto,Homepage
  1210. }
  1211. FileDelete,VersionCheck.txt ;; delete version check
  1212. }
  1213. }
  1214. textPrompt(thisText) {
  1215. Gui,7: +AlwaysOnTop -SysMenu +ToolWindow
  1216. Gui,7: Add,Text,x5 y5, Enter the text you want to insert:
  1217. Gui,7: Add,Edit,x20 y25 r1 vpromptText
  1218. Gui,7: Add,Text,x5 y50,Your text will be replace the `%p variable:
  1219. Gui,7: Add,Text,w300 Wrap x20 y70,%thisText%
  1220. Gui,7: Show,auto,Enter desired text
  1221. Hotkey,IfWinActive,Enter desired text
  1222. Hotkey,Enter,SubmitPrompt
  1223. ;Hotkey,Space,
  1224. WinWaitClose,Enter desired text
  1225. }
  1226. return
  1227. SubmitPrompt:
  1228. Gui, 7: Submit
  1229. Gui, 7: Destroy
  1230. StringReplace,ReplacementText,ReplacementText,`%p,%promptText%
  1231. return
  1232. HexAll:
  1233. ;MsgBox,Hexing time!
  1234. FileCopyDir,replacements,resources\backup\replacements
  1235. FileCopyDir,bank,resources\backup\bank
  1236. Loop, %A_ScriptDir%\replacements\*.txt
  1237. {
  1238. StringReplace, thisFile, A_LoopFileName, .txt,,All
  1239. thisFile:=Hexify(thisFile)
  1240. ;MsgBox,% thisFile
  1241. FileMove,%A_ScriptDir%\replacements\%A_LoopFileName%,%A_ScriptDir%\replacements\%thisFile%.txt
  1242. }
  1243. Loop, %A_ScriptDir%\bank\*.csv
  1244. {
  1245. FileRead,thisBank,%A_ScriptDir%\bank\%A_LoopFileName%
  1246. Loop,Parse,thisBank,CSV
  1247. {
  1248. thisString:=Hexify(A_LoopField)
  1249. hexBank = %hexBank%%thisString%,
  1250. }
  1251. FileDelete,%A_ScriptDir%\bank\%A_LoopFileName%
  1252. FileAppend,%hexBank%,%A_ScriptDir%\bank\%A_LoopFileName%
  1253. }
  1254. ;TODO: Also hexify .csv files
  1255. IniWrite,1,texter.ini,Settings,Hexified
  1256. IniWrite,1,texter.ini,Bundles,Default
  1257. return
  1258. Hexify(x) ;Stolen from Autoclip/Laszlo
  1259. {
  1260. StringLen,len,x
  1261. format=%A_FormatInteger%
  1262. SetFormat,Integer,Hex
  1263. hex=
  1264. Loop,%len%
  1265. {
  1266. Transform,y,Asc,%x%
  1267. StringTrimLeft,y,y,2
  1268. hex=%hex%%y%
  1269. StringTrimLeft,x,x,1
  1270. }
  1271. SetFormat,Integer,%format%
  1272. Return,hex
  1273. }
  1274. DeHexify(x)
  1275. {
  1276. StringLen,len,x
  1277. ;len:=(len-4)/2
  1278. string=
  1279. Loop,%len%
  1280. {
  1281. StringLeft,hex,x,2
  1282. hex=0x%hex%
  1283. Transform,y,Chr,%hex%
  1284. string=%string%%y%
  1285. StringTrimLeft,x,x,2
  1286. }
  1287. Return,string
  1288. }
  1289. EXIT:
  1290. ExitApp