From f6f1b18fc675648e5221311fa439d791c9829db1 Mon Sep 17 00:00:00 2001 From: "simon.laframboise@gmail.com" Date: Sun, 1 May 2016 14:19:55 -0400 Subject: [PATCH] Added ability to select wordlist and made it more network friendly Now users can choose the wordlist they would like to load. This still requires a restart though. The default saving location was changed from A_scriptdir to PathToUserFiles, defines in Preference File, this allows having only one Typing aid on the network and multiple users using it (with a common wordlist) --- Source/Includes/Preferences File.ahk | 39 +++++++++++++++++++++++++--- Source/Includes/Sending.ahk | 13 ++++++++++ Source/Includes/Settings.ahk | 31 ++++++++++++++++++++-- Source/Includes/Wordlist.ahk | 31 +++++++++++----------- 4 files changed, 93 insertions(+), 21 deletions(-) diff --git a/Source/Includes/Preferences File.ahk b/Source/Includes/Preferences File.ahk index 5f1f78b..fc26d42 100644 --- a/Source/Includes/Preferences File.ahk +++ b/Source/Includes/Preferences File.ahk @@ -49,6 +49,7 @@ ReadPreferences(RestoreDefaults = false,RestorePreferences = false) global dft_ListBoxNotDPIAwareProgramExecutables global dft_HelperWindowProgramExecutables global dft_HelperWindowProgramTitles + global dft_Wordlist global prefs_IncludeProgramExecutables global prefs_IncludeProgramTitles @@ -82,15 +83,28 @@ ReadPreferences(RestoreDefaults = false,RestorePreferences = false) global prefs_ListBoxNotDPIAwareProgramExecutables global prefs_HelperWindowProgramExecutables global prefs_HelperWindowProgramTitles + global prefs_Wordlist ;g_PrefsFile is global so it works in Settings.ahk global g_PrefsFile global g_PrefsSections global g_XY - g_PrefsFile = %A_ScriptDir%\Preferences.ini - Defaults = %A_ScriptDir%\Defaults.ini - LastState = %A_ScriptDir%\LastState.ini + global PathToUserFiles + global Wordlist + global WordlistFileName + global Default_Wordlist + + PathToUserFiles = %A_MyDocuments%\TypingAid + IfNotExist, %PathToUserFiles% + FileCreateDir, %PathToUserFiles% + + Default_Wordlist = %PathToUserFiles%\wordlist.txt + + + g_PrefsFile = %PathToUserFiles%\Preferences.ini + Defaults = %PathToUserFiles%\Defaults.ini + LastState = %PathToUserFiles%\LastState.ini MaybeFixFileEncoding(g_PrefsFile,"UTF-16") MaybeFixFileEncoding(Defaults,"UTF-16") @@ -148,6 +162,7 @@ ReadPreferences(RestoreDefaults = false,RestorePreferences = false) dft_HelperWindowProgramExecutables,prefs_HelperWindowProgramExecutables,HelperWindow,%SpaceVar% dft_HelperWindowProgramTitles,prefs_HelperWindowProgramTitles,HelperWindow,%SpaceVar% ,XY,HelperWindow,%SpaceVar% + dft_Wordlist,prefs_Wordlist,Settings,%Default_Wordlist% ) g_PrefsSections := Object() @@ -191,6 +206,9 @@ ReadPreferences(RestoreDefaults = false,RestorePreferences = false) } } + wordlist = %prefs_wordlist% + SplitPath, wordlist, wordlistname + ValidatePreferences() ParseTerminatingCharacters() @@ -218,6 +236,8 @@ ReadPreferences(RestoreDefaults = false,RestorePreferences = false) } ConstructHelpStrings() + + Return } @@ -233,6 +253,16 @@ ValidatePreferences() global dft_ListBoxCharacterWidth, dft_ListBoxFontFixed, dft_ListBoxFontSize, dft_ListBoxMaxWidth, dft_ListBoxOffset, dft_ListBoxOpacity, dft_ListBoxRows global prefs_NoBackSpace, prefs_NumPresses, prefs_SendMethod, prefs_ShowLearnedFirst, prefs_SuppressMatchingWord, prefs_TerminatingCharacters global dft_NoBackSpace, dft_NumPresses, dft_SendMethod, dft_ShowLearnedFirst, dft_SuppressMatchingWord, dft_TerminatingCharacters + global dft_Wordlist, prefs_Wordlist + + IfNotExist, %prefs_Wordlist% + { + IfNotEqual, prefs_Wordlist, %dft_Wordlist% + { + MsgBox, The file selected for words %prefs_wordlist% can't be accessed, reverting to default + prefs_Wordlist := dft_Wordlist + } + } if prefs_Length is not integer { @@ -308,7 +338,7 @@ ValidatePreferences() if prefs_SuppressMatchingWord not in On,Off prefs_SuppressMatchingWord := dft_SuppressMatchingWord - if prefs_SendMethod not in 1,2,3,1C,2C,3C,4C + if prefs_SendMethod not in 1,2,3,1C,2C,3C,4C,4 prefs_SendMethod := dft_SendMethod ;SendPlay does not work when not running as Administrator, switch to SendInput @@ -500,6 +530,7 @@ SavePreferences(PrefsToSave) Return } + ConstructHelpStrings() { global diff --git a/Source/Includes/Sending.ahk b/Source/Includes/Sending.ahk index c12234e..945135b 100644 --- a/Source/Includes/Sending.ahk +++ b/Source/Includes/Sending.ahk @@ -171,6 +171,19 @@ SendFull(SendValue,ForceBackspace=false) Return } + IfEqual, prefs_SendMethod, 4 + { + if (BackSpaceWord) + { + sending = {BS %BackSpaceLen%}%SendValue% + } Else { + sending = %SendValue% + } + SendEvent, %sending% ; First do the backspaces, Then send word (Raw because we want the string exactly as in wordlist.txt) + Return + } + + ClipboardSave := ClipboardAll Clipboard = Clipboard := SendValue diff --git a/Source/Includes/Settings.ahk b/Source/Includes/Settings.ahk index ca01586..8385a06 100644 --- a/Source/Includes/Settings.ahk +++ b/Source/Includes/Settings.ahk @@ -45,6 +45,10 @@ ConstructGui() ; Must be global for colors to function, colors will not function if static global Menu_VisitForum + ; Adding path to wordlist + global prefs_Wordlist + + Menu_CaseCorrection= Menu_ArrowKeyMethodOptionsText= @@ -216,8 +220,8 @@ ConstructGui() Gui, MenuGui:Add, GroupBox, x%MenuGroup3of3BoxX% y%MenuRowY% w%MenuThreeColGroupWidth% h%MenuRowHeight% , Send Method - Menu_SendMethodOptionsText=1 - Default (Type)|2 - Fast (Type)|3 - Slow (Type)|4 - Default (Paste)|5 - Fast (Paste)|6 - Slow (Paste)|7 - Alternate method - Menu_SendMethodOptionsCode=1|2|3|1C|2C|3C|4C + Menu_SendMethodOptionsText=1 - Default (Type)|2 - Fast (Type)|3 - Slow (Type)|4 - Default (Paste)|5 - Fast (Paste)|6 - Slow (Paste)|7 - Alternate method|8 - Raw Off + Menu_SendMethodOptionsCode=1|2|3|1C|2C|3C|4C|4 Loop, parse, Menu_SendMethodOptionsCode, | { If (prefs_SendMethod = A_LoopField) @@ -271,6 +275,19 @@ ConstructGui() Gui, MenuGui:Font, cGreen Gui, MenuGui:Add, Text, x%MenuGroup3of3HelpX% y%MenuRowHelpY% vhelpinfo_AutoSpace gHelpMe, %MenuGuiHelpIcon% Gui, MenuGui:Font, cBlack + + MenuRowY := MenuRowY + MenuRowHeight + MenuSeparatorY + MenuRowHelpY := MenuRowY - MenuHelpIndentY + MenuRowEditY := MenuRowY + MenuEditIndentY + + ;WordlistFile + + Gui, MenuGui:Add, GroupBox, x%MenuGroup1BoxX% y%MenuRowY% w%MenuOneColGroupWidth% h%MenuRowHeight% , Wordlist to load words from + Gui, MenuGui:Add, Edit, x%MenuGroup1EditX% y%MenuRowEditY% w%MenuOneColEditWidthEdit% r1 vprefs_Wordlist gEditValue, %prefs_Wordlist% + Gui, MenuGui:Add, Button, x%MenuOneColEditButton% yp w130 gSetWordlistFile, Edit + Gui, MenuGui:Font, cGreen + ;Gui, MenuGui:Add, Text, x%MenuGroup1of1HelpX% y%MenuRowHelpY% vhelpinfo_HelperWindowProgramExecutables gHelpMe, %MenuGuiHelpIcon% + Gui, MenuGui:Font, cBlack Gui, MenuGui:Tab, 2 ; listbox --------------------------------------------------------- @@ -679,6 +696,16 @@ SetHelpProcess: GetList("prefs_HelperWindowProgramExecutables",1) Return +SetWordlistFile: +FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt) +if SelectedFile = + Return +else + GuiControl, Text, prefs_Wordlist, %SelectedFile% + Menu_ValueChanged := true + Menu_ChangedPrefs["prefs_Wordlist"] := prefs_Wordlist +Return + GetList(TitleType,GetExe) { global Menu_GetExe diff --git a/Source/Includes/Wordlist.ahk b/Source/Includes/Wordlist.ahk index b5bc519..f577b7a 100644 --- a/Source/Includes/Wordlist.ahk +++ b/Source/Includes/Wordlist.ahk @@ -9,19 +9,20 @@ ReadWordList() ;mark the wordlist as not done g_WordListDone = 0 - WordlistFileName = wordlist.txt - - Wordlist = %A_ScriptDir%\%WordlistFileName% - WordlistLearned = %A_ScriptDir%\WordlistLearned.txt + global PathToUserFiles + global Wordlist + global WordlistFileName + + WordlistLearned = %PathToUserFiles%\WordlistLearned.txt MaybeFixFileEncoding(Wordlist,"UTF-8") MaybeFixFileEncoding(WordlistLearned,"UTF-8") - g_WordListDB := DBA.DataBaseFactory.OpenDataBase("SQLite", A_ScriptDir . "\WordlistLearned.db" ) + g_WordListDB := DBA.DataBaseFactory.OpenDataBase("SQLite", PathToUserFiles . "\WordlistLearned.db" ) if !g_WordListDB { - msgbox Problem opening database '%A_ScriptDir%\WordlistLearned.db' - fatal error... + msgbox Problem opening database '%PathToUserFiles%\WordlistLearned.db' - fatal error... exitapp } @@ -417,23 +418,23 @@ MaybeUpdateWordlist() { StringTrimRight, TempWordList, TempWordList, 2 - FileDelete, %A_ScriptDir%\Temp_WordlistLearned.txt - FileAppendDispatch(TempWordList, A_ScriptDir . "\Temp_WordlistLearned.txt") - FileCopy, %A_ScriptDir%\Temp_WordlistLearned.txt, %A_ScriptDir%\WordlistLearned.txt, 1 - FileDelete, %A_ScriptDir%\Temp_WordlistLearned.txt + FileDelete, %PathToUserFiles%\Temp_WordlistLearned.txt + FileAppendDispatch(TempWordList, PathToUserFiles . "\Temp_WordlistLearned.txt") + FileCopy, %PathToUserFiles%\Temp_WordlistLearned.txt, %PathToUserFiles%\WordlistLearned.txt, 1 + FileDelete, %PathToUserFiles%\Temp_WordlistLearned.txt ; Convert the Old Wordlist file to not have ;LEARNEDWORDS; IfEqual, g_LegacyLearnedWords, 1 { TempWordList = - FileRead, ParseWords, %A_ScriptDir%\Wordlist.txt + FileRead, ParseWords, %PathToUserFiles%\Wordlist.txt LearnedWordsPos := InStr(ParseWords, "`;LEARNEDWORDS`;",true,1) ;Check for Learned Words TempWordList := SubStr(ParseWords, 1, LearnedwordsPos - 1) ;Grab all non-learned words out of list ParseWords = - FileDelete, %A_ScriptDir%\Temp_Wordlist.txt - FileAppendDispatch(TempWordList, A_ScriptDir . "\Temp_Wordlist.txt") - FileCopy, %A_ScriptDir%\Temp_Wordlist.txt, %A_ScriptDir%\Wordlist.txt, 1 - FileDelete, %A_ScriptDir%\Temp_Wordlist.txt + FileDelete, %PathToUserFiles%\Temp_Wordlist.txt + FileAppendDispatch(TempWordList, PathToUserFiles . "\Temp_Wordlist.txt") + FileCopy, %PathToUserFiles%\Temp_Wordlist.txt, %PathToUserFiles%\Wordlist.txt, 1 + FileDelete, %PathToUserFiles%\Temp_Wordlist.txt } } }