namespace lyx {
-class BufferParams;
-
-class ASpell : public SpellChecker {
+class ASpell : public SpellChecker
+{
public:
- /**
- * Initialise the spellchecker with the given buffer params and language.
- */
- ASpell(BufferParams const & params, std::string const & lang);
-
- virtual ~ASpell();
+ ASpell();
+ ~ASpell();
/// 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
- virtual void insert(WordLangTuple const &);
+ void insert(WordLangTuple const &);
/// accept the given word temporarily
- virtual void accept(WordLangTuple const &);
+ void accept(WordLangTuple const &);
/// return the next near miss after a SUGGESTED_WORDS result
- virtual docstring const nextMiss();
+ docstring const nextMiss();
/// give an error message on messy exit
- virtual docstring const error();
+ docstring const error();
private:
/// add a speller of the given language
#include "LyX.h"
-#include "LayoutFile.h"
+#include "ASpell_local.h"
#include "Buffer.h"
#include "BufferList.h"
#include "CmdDef.h"
#include "FuncStatus.h"
#include "KeyMap.h"
#include "Language.h"
+#include "LayoutFile.h"
#include "Lexer.h"
#include "LyXAction.h"
#include "LyXFunc.h"
// The language used will be derived from the environment
// variables.
messages_["GUI"] = Messages();
+
+#if defined(USE_ASPELL)
+ spell_checker_ = new ASpell();
+#else
+ spell_checker_ = 0;
+#endif
+ }
+
+ ~Impl()
+ {
+ delete spell_checker_;
}
+
/// our function handler
LyXFunc lyxfunc_;
///
///
graphics::Previews preview_;
+ ///
+ SpellChecker * spell_checker_;
};
///
return singleton_->pimpl_->toplevel_cmddef_;
}
+
+SpellChecker * theSpellChecker()
+{
+ return singleton_->pimpl_->spell_checker_;
+}
+
} // namespace lyx
class Server;
class ServerSocket;
class Session;
+class SpellChecker;
extern bool use_gui;
friend graphics::Previews & thePreviews();
friend Session & theSession();
friend CmdDef & theTopLevelCmdDef();
+ friend SpellChecker * theSpellChecker();
friend void setRcGuiLanguage();
friend void emergencyCleanup();
friend void execBatchCommands();
} // namespace lyx
#endif // LYX_H
+
#include "Cursor.h"
#include "CutAndPaste.h"
#include "Language.h"
+#include "LyX.h"
#include "LyXRC.h"
#include "Paragraph.h"
GuiSpellchecker::~GuiSpellchecker()
{
- delete speller_;
}
}
-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 &)
{
LYXERR(Debug::GUI, "Spellchecker::initialiseParams");
- speller_ = createSpeller(buffer().params());
+ speller_ = theSpellChecker();
if (!speller_)
return false;
Alert::error(_("Spellchecker error"),
_("The spellchecker could not be started\n")
+ speller_->error());
- delete speller_;
speller_ = 0;
}
void GuiSpellchecker::clearParams()
{
LYXERR(Debug::GUI, "Spellchecker::clearParams");
- delete speller_;
speller_ = 0;
}
cur.resetAnchor();
cur.setCursor(to);
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;
return WordLangTuple(word, lang_code);
}
partialUpdate(SPELL_PROGRESSED);
}
- // speller might be dead ...
- if (!checkAlive())
- return;
-
res = speller_->check(word_);
- // ... or it might just be reporting an error
- if (!checkAlive())
+ // ... just bail out if the spellchecker reports an error.
+ if (!speller_->error().empty()) {
+ docstring const message =
+ _("The spellchecker has failed.\n") + speller_->error();
+ slotClose();
return;
+ }
}
LYXERR(Debug::GUI, "Found word \"" << to_utf8(getWord()) << "\"");
}
-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()
{
- if (!checkAlive() || count_ == 0) {
+ if (count_ == 0) {
slotClose();
return;
}