/* This file is part of
- * ======================================================
+ * ======================================================
*
* LyX, The Document Processor
*
#pragma implementation
#endif
-#ifdef HAVE_SYS_SELECT_H
-# ifdef HAVE_STRINGS_H
- // <strings.h> is needed at least on AIX because FD_ZERO uses bzero().
- // BUT we cannot include both string.h and strings.h on Irix 6.5 :(
-# ifdef _AIX
-# include <strings.h>
-# endif
-# endif
-#include <sys/select.h>
-#endif
-
+#include "ControlSpellchecker.h"
#include "buffer.h"
#include "lyxrc.h"
#include "BufferView.h"
-#include "LyXView.h"
+#include "lyxtext.h"
#include "gettext.h"
-#include "support/lstrings.h"
#include "language.h"
#include "ViewBase.h"
-#include "ButtonControllerBase.h"
-#include "ControlSpellchecker.h"
#include "Dialogs.h"
#include "Liason.h"
+#include "frontends/LyXView.h"
+
+#include "support/lstrings.h"
+
# include "sp_ispell.h"
#ifdef USE_PSPELL
# include "sp_pspell.h"
#endif
-#include "debug.h"
+#include <sys/types.h> // needed by <sys/select.h> at least on freebsd
-using SigC::slot;
+#ifdef HAVE_SYS_SELECT_H
+# ifdef HAVE_STRINGS_H
+ // <strings.h> is needed at least on AIX because FD_ZERO uses bzero().
+ // BUT we cannot include both string.h and strings.h on Irix 6.5 :(
+# ifdef _AIX
+# include <strings.h>
+# endif
+# endif
+#include <sys/select.h>
+#endif
ControlSpellchecker::ControlSpellchecker(LyXView & lv, Dialogs & d)
- : ControlDialog<ControlConnectBD>(lv, d),
+ : ControlDialogBD(lv, d),
rtl_(false), newval_(0.0), oldval_(0), newvalue_(0), count_(0),
stop_(false), result_(SpellBase::ISP_OK), speller_(0)
-{
- d_.showSpellchecker.connect(SigC::slot(this, &ControlSpellchecker::show));
-}
+{}
void ControlSpellchecker::setParams()
if (lyxrc.use_pspell) {
tmp = (lyxrc.isp_use_alt_lang) ?
lyxrc.isp_alt_lang : lv_.buffer()->params.language->code();
-
+
speller_ = new PSpell(lv_.view()->buffer()->params, tmp);
} else {
#endif
tmp = (lyxrc.isp_use_alt_lang) ?
lyxrc.isp_alt_lang : lv_.buffer()->params.language->lang();
-
+
speller_ = new ISpell(lv_.view()->buffer()->params, tmp);
#ifdef USE_PSPELL
}
#endif
-
+
if (lyxrc.isp_use_alt_lang) {
Language const * lang = languages.getLanguage(tmp);
if (lang)
} else {
rtl_ = lv_.buffer()->params.language->RightToLeft();
}
-
+
if (speller_->error() != 0) {
#if 0
message_ = speller_->error();
{
result_ = SpellBase::ISP_OK;
stop_ = false;
-
+
+ // clear any old selection
+ LyXText * text = lv_.view()->getLyXText();
+ lv_.view()->toggleSelection(true);
+ lv_.view()->update(text, BufferView::SELECT);
+
while ((result_==SpellBase::ISP_OK || result_==SpellBase::ISP_IGNORE) &&
!stop_) {
word_ = lv_.view()->nextWord(newval_);
-
+
if (word_.empty()) {
clearParams();
break;
}
-
+
++count_;
// Update slider if and only if value has changed
// set progress bar
view().partialUpdate(0);
}
-
+
if (!speller_->alive()) clearParams();
-
+
result_ = speller_->check(word_);
}
-
+
if (!stop_ && !word_.empty())
lv_.view()->selectLastWord();
// segfaults when nextMiss is 0
string tmp;
char const * w = speller_->nextMiss();
-
+
if (w!=0) {
tmp = w;
if (rtl_) std::reverse(tmp.begin(), tmp.end());
}
-
+
return tmp;
}
void ControlSpellchecker::clearParams()
{
if (!speller_) return;
-
+
if (speller_->alive()) {
speller_->close();
message_ = tostr(count_);
// make sure that the dialog is not launched
emergency_exit_ = true;
}
-
+
delete speller_;
-
+
lv_.view()->endOfSpellCheck();
- // show closing message
- view().partialUpdate(2);
+ // show closing message if any words were checked.
+ if (count_ > 0)
+ view().partialUpdate(2);
// reset values to initial
rtl_ = false;
- word_ = "";
+ word_.erase();
newval_ = 0.0;
oldval_ = 0;
newvalue_ = 0;
count_ = 0;
- message_ = "";
+ message_.erase();
stop_ = false;
result_ = SpellBase::ISP_OK;
speller_ = 0;
}
-
-
-void ControlSpellchecker::options()
-{
- lv_.getDialogs()->showSpellcheckerPreferences();
-}