STORM-1738 Initial callback work

warn-on-failure:open-license
master
Jonathan Yap 2012-02-01 10:16:13 -05:00
commit 4778d82ec6
17 changed files with 9511 additions and 5 deletions

View File

@ -31,6 +31,7 @@
#include "llwidgetreg.h"
// linden library includes
#include "llautocorrect.h"
#include "llcontrol.h" // LLControlGroup
#include "lldir.h"
#include "lldiriterator.h"
@ -107,6 +108,16 @@ public:
};
TestImageProvider gTestImageProvider;
// Mock Autocorrect
AutoCorrect* AutoCorrect::getInstance()
{
return NULL;
}
std::string AutoCorrect::replaceWord(std::string currentWord)
{
return currentWord;
}
static std::string get_xui_dir()
{
std::string delim = gDirUtilp->getDirDelimiter();

View File

@ -195,7 +195,6 @@ LLLineEditor::~LLLineEditor()
gFocusMgr.releaseFocusIfNeeded( this );
}
void LLLineEditor::onFocusReceived()
{
gEditMenuHandler = this;
@ -866,6 +865,13 @@ void LLLineEditor::addChar(const llwchar uni_char)
LLUI::reportBadKeystroke();
}
// *TODO implement callback routine
if (!mReadOnly /*&& autocorrectCallbackRoutine != NULL */)
{
// call callback
// autotocorrectCallbackRoutine(mText&, mCursorPos&);
}
getWindow()->hideCursorUntilMouseMove();
}

View File

@ -169,6 +169,10 @@ public:
virtual BOOL setTextArg( const std::string& key, const LLStringExplicit& text );
virtual BOOL setLabelArg( const std::string& key, const LLStringExplicit& text );
// *TODO Make this work
typedef boost::function<void()> autocorrect_callback_t;
autocorrect_callback_t mAutocorrectCallback;
void setAutocorrectCallback(autocorrect_callback_t cb) { mAutocorrectCallback = cb; }
void setLabel(const LLStringExplicit &new_label) { mLabel = new_label; }
const std::string& getLabel() { return mLabel.getString(); }

View File

@ -97,6 +97,8 @@ set(viewer_SOURCE_FILES
llassetuploadresponders.cpp
llattachmentsmgr.cpp
llaudiosourcevo.cpp
llautocorrect.cpp
llautocorrectfloater.cpp
llavataractions.cpp
llavatariconctrl.cpp
llavatarlist.cpp
@ -653,6 +655,8 @@ set(viewer_HEADER_FILES
llassetuploadresponders.h
llattachmentsmgr.h
llaudiosourcevo.h
llautocorrect.h
llautocorrectfloater.h
llavataractions.h
llavatariconctrl.h
llavatarlist.h

View File

@ -346,6 +346,17 @@
<key>Value</key>
<integer>0</integer>
</map>
<key>AutoCorrectCount</key>
<map>
<key>Comment</key>
<string>How many words have been auto replaced.</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>S32</string>
<key>Value</key>
<integer>0</integer>
</map>
<key>AutoAcceptNewInventory</key>
<map>
<key>Comment</key>
@ -1617,6 +1628,17 @@
<key>Value</key>
<integer>0</integer>
</map>
<key>CmdLineAutocorrect</key>
<map>
<key>Comment</key>
<string>Command for adding new entries to autocorrect</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>String</string>
<key>Value</key>
<string>/addac</string>
</map>
<key>CmdLineDisableVoice</key>
<map>
<key>Comment</key>
@ -2786,6 +2808,17 @@
<key>Value</key>
<integer>1</integer>
</map>
<key>EnableAutoCorrect</key>
<map>
<key>Comment</key>
<string>Enables or disables the autocorrect function</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>0</integer>
</map>
<key>EnableGroupChatPopups</key>
<map>
<key>Comment</key>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,456 @@
/**
* @file llautocorrect.cpp
* @brief Auto Correct 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
*/
#include "llviewerprecompiledheaders.h"
#include "llautocorrect.h"
#include "llsdserialize.h"
#include "llboost.h"
#include "llcontrol.h"
#include "llviewercontrol.h"
#include "llnotificationsutil.h"
AutoCorrect* AutoCorrect::sInstance;
AutoCorrect::AutoCorrect()
{
sInstance = this;
sInstance->loadFromDisk();
}
AutoCorrect::~AutoCorrect()
{
sInstance = NULL;
}
void AutoCorrect::autocorrectCallback(LLUIString& inputText, S32& cursorPos)
{
static LLCachedControl<bool> doAnything(gSavedSettings, "EnableAutoCorrect");
if(doAnything)
{
S32 wordStart = 0;
S32 wordEnd = cursorPos-1;
if(wordEnd < 1)
return;
LLWString text = inputText.getWString();
if(text.size()<1)
return;
if(LLWStringUtil::isPartOfWord(text[wordEnd]))
return;//we only check on word breaks
wordEnd--;
if(LLWStringUtil::isPartOfWord(text[wordEnd]))
{
while ((wordEnd > 0) && (' ' != text[wordEnd-1]))
{
wordEnd--;
}
wordStart=wordEnd;
while ((wordEnd < (S32)text.length()) && (' ' != text[wordEnd]))
{
wordEnd++;
}
std::string strLastWord = std::string(text.begin(), text.end());
std::string lastTypedWord = strLastWord.substr(wordStart, wordEnd-wordStart);
std::string correctedWord(replaceWord(lastTypedWord));
if(correctedWord != lastTypedWord)
{
LLWString strNew = utf8str_to_wstring(correctedWord);
LLWString strOld = utf8str_to_wstring(lastTypedWord);
int nDiff = strNew.size() - strOld.size();
//int wordStart = regText.find(lastTypedWord);
text.replace(wordStart,lastTypedWord.length(),strNew);
inputText = wstring_to_utf8str(text);
cursorPos+=nDiff;
}
}
}
}
AutoCorrect* AutoCorrect::getInstance()
{
if(sInstance)return sInstance;
else
{
sInstance = new AutoCorrect();
return sInstance;
}
}
void AutoCorrect::save()
{
saveToDisk(mAutoCorrects);
}
std::string AutoCorrect::getFileName()
{
std::string path=gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "");
if (!path.empty())
{
path = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "settings_autocorrect.xml");
}
return path;
}
std::string AutoCorrect::getDefaultFileName()
{
std::string path=gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "");
if (!path.empty())
{
path = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "settings_autocorrect.xml");
}
return path;
}
LLSD AutoCorrect::exportList(std::string listName)
{
LLSD toReturn;
if(mAutoCorrects.has(listName))
{
toReturn["listName"]=listName;
toReturn["data"]=mAutoCorrects[listName]["data"];
toReturn["author"]=mAutoCorrects[listName]["author"];
toReturn["wordStyle"]=mAutoCorrects[listName]["wordStyle"];
toReturn["priority"]=mAutoCorrects[listName]["priority"];
}
return toReturn;
}
BOOL AutoCorrect::addCorrectionList(LLSD newList)
{
if(newList.has("listName"))
{
std::string name = newList["listName"];
//if(!mAutoCorrects.has(name)){
LLSD newPart;
newPart["data"]=newList["data"];
newPart["enabled"]=TRUE;
newPart["announce"]=FALSE;
newPart["author"]=newList["author"];
newPart["wordStyle"]=newList["wordStyle"];
newPart["priority"]=newList["priority"].asInteger();
llinfos << "adding new list with settings priority "<<newPart["priority"].asInteger() <<llendl;
mAutoCorrects[name]=newPart;
return TRUE;
}
return FALSE;
}
BOOL AutoCorrect::removeCorrectionList(std::string listName)
{
if(mAutoCorrects.has(listName))
{
mAutoCorrects.erase(listName);
return TRUE;
}
return FALSE;
}
BOOL AutoCorrect::setListEnabled(std::string listName, BOOL enabled)
{
if(mAutoCorrects.has(listName))
{
mAutoCorrects[listName]["enabled"]=enabled;
return TRUE;
}
return FALSE;
}
BOOL AutoCorrect::setListAnnounceeState(std::string listName, BOOL announce)
{
if(mAutoCorrects.has(listName))
{
mAutoCorrects[listName]["announce"]=announce;
return TRUE;
}
return FALSE;
}
BOOL AutoCorrect::setListStyle(std::string listName, BOOL announce)
{
if(mAutoCorrects.has(listName))
{
mAutoCorrects[listName]["wordStyle"]=announce;
return TRUE;
}
return FALSE;
}
BOOL AutoCorrect::setListPriority(std::string listName, int priority)
{
if(mAutoCorrects.has(listName))
{
mAutoCorrects[listName]["priority"]=priority;
return TRUE;
}
return FALSE;
}
LLSD AutoCorrect::getAutoCorrects()
{
//loadFromDisk();
return mAutoCorrects;
}
void AutoCorrect::loadFromDisk()
{
std::string filename=getFileName();
if (filename.empty())
{
llinfos << "no valid user directory." << llendl;
}
if(!gDirUtilp->fileExists(filename))
{
std::string defaultName = getDefaultFileName();
llinfos << " user settings file doesnt exist, going to try and read default one from "<<defaultName.c_str()<< llendl;
if(gDirUtilp->fileExists(defaultName))
{
LLSD blankllsd;
llifstream file;
file.open(defaultName.c_str());
if (file.is_open())
{
LLSDSerialize::fromXMLDocument(blankllsd, file);
}
file.close();
saveToDisk(blankllsd);
}else
saveToDisk(getExampleLLSD());
}
else
{
llifstream file;
file.open(filename.c_str());
if (file.is_open())
{
LLSDSerialize::fromXML(mAutoCorrects, file);
}
file.close();
}
}
void AutoCorrect::saveToDisk(LLSD newSettings)
{
mAutoCorrects=newSettings;
std::string filename=getFileName();
llofstream file;
file.open(filename.c_str());
LLSDSerialize::toPrettyXML(mAutoCorrects, file);
file.close();
}
void AutoCorrect::runTest()
{
std::string startS("He just abandonned all his abilties");
std::string endS = replaceWords(startS);
llinfos << "!!! Test of autoreplace; start with "<<startS.c_str() << " end with " << endS.c_str()<<llendl;
}
BOOL AutoCorrect::saveListToDisk(std::string listName, std::string fileName)
{
if(mAutoCorrects.has(listName))
{
llofstream file;
file.open(fileName.c_str());
LLSDSerialize::toPrettyXML(exportList(listName), file);
file.close();
return TRUE;
}
return FALSE;
}
LLSD AutoCorrect::getAutoCorrectEntries(std::string listName)
{
LLSD toReturn;
if(mAutoCorrects.has(listName))
{
toReturn=mAutoCorrects[listName];
}
return toReturn;
}
std::string AutoCorrect::replaceWord(std::string currentWord)
{
static LLCachedControl<bool> doAnything(gSavedSettings, "EnableAutoCorrect");
if(!(doAnything))return currentWord;
//loop through priorities
for(int currentPriority = 10;currentPriority>=0;currentPriority--)
{
LLSD::map_const_iterator loc_it = mAutoCorrects.beginMap();
LLSD::map_const_iterator loc_end = mAutoCorrects.endMap();
for (; loc_it != loc_end; ++loc_it)
{
const std::string& location = (*loc_it).first;
//llinfos << "location is "<<location.c_str() << " word is "<<currentWord.c_str()<<llendl;
const LLSD& loc_map = (*loc_it).second;
if(loc_map["priority"].asInteger()==currentPriority)
{
if(!loc_map["wordStyle"].asBoolean())
{
//this means look for partial matches instead of a full word
if(loc_map["enabled"].asBoolean())
{
LLSD::map_const_iterator inner_it = loc_map["data"].beginMap();
LLSD::map_const_iterator inner_end = loc_map["data"].endMap();
for (; inner_it != inner_end; ++inner_it)
{
const std::string& wrong = (*inner_it).first;
const std::string& right = (*inner_it).second;
int location = currentWord.find(wrong);
if(location != std::string::npos)
{
currentWord=currentWord.replace(location,wrong.length(),right);
}
}
}
}else
if((loc_map["data"].has(currentWord))&&(loc_map["enabled"].asBoolean()))
{
std::string replacement = loc_map["data"][currentWord];
if(loc_map["announce"].asBoolean())
{
LLSD args;
//"[Before]" has been auto replaced by "[Replacement]"
// based on your [ListName] list.
args["BEFORE"] = currentWord;
args["LISTNAME"]=location;
args["REPLACEMENT"]=replacement;
LLNotificationsUtil::add("AutoReplace",args);
}
gSavedSettings.setS32("AutoCorrectCount",gSavedSettings.getS32("AutoCorrectCount")+1);
llinfos << "found a word in list " << location.c_str() << " and it will replace " << currentWord.c_str() << " => " << replacement.c_str() << llendl;
return replacement;
}
}
}
}
return currentWord;
}
std::string AutoCorrect::replaceWords(std::string words)
{
static LLCachedControl<bool> doAnything(gSavedSettings, "EnableAutoCorrect");
if(!(doAnything))return words;
//TODO update this function to use the "wordStyle" thing,
//but so far this function is never used, so later
boost_tokenizer tokens(words, boost::char_separator<char>(" "));
for (boost_tokenizer::iterator token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter)
{
std::string currentWord(*token_iter);
LLSD::map_const_iterator loc_it = mAutoCorrects.beginMap();
LLSD::map_const_iterator loc_end = mAutoCorrects.endMap();
for (; loc_it != loc_end; ++loc_it)
{
const std::string& location = (*loc_it).first;
//llinfos << "location is "<<location.c_str() << " word is "<<currentWord.c_str()<<llendl;
const LLSD& loc_map = (*loc_it).second;
if((loc_map["data"].has(currentWord))&&(loc_map["enabled"].asBoolean()))
{
std::string replacement = loc_map["data"][currentWord];
if(loc_map["announce"].asBoolean())
{
LLSD args;
//"[Before]" has been auto replaced by "[Replacement]"
// based on your [ListName] list.
args["BEFORE"] = currentWord;
args["LISTNAME"]=location;
args["REPLACEMENT"]=replacement;
LLNotificationsUtil::add("AutoReplace",args);
}
llinfos << "found a word in list " << location.c_str() << " and it will replace " << currentWord.c_str() << " => " << replacement.c_str() << llendl;
int wordStart = words.find(currentWord);
words.replace(wordStart,currentWord.length(),replacement);
return replaceWords(words);//lol recursion!
}
}
}
return words;
}
BOOL AutoCorrect::addEntryToList(std::string wrong, std::string right, std::string listName)
{
// *HACK: Make sure the "Custom" list exists, because the design of this
// system prevents us from updating it by changing the original file...
if(mAutoCorrects.has(listName))
{
mAutoCorrects[listName]["data"][wrong]=right;
return TRUE;
}
else if(listName == "Custom")
{
mAutoCorrects[listName]["announce"] = 0;
mAutoCorrects[listName]["author"] = "You";
mAutoCorrects[listName]["data"][wrong] = right;
mAutoCorrects[listName]["enabled"] = 1;
mAutoCorrects[listName]["priority"] = 10;
mAutoCorrects[listName]["wordStyle"] = 1;
return TRUE;
}
return FALSE;
}
BOOL AutoCorrect::removeEntryFromList(std::string wrong, std::string listName)
{
if(mAutoCorrects.has(listName))
{
if(mAutoCorrects[listName]["data"].has(wrong))
{
mAutoCorrects[listName]["data"].erase(wrong);
return TRUE;
}
}
return FALSE;
}
LLSD AutoCorrect::getExampleLLSD()
{
LLSD toReturn;
LLSD listone;
LLSD listtwo;
LLSD itemOne;
itemOne["wrong"]="wrong1";
itemOne["right"]="right1";
listone[0]=itemOne;
LLSD itemTwo;
itemTwo["wrong"]="wrong2";
itemTwo["right"]="right2";
listone[1]=itemTwo;
toReturn["listOne"]=listone;
itemOne["wrong"]="secondwrong1";
itemOne["right"]="secondright1";
listone[0]=itemOne;
itemTwo["wrong"]="secondwrong2";
itemTwo["right"]="secondright2";
listone[1]=itemTwo;
toReturn["listTwo"]=listone;
return toReturn;
}

View File

@ -0,0 +1,64 @@
/**
* @file llautocorrect.h
* @brief Auto Correct 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_CORRECT
#define AUTO_CORRECT
#include "lllineeditor.h"
class AutoCorrect
{
AutoCorrect();
~AutoCorrect();
static AutoCorrect* sInstance;
public:
void autocorrectCallback(LLUIString& inputText, S32& cursorPos);
static AutoCorrect* getInstance();
BOOL addCorrectionList(LLSD newList);
BOOL removeCorrectionList(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 getAutoCorrects();
LLSD getAutoCorrectEntries(std::string listName);
void save();
void loadFromDisk();
private:
void saveToDisk(LLSD newSettings);
LLSD getExampleLLSD();
std::string getFileName();
std::string getDefaultFileName();
LLSD mAutoCorrects;
};
#endif

View File

@ -0,0 +1,384 @@
/**
* @file llautocorrectfloater.cpp
* @brief Auto Correct List floater
* @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
*/
#include "llviewerprecompiledheaders.h"
#include "llautocorrectfloater.h"
#include "llagentdata.h"
#include "llcommandhandler.h"
#include "llfloater.h"
#include "lluictrlfactory.h"
#include "llagent.h"
#include "llpanel.h"
#include "llbutton.h"
#include "llcolorswatch.h"
#include "llcombobox.h"
#include "llview.h"
#include "llhttpclient.h"
#include "llbufferstream.h"
#include "llcheckboxctrl.h"
#include "llviewercontrol.h"
#include "llui.h"
#include "llcontrol.h"
#include "llscrollingpanellist.h"
#include "llautocorrect.h"
#include "llfilepicker.h"
#include "llfile.h"
#include "llsdserialize.h"
//#include "llfloaterchat.h"
#include "llchat.h"
#include "llinventorymodel.h"
#include "llhost.h"
#include "llassetstorage.h"
#include "roles_constants.h"
#include "llviewertexteditor.h"
#include <boost/tokenizer.hpp>
#include <iosfwd>
#include "llfloaterreg.h"
#include "llinspecttoast.h"
#include "llnotificationhandler.h"
#include "llnotificationmanager.h"
AutoCorrectFloater::AutoCorrectFloater(const LLSD& key) :
LLFloater(key)
{
}
void AutoCorrectFloater::onClose(bool app_quitting)
{
destroy();
}
BOOL AutoCorrectFloater::postBuild(void)
{
namesList = getChild<LLScrollListCtrl>("ac_list_name");
entryList = getChild<LLScrollListCtrl>("ac_list_entry");
childSetCommitCallback("ac_enable",onBoxCommitEnabled,this);
childSetCommitCallback("ac_list_enabled",onEntrySettingChange,this);
childSetCommitCallback("ac_list_show",onEntrySettingChange,this);
childSetCommitCallback("ac_list_style",onEntrySettingChange,this);
childSetCommitCallback("ac_priority",onEntrySettingChange,this);
updateEnabledStuff();
updateNamesList();
namesList->setCommitOnSelectionChange(TRUE);
childSetCommitCallback("ac_list_name", onSelectName, this);
childSetAction("ac_deletelist",removeList,this);
childSetAction("ac_rementry",deleteEntry,this);
childSetAction("ac_exportlist",exportList,this);
childSetAction("ac_addentry",addEntry,this);
childSetAction("ac_loadlist",loadList,this);
return true;
}
void AutoCorrectFloater::onSelectName(LLUICtrl* ctrl, void* user_data)
{
if ( user_data )
{
AutoCorrectFloater* self = ( AutoCorrectFloater* )user_data;
if ( self )
self->updateItemsList();
}
}
void AutoCorrectFloater::updateItemsList()
{
entryList->deleteAllItems();
if((namesList->getAllSelected().size())<=0)
{
updateListControlsEnabled(FALSE);
return;
}
updateListControlsEnabled(TRUE);
std::string listName= namesList->getFirstSelected()->getColumn(0)->getValue().asString();
LLSD listData = AutoCorrect::getInstance()->getAutoCorrectEntries(listName);
childSetValue("ac_list_enabled",listData["enabled"].asBoolean());
childSetValue("ac_list_style",listData["wordStyle"].asBoolean());
childSetValue("ac_list_show",listData["announce"].asBoolean());
childSetValue("ac_text_name",listName);
childSetValue("ac_text_author",listData["author"]);
childSetValue("ac_priority",listData["priority"]);
static LLCachedControl<S32> countAuto(gSavedSettings, "AutoCorrectCount");
childSetValue("ac_stats",(S32)countAuto);
LLSD autoCorrects = listData["data"];
LLSD::map_const_iterator loc_it = autoCorrects.beginMap();
LLSD::map_const_iterator loc_end = autoCorrects.endMap();
for ( ; loc_it != loc_end; ++loc_it)
{
const std::string& wrong = (*loc_it).first;
const std::string& right = (*loc_it).second;
//std::string lentry(wrong+"=>"+right);
LLSD element;
element["id"] = wrong;
LLSD& s_column = element["columns"][0];
s_column["column"] = "Search";
s_column["value"] = wrong;
s_column["font"] = "SANSSERIF";
LLSD& r_column = element["columns"][1];
r_column["column"] = "Replace";
r_column["value"] = right;
r_column["font"] = "SANSSERIF";
entryList->addElement(element, ADD_BOTTOM);
}
}
void AutoCorrectFloater::updateNamesList()
{
namesList->deleteAllItems();
static LLCachedControl<bool> enabledd(gSavedSettings, "EnableAutoCorrect");
if(!(enabledd))
{
updateItemsList();
return;
}
static LLCachedControl<S32> countAuto(gSavedSettings, "AutoCorrectCount");
childSetValue("ac_stats",(S32)countAuto);
LLSD autoCorrects = AutoCorrect::getInstance()->getAutoCorrects();
LLSD::map_const_iterator loc_it = autoCorrects.beginMap();
LLSD::map_const_iterator loc_end = autoCorrects.endMap();
for ( ; loc_it != loc_end; ++loc_it)
{
const std::string& listName = (*loc_it).first;
LLSD element;
element["id"] = listName;
LLSD& friend_column = element["columns"][0];
friend_column["column"] = "Entries";
friend_column["value"] = listName;
//friend_column["font"] = "SANSSERIF";
const LLSD& loc_map = (*loc_it).second;
if(loc_map["enabled"].asBoolean())
friend_column["font"] = "SANSSERIF";
//friend_column["style"] = "BOLD";
else
friend_column["font"] = "SANSSERIF_SMALL";
//friend_column["style"] = "NORMAL";
if(namesList)
namesList->addElement(element, ADD_BOTTOM);
}
updateItemsList();
}
void AutoCorrectFloater::updateListControlsEnabled(BOOL selected)
{
childSetEnabled("ac_text1",selected);
childSetEnabled("ac_text2",selected);
childSetEnabled("ac_text_name",selected);
childSetEnabled("ac_text_author",selected);
childSetEnabled("ac_list_enabled",selected);
childSetEnabled("ac_list_show",selected);
childSetEnabled("ac_list_style",selected);
childSetEnabled("ac_deletelist",selected);
childSetEnabled("ac_exportlist",selected);
childSetEnabled("ac_addentry",selected);
childSetEnabled("ac_rementry",selected);
childSetEnabled("ac_priority",selected);
}
void AutoCorrectFloater::updateEnabledStuff()
{
static LLCachedControl<bool> enabledd(gSavedSettings, "EnableAutoCorrect");
if(!(enabledd))
{
LLCheckBoxCtrl *enBox = getChild<LLCheckBoxCtrl>("ac_enable");
enBox->setDisabledColor(LLColor4::red);
getChild<LLCheckBoxCtrl>("ac_enable")->setEnabledColor(LLColor4(1.0f,0.0f,0.0f,1.0f));
}else
{
getChild<LLCheckBoxCtrl>("ac_enable")->setEnabledColor(
LLUIColorTable::instance().getColor( "LabelTextColor" ));
}
childSetEnabled("ac_list_name",enabledd);
childSetEnabled("ac_list_entry",enabledd);
updateListControlsEnabled(enabledd);
updateNamesList();
AutoCorrect::getInstance()->save();
}
void AutoCorrectFloater::setData(void * data)
{
//empanel = (LLPanel*)data;
}
void AutoCorrectFloater::onBoxCommitEnabled(LLUICtrl* caller, void* user_data)
{
if ( user_data )
{
AutoCorrectFloater* self = ( AutoCorrectFloater* )user_data;
if ( self )
{
self->updateEnabledStuff();
}
}
}
void AutoCorrectFloater::onEntrySettingChange(LLUICtrl* caller, void* user_data)
{
if ( user_data )
{
AutoCorrectFloater* self = ( AutoCorrectFloater* )user_data;
if ( self )
{
std::string listName= self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
AutoCorrect::getInstance()->setListEnabled(listName,self->childGetValue("ac_list_enabled").asBoolean());
AutoCorrect::getInstance()->setListAnnounceeState(listName,self->childGetValue("ac_list_show").asBoolean());
AutoCorrect::getInstance()->setListStyle(listName,self->childGetValue("ac_list_style").asBoolean());
AutoCorrect::getInstance()->setListPriority(listName,self->childGetValue("ac_priority").asInteger());
//sInstance->updateEnabledStuff();
self->updateItemsList();
AutoCorrect::getInstance()->save();
}
}
}
void AutoCorrectFloater::deleteEntry(void* data)
{
if ( data )
{
AutoCorrectFloater* self = ( AutoCorrectFloater* )data;
if ( self )
{
std::string listName=self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
if((self->entryList->getAllSelected().size())>0)
{
std::string wrong= self->entryList->getFirstSelected()->getColumn(0)->getValue().asString();
AutoCorrect::getInstance()->removeEntryFromList(wrong,listName);
self->updateItemsList();
AutoCorrect::getInstance()->save();
}
}
}
}
void AutoCorrectFloater::loadList(void* data)
{
LLFilePicker& picker = LLFilePicker::instance();
if(!picker.getOpenFile( LLFilePicker::FFLOAD_XML) )
{return;
}
llifstream file;
file.open(picker.getFirstFile().c_str());
LLSD blankllsd;
if (file.is_open())
{
LLSDSerialize::fromXMLDocument(blankllsd, file);
}
file.close();
gSavedSettings.setBOOL("EnableAutoCorrect",true);
AutoCorrect::getInstance()->addCorrectionList(blankllsd);
if ( data )
{
AutoCorrectFloater* self = ( AutoCorrectFloater* )data;
if ( self )
self->updateEnabledStuff();
}
}
void AutoCorrectFloater::removeList(void* data)
{
if ( data )
{
AutoCorrectFloater* self = ( AutoCorrectFloater* )data;
if ( self )
{
std::string listName= self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
AutoCorrect::getInstance()->removeCorrectionList(listName);
self->updateEnabledStuff();
}
}
}
void AutoCorrectFloater::exportList(void *data)
{
if ( data )
{
AutoCorrectFloater* self = ( AutoCorrectFloater* )data;
if ( self )
{
std::string listName=self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
LLFilePicker& picker = LLFilePicker::instance();
if(!picker.getSaveFile( LLFilePicker::FFSAVE_XML) )
{return;
}
llofstream file;
file.open(picker.getFirstFile().c_str());
LLSDSerialize::toPrettyXML(AutoCorrect::getInstance()->exportList(listName), file);
file.close();
}
}
}
void AutoCorrectFloater::addEntry(void* data)
{
if ( data )
{
AutoCorrectFloater* self = ( AutoCorrectFloater* )data;
if ( self )
{
std::string listName= self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
LLChat chat;
chat.mText ="To add an entry, please type in chat \""+gSavedSettings.getString("CmdLineAutocorrect")+" "+listName+"|wrongWord|rightWord\"";
chat.mSourceType = CHAT_SOURCE_SYSTEM;
LLSD args;
args["type"] = LLNotificationsUI::NT_NEARBYCHAT;
LLNotificationsUI::LLNotificationManager::instance().onChat(chat, args);
}
}
}
AutoCorrectFloater* AutoCorrectFloater::showFloater()
{
AutoCorrectFloater *floater = dynamic_cast<AutoCorrectFloater*>(LLFloaterReg::getInstance("autocorrect"));
if(floater)
{
floater->setVisible(true);
floater->setFrontmost(true);
floater->center();
return floater;
}
else
{
LL_WARNS("AutoCorrect") << "Can't find floater!" << LL_ENDL;
return NULL;
}
}

View File

@ -0,0 +1,67 @@
/**
* @file llautocorrectfloater.h
* @brief Auto Correct List floater
* @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 AUTOCORRECTFLOATER_H
#define AUTOCORRECTFLOATER_H
#include "llfloater.h"
#include "llmediactrl.h"
#include "llscrolllistctrl.h"
#include "llviewerinventory.h"
#include <boost/bind.hpp>
class AutoCorrectFloater :
public LLFloater
{
public:
AutoCorrectFloater(const LLSD& key);
/*virtual*/ BOOL postBuild();
/*virtual*/ void onClose(bool app_quitting);
static AutoCorrectFloater* showFloater();
void setData(void * data);
void updateEnabledStuff();
void updateNamesList();
void updateListControlsEnabled(BOOL selected);
void updateItemsList();
LLScrollListCtrl *namesList;
LLScrollListCtrl *entryList;
//LLPanel * empanel;
private:
//static JCInvDropTarget* mNotecardDropTarget;
static void onBoxCommitEnabled(LLUICtrl* caller, void* user_data);
static void onEntrySettingChange(LLUICtrl* caller, void* user_data);
static void onSelectName(LLUICtrl* caller, void* user_data);
//static void ResponseItemDrop(LLViewerInventoryItem* item);
//static void onNotecardLoadComplete(LLVFS *vfs,const LLUUID& asset_uuid,LLAssetType::EType type,void* user_data, S32 status, LLExtStat ext_status);
static void deleteEntry(void* data);
static void addEntry(void* data);
static void exportList(void* data);
static void removeList(void* data);
static void loadList(void* data);
};
#endif // AUTOCORRECTFLOATER_H

View File

@ -35,7 +35,7 @@
#include "llfloaterpreference.h"
#include "message.h"
#include "llautocorrectfloater.h"
#include "llagent.h"
#include "llavatarconstants.h"
#include "llcheckboxctrl.h"
@ -354,6 +354,8 @@ LLFloaterPreference::LLFloaterPreference(const LLSD& key)
gSavedSettings.getControl("NameTagShowUsernames")->getCommitSignal()->connect(boost::bind(&handleNameTagOptionChanged, _2));
gSavedSettings.getControl("NameTagShowFriends")->getCommitSignal()->connect(boost::bind(&handleNameTagOptionChanged, _2));
gSavedSettings.getControl("UseDisplayNames")->getCommitSignal()->connect(boost::bind(&handleDisplayNamesOptionChanged, _2));
mCommitCallbackRegistrar.add("Pref.ShowAC", boost::bind(&AutoCorrectFloater::showFloater));
LLAvatarPropertiesProcessor::getInstance()->addObserver( gAgent.getID(), this );
}

View File

@ -251,6 +251,7 @@ BOOL LLIMFloater::postBuild()
slide_right->setVisible(!mControlPanel->getParent()->getVisible());
slide_right->setClickedCallback(boost::bind(&LLIMFloater::onSlide, this));
// *TODO Establish LineEditor with autocorrect callback
mInputEditor = getChild<LLLineEditor>("chat_editor");
mInputEditor->setMaxTextLength(1023);
// enable line history support for instant message bar

View File

@ -51,6 +51,7 @@
#include "lltranslate.h"
#include "llresizehandle.h"
#include "llautocorrect.h"
S32 LLNearbyChatBar::sLastSpecialChatChannel = 0;
@ -87,6 +88,8 @@ BOOL LLNearbyChatBar::postBuild()
{
mChatBox = getChild<LLLineEditor>("chat_box");
// *TODO Establish LineEditor with autocorrect callback
// mChatBox->setAutocorrectCallback(boost::bind(&AutoCorrect::autocorrectCallback));
mChatBox->setCommitCallback(boost::bind(&LLNearbyChatBar::onChatBoxCommit, this));
mChatBox->setKeystrokeCallback(&onChatBoxKeystroke, this);
mChatBox->setFocusLostCallback(boost::bind(&onChatBoxFocusLost, _1, this));

View File

@ -30,7 +30,7 @@
#include "llfloaterreg.h"
#include "llviewerfloaterreg.h"
#include "llautocorrectfloater.h"
#include "llcompilequeue.h"
#include "llcallfloater.h"
#include "llfasttimerview.h"
@ -170,6 +170,7 @@ void LLViewerFloaterReg::registerFloaters()
LLFloaterReg::add("about_land", "floater_about_land.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterLand>);
LLFloaterReg::add("appearance", "floater_my_appearance.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterSidePanelContainer>);
LLFloaterReg::add("auction", "floater_auction.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAuction>);
LLFloaterReg::add("autocorrect", "floater_autocorrect.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<AutoCorrectFloater>);
LLFloaterReg::add("avatar", "floater_avatar.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAvatar>);
LLFloaterReg::add("avatar_picker", "floater_avatar_picker.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAvatarPicker>);
LLFloaterReg::add("avatar_textures", "floater_avatar_textures.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAvatarTextures>);

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<floater border="true" can_close="true" can_minimize="true" bottom="400" left="300" can_resize="false" height="430" width="400"
name="ac_floater" title="Autocorrect Settings">
<check_box bottom_delta="50" left_delta="5" height="16" width="100" enabled="true" follows="left|top"
font="SansSerifSmall" mouse_opaque="true" radio_style="false" label="Enable Autocorrect"
control_name="EnableAutoCorrect" name="ac_enable" tool_tip="You must have this check box enabled to use any of these settings,
it will search your writable text entry, and replace any of the search entries with their replacement"/>
<button bottom_delta="-2" left_delta="150" height="22" width="80" enabled="true" follows="left|top"
font="SansSerif" mouse_opaque="true" halign="center" scale_image="true"
name="ac_loadlist" label="Load List.." tool_tip="Click this to load a previously exported list from a file."/>
<view_border bottom_delta="10" left_delta="100" height="40" width="120" follows="left|top"
bevel_style="in" mouse_opaque="false" name="ac_notecard_target"/>
<text bottom_delta="-18" left_delta="0" height="16" width="120" follows="left|top" halign="center"
font="SansSerifSmall" mouse_opaque="true" name="ac_notecard"
><!--
Drop a Notecard here
to load from it.-->
</text>
<view_border bottom="70" left="2" height="0" width="396" follows="left|top"
bevel_style="none" border_thickness="1" mouse_opaque="false" name="divisor1"/>
<text top="-355" left_delta="0" height="16" width="400" follows="left|top" halign="center"
font="SansSerifSmall" mouse_opaque="true" name="ac_text1"
>List Name List Entries</text>
<scroll_list bottom_delta="280" left_delta="0" height="280" width="199" follows="left|top"
column_padding="0" draw_heading="true" multi_select="false"
name="ac_list_name" search_column="1">
</scroll_list>
<scroll_list top_delta="0" left_delta="199" height="180" width="198" follows="left|top"
column_padding="0" draw_heading="true" multi_select="false"
name="ac_list_entry" search_column="1">
</scroll_list>
<view_border bottom_delta="20" left_delta="10" height="16" width="180" follows="left|top"
bevel_style="in" mouse_opaque="false" name="ac_box1"/>
<text bottom_delta="0" left_delta="0" height="16" width="180" follows="left|top" halign="center"
font="SansSerifSmall" mouse_opaque="true" name="ac_text_name"
>List Name</text>
<text bottom_delta="20" left_delta="-2" height="16" width="40" follows="left|top" halign="center"
font="SansSerifSmall" mouse_opaque="true" name="ac_text2"
>Author:</text>
<view_border bottom_delta="-0" left_delta="42" height="16" width="140" follows="left|top"
bevel_style="in" mouse_opaque="false" name="ac_box2"/>
<text bottom_delta="0" left_delta="0" height="16" width="140" follows="left|top" halign="center"
font="SansSerifSmall" mouse_opaque="true" name="ac_text_author"
>Author Name</text>
<check_box bottom_delta="20" left_delta="-32" height="16" width="100" enabled="true" follows="left|top"
font="SansSerifSmall" mouse_opaque="true" radio_style="false" label="Enabled, priority:"
control_name="ac_enabled" name="ac_list_enabled" tool_tip="Whether or not you wish to use this particular list."/>
<spinner bottom_delta="-0" left_delta="120" height="16" width="50" follows="left|top"
decimal_digits="0" increment="1" min_val="0" max_val="10" mouse_opaque="true"
label="" label_width="0" name="ac_priority" tool_tip="This number determine what order your list will be used to replace words. A higher priority means it will be used before lower priority lists."/>
<check_box bottom_delta="20" left_delta="-120" height="16" width="100" enabled="true" follows="left|top"
font="SansSerifSmall" mouse_opaque="true" radio_style="false" label="Show Notifications"
control_name="ac_list_show" name="ac_list_show" tool_tip="Having this enabled will make a notification pop up every time a word is replaced."/>
<check_box bottom_delta="20" left_delta="-0" height="16" width="100" enabled="true" follows="left|top"
font="SansSerifSmall" mouse_opaque="true" radio_style="false" label="Word Style"
control_name="ac_list_style" name="ac_list_style" tool_tip="Having this checked means the list is for full words that should be replaced, unchecked means that it will look within words contents as well."/>
<view_border bottom="405" left="201" height="40" width="0" follows="left|top"
bevel_style="none" border_thickness="1" mouse_opaque="false" name="divisor2"/>
<view_border bottom_delta="-0" left="2" height="0" width="396" follows="left|top"
bevel_style="none" border_thickness="1" mouse_opaque="false" name="divisor3"/>
<button bottom="400" left="5" height="22" width="90" enabled="true" follows="left|top"
font="SansSerif" mouse_opaque="true" halign="center" scale_image="true"
name="ac_deletelist" label="Delete List" tool_tip="This will delete the entire list of words and their replacements, it is not reversible."/>
<button bottom_delta="-0" left_delta="95" height="22" width="90" enabled="true" follows="left|top"
font="SansSerif" mouse_opaque="true" halign="center" scale_image="true"
name="ac_exportlist" label="Export List" tool_tip="This will save your current list to a file so you can share it with your friends or edit it."/>
<button bottom_delta="0" left_delta="110" height="22" width="90" enabled="true" follows="left|top"
font="SansSerif" mouse_opaque="true" halign="center" scale_image="true"
name="ac_addentry" label="Add Entry"/>
<button bottom_delta="0" left_delta="95" height="22" width="90" enabled="true" follows="left|top"
font="SansSerif" mouse_opaque="true" halign="center" scale_image="true"
name="ac_rementry" label="Remove Entry"/>
<text bottom_delta="25" left_delta="-240" height="16" width="170" follows="left|top" halign="center"
font="SansSerifSmall" mouse_opaque="true" name="ac_text3"
>Words automatically corrected:</text>
<view_border bottom_delta="-0" left_delta="180" height="16" width="70" follows="left|top"
bevel_style="in" mouse_opaque="false" name="ac_statsbox"/>
<text bottom_delta="0" left_delta="0" height="16" width="70" follows="left|top" halign="center"
font="SansSerifSmall" mouse_opaque="true" name="ac_stats"
>Count</text>
</floater>

View File

@ -6763,6 +6763,13 @@ One or more of your Voice Morphs will expire in less than [INTERVAL] days.
<tag>voice</tag>
</notification>
<notification
icon="notifytip.tga"
name="AutoReplace"
type="notifytip">
&apos;[BEFORE]&apos; has been auto replaced by &apos;[REPLACEMENT]&apos;
based on your [LISTNAME] list.
</notification>
<notification
icon="notify.tga"
name="VoiceEffectsNew"

View File

@ -211,9 +211,20 @@
layout="topleft"
left="30"
name="ok_btn"
top="-40"
top="-50"
width="170">
<button.commit_callback
function="Pref.TranslationSettings" />
</button>
</panel>
<button
follows="top|left"
height="23"
layout="topleft"
top_pad="-23"
left_pad="5"
name="ac_showgui"
commit_callback.function="Pref.ShowAC"
label="AutoCorrect Settings"
width="150">
</button>
</panel>