summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llautoreplace.cpp50
-rw-r--r--indra/newview/llautoreplace.h51
-rw-r--r--indra/newview/llfloaterimnearbychat.cpp2
-rw-r--r--indra/newview/llfloaterimsession.cpp6
4 files changed, 43 insertions, 66 deletions
diff --git a/indra/newview/llautoreplace.cpp b/indra/newview/llautoreplace.cpp
index d71cf290d6..94773e312c 100644
--- a/indra/newview/llautoreplace.cpp
+++ b/indra/newview/llautoreplace.cpp
@@ -30,29 +30,17 @@
#include "llviewercontrol.h"
#include "llnotificationsutil.h"
-LLAutoReplace* LLAutoReplace::sInstance;
-
const char* LLAutoReplace::SETTINGS_FILE_NAME = "autoreplace.xml";
-LLAutoReplace::LLAutoReplace()
-{
-}
-
-LLAutoReplace::~LLAutoReplace()
-{
- sInstance = NULL;
-}
-
-void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
+void LLAutoReplace::autoreplaceCallback(LLWString& inputText, S32& cursorPos)
{
static LLCachedControl<bool> perform_autoreplace(gSavedSettings, "AutoReplace");
if(perform_autoreplace)
{
S32 wordEnd = cursorPos-1;
- LLWString text = inputText.getWString();
- bool atSpace = (text[wordEnd] == ' ');
- bool haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd]));
+ bool atSpace = (inputText[wordEnd] == ' ');
+ bool haveWord = (LLWStringUtil::isPartOfWord(inputText[wordEnd]));
if (atSpace || haveWord)
{
@@ -60,7 +48,7 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
{
// find out if this space immediately follows a word
wordEnd--;
- haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd]));
+ haveWord = (LLWStringUtil::isPartOfWord(inputText[wordEnd]));
}
if (haveWord)
{
@@ -68,14 +56,14 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
std::string word;
S32 wordStart = wordEnd;
for ( S32 backOne = wordStart - 1;
- backOne >= 0 && LLWStringUtil::isPartOfWord(text[backOne]);
+ backOne >= 0 && LLWStringUtil::isPartOfWord(inputText[backOne]);
backOne--
)
{
wordStart--; // walk wordStart back to the beginning of the word
}
LL_DEBUGS("AutoReplace")<<"wordStart: "<<wordStart<<" wordEnd: "<<wordEnd<<LL_ENDL;
- std::string strText = std::string(text.begin(), text.end());
+ std::string strText = std::string(inputText.begin(), inputText.end());
std::string lastWord = strText.substr(wordStart, wordEnd-wordStart+1);
std::string replacementWord( mSettings.replaceWord( lastWord ) );
@@ -89,8 +77,7 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
LLWString strOld = utf8str_to_wstring(lastWord);
int size_change = strNew.size() - strOld.size();
- text.replace(wordStart,lastWord.length(),strNew);
- inputText = wstring_to_utf8str(text);
+ inputText.replace(wordStart,lastWord.length(),strNew);
cursorPos+=size_change;
}
}
@@ -99,16 +86,6 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
}
}
-LLAutoReplace* LLAutoReplace::getInstance()
-{
- if(!sInstance)
- {
- sInstance = new LLAutoReplace();
- sInstance->loadFromSettings();
- }
- return sInstance;
-}
-
std::string LLAutoReplace::getUserSettingsFileName()
{
std::string path=gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "");
@@ -147,6 +124,15 @@ void LLAutoReplace::setSettings(const LLAutoReplaceSettings& newSettings)
saveToUserSettings();
}
+LLAutoReplace::LLAutoReplace()
+{
+}
+
+void LLAutoReplace::initSingleton()
+{
+ loadFromSettings();
+}
+
void LLAutoReplace::loadFromSettings()
{
std::string filename=getUserSettingsFileName();
@@ -220,7 +206,7 @@ void LLAutoReplace::saveToUserSettings()
std::string filename=getUserSettingsFileName();
llofstream file;
file.open(filename.c_str());
- LLSDSerialize::toPrettyXML(mSettings.getAsLLSD(), file);
+ LLSDSerialize::toPrettyXML(mSettings.asLLSD(), file);
file.close();
LL_INFOS("AutoReplace") << "settings saved to '" << filename << "'" << LL_ENDL;
}
@@ -801,7 +787,7 @@ LLSD LLAutoReplaceSettings::getExampleLLSD()
return example;
}
-const LLSD& LLAutoReplaceSettings::getAsLLSD()
+const LLSD& LLAutoReplaceSettings::asLLSD()
{
return mLists;
}
diff --git a/indra/newview/llautoreplace.h b/indra/newview/llautoreplace.h
index f720cc4eda..bbb86294bc 100644
--- a/indra/newview/llautoreplace.h
+++ b/indra/newview/llautoreplace.h
@@ -132,7 +132,7 @@ class LLAutoReplaceSettings
LLSD getExampleLLSD();
/// Get the actual settings as LLSD
- const LLSD& getAsLLSD();
+ const LLSD& asLLSD();
///< @note for use only in AutoReplace::saveToUserSettings
private:
@@ -190,42 +190,37 @@ class LLAutoReplaceSettings
*/
class LLAutoReplace : public LLSingleton<LLAutoReplace>
{
- public:
- LLAutoReplace();
- ~LLAutoReplace();
-
- /// @return a pointer to the active instance
- static LLAutoReplace* getInstance();
+public:
+ /// Callback that provides the hook for use in text entry methods
+ void autoreplaceCallback(LLWString& inputText, S32& cursorPos);
- /// Callback that provides the hook for use in text entry methods
- void autoreplaceCallback(LLUIString& inputText, S32& cursorPos);
+ /// Get a copy of the current settings
+ LLAutoReplaceSettings getSettings();
- /// Get a copy of the current settings
- LLAutoReplaceSettings getSettings();
+ /// Commit new settings after making changes
+ void setSettings(const LLAutoReplaceSettings& settings);
- /// Commit new settings after making changes
- void setSettings(const LLAutoReplaceSettings& settings);
-
- private:
- friend class LLSingleton<LLAutoReplace>;
- static LLAutoReplace* sInstance; ///< the active settings instance
+private:
+ friend class LLSingleton<LLAutoReplace>;
+ LLAutoReplace();
+ /*virtual*/ void initSingleton();
- LLAutoReplaceSettings mSettings; ///< configuration information
+ LLAutoReplaceSettings mSettings; ///< configuration information
- /// Read settings from persistent storage
- void loadFromSettings();
+ /// Read settings from persistent storage
+ void loadFromSettings();
- /// Make the newSettings active and write them to user storage
- void saveToUserSettings();
+ /// Make the newSettings active and write them to user storage
+ void saveToUserSettings();
- /// Compute the user settings file name
- std::string getUserSettingsFileName();
+ /// Compute the user settings file name
+ std::string getUserSettingsFileName();
- /// Compute the (read-ony) application settings file name
- std::string getAppSettingsFileName();
+ /// Compute the (read-ony) application settings file name
+ std::string getAppSettingsFileName();
- /// basename for the settings files
- static const char* SETTINGS_FILE_NAME;
+ /// basename for the settings files
+ static const char* SETTINGS_FILE_NAME;
};
#endif /* LLAUTOREPLACE_H */
diff --git a/indra/newview/llfloaterimnearbychat.cpp b/indra/newview/llfloaterimnearbychat.cpp
index 797d590e1f..73eb822036 100644
--- a/indra/newview/llfloaterimnearbychat.cpp
+++ b/indra/newview/llfloaterimnearbychat.cpp
@@ -66,6 +66,7 @@
#include "llrootview.h"
#include "llviewerchat.h"
#include "lltranslate.h"
+#include "llautoreplace.h"
S32 LLFloaterIMNearbyChat::sLastSpecialChatChannel = 0;
@@ -112,6 +113,7 @@ BOOL LLFloaterIMNearbyChat::postBuild()
setIsSingleInstance(TRUE);
BOOL result = LLFloaterIMSessionTab::postBuild();
+ mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2));
mInputEditor->setCommitCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxCommit, this));
mInputEditor->setKeystrokeCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxKeystroke, this));
mInputEditor->setFocusLostCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxFocusLost, this));
diff --git a/indra/newview/llfloaterimsession.cpp b/indra/newview/llfloaterimsession.cpp
index a09dc1914f..a2c7bacb5d 100644
--- a/indra/newview/llfloaterimsession.cpp
+++ b/indra/newview/llfloaterimsession.cpp
@@ -332,13 +332,7 @@ BOOL LLFloaterIMSession::postBuild()
BOOL result = LLFloaterIMSessionTab::postBuild();
mInputEditor->setMaxTextLength(1023);
- // enable line history support for instant message bar
- // XXX stinson TODO : resolve merge by adding autoreplace to text editors
-#if 0
- // *TODO Establish LineEditor with autoreplace callback
mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2));
-#endif
-
mInputEditor->setFocusReceivedCallback( boost::bind(onInputEditorFocusReceived, _1, this) );
mInputEditor->setFocusLostCallback( boost::bind(onInputEditorFocusLost, _1, this) );
mInputEditor->setKeystrokeCallback( boost::bind(onInputEditorKeystroke, _1, this) );