Beispiel #1
0
// static
bool LLSpellChecker::canRemoveDictionary(const std::string& dict_language)
{
	// Only user-installed inactive dictionaries can be removed
	const LLSD dict_info = getDictionaryData(dict_language);
	return 
		(dict_info["user_installed"].asBoolean()) && 
		( (!getUseSpellCheck()) || (!LLSpellChecker::instance().isActiveDictionary(dict_language)) );
}
Beispiel #2
0
// static
void LLSpellChecker::setUseSpellCheck(const std::string& dict_name)
{
	if ( (((dict_name.empty()) && (getUseSpellCheck())) || (!dict_name.empty())) && 
		 (LLSpellChecker::instance().mDictName != dict_name) )
	{
		LLSpellChecker::instance().initHunspell(dict_name);
	}
}
Beispiel #3
0
void LLSpellChecker::setSecondaryDictionaries(dict_list_t dict_list)
{
	if (!getUseSpellCheck())
	{
		return;
	}

	// Check if we're only adding secondary dictionaries, or removing them
	dict_list_t dict_add(llmax(dict_list.size(), mDictSecondary.size())), dict_rem(llmax(dict_list.size(), mDictSecondary.size()));
	dict_list.sort();
	mDictSecondary.sort();
	dict_list_t::iterator end_added = std::set_difference(dict_list.begin(), dict_list.end(), mDictSecondary.begin(), mDictSecondary.end(), dict_add.begin());
	dict_list_t::iterator end_removed = std::set_difference(mDictSecondary.begin(), mDictSecondary.end(), dict_list.begin(), dict_list.end(), dict_rem.begin());

	if (end_removed != dict_rem.begin())		// We can't remove secondary dictionaries so we need to recreate the Hunspell instance
	{
		mDictSecondary = dict_list;

		std::string dict_language = mDictLanguage;
		initHunspell(dict_language);
	}
	else if (end_added != dict_add.begin())		// Add the new secondary dictionaries one by one
	{
		const std::string app_path = getDictionaryAppPath();
		const std::string user_path = getDictionaryUserPath();
		for (dict_list_t::const_iterator it_added = dict_add.begin(); it_added != end_added; ++it_added)
		{
			const LLSD dict_entry = getDictionaryData(*it_added);
			if ( (!dict_entry.isDefined()) || (!dict_entry["installed"].asBoolean()) )
			{
				continue;
			}

			const std::string strFileDic = dict_entry["name"].asString() + ".dic";
			if (gDirUtilp->fileExists(user_path + strFileDic))
			{
				mHunspell->add_dic((user_path + strFileDic).c_str());
			}
			else if (gDirUtilp->fileExists(app_path + strFileDic))
			{
				mHunspell->add_dic((app_path + strFileDic).c_str());
			}
		}
		mDictSecondary = dict_list;
		sSettingsChangeSignal();
	}
}