From 9bdb1d82f867147af44def8c1cca3dfb8259b99c Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Fri, 11 May 2012 12:22:43 -0400 Subject: rename feature from "autocorrect" to "autoreplace", change names accordingly --- indra/newview/llautoreplace.h | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 indra/newview/llautoreplace.h (limited to 'indra/newview/llautoreplace.h') diff --git a/indra/newview/llautoreplace.h b/indra/newview/llautoreplace.h new file mode 100644 index 0000000000..b11c124a62 --- /dev/null +++ b/indra/newview/llautoreplace.h @@ -0,0 +1,65 @@ +/** + * @file llautoreplace.h + * @brief Auto Replace Manager + * @copyright Copyright (c) 2011 LordGregGreg Back + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef AUTO_REPLACE +#define AUTO_REPLACE + +#include "lllineeditor.h" + +class AutoReplace : public LLSingleton +{ + AutoReplace(); + ~AutoReplace(); + static AutoReplace* sInstance; +public: + void autoreplaceCallback(LLUIString& inputText, S32& cursorPos); + static AutoReplace* getInstance(); + BOOL addReplacementList(LLSD newList); + BOOL removeReplacementList(std::string listName); + BOOL setListEnabled(std::string listName, BOOL enabled); + BOOL setListAnnounceeState(std::string listName, BOOL announce); + BOOL setListPriority(std::string listName, int priority); + BOOL setListStyle(std::string listName, BOOL announce); + std::string replaceWords(std::string words); + std::string replaceWord(std::string currentWord); + BOOL addEntryToList(std::string wrong, std::string right, std::string listName); + BOOL removeEntryFromList(std::string wrong, std::string listName); + BOOL saveListToDisk(std::string listName, std::string fileName); + LLSD exportList(std::string listName); + void runTest(); + LLSD getAutoReplaces(); + LLSD getAutoReplaceEntries(std::string listName); + void save(); + + void loadFromDisk(); + +private: + friend class LLSingleton; + void saveToDisk(LLSD newSettings); + LLSD getExampleLLSD(); + std::string getFileName(); + std::string getDefaultFileName(); + + LLSD mAutoReplaces; + +}; + + + +#endif -- cgit v1.2.3 From 6d9c0fab8f2c19fa624e3c1f697ee9c7f08d9245 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Fri, 11 May 2012 14:31:45 -0400 Subject: remove author tracking, non-wordstyle option, and notifications --- indra/newview/llautoreplace.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/llautoreplace.h') diff --git a/indra/newview/llautoreplace.h b/indra/newview/llautoreplace.h index b11c124a62..6c531d0040 100644 --- a/indra/newview/llautoreplace.h +++ b/indra/newview/llautoreplace.h @@ -33,9 +33,7 @@ public: BOOL addReplacementList(LLSD newList); BOOL removeReplacementList(std::string listName); BOOL setListEnabled(std::string listName, BOOL enabled); - BOOL setListAnnounceeState(std::string listName, BOOL announce); BOOL setListPriority(std::string listName, int priority); - BOOL setListStyle(std::string listName, BOOL announce); std::string replaceWords(std::string words); std::string replaceWord(std::string currentWord); BOOL addEntryToList(std::string wrong, std::string right, std::string listName); -- cgit v1.2.3 From 0d11c70e8e68ea2c33cdf01b56b6f2f81ed46f1e Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Sat, 12 May 2012 12:59:07 -0400 Subject: STORM-1738: fix class name and other coding standards issues --- indra/newview/llautoreplace.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'indra/newview/llautoreplace.h') diff --git a/indra/newview/llautoreplace.h b/indra/newview/llautoreplace.h index 6c531d0040..27533c4ef1 100644 --- a/indra/newview/llautoreplace.h +++ b/indra/newview/llautoreplace.h @@ -17,19 +17,19 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AUTO_REPLACE -#define AUTO_REPLACE +#ifndef LLAUTOREPLACE_H +#define LLAUTOREPLACE_H #include "lllineeditor.h" -class AutoReplace : public LLSingleton +class LLAutoReplace : public LLSingleton { - AutoReplace(); - ~AutoReplace(); - static AutoReplace* sInstance; + LLAutoReplace(); + ~LLAutoReplace(); + static LLAutoReplace* sInstance; public: void autoreplaceCallback(LLUIString& inputText, S32& cursorPos); - static AutoReplace* getInstance(); + static LLAutoReplace* getInstance(); BOOL addReplacementList(LLSD newList); BOOL removeReplacementList(std::string listName); BOOL setListEnabled(std::string listName, BOOL enabled); @@ -48,7 +48,7 @@ public: void loadFromDisk(); private: - friend class LLSingleton; + friend class LLSingleton; void saveToDisk(LLSD newSettings); LLSD getExampleLLSD(); std::string getFileName(); @@ -58,6 +58,4 @@ private: }; - - #endif -- cgit v1.2.3 From 04ab2cf43b5341900737f0d480bce0b8205add8e Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 23 May 2012 21:30:13 -0400 Subject: storm-1738: restructure code, preferences storage, preferences ui; ui not completely tested --- indra/newview/llautoreplace.h | 220 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 192 insertions(+), 28 deletions(-) (limited to 'indra/newview/llautoreplace.h') diff --git a/indra/newview/llautoreplace.h b/indra/newview/llautoreplace.h index 27533c4ef1..944676fedd 100644 --- a/indra/newview/llautoreplace.h +++ b/indra/newview/llautoreplace.h @@ -1,7 +1,9 @@ /** * @file llautoreplace.h * @brief Auto Replace Manager - * @copyright Copyright (c) 2011 LordGregGreg Back + * $LicenseInfo:firstyear=2012&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,40 +24,202 @@ #include "lllineeditor.h" +class LLAutoReplace; + +/** The configuration data for the LLAutoReplace object + * + * This is a separate class so that the LLFloaterAutoReplaceSettings + * can have a copy of the configuration to manipulate before committing + * the changes back to the LLAutoReplace singleton that provides the + * autoreplace callback. + */ +class LLAutoReplaceSettings +{ + public: + LLAutoReplaceSettings(); + ~LLAutoReplaceSettings(); + + /// Constructor for creating a tempory copy of the current settings + LLAutoReplaceSettings(const LLAutoReplaceSettings& settings); + + /// Replace the current settings with new ones + void set(const LLAutoReplaceSettings& newSettings); + + /// Load the current settings read from an LLSD file + bool setFromLLSD(const LLSD& settingsFromLLSD); + ///< @returns whether or not the settingsFromLLSD were valid + + // ================================================================ + ///@{ @name List Operations + // ================================================================ + + /// @returns the configured list names as an LLSD Array of strings + LLSD getListNames(); + + /// Status values returned from the addList method + typedef enum + { + AddListOk, + AddListDuplicateName, + AddListInvalidList, + } AddListResult; + + /// Inserts a new list at the end of the priority order + AddListResult addList(const LLSD& newList); + + /// Removes the named list, @returns false if not found + bool removeReplacementList(std::string listName); + + /// Move the named list up in the priority order + bool increaseListPriority(std::string listName); + ///< @returns false if the list is not found + + /// Move the named list down in the priority order + bool decreaseListPriority(std::string listName); + ///< @returns false if the list is not found + + /// Get a copy of just one list (for saving to an export file) + const LLSD* exportList(std::string listName); + /// @returns an LLSD map + + /// Checks for required elements, and that each has the correct type. + bool listIsValid(const LLSD& listSettings); + + /// Checks for required elements, and that each has the correct type. + bool listNameIs(const LLSD& listSettings); + + /// Checks to see if a new lists name conflicts with one in the settings + bool listNameIsUnique(const LLSD& newList); + /// @note must be called with LLSD that has passed listIsValid + + /// Initializes emptyList to an empty list named 'Empty' + static void createEmptyList(LLSD& emptyList); + + /// Resets the name of a list to a new value + static void setListName(LLSD& list, const std::string& newName); + + /// Gets the name of a list + static std::string getListName(LLSD& list); + + ///@} + // ================================================================ + ///@{ @name Replacement Entry Operations + // ================================================================ + + /// Get the replacements specified by a given list + const LLSD* getListEntries(std::string listName); + ///< @returns an LLSD Map of keyword -> replacement test pairs + + /// Get the replacement for the keyword from the specified list + std::string replacementFor(std::string keyword, std::string listName); + + /// Adds a keywword/replacement pair to the named list + bool addEntryToList(std::string keyword, std::string replacement, std::string listName); + + /// Removes the keywword and its replacement from the named list + bool removeEntryFromList(std::string keyword, std::string listName); + + /** + * Look for currentWord in the lists in order, returning any substitution found + * If no configured substitution is found, returns currentWord + */ + std::string replaceWord(const std::string currentWord /**< word to search for */ ); + + /// Provides a hard-coded example of settings + LLSD getExampleLLSD(); + + private: + /// Efficiently and safely compare list names + bool listNameMatches( const LLSD& list, const std::string name ); + + /// The actual llsd data structure + LLSD mLists; + + static const std::string AUTOREPLACE_LIST_NAME; ///< key for looking up list names + static const std::string AUTOREPLACE_LIST_REPLACEMENTS; ///< key for looking up replacement map + + /**< + * LLSD structure of the lists + * - The configuration is an array (mLists), + * - Each entry in the array is a replacement list + * - Each replacement list is a map with three keys: + * @verbatim + * "name" String the name of the list + * "replacements" Map keyword -> replacement pairs + * + * + * + * + * name List 1 + * data + * + * keyword1 replacement1 + * keyword2 replacement2 + * + * + * + * name List 2 + * data + * + * keyword1 replacement1 + * keyword2 replacement2 + * + * + * + * + * @endverbatim + */ +}; + +/** Provides a facility to auto-replace text dynamically as it is entered. + * + * When the end of a word is detected (defined as any punctuation character, + * or any whitespace except newline or return), the preceding word is used + * as a lookup key in an ordered list of maps. If a match is found in any + * map, the keyword is replaced by the associated value from the map. + * + * See the autoreplaceCallback method for how to add autoreplace functionality + * to a text entry tool. + */ class LLAutoReplace : public LLSingleton { + public: LLAutoReplace(); ~LLAutoReplace(); - static LLAutoReplace* sInstance; -public: - void autoreplaceCallback(LLUIString& inputText, S32& cursorPos); + + /// @return a pointer to the active instance static LLAutoReplace* getInstance(); - BOOL addReplacementList(LLSD newList); - BOOL removeReplacementList(std::string listName); - BOOL setListEnabled(std::string listName, BOOL enabled); - BOOL setListPriority(std::string listName, int priority); - std::string replaceWords(std::string words); - std::string replaceWord(std::string currentWord); - BOOL addEntryToList(std::string wrong, std::string right, std::string listName); - BOOL removeEntryFromList(std::string wrong, std::string listName); - BOOL saveListToDisk(std::string listName, std::string fileName); - LLSD exportList(std::string listName); - void runTest(); - LLSD getAutoReplaces(); - LLSD getAutoReplaceEntries(std::string listName); - void save(); - - void loadFromDisk(); - -private: + + /// Callback that provides the hook for use in text entry methods + void autoreplaceCallback(LLUIString& inputText, S32& cursorPos); + + /// Get a copy of the current settings to be manipulated in the preferences dialog + LLAutoReplaceSettings getSettings(); + ///< @note: the caller is respon + + /// Commit new settings after making changes + void setSettings(const LLAutoReplaceSettings& settings); + + private: friend class LLSingleton; - void saveToDisk(LLSD newSettings); - LLSD getExampleLLSD(); - std::string getFileName(); - std::string getDefaultFileName(); + static LLAutoReplace* sInstance; ///< the active settings instance + + LLAutoReplaceSettings mSettings; ///< configuration information + + /// Write the current lists out to the settings storage + void saveToUserSettings(const LLSD& newSettings); + + /// Read settings from persistent storage + void loadFromSettings(); + + /// Compute the user settings file name + std::string getUserSettingsFileName(); - LLSD mAutoReplaces; + /// Compute the (read-ony) application settings file name + std::string getAppSettingsFileName(); + /// basename for the settings files + static const char* SETTINGS_FILE_NAME; }; -#endif +#endif /* LLAUTOREPLACE_H */ -- cgit v1.2.3 From 6075badea0dbfe0eab451913a54bb729a498c39b Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Fri, 25 May 2012 19:24:38 -0400 Subject: fix problems due to LLSD-30, and implement persistent settings --- indra/newview/llautoreplace.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'indra/newview/llautoreplace.h') diff --git a/indra/newview/llautoreplace.h b/indra/newview/llautoreplace.h index 944676fedd..c097e96b9e 100644 --- a/indra/newview/llautoreplace.h +++ b/indra/newview/llautoreplace.h @@ -42,7 +42,7 @@ class LLAutoReplaceSettings /// Constructor for creating a tempory copy of the current settings LLAutoReplaceSettings(const LLAutoReplaceSettings& settings); - /// Replace the current settings with new ones + /// Replace the current settings with new ones and save them to the user settings file void set(const LLAutoReplaceSettings& newSettings); /// Load the current settings read from an LLSD file @@ -127,6 +127,10 @@ class LLAutoReplaceSettings /// Provides a hard-coded example of settings LLSD getExampleLLSD(); + + /// Get the actual settings as LLSD + const LLSD& getAsLLSD(); + ///< @note for use only in AutoReplace::saveToUserSettings private: /// Efficiently and safely compare list names @@ -193,9 +197,8 @@ class LLAutoReplace : public LLSingleton /// Callback that provides the hook for use in text entry methods void autoreplaceCallback(LLUIString& inputText, S32& cursorPos); - /// Get a copy of the current settings to be manipulated in the preferences dialog + /// Get a copy of the current settings LLAutoReplaceSettings getSettings(); - ///< @note: the caller is respon /// Commit new settings after making changes void setSettings(const LLAutoReplaceSettings& settings); @@ -206,12 +209,12 @@ class LLAutoReplace : public LLSingleton LLAutoReplaceSettings mSettings; ///< configuration information - /// Write the current lists out to the settings storage - void saveToUserSettings(const LLSD& newSettings); - /// Read settings from persistent storage void loadFromSettings(); + /// Make the newSettings active and write them to user storage + void saveToUserSettings(); + /// Compute the user settings file name std::string getUserSettingsFileName(); -- cgit v1.2.3 From 1acae5b2915aacff7a2c7892ea2ab094b60b67c9 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Mon, 11 Jun 2012 08:21:39 -0400 Subject: fix error notices to be more prominent for invalid list names and keywords --- indra/newview/llautoreplace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llautoreplace.h') diff --git a/indra/newview/llautoreplace.h b/indra/newview/llautoreplace.h index c097e96b9e..30b1fd2c65 100644 --- a/indra/newview/llautoreplace.h +++ b/indra/newview/llautoreplace.h @@ -114,7 +114,7 @@ class LLAutoReplaceSettings std::string replacementFor(std::string keyword, std::string listName); /// Adds a keywword/replacement pair to the named list - bool addEntryToList(std::string keyword, std::string replacement, std::string listName); + bool addEntryToList(LLWString keyword, LLWString replacement, std::string listName); /// Removes the keywword and its replacement from the named list bool removeEntryFromList(std::string keyword, std::string listName); -- cgit v1.2.3