* store the full Language in WordLangTuple.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33378 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2010-02-09 11:26:49 +00:00
parent 3a251f0056
commit 707935ab23
9 changed files with 51 additions and 57 deletions

View File

@ -161,7 +161,7 @@ SpellChecker::Result AspellChecker::check(WordLangTuple const & word)
{
AspellSpeller * m =
d->speller(word.lang_code(), word.lang_variety());
d->speller(word.lang()->code(), word.lang()->variety());
if (!m)
return OK;
@ -180,7 +180,7 @@ SpellChecker::Result AspellChecker::check(WordLangTuple const & word)
void AspellChecker::insert(WordLangTuple const & word)
{
Spellers::iterator it = d->spellers_.find(
d->spellerID(word.lang_code(), word.lang_variety()));
d->spellerID(word.lang()->code(), word.lang()->variety()));
if (it != d->spellers_.end())
aspell_speller_add_to_personal(it->second.speller, to_utf8(word.word()).c_str(), -1);
}
@ -189,7 +189,7 @@ void AspellChecker::insert(WordLangTuple const & word)
void AspellChecker::accept(WordLangTuple const & word)
{
Spellers::iterator it = d->spellers_.find(
d->spellerID(word.lang_code(), word.lang_variety()));
d->spellerID(word.lang()->code(), word.lang()->variety()));
if (it != d->spellers_.end())
aspell_speller_add_to_session(it->second.speller, to_utf8(word.word()).c_str(), -1);
}
@ -200,7 +200,7 @@ void AspellChecker::suggest(WordLangTuple const & wl,
{
suggestions.clear();
AspellSpeller * m =
d->speller(wl.lang_code(), wl.lang_variety());
d->speller(wl.lang()->code(), wl.lang()->variety());
if (!m)
return;

View File

@ -105,7 +105,7 @@ EnchantChecker::~EnchantChecker()
SpellChecker::Result EnchantChecker::check(WordLangTuple const & word)
{
enchant::Dict * m = d->speller(word.lang_code());
enchant::Dict * m = d->speller(word.lang()->code());
if (!m)
return OK;
@ -121,7 +121,7 @@ SpellChecker::Result EnchantChecker::check(WordLangTuple const & word)
void EnchantChecker::insert(WordLangTuple const & word)
{
Spellers::iterator it = d->spellers_.find(word.lang_code());
Spellers::iterator it = d->spellers_.find(word.lang()->code());
if (it != d->spellers_.end())
it->second.speller->add(to_utf8(word.word()));
}
@ -129,7 +129,7 @@ void EnchantChecker::insert(WordLangTuple const & word)
void EnchantChecker::accept(WordLangTuple const & word)
{
Spellers::iterator it = d->spellers_.find(word.lang_code());
Spellers::iterator it = d->spellers_.find(word.lang()->code());
if (it != d->spellers_.end())
it->second.speller->add_to_session(to_utf8(word.word()));
}
@ -139,7 +139,7 @@ void EnchantChecker::suggest(WordLangTuple const & wl,
docstring_list & suggestions)
{
suggestions.clear();
enchant::Dict * m = d->speller(wl.lang_code());
enchant::Dict * m = d->speller(wl.lang()->code());
if (!m)
return;

View File

@ -147,7 +147,7 @@ bool HunspellChecker::Private::isIgnored(WordLangTuple const & wl) const
{
IgnoreList::const_iterator it = ignored_.begin();
for (; it != ignored_.end(); ++it) {
if ((*it).lang_code() != wl.lang_code())
if ((*it).lang()->code() != wl.lang()->code())
continue;
if ((*it).word() == wl.word())
return true;
@ -173,7 +173,7 @@ SpellChecker::Result HunspellChecker::check(WordLangTuple const & wl)
return OK;
string const word_to_check = to_utf8(wl.word());
Hunspell * h = d->speller(wl.lang_code());
Hunspell * h = d->speller(wl.lang()->code());
if (!h)
return OK;
int info;
@ -196,7 +196,7 @@ SpellChecker::Result HunspellChecker::check(WordLangTuple const & wl)
void HunspellChecker::insert(WordLangTuple const & wl)
{
string const word_to_check = to_utf8(wl.word());
Hunspell * h = d->speller(wl.lang_code());
Hunspell * h = d->speller(wl.lang()->code());
if (!h)
return;
h->add(word_to_check.c_str());
@ -214,7 +214,7 @@ void HunspellChecker::suggest(WordLangTuple const & wl,
{
suggestions.clear();
string const word_to_check = to_utf8(wl.word());
Hunspell * h = d->speller(wl.lang_code());
Hunspell * h = d->speller(wl.lang()->code());
if (!h)
return;
char ** suggestion_list;

View File

@ -45,8 +45,12 @@ public:
std::string const & encodingStr() const { return encodingStr_; }
///
std::string const & code() const { return code_; }
/// set code (needed for rc.spellchecker_alt_lang)
void setCode(std::string const c) { code_ = c; }
///
std::string const & variety() const { return variety_; }
/// set variety (needed for rc.spellchecker_alt_lang)
void setVariety(std::string const v) { variety_ = v; }
///
std::string const & latex_options() const { return latex_options_; }
///

View File

@ -986,7 +986,7 @@ void LyXAction::init()
* spell checker dictionary.
* \li Syntax: spelling-add [<STRING>] [<LANG>]
* \li Params: <WORD>: word to add
<LANG>: language code (see file languages)
<LANG>: language name (see file languages)
* \li Origin: JSpitzm, 18 Jan 2010
* \endvar
*/
@ -997,7 +997,7 @@ void LyXAction::init()
* in the current session for the given language.
* \li Syntax: spelling-ignore [<WORD>] [<LANG>]
* \li Params: <WORD>: word to ignore
<LANG>: language code (see file languages)
<LANG>: language name (see file languages)
* \li Origin: JSpitzm, 18 Jan 2010
* \endvar
*/

View File

@ -3170,17 +3170,17 @@ bool Paragraph::spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
return false;
docstring word = asString(from, to, AS_STR_INSETS);
string lang_code;
string lang_variety;
if (!lyxrc.spellchecker_alt_lang.empty())
lang_variety = split(lyxrc.spellchecker_alt_lang, lang_code, '-');
else {
lang_code = getFontSettings(
d->inset_owner_->buffer().params(), from).language()->code();
lang_variety = getFontSettings(
d->inset_owner_->buffer().params(), from).language()->variety();
Language * lang = const_cast<Language *>(getFontSettings(
d->inset_owner_->buffer().params(), from).language());
if (lang == d->inset_owner_->buffer().params().language
&& !lyxrc.spellchecker_alt_lang.empty()) {
string lang_code;
string const lang_variety =
split(lyxrc.spellchecker_alt_lang, lang_code, '-');
lang->setCode(lang_code);
lang->setVariety(lang_variety);
}
wl = WordLangTuple(word, lang_code, lang_variety);
wl = WordLangTuple(word, lang);
SpellChecker::Result res = speller->check(wl);
// Just ignore any error that the spellchecker reports.
// FIXME: we should through out an exception and catch it in the GUI to

View File

@ -2000,8 +2000,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_SPELLING_ADD: {
docstring word = from_utf8(cmd.getArg(0));
string code;
string variety;
Language * lang;
if (word.empty()) {
word = cur.selectionAsString(false);
// FIXME
@ -2010,19 +2009,17 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
selectWordWhenUnderCursor(cur, WHOLE_WORD);
word = cur.selectionAsString(false);
}
code = cur.getFont().language()->code();
variety = cur.getFont().language()->variety();
lang = const_cast<Language *>(cur.getFont().language());
} else
variety = split(cmd.getArg(1), code, '-');
WordLangTuple wl(word, code, variety);
lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
WordLangTuple wl(word, lang);
theSpellChecker()->insert(wl);
break;
}
case LFUN_SPELLING_IGNORE: {
docstring word = from_utf8(cmd.getArg(0));
string code;
string variety;
Language * lang;
if (word.empty()) {
word = cur.selectionAsString(false);
// FIXME
@ -2031,11 +2028,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
selectWordWhenUnderCursor(cur, WHOLE_WORD);
word = cur.selectionAsString(false);
}
code = cur.getFont().language()->code();
variety = cur.getFont().language()->variety();
lang = const_cast<Language *>(cur.getFont().language());
} else
variety = split(cmd.getArg(1), code, '-');
WordLangTuple wl(word, code, variety);
lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
WordLangTuple wl(word, lang);
theSpellChecker()->accept(wl);
break;
}

View File

@ -12,6 +12,8 @@
#ifndef WORD_LANG_TUPLE_H
#define WORD_LANG_TUPLE_H
#include "Language.h"
#include "support/docstring.h"
@ -19,18 +21,19 @@ namespace lyx {
/**
* A word and its given language code ("en_US")
* plus a variety if needed.
* This is used for spellchecking.
* A word and its given language.
* This is used for spellchecking
* and thesaurus.
*/
class WordLangTuple {
public:
WordLangTuple() {}
WordLangTuple(docstring const & w, std::string const & c,
std::string const & v = std::string())
: word_(w), code_(c), variety_(v)
{}
WordLangTuple(docstring const & w, Language * l)
: word_(w)
{
lang_ = l;
}
/// return the word
docstring const & word() const {
@ -38,22 +41,15 @@ public:
}
/// return its language code
std::string const & lang_code() const {
return code_;
}
/// return the language variety
std::string const & lang_variety() const {
return variety_;
Language const * lang() const {
return lang_;
}
private:
/// the word
docstring word_;
/// language code of word
std::string code_;
/// language variety of word
std::string variety_;
/// language of word
Language * lang_;
};

View File

@ -753,9 +753,7 @@ void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
add(item);
if (i > 0)
add(MenuItem(MenuItem::Separator));
docstring arg = wl.word() + " " + from_ascii(wl.lang_code());
if (!wl.lang_variety().empty())
arg += from_ascii("-") + from_ascii(wl.lang_variety());
docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|c"),
FuncRequest(LFUN_SPELLING_ADD, arg)));
add(MenuItem(MenuItem::Command, qt_("Ignore all|I"),