Dear all,

This patch (for 1.5) removes pspell and ispell related code and simplify the controller interaction with the aspell library. I propose to commit this and then switch to enchant.

Abdel.

Index: aspell.C
===================================================================
--- aspell.C    (revision 14911)
+++ aspell.C    (working copy)
@@ -23,9 +23,18 @@
 using std::string;
 
 
-ASpell::ASpell(BufferParams const &, string const & lang)
+ASpell::ASpell(string const & lang)
        : els(0), spell_error_object(0)
 {
+       if (!lang.empty())
+               addSpeller(lang);
+}
+
+
+void ASpell::reset(string const & lang)
+{
+       els = 0;
+       spell_error_object =0;
        addSpeller(lang);
 }
 
Index: aspell_local.h
===================================================================
--- aspell_local.h      (revision 14911)
+++ aspell_local.h      (working copy)
@@ -30,7 +30,7 @@
        /**
         * Initialise the spellchecker with the given buffer params and 
language.
         */
-       ASpell(BufferParams const & params, std::string const & lang);
+       ASpell(std::string const & lang = "");
 
        virtual ~ASpell();
 
@@ -55,6 +55,9 @@
        /// give an error message on messy exit
        virtual std::string const error();
 
+       /// reset the spellchecker with the given language.
+       void reset(std::string const & lang);
+
 private:
        /// add a speller of the given language
        void addSpeller(std::string const & lang);
Index: frontends/controllers/ControlSpellchecker.C
===================================================================
--- frontends/controllers/ControlSpellchecker.C (revision 14911)
+++ frontends/controllers/ControlSpellchecker.C (working copy)
@@ -23,18 +23,6 @@
 #include "lyxrc.h"
 #include "paragraph.h"
 
-#if defined(USE_ASPELL)
-# include "aspell_local.h"
-#elif defined(USE_PSPELL)
-# include "pspell.h"
-#endif
-
-#if defined(USE_ISPELL)
-# include "ispell.h"
-#else
-# include "SpellBase.h"
-#endif
-
 #include "support/textutils.h"
 #include "support/convert.h"
 
@@ -56,62 +44,35 @@
 ControlSpellchecker::ControlSpellchecker(Dialog & parent)
        : Dialog::Controller(parent), exitEarly_(false),
          oldval_(0), newvalue_(0), count_(0)
-{}
+{
+}
 
 
 ControlSpellchecker::~ControlSpellchecker()
 {}
 
 
-namespace {
-
-SpellBase * getSpeller(BufferParams const & bp)
-{
-       string lang = (lyxrc.isp_use_alt_lang)
-                     ? lyxrc.isp_alt_lang
-                     : bp.language->code();
-
-#if defined(USE_ASPELL)
-       if (lyxrc.use_spell_lib)
-               return new ASpell(bp, lang);
-#elif defined(USE_PSPELL)
-       if (lyxrc.use_spell_lib)
-               return new PSpell(bp, lang);
-#endif
-
-#if defined(USE_ISPELL)
-       lang = (lyxrc.isp_use_alt_lang) ?
-               lyxrc.isp_alt_lang : bp.language->lang();
-
-       return new ISpell(bp, lang);
-#else
-       return new SpellBase;
-#endif
-}
-
-} // namespace anon
-
-
 bool ControlSpellchecker::initialiseParams(std::string const &)
 {
        lyxerr[Debug::GUI] << "Spellchecker::initialiseParams" << endl;
 
-       speller_.reset(getSpeller(kernel().buffer().params()));
-       if (!speller_.get())
-               return false;
+       string const lang = (lyxrc.isp_use_alt_lang)
+                     ? lyxrc.isp_alt_lang
+                     : kernel().buffer().params().language->code();
 
+       speller_.reset(lang);
+
        // reset values to initial
        oldval_ = 0;
        newvalue_ = 0;
        count_ = 0;
 
-       bool const success = speller_->error().empty();
+       bool const success = speller_.error().empty();
 
        if (!success) {
                Alert::error(_("Spellchecker error"),
                             _("The spellchecker could not be started\n")
-                            + speller_->error());
-               speller_.reset(0);
+                            + speller_.error());
        }
 
        return success;
@@ -120,8 +81,6 @@
 
 void ControlSpellchecker::clearParams()
 {
-       lyxerr[Debug::GUI] << "Spellchecker::clearParams" << endl;
-       speller_.reset(0);
 }
 
 
@@ -234,7 +193,7 @@
                if (!checkAlive())
                        return;
 
-               res = speller_->check(word_);
+               res = speller_.check(word_);
 
                // ... or it might just be reporting an error
                if (!checkAlive())
@@ -260,27 +219,21 @@
 
 bool ControlSpellchecker::checkAlive()
 {
-       if (speller_->alive() && speller_->error().empty())
+       if (speller_.error().empty())
                return true;
 
-       string 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();
-
        dialog().CancelButton();
-
-       Alert::error(_("The spellchecker has failed"), message);
+       Alert::error(_("The spellchecker has failed"), speller_.error());
        return false;
 }
 
 
 void ControlSpellchecker::showSummary()
 {
-       if (!checkAlive() || count_ == 0) {
+       if (!checkAlive())
+               return;
+
+       if (count_ == 0) {
                dialog().CancelButton();
                return;
        }
@@ -319,14 +272,14 @@
 
 void ControlSpellchecker::insert()
 {
-       speller_->insert(word_);
+       speller_.insert(word_);
        check();
 }
 
 
-string const ControlSpellchecker::getSuggestion() const
+string const ControlSpellchecker::getSuggestion()
 {
-       return speller_->nextMiss();
+       return speller_.nextMiss();
 }
 
 
@@ -338,7 +291,7 @@
 
 void ControlSpellchecker::ignoreAll()
 {
-       speller_->accept(word_);
+       speller_.accept(word_);
        check();
 }
 
Index: frontends/controllers/ControlSpellchecker.h
===================================================================
--- frontends/controllers/ControlSpellchecker.h (revision 14911)
+++ frontends/controllers/ControlSpellchecker.h (working copy)
@@ -14,7 +14,7 @@
 
 #include "Dialog.h"
 #include "WordLangTuple.h"
-#include <boost/scoped_ptr.hpp>
+# include "aspell_local.h"
 
 class SpellBase;
 
@@ -60,7 +60,7 @@
        void check();
 
        /// get suggestion
-       std::string const getSuggestion() const;
+       std::string const getSuggestion();
 
        /// get word
        std::string const getWord() const;
@@ -93,7 +93,7 @@
        int count_;
 
        /// The actual spellchecker object
-       boost::scoped_ptr<SpellBase> speller_;
+       ASpell speller_;
 };
 
 } // namespace frontend
Index: frontends/qt4/QSpellchecker.C
===================================================================
--- frontends/qt4/QSpellchecker.C       (revision 14911)
+++ frontends/qt4/QSpellchecker.C       (working copy)
@@ -46,8 +46,8 @@
 
 void QSpellchecker::update_contents()
 {
-       if (isVisible() || controller().exitEarly()) {
-               controller().check();
+       if (isVisible()) {
+//             controller().check();
        }
 }
 

Reply via email to