]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiSpellchecker.cpp
Make BufferView::singeParUpdate more robust
[lyx.git] / src / frontends / qt / GuiSpellchecker.cpp
index dd1f9e962a1b82a6e0c4027cd472c6d3dc306ea2..66952eb7dc1a413c793ba813c6b787dc1f760b70 100644 (file)
@@ -72,8 +72,6 @@ struct SpellcheckerWidget::Private
        void check();
        /// close the spell checker dialog
        void hide() const;
-       /// make/restore a selection between from and to
-       void setSelection(DocIterator const & from, DocIterator const & to) const;
        /// if no selection was checked:
        /// ask the user if the check should start over
        bool continueFromBeginning();
@@ -192,8 +190,9 @@ void SpellcheckerWidget::on_suggestionsLW_itemClicked(QListWidgetItem * item)
 }
 
 
-void SpellcheckerWidget::on_replaceCO_highlighted(const QString & str)
+void SpellcheckerWidget::on_replaceCO_highlighted(int index)
 {
+       QString const str = d->ui.replaceCO->itemText(index);
        QListWidget * lw = d->ui.suggestionsLW;
        if (lw->currentItem() && lw->currentItem()->text() == str)
                return;
@@ -338,7 +337,7 @@ void SpellcheckerWidget::Private::hide() const
        if (isCurrentBuffer(bvcur)) {
                if (!begin_.empty() && !end_.empty()) {
                        // restore previous selection
-                       setSelection(begin_, end_);
+                       bv->setSelection(begin_, end_);
                } else {
                        // restore cursor position
                        bvcur.setCursor(start_);
@@ -348,29 +347,6 @@ void SpellcheckerWidget::Private::hide() const
        }
 }
 
-void SpellcheckerWidget::Private::setSelection(
-       DocIterator const & from, DocIterator const & to) const
-{
-       BufferView * bv = gv_->documentBufferView();
-       DocIterator end = to;
-
-       if (from.pit() != end.pit()) {
-               // there are multiple paragraphs in selection
-               Cursor & bvcur = bv->cursor();
-               bvcur.setCursor(from);
-               bvcur.clearSelection();
-               bvcur.selection(true);
-               bvcur.setCursor(end);
-               bvcur.selection(true);
-       } else {
-               // FIXME LFUN
-               // If we used a LFUN, dispatch would do all of this for us
-               int const size = end.pos() - from.pos();
-               bv->putSelectionAt(from, size, false);
-       }
-       bv->processUpdateFlags(Update::Force | Update::FitCursor);
-}
-
 void SpellcheckerWidget::Private::forward()
 {
        DocIterator const from = cursor();
@@ -390,6 +366,13 @@ void SpellcheckerWidget::Private::forward()
        if (isWrapAround(cursor())) {
                hide();
        }
+       // If we reached the end of the document
+       // and have not yet wrapped (which was
+       // checked above), continue from beginning
+       if (cursor().pit() == cursor().lastpit()
+           && cursor().pos() == cursor().lastpos()
+           && cursor().text()->isMainText())
+               continueFromBeginning();
 }
 
 
@@ -421,6 +404,20 @@ bool SpellcheckerWidget::initialiseParams(std::string const &)
 }
 
 
+void SpellcheckerWidget::on_skipAllPB_clicked()
+{
+       /// ignore all occurrences of word
+       if (d->disabled())
+               return;
+       LYXERR(Debug::GUI, "Spellchecker: skip all button");
+       if (d->word_.lang() && !d->word_.word().empty())
+               theSpellChecker()->accept(d->word_);
+       d->forward();
+       d->check();
+       d->canCheck();
+}
+
+
 void SpellcheckerWidget::on_ignoreAllPB_clicked()
 {
        /// ignore all occurrences of word
@@ -428,7 +425,8 @@ void SpellcheckerWidget::on_ignoreAllPB_clicked()
                return;
        LYXERR(Debug::GUI, "Spellchecker: ignore all button");
        if (d->word_.lang() && !d->word_.word().empty())
-               theSpellChecker()->accept(d->word_);
+               dispatch(FuncRequest(LFUN_SPELLING_ADD_LOCAL,
+                                    d->word_.word() + " " + from_ascii(d->word_.lang()->lang())));
        d->forward();
        d->check();
        d->canCheck();
@@ -448,12 +446,25 @@ void SpellcheckerWidget::on_addPB_clicked()
 }
 
 
+void SpellcheckerWidget::on_skipPB_clicked()
+{
+       /// ignore this occurrence of word
+       if (d->disabled())
+               return;
+       LYXERR(Debug::GUI, "Spellchecker: skip button");
+       d->forward();
+       d->check();
+       d->canCheck();
+}
+
+
 void SpellcheckerWidget::on_ignorePB_clicked()
 {
        /// ignore this occurrence of word
        if (d->disabled())
                return;
        LYXERR(Debug::GUI, "Spellchecker: ignore button");
+       dispatch(FuncRequest(LFUN_FONT_NO_SPELLCHECK));
        d->forward();
        d->check();
        d->canCheck();
@@ -596,7 +607,7 @@ void SpellcheckerWidget::Private::check()
                return;
        setLanguage(word_lang.lang());
        // mark misspelled word
-       setSelection(from, to);
+       bv->setSelection(from, to);
        // enable relevant widgets
        updateView();
 }