+void SpellcheckerWidget::updateView()
+{
+ BufferView * bv = d->gv_->documentBufferView();
+ // we need a buffer view and the buffer has to be writable
+ bool const enabled = bv != 0 && !bv->buffer().isReadonly();
+ setEnabled(enabled);
+ if (enabled && hasFocus()) {
+ Cursor const & cursor = bv->cursor();
+ if (d->start_.empty() || !d->isCurrentBuffer(cursor)) {
+ if (cursor.selection()) {
+ d->begin_ = cursor.selectionBegin();
+ d->end_ = cursor.selectionEnd();
+ d->start_ = d->begin_;
+ bv->cursor().setCursor(d->start_);
+ } else {
+ d->begin_ = DocIterator();
+ d->end_ = DocIterator();
+ d->start_ = cursor;
+ }
+ d->wrapAround(false);
+ d->check();
+ }
+ }
+}
+
+DocIterator const SpellcheckerWidget::Private::cursor() const
+{
+ BufferView * bv = gv_->documentBufferView();
+ return bv ? bv->cursor() : DocIterator();
+}
+
+bool SpellcheckerWidget::Private::continueFromBeginning()
+{
+ DocIterator const current_ = cursor();
+ if (isCurrentBuffer(current_) && !begin_.empty()) {
+ // selection was checked
+ // start over from beginning makes no sense
+ fixPositionsIfBroken();
+ hide();
+ if (current_ == start_) {
+ // no errors found... tell the user the good news
+ // so there is some feedback
+ QMessageBox::information(p,
+ qt_("Spell Checker"),
+ qt_("Spell check of the selection done, "
+ "did not find any errors."));
+ }
+ return false;
+ }
+ QMessageBox::StandardButton const answer = QMessageBox::question(p,
+ qt_("Spell Checker"),
+ qt_("We reached the end of the document, would you like to "
+ "continue from the beginning?"),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ if (answer == QMessageBox::No) {
+ fixPositionsIfBroken();
+ hide();
+ return false;
+ }
+ // there is no selection, start over from the beginning now
+ wrapAround(true);
+ dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
+ return true;
+}
+
+bool SpellcheckerWidget::Private::isCurrentBuffer(DocIterator const & cursor) const
+{
+ return start_.buffer() == cursor.buffer();
+}
+
+bool SpellcheckerWidget::Private::atLastPos(DocIterator const & cursor) const