mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
* Singleton-ify the used SpellChecker object.
* Simplify Aspell construction as the object is capable of supporting multiple languages at the same time. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28974 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
29c40527e5
commit
34bddccb13
@ -25,10 +25,8 @@ using namespace std;
|
|||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
ASpell::ASpell(BufferParams const &, string const & lang)
|
ASpell::ASpell(): els(0), spell_error_object(0)
|
||||||
: els(0), spell_error_object(0)
|
|
||||||
{
|
{
|
||||||
addSpeller(lang);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,32 +25,27 @@ struct AspellConfig;
|
|||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
class BufferParams;
|
|
||||||
|
|
||||||
|
class ASpell : public SpellChecker
|
||||||
class ASpell : public SpellChecker {
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
ASpell();
|
||||||
* Initialise the spellchecker with the given buffer params and language.
|
~ASpell();
|
||||||
*/
|
|
||||||
ASpell(BufferParams const & params, std::string const & lang);
|
|
||||||
|
|
||||||
virtual ~ASpell();
|
|
||||||
|
|
||||||
/// check the given word and return the result
|
/// check the given word and return the result
|
||||||
virtual enum Result check(WordLangTuple const &);
|
enum Result check(WordLangTuple const &);
|
||||||
|
|
||||||
/// insert the given word into the personal dictionary
|
/// insert the given word into the personal dictionary
|
||||||
virtual void insert(WordLangTuple const &);
|
void insert(WordLangTuple const &);
|
||||||
|
|
||||||
/// accept the given word temporarily
|
/// accept the given word temporarily
|
||||||
virtual void accept(WordLangTuple const &);
|
void accept(WordLangTuple const &);
|
||||||
|
|
||||||
/// return the next near miss after a SUGGESTED_WORDS result
|
/// return the next near miss after a SUGGESTED_WORDS result
|
||||||
virtual docstring const nextMiss();
|
docstring const nextMiss();
|
||||||
|
|
||||||
/// give an error message on messy exit
|
/// give an error message on messy exit
|
||||||
virtual docstring const error();
|
docstring const error();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// add a speller of the given language
|
/// add a speller of the given language
|
||||||
|
23
src/LyX.cpp
23
src/LyX.cpp
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include "LyX.h"
|
#include "LyX.h"
|
||||||
|
|
||||||
#include "LayoutFile.h"
|
#include "ASpell_local.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "BufferList.h"
|
#include "BufferList.h"
|
||||||
#include "CmdDef.h"
|
#include "CmdDef.h"
|
||||||
@ -31,6 +31,7 @@
|
|||||||
#include "FuncStatus.h"
|
#include "FuncStatus.h"
|
||||||
#include "KeyMap.h"
|
#include "KeyMap.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
|
#include "LayoutFile.h"
|
||||||
#include "Lexer.h"
|
#include "Lexer.h"
|
||||||
#include "LyXAction.h"
|
#include "LyXAction.h"
|
||||||
#include "LyXFunc.h"
|
#include "LyXFunc.h"
|
||||||
@ -127,7 +128,19 @@ struct LyX::Impl
|
|||||||
// The language used will be derived from the environment
|
// The language used will be derived from the environment
|
||||||
// variables.
|
// variables.
|
||||||
messages_["GUI"] = Messages();
|
messages_["GUI"] = Messages();
|
||||||
|
|
||||||
|
#if defined(USE_ASPELL)
|
||||||
|
spell_checker_ = new ASpell();
|
||||||
|
#else
|
||||||
|
spell_checker_ = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Impl()
|
||||||
|
{
|
||||||
|
delete spell_checker_;
|
||||||
|
}
|
||||||
|
|
||||||
/// our function handler
|
/// our function handler
|
||||||
LyXFunc lyxfunc_;
|
LyXFunc lyxfunc_;
|
||||||
///
|
///
|
||||||
@ -169,6 +182,8 @@ struct LyX::Impl
|
|||||||
|
|
||||||
///
|
///
|
||||||
graphics::Previews preview_;
|
graphics::Previews preview_;
|
||||||
|
///
|
||||||
|
SpellChecker * spell_checker_;
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -1245,4 +1260,10 @@ CmdDef & theTopLevelCmdDef()
|
|||||||
return singleton_->pimpl_->toplevel_cmddef_;
|
return singleton_->pimpl_->toplevel_cmddef_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpellChecker * theSpellChecker()
|
||||||
|
{
|
||||||
|
return singleton_->pimpl_->spell_checker_;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -32,6 +32,7 @@ class Movers;
|
|||||||
class Server;
|
class Server;
|
||||||
class ServerSocket;
|
class ServerSocket;
|
||||||
class Session;
|
class Session;
|
||||||
|
class SpellChecker;
|
||||||
|
|
||||||
extern bool use_gui;
|
extern bool use_gui;
|
||||||
|
|
||||||
@ -137,6 +138,7 @@ private:
|
|||||||
friend graphics::Previews & thePreviews();
|
friend graphics::Previews & thePreviews();
|
||||||
friend Session & theSession();
|
friend Session & theSession();
|
||||||
friend CmdDef & theTopLevelCmdDef();
|
friend CmdDef & theTopLevelCmdDef();
|
||||||
|
friend SpellChecker * theSpellChecker();
|
||||||
friend void setRcGuiLanguage();
|
friend void setRcGuiLanguage();
|
||||||
friend void emergencyCleanup();
|
friend void emergencyCleanup();
|
||||||
friend void execBatchCommands();
|
friend void execBatchCommands();
|
||||||
@ -158,3 +160,4 @@ void execBatchCommands();
|
|||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
#endif // LYX_H
|
#endif // LYX_H
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "Cursor.h"
|
#include "Cursor.h"
|
||||||
#include "CutAndPaste.h"
|
#include "CutAndPaste.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
|
#include "LyX.h"
|
||||||
#include "LyXRC.h"
|
#include "LyXRC.h"
|
||||||
#include "Paragraph.h"
|
#include "Paragraph.h"
|
||||||
|
|
||||||
@ -75,7 +76,6 @@ GuiSpellchecker::GuiSpellchecker(GuiView & lv)
|
|||||||
|
|
||||||
GuiSpellchecker::~GuiSpellchecker()
|
GuiSpellchecker::~GuiSpellchecker()
|
||||||
{
|
{
|
||||||
delete speller_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -193,24 +193,11 @@ void GuiSpellchecker::partialUpdate(int state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static SpellChecker * createSpeller(BufferParams const & bp)
|
|
||||||
{
|
|
||||||
string lang = lyxrc.spellchecker_use_alt_lang
|
|
||||||
? lyxrc.spellchecker_alt_lang
|
|
||||||
: bp.language->code();
|
|
||||||
|
|
||||||
#if defined(USE_ASPELL)
|
|
||||||
return new ASpell(bp, lang);
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool GuiSpellchecker::initialiseParams(string const &)
|
bool GuiSpellchecker::initialiseParams(string const &)
|
||||||
{
|
{
|
||||||
LYXERR(Debug::GUI, "Spellchecker::initialiseParams");
|
LYXERR(Debug::GUI, "Spellchecker::initialiseParams");
|
||||||
|
|
||||||
speller_ = createSpeller(buffer().params());
|
speller_ = theSpellChecker();
|
||||||
if (!speller_)
|
if (!speller_)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -225,7 +212,6 @@ bool GuiSpellchecker::initialiseParams(string const &)
|
|||||||
Alert::error(_("Spellchecker error"),
|
Alert::error(_("Spellchecker error"),
|
||||||
_("The spellchecker could not be started\n")
|
_("The spellchecker could not be started\n")
|
||||||
+ speller_->error());
|
+ speller_->error());
|
||||||
delete speller_;
|
|
||||||
speller_ = 0;
|
speller_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +222,6 @@ bool GuiSpellchecker::initialiseParams(string const &)
|
|||||||
void GuiSpellchecker::clearParams()
|
void GuiSpellchecker::clearParams()
|
||||||
{
|
{
|
||||||
LYXERR(Debug::GUI, "Spellchecker::clearParams");
|
LYXERR(Debug::GUI, "Spellchecker::clearParams");
|
||||||
delete speller_;
|
|
||||||
speller_ = 0;
|
speller_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +240,9 @@ static WordLangTuple nextWord(Cursor & cur, ptrdiff_t & progress)
|
|||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cur.setCursor(to);
|
cur.setCursor(to);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
string lang_code = from.paragraph().getFontSettings(buf.params(), cur.pos()).language()->code();
|
string lang_code = lyxrc.spellchecker_use_alt_lang
|
||||||
|
? lyxrc.spellchecker_alt_lang
|
||||||
|
: from.paragraph().getFontSettings(buf.params(), cur.pos()).language()->code();
|
||||||
++progress;
|
++progress;
|
||||||
return WordLangTuple(word, lang_code);
|
return WordLangTuple(word, lang_code);
|
||||||
}
|
}
|
||||||
@ -304,15 +291,15 @@ void GuiSpellchecker::check()
|
|||||||
partialUpdate(SPELL_PROGRESSED);
|
partialUpdate(SPELL_PROGRESSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// speller might be dead ...
|
|
||||||
if (!checkAlive())
|
|
||||||
return;
|
|
||||||
|
|
||||||
res = speller_->check(word_);
|
res = speller_->check(word_);
|
||||||
|
|
||||||
// ... or it might just be reporting an error
|
// ... just bail out if the spellchecker reports an error.
|
||||||
if (!checkAlive())
|
if (!speller_->error().empty()) {
|
||||||
|
docstring const message =
|
||||||
|
_("The spellchecker has failed.\n") + speller_->error();
|
||||||
|
slotClose();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LYXERR(Debug::GUI, "Found word \"" << to_utf8(getWord()) << "\"");
|
LYXERR(Debug::GUI, "Found word \"" << to_utf8(getWord()) << "\"");
|
||||||
@ -334,28 +321,9 @@ void GuiSpellchecker::check()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GuiSpellchecker::checkAlive()
|
|
||||||
{
|
|
||||||
if (speller_->error().empty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
docstring message;
|
|
||||||
if (speller_->error().empty())
|
|
||||||
message = _("The spellchecker has died for some reason.\n"
|
|
||||||
"Maybe it has been killed.");
|
|
||||||
else
|
|
||||||
message = _("The spellchecker has failed.\n") + speller_->error();
|
|
||||||
|
|
||||||
slotClose();
|
|
||||||
|
|
||||||
Alert::error(_("The spellchecker has failed"), message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiSpellchecker::showSummary()
|
void GuiSpellchecker::showSummary()
|
||||||
{
|
{
|
||||||
if (!checkAlive() || count_ == 0) {
|
if (count_ == 0) {
|
||||||
slotClose();
|
slotClose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user