* Spellchecker dialog:

- mark languages that can be spell checked.
* Thesaurus dialog:
	- mark languages that have a thesaurus dictionary.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33405 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2010-02-10 08:10:31 +00:00
parent 56d18d2410
commit 5c59e8c7cb
13 changed files with 125 additions and 11 deletions

View File

@ -223,6 +223,42 @@ void AspellChecker::suggest(WordLangTuple const & wl,
}
bool AspellChecker::hasDictionary(Language const * lang) const
{
if (!lang)
return false;
// code taken from aspell's list-dicts example
AspellConfig * config;
AspellDictInfoList * dlist;
AspellDictInfoEnumeration * dels;
const AspellDictInfo * entry;
config = new_aspell_config();
/* the returned pointer should _not_ need to be deleted */
dlist = get_aspell_dict_info_list(config);
/* config is no longer needed */
delete_aspell_config(config);
dels = aspell_dict_info_list_elements(dlist);
bool have = false;
while ((entry = aspell_dict_info_enumeration_next(dels)) != 0)
{
if (entry->code == lang->code()
&& (lang->variety().empty() || entry->jargon == lang->variety())) {
have = true;
break;
}
}
delete_aspell_dict_info_enumeration(dels);
return have;
}
docstring const AspellChecker::error()
{
char const * err = 0;

View File

@ -29,6 +29,7 @@ public:
void suggest(WordLangTuple const &, docstring_list &);
void insert(WordLangTuple const &);
void accept(WordLangTuple const &);
bool hasDictionary(Language const * lang) const;
docstring const error();
//@}

View File

@ -159,6 +159,15 @@ void EnchantChecker::suggest(WordLangTuple const & wl,
}
bool EnchantChecker::hasDictionary(Language const * lang) const
{
if (!lang)
return false;
enchant::Broker * instance = enchant::Broker::instance();
return (instance->dict_exists(lang->code()));
}
docstring const EnchantChecker::error()
{
return docstring();

View File

@ -35,6 +35,7 @@ public:
void suggest(WordLangTuple const &, docstring_list &);
void insert(WordLangTuple const &);
void accept(WordLangTuple const &);
bool hasDictionary(Language const * lang) const;
docstring const error();
///@}

View File

@ -51,6 +51,7 @@ struct HunspellChecker::Private
~Private();
bool haveDictionary(string const & lang) const;
Hunspell * addSpeller(string const & lang);
Hunspell * speller(string const & lang);
/// ignored words
@ -94,7 +95,7 @@ bool haveLanguageFiles(string const & hpath)
}
Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
bool HunspellChecker::Private::haveDictionary(string const & lang) const
{
string hunspell_path = lyxrc.hunspelldir_path;
LYXERR(Debug::FILES, "hunspell path: " << external_path(hunspell_path));
@ -111,7 +112,7 @@ Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
//frontend::Alert::error(_("Hunspell Path Not Found"),
// _("You must set the Hunspell dictionary path in Tools>Preferences>Paths."));
}
return 0;
return false;
}
hunspell_path = external_path(addName(hunspell_path, lang));
@ -122,9 +123,20 @@ Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
// FIXME: We should indicate somehow that this language is not
// supported, probably by popping a warning. But we'll need to
// remember which warnings we've issued.
return 0;
return false;
}
}
return true;
}
Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
{
string hunspell_path = lyxrc.hunspelldir_path;
if (!haveDictionary(lang))
return 0;
FileName const affix(hunspell_path + ".aff");
FileName const dict(hunspell_path + ".dic");
Hunspell * h = new Hunspell(affix.absFilename().c_str(), dict.absFilename().c_str());
@ -227,6 +239,14 @@ void HunspellChecker::suggest(WordLangTuple const & wl,
}
bool HunspellChecker::hasDictionary(Language const * lang) const
{
if (!lang)
return false;
return (d->haveDictionary(lang->code()));
}
docstring const HunspellChecker::error()
{
return docstring();

View File

@ -29,6 +29,7 @@ public:
void suggest(WordLangTuple const &, docstring_list &);
void insert(WordLangTuple const &);
void accept(WordLangTuple const &);
bool hasDictionary(Language const * lang) const;
docstring const error();
///@}

View File

@ -19,6 +19,7 @@
namespace lyx {
class BufferParams;
class Language;
class WordLangTuple;
class docstring_list;
@ -56,6 +57,9 @@ public:
/// accept the given word temporarily
virtual void accept(WordLangTuple const &) = 0;
/// check if dictionary exists
virtual bool hasDictionary(Language const *) const = 0;
/// give an error message on messy exit
virtual docstring const error() = 0;
};

View File

@ -79,6 +79,10 @@ struct Thesaurus::Private
return false;
}
///
typedef std::pair<std::string, std::string> ThesFiles;
///
ThesFiles getThesaurus(docstring const & lang);
/// add a thesaurus to the list
bool addThesaurus(docstring const & lang);
@ -86,15 +90,16 @@ struct Thesaurus::Private
Thesauri thes_;
};
bool Thesaurus::Private::addThesaurus(docstring const & lang)
pair<string, string> Thesaurus::Private::getThesaurus(docstring const & lang)
{
string const thes_path = external_path(lyxrc.thesaurusdir_path);
LYXERR(Debug::FILES, "thesaurus path: " << thes_path);
if (thes_path.empty())
return false;
return make_pair(string(), string());
if (thesaurusAvailable(lang))
return true;
return make_pair(string(), string());
FileNameList const idx_files = FileName(thes_path).dirList("idx");
FileNameList const data_files = FileName(thes_path).dirList("dat");
@ -121,6 +126,16 @@ bool Thesaurus::Private::addThesaurus(docstring const & lang)
}
}
return make_pair(idx, data);
}
bool Thesaurus::Private::addThesaurus(docstring const & lang)
{
ThesFiles files = getThesaurus(lang);
string const idx = files.first;
string const data = files.second;
if (idx.empty() || data.empty())
return false;
@ -137,6 +152,13 @@ bool Thesaurus::thesaurusAvailable(docstring const & lang) const
}
bool Thesaurus::thesaurusInstalled(docstring const & lang) const
{
pair<string, string> files = d->getThesaurus(lang);
return (!files.first.empty() && !files.second.empty());
}
Thesaurus::Meanings Thesaurus::lookup(docstring const & t, docstring const & lang)
{
Meanings meanings;

View File

@ -39,8 +39,12 @@ public:
* look up some text in the thesaurus
*/
Meanings lookup(docstring const & text, docstring const & lang);
/// check if a thesaurus for a given language \p lang is available
/** check if a thesaurus for a given language \p lang is available
* (installed and loaded)
*/
bool thesaurusAvailable(docstring const & lang) const;
/// check if a thesaurus for a given language \p lang is installed
bool thesaurusInstalled(docstring const & lang) const;
private:
struct Private;

View File

@ -50,6 +50,7 @@
#include "Server.h"
#include "Session.h"
#include "SpellChecker.h"
#include "Thesaurus.h"
#include "version.h"
#include "support/convert.h"
@ -1973,16 +1974,28 @@ QAbstractItemModel * GuiApplication::languageModel()
return d->language_model_;
QStandardItemModel * lang_model = new QStandardItemModel(this);
lang_model->insertColumns(0, 1);
lang_model->insertColumns(0, 3);
int current_row;
QIcon speller(getPixmap("images/", "dialog-show_spellchecker", "png"));
QIcon saurus(getPixmap("images/", "thesaurus-entry", "png"));
Languages::const_iterator it = lyx::languages.begin();
Languages::const_iterator end = lyx::languages.end();
for (; it != end; ++it) {
current_row = lang_model->rowCount();
lang_model->insertRows(current_row, 1);
QModelIndex item = lang_model->index(current_row, 0);
lang_model->setData(item, qt_(it->second.display()), Qt::DisplayRole);
lang_model->setData(item, toqstr(it->second.lang()), Qt::UserRole);
QModelIndex pl_item = lang_model->index(current_row, 0);
QModelIndex sp_item = lang_model->index(current_row, 1);
QModelIndex th_item = lang_model->index(current_row, 2);
lang_model->setData(pl_item, qt_(it->second.display()), Qt::DisplayRole);
lang_model->setData(pl_item, toqstr(it->second.lang()), Qt::UserRole);
lang_model->setData(sp_item, qt_(it->second.display()), Qt::DisplayRole);
lang_model->setData(sp_item, toqstr(it->second.lang()), Qt::UserRole);
if (theSpellChecker()->hasDictionary(&it->second))
lang_model->setData(sp_item, speller, Qt::DecorationRole);
lang_model->setData(th_item, qt_(it->second.display()), Qt::DisplayRole);
lang_model->setData(th_item, toqstr(it->second.lang()), Qt::UserRole);
if (thesaurus.thesaurusInstalled(from_ascii(it->second.code())))
lang_model->setData(th_item, saurus, Qt::DecorationRole);
}
d->language_model_ = new QSortFilterProxyModel(this);
d->language_model_->setSourceModel(lang_model);

View File

@ -852,6 +852,7 @@ GuiDocument::GuiDocument(GuiView & lv)
// FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
language_model->sort(0);
langModule->languageCO->setModel(language_model);
langModule->languageCO->setModelColumn(0);
// Always put the default encoding in the first position.
langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));

View File

@ -83,6 +83,7 @@ GuiSpellchecker::GuiSpellchecker(GuiView & lv)
// FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
language_model->sort(0);
d->ui.languageCO->setModel(language_model);
d->ui.languageCO->setModelColumn(1);
d->ui.wordED->setReadOnly(true);

View File

@ -77,6 +77,7 @@ GuiThesaurus::GuiThesaurus(GuiView & lv)
// FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
language_model->sort(0);
languageCO->setModel(language_model);
languageCO->setModelColumn(2);
bc().setCancel(closePB);
bc().setApply(replacePB);