#7429 dismiss spell checker dialog when wrap around is detected

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38361 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stephan Witt 2011-04-13 11:38:07 +00:00
parent 7dda20bc9d
commit 062ad0335f

View File

@ -60,7 +60,7 @@ namespace frontend {
struct SpellcheckerWidget::Private struct SpellcheckerWidget::Private
{ {
Private(SpellcheckerWidget * parent, DockView * dv) Private(SpellcheckerWidget * parent, DockView * dv)
: p(parent), dv_(dv), start_(true), incheck_(false) {} : p(parent), dv_(dv), incheck_(false), wrap_around_(false) {}
/// update from controller /// update from controller
void updateSuggestions(docstring_list & words); void updateSuggestions(docstring_list & words);
/// move to next position after current word /// move to next position after current word
@ -90,9 +90,11 @@ struct SpellcheckerWidget::Private
/// current word being checked and lang code /// current word being checked and lang code
WordLangTuple word_; WordLangTuple word_;
/// ///
bool start_; DocIterator start_;
/// ///
bool incheck_; bool incheck_;
///
bool wrap_around_;
}; };
@ -175,15 +177,8 @@ void SpellcheckerWidget::updateView()
{ {
BufferView * bv = d->gv_->documentBufferView(); BufferView * bv = d->gv_->documentBufferView();
setEnabled(bv != 0); setEnabled(bv != 0);
if (bv && hasFocus() && d->start_) { if (bv && hasFocus() && d->start_.empty()) {
d->start_ = false; d->start_ = bv->cursor();
BufferView * bv = d->gv_->documentBufferView();
std::set<Language const *> languages =
bv->buffer().masterBuffer()->getLanguages();
if (!languages.empty())
d->setLanguage(*languages.begin());
d->check(); d->check();
} }
} }
@ -191,17 +186,18 @@ void SpellcheckerWidget::updateView()
bool SpellcheckerWidget::Private::continueFromBeginning() bool SpellcheckerWidget::Private::continueFromBeginning()
{ {
QMessageBox::StandardButton const answer = QMessageBox::question(p, QMessageBox::StandardButton const answer = QMessageBox::question(p,
qt_("Spell Checker"), qt_("Spell Checker"),
qt_("We reached the end of the document, would you like to " qt_("We reached the end of the document, would you like to "
"continue from the beginning?"), "continue from the beginning?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No); QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (answer == QMessageBox::No) { if (answer == QMessageBox::No) {
dv_->hide(); dv_->hide();
return false; return false;
} }
dispatch(FuncRequest(LFUN_BUFFER_BEGIN)); dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
return true; wrap_around_ = true;
return true;
} }
@ -220,6 +216,9 @@ void SpellcheckerWidget::Private::forward()
//FIXME we must be at the end of a cell //FIXME we must be at the end of a cell
dispatch(FuncRequest(LFUN_CHAR_FORWARD)); dispatch(FuncRequest(LFUN_CHAR_FORWARD));
} }
if (wrap_around_ && start_ < bv->cursor()) {
dv_->hide();
}
} }
@ -237,7 +236,16 @@ void SpellcheckerWidget::on_languageCO_activated(int index)
bool SpellcheckerWidget::initialiseParams(std::string const &) bool SpellcheckerWidget::initialiseParams(std::string const &)
{ {
d->start_ = true; BufferView * bv = d->gv_->documentBufferView();
if (bv == 0)
return false;
std::set<Language const *> languages =
bv->buffer().masterBuffer()->getLanguages();
if (!languages.empty())
d->setLanguage(*languages.begin());
d->start_ = DocIterator();
d->wrap_around_ = false;
d->incheck_ = false;
return true; return true;
} }
@ -380,11 +388,20 @@ void SpellcheckerWidget::Private::check()
// end of document // end of document
if (from == doc_iterator_end(&bv->buffer())) { if (from == doc_iterator_end(&bv->buffer())) {
if (wrap_around_ || start_ == doc_iterator_begin(&bv->buffer())) {
dv_->hide();
return;
}
if (continueFromBeginning()) if (continueFromBeginning())
check(); check();
return; return;
} }
if (wrap_around_ && start_ < from) {
dv_->hide();
return;
}
word_ = word_lang; word_ = word_lang;
// set suggestions // set suggestions