diff --git a/ctrl/SlyEdit.cfg b/ctrl/SlyEdit.cfg index 6e43aa6a5289df826d7c4fc26c4c5541d39061cc..93219c2ba6e81eebd4f26a4e38d8fc3eae8dfad0 100644 --- a/ctrl/SlyEdit.cfg +++ b/ctrl/SlyEdit.cfg @@ -25,6 +25,15 @@ enableTextReplacements=true ; The name of the file where tag lines are stored tagLineFilename=SlyEdit_Taglines.txt +; Text to add to the front of a tagline when adding it to the message. +; This can be blank (nothing after the =) if no prefix is desired. +taglinePrefix=... +; Whether or not to add double-quotes around taglines +quoteTaglines=false +; Whether or not to shuffle (randomize) the list of taglines when they are +; displayed for the user to choose from +shuffleTaglines=true + ; Whether or not to allow users to change their user settings. allowUserSettings=true diff --git a/exec/SlyEdit.js b/exec/SlyEdit.js index a2fa1bf092e56db021a8eebc7ee01e56ff0d28be..e54f894d90e360fca4608638266e0fc8d8f90b2c 100644 --- a/exec/SlyEdit.js +++ b/exec/SlyEdit.js @@ -72,6 +72,11 @@ * overwrite mode in DCT mode when using a wide * terminal; the text replacement list now only draws * the side borders once. + * 2013-09-18 Eric Oulashin Version 1.32 + * Releasing this version. + * 2013-09-19 Eric Oulashin Version 1.33 + * Added 3 options to the SlyEdit configuration file: + * taglinePrefix, quoteTaglines, and shuffleTaglines. */ /* Command-line arguments: @@ -149,8 +154,8 @@ if (!console.term_supports(USER_ANSI)) } // Constants -const EDITOR_VERSION = "1.32"; -const EDITOR_VER_DATE = "2013-09-18"; +const EDITOR_VERSION = "1.33"; +const EDITOR_VER_DATE = "2013-09-19"; // Program variables @@ -5580,6 +5585,11 @@ function doTaglineSelection() if (taglines.length == 0) return; + // If the configuration option to shuffle the taglines is enabled, then + // shuffle them. + if (gConfigSettings.shuffleTaglines) + shuffleArray(taglines); + // Create the list box for the taglines. Make the box up to 14 lines tall. var boxHeight = (taglines.length > 12 ? 14 : taglines.length+2); var boxTopRow = gEditTop + Math.floor((gEditHeight/2) - (boxHeight/2)); @@ -5608,6 +5618,17 @@ function doTaglineSelection() retObj.taglineWasSelected = true; } + // If a tagline was selected, then add the tagline prefix in front of it, and + // also quote the tagline if the option to do so is enabled. + if (retObj.taglineWasSelected) + { + if (gConfigSettings.taglinePrefix.length > 0) + retObj.tagline = gConfigSettings.taglinePrefix + retObj.tagline; + // If the option to quote taglines is enabled, then do it. + if (gConfigSettings.quoteTaglines) + retObj.tagline = "\"" + retObj.tagline + "\""; + } + return retObj; } diff --git a/exec/SlyEdit_Misc.js b/exec/SlyEdit_Misc.js index 7f4688c934439c0ade0e75389919742b7d2e3609..30c172ac83624870a2fc58ed161ec8a4f7032a39 100644 --- a/exec/SlyEdit_Misc.js +++ b/exec/SlyEdit_Misc.js @@ -60,6 +60,10 @@ * to display the hotkey Ctrl-U for user settings. * Moved the options for author initials in quote * lines to user settings. + * 2013-09-19 Eric Oulashin Added the shuffleArray() function. Added 3 + * more options to the config file, to be read by + * ReadSlyEditConfigFile(): taglinePrefix, quoteTaglines, + * and shuffleTaglines. */ // Note: These variables are declared with "var" instead of "const" to avoid @@ -1532,7 +1536,10 @@ function ReadSlyEditConfigFile() cfgObj.enableTextReplacements = false; cfgObj.textReplacementsUseRegex = false; cfgObj.enableTaglines = false; - cfgObj.tagLineFilename = "SlyEdit_Taglines.txt"; + cfgObj.tagLineFilename = genFullPathCfgFilename("SlyEdit_Taglines.txt", gStartupPath); + cfgObj.taglinePrefix = "... "; + cfgObj.quoteTaglines = false; + cfgObj.shuffleTaglines = false; cfgObj.allowUserSettings = true; // General SlyEdit color settings @@ -1663,7 +1670,8 @@ function ReadSlyEditConfigFile() var commentPos = 0; // Position of the start of a comment var setting = null; // A setting name (string) var settingUpper = null; // Upper-case setting name - var value = null; // A value for a setting (string) + var value = null; // A value for a setting (string), with spaces trimmed + var valueLiteral = null; // The value as it is in the config file, no processing var valueUpper = null; // Upper-cased value while (!cfgFile.eof) { @@ -1713,7 +1721,8 @@ function ReadSlyEditConfigFile() // Read the setting & value, and trim leading & trailing spaces. setting = trimSpaces(fileLine.substr(0, equalsPos), true, false, true); settingUpper = setting.toUpperCase(); - value = trimSpaces(fileLine.substr(equalsPos+1), true, false, true); + valueLiteral = fileLine.substr(equalsPos+1); + value = trimSpaces(valueLiteral, true, false, true); valueUpper = value.toUpperCase(); if (settingsMode == "behavior") @@ -1759,6 +1768,12 @@ function ReadSlyEditConfigFile() cfgObj.enableTaglines = (valueUpper == "TRUE"); else if (settingUpper == "TAGLINEFILENAME") cfgObj.tagLineFilename = genFullPathCfgFilename(value, gStartupPath); + else if (settingUpper == "TAGLINEPREFIX") + cfgObj.taglinePrefix = valueLiteral; + else if (settingUpper == "QUOTETAGLINES") + cfgObj.quoteTaglines = (valueUpper == "TRUE"); + else if (settingUpper == "SHUFFLETAGLINES") + cfgObj.shuffleTaglines = (valueUpper == "TRUE"); else if (settingUpper == "ALLOWUSERSETTINGS") cfgObj.allowUserSettings = (valueUpper == "TRUE"); } @@ -3803,6 +3818,33 @@ function chgCharInStr(pStr, pCharIndex, pNewText) return (pStr.substr(0, pCharIndex) + pNewText + pStr.substr(pCharIndex+1)); } +// Shuffles (randomizes) the contents of an array and returns the new +// array. This function came from the following web page: +// http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript +// +// Parameters: +// pArray: The array to shuffle +// +// Return value: The new array +function shuffleArray(pArray) +{ + var counter = pArray.length, temp, index; + + // While there are elements in the pArray + while (counter--) + { + // Pick a random index + index = (Math.random() * (counter + 1)) | 0; + + // And swap the last element with it + temp = pArray[counter]; + pArray[counter] = pArray[index]; + pArray[index] = temp; + } + + return pArray; +} + // This function displays debug text at a given location on the screen, then // moves the cursor back to a given location. //