DRTVWR-493 LLSpellcheck doesn't need separate init

meow-7.2.2
andreykproductengine 2019-06-27 22:14:52 +03:00
parent 03f8125405
commit 2752e342f6
3 changed files with 22 additions and 40 deletions

View File

@ -44,7 +44,6 @@ static const std::string DICT_FILE_IGNORE = "user_ignore.dic";
static const std::string DICT_FILE_MAIN = "dictionaries.xml";
static const std::string DICT_FILE_USER = "user_dictionaries.xml";
LLSD LLSpellChecker::sDictMap;
LLSpellChecker::settings_change_signal_t LLSpellChecker::sSettingsChangeSignal;
LLSpellChecker::LLSpellChecker()
@ -94,10 +93,9 @@ S32 LLSpellChecker::getSuggestions(const std::string& word, std::vector<std::str
return suggestions.size();
}
// static
const LLSD LLSpellChecker::getDictionaryData(const std::string& dict_language)
{
for (LLSD::array_const_iterator it = sDictMap.beginArray(); it != sDictMap.endArray(); ++it)
for (LLSD::array_const_iterator it = mDictMap.beginArray(); it != mDictMap.endArray(); ++it)
{
const LLSD& dict_entry = *it;
if (dict_language == dict_entry["language"].asString())
@ -108,14 +106,12 @@ const LLSD LLSpellChecker::getDictionaryData(const std::string& dict_language)
return LLSD();
}
// static
bool LLSpellChecker::hasDictionary(const std::string& dict_language, bool check_installed)
{
const LLSD dict_info = getDictionaryData(dict_language);
return dict_info.has("language") && ( (!check_installed) || (dict_info["installed"].asBoolean()) );
}
// static
void LLSpellChecker::setDictionaryData(const LLSD& dict_info)
{
const std::string dict_language = dict_info["language"].asString();
@ -124,7 +120,7 @@ void LLSpellChecker::setDictionaryData(const LLSD& dict_info)
return;
}
for (LLSD::array_iterator it = sDictMap.beginArray(); it != sDictMap.endArray(); ++it)
for (LLSD::array_iterator it = mDictMap.beginArray(); it != mDictMap.endArray(); ++it)
{
LLSD& dict_entry = *it;
if (dict_language == dict_entry["language"].asString())
@ -133,7 +129,7 @@ void LLSpellChecker::setDictionaryData(const LLSD& dict_info)
return;
}
}
sDictMap.append(dict_info);
mDictMap.append(dict_info);
return;
}
@ -147,14 +143,14 @@ void LLSpellChecker::refreshDictionaryMap()
std::string user_filename(user_path + DICT_FILE_MAIN);
llifstream user_file(user_filename.c_str(), std::ios::binary);
if ( (!user_file.is_open())
|| (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXMLDocument(sDictMap, user_file))
|| (0 == sDictMap.size()) )
|| (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXMLDocument(mDictMap, user_file))
|| (0 == mDictMap.size()) )
{
std::string app_filename(app_path + DICT_FILE_MAIN);
llifstream app_file(app_filename.c_str(), std::ios::binary);
if ( (!app_file.is_open())
|| (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXMLDocument(sDictMap, app_file))
|| (0 == sDictMap.size()) )
|| (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXMLDocument(mDictMap, app_file))
|| (0 == mDictMap.size()) )
{
return;
}
@ -178,7 +174,7 @@ void LLSpellChecker::refreshDictionaryMap()
// Look for installed dictionaries
std::string tmp_app_path, tmp_user_path;
for (LLSD::array_iterator it = sDictMap.beginArray(); it != sDictMap.endArray(); ++it)
for (LLSD::array_iterator it = mDictMap.beginArray(); it != mDictMap.endArray(); ++it)
{
LLSD& sdDict = *it;
tmp_app_path = (sdDict.has("name")) ? app_path + sdDict["name"].asString() : LLStringUtil::null;
@ -416,7 +412,6 @@ bool LLSpellChecker::getUseSpellCheck()
return (LLSpellChecker::instanceExists()) && (LLSpellChecker::instance().mHunspell);
}
// static
bool LLSpellChecker::canRemoveDictionary(const std::string& dict_language)
{
// Only user-installed inactive dictionaries can be removed
@ -426,7 +421,6 @@ bool LLSpellChecker::canRemoveDictionary(const std::string& dict_language)
( (!getUseSpellCheck()) || (!LLSpellChecker::instance().isActiveDictionary(dict_language)) );
}
// static
void LLSpellChecker::removeDictionary(const std::string& dict_language)
{
if (!canRemoveDictionary(dict_language))
@ -499,12 +493,3 @@ void LLSpellChecker::setUseSpellCheck(const std::string& dict_language)
LLSpellChecker::instance().initHunspell(dict_language);
}
}
// static
void LLSpellChecker::initClass()
{
if (sDictMap.isUndefined())
{
refreshDictionaryMap();
}
}

View File

@ -34,10 +34,9 @@
class Hunspell;
class LLSpellChecker : public LLSingleton<LLSpellChecker>, public LLInitClass<LLSpellChecker>
class LLSpellChecker : public LLSingleton<LLSpellChecker>
{
LLSINGLETON(LLSpellChecker);
friend class LLInitClass<LLSpellChecker>;
~LLSpellChecker();
public:
@ -57,26 +56,24 @@ public:
bool isActiveDictionary(const std::string& dict_language) const;
void setSecondaryDictionaries(dict_list_t dict_list);
static bool canRemoveDictionary(const std::string& dict_language);
bool canRemoveDictionary(const std::string& dict_language);
static const std::string getDictionaryAppPath();
static const std::string getDictionaryUserPath();
static const LLSD getDictionaryData(const std::string& dict_language);
static const LLSD& getDictionaryMap() { return sDictMap; }
const LLSD getDictionaryData(const std::string& dict_language);
const LLSD& getDictionaryMap() { return mDictMap; }
static bool getUseSpellCheck();
static bool hasDictionary(const std::string& dict_language, bool check_installed = false);
static void refreshDictionaryMap();
static void removeDictionary(const std::string& dict_language);
bool hasDictionary(const std::string& dict_language, bool check_installed = false);
void refreshDictionaryMap();
void removeDictionary(const std::string& dict_language);
static void setUseSpellCheck(const std::string& dict_language);
protected:
static LLSD loadUserDictionaryMap();
static void setDictionaryData(const LLSD& dict_info);
void setDictionaryData(const LLSD& dict_info);
static void saveUserDictionaryMap(const LLSD& dict_map);
public:
typedef boost::signals2::signal<void()> settings_change_signal_t;
static boost::signals2::connection setSettingsChangeCallback(const settings_change_signal_t::slot_type& cb);
protected:
static void initClass();
protected:
Hunspell* mHunspell;
@ -84,8 +81,8 @@ protected:
std::string mDictFile;
dict_list_t mDictSecondary;
std::vector<std::string> mIgnoreList;
LLSD mDictMap;
static LLSD sDictMap;
static settings_change_signal_t sSettingsChangeSignal;
};

View File

@ -56,7 +56,7 @@ void LLFloaterSpellCheckerSettings::draw()
bool enable_remove = !sel_items.empty();
for (std::vector<LLScrollListItem*>::const_iterator sel_it = sel_items.begin(); sel_it != sel_items.end(); ++sel_it)
{
enable_remove &= LLSpellChecker::canRemoveDictionary((*sel_it)->getValue().asString());
enable_remove &= LLSpellChecker::getInstance()->canRemoveDictionary((*sel_it)->getValue().asString());
}
getChild<LLUICtrl>("spellcheck_remove_btn")->setEnabled(enable_remove);
}
@ -121,7 +121,7 @@ void LLFloaterSpellCheckerSettings::onClose(bool app_quitting)
for (std::vector<LLScrollListItem*>::const_iterator item_it = list_items.begin(); item_it != list_items.end(); ++item_it)
{
const std::string language = (*item_it)->getValue().asString();
if (LLSpellChecker::hasDictionary(language, true))
if (LLSpellChecker::getInstance()->hasDictionary(language, true))
{
list_dict.push_back(language);
}
@ -164,7 +164,7 @@ void LLFloaterSpellCheckerSettings::refreshDictionaries(bool from_settings)
}
dict_combo->clearRows();
const LLSD& dict_map = LLSpellChecker::getDictionaryMap();
const LLSD& dict_map = LLSpellChecker::getInstance()->getDictionaryMap();
if (dict_map.size())
{
for (LLSD::array_const_iterator dict_it = dict_map.beginArray(); dict_it != dict_map.endArray(); ++dict_it)
@ -216,7 +216,7 @@ void LLFloaterSpellCheckerSettings::refreshDictionaries(bool from_settings)
for (LLSpellChecker::dict_list_t::const_iterator it = active_list.begin(); it != active_list.end(); ++it)
{
const std::string language = *it;
const LLSD dict = LLSpellChecker::getDictionaryData(language);
const LLSD dict = LLSpellChecker::getInstance()->getDictionaryData(language);
row["value"] = language;
row["columns"][0]["value"] = (!dict["user_installed"].asBoolean()) ? language : language + " " + LLTrans::getString("UserDictionary");
active_ctrl->addElement(row);
@ -380,7 +380,7 @@ void LLFloaterSpellCheckerImport::onBtnOK()
custom_file_out.close();
}
LLSpellChecker::refreshDictionaryMap();
LLSpellChecker::getInstance()->refreshDictionaryMap();
}
closeFloater(false);