X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiSpellchecker.cpp;h=10edda44629b9b24705a5ed14d0113403dce9b3c;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=3cd6ca097fbe26460ee1d8cd7899aa42ca6a0f78;hpb=ef5f53017a28025cfa972166bb371530af570e6b;p=lyx.git diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index 3cd6ca097f..10edda4462 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -24,9 +24,11 @@ #include "buffer_funcs.h" #include "Cursor.h" #include "CutAndPaste.h" +#include "FuncRequest.h" #include "Language.h" #include "LyX.h" #include "LyXRC.h" +#include "lyxfind.h" #include "Paragraph.h" #include "WordLangTuple.h" @@ -39,6 +41,7 @@ #include "support/textutils.h" #include +#include #include "SpellChecker.h" @@ -75,6 +78,8 @@ GuiSpellchecker::GuiSpellchecker(GuiView & lv) this, SLOT(on_replacePB_clicked())); d->ui.wordED->setReadOnly(true); + + d->ui.suggestionsLW->installEventFilter(this); } @@ -90,7 +95,25 @@ void GuiSpellchecker::on_closePB_clicked() } -void GuiSpellchecker::on_suggestionsLW_changed(QListWidgetItem * item) +bool GuiSpellchecker::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == d->ui.suggestionsLW && event->type() == QEvent::KeyPress) { + QKeyEvent *e = static_cast (event); + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { + on_suggestionsLW_itemClicked(d->ui.suggestionsLW->currentItem()); + on_replacePB_clicked(); + return true; + } else if (e->key() == Qt::Key_Right) { + on_suggestionsLW_itemClicked(d->ui.suggestionsLW->currentItem()); + return true; + } + } + // standard event processing + return QWidget::eventFilter(obj, event); +} + + +void GuiSpellchecker::on_suggestionsLW_itemClicked(QListWidgetItem * item) { if (d->ui.replaceCO->count() != 0) d->ui.replaceCO->setItemText(0, item->text()); @@ -101,7 +124,7 @@ void GuiSpellchecker::on_suggestionsLW_changed(QListWidgetItem * item) } -void GuiSpellchecker::on_replaceC0_highlighted(const QString & str) +void GuiSpellchecker::on_replaceCO_highlighted(const QString & str) { QListWidget * lw = d->ui.suggestionsLW; if (lw->currentItem() && lw->currentItem()->text() == str) @@ -123,7 +146,7 @@ void GuiSpellchecker::updateView() } -void GuiSpellchecker::on_replaceAllPB_clicked() +void GuiSpellchecker::on_ignoreAllPB_clicked() { /// replace all occurances of word theSpellChecker()->accept(d->word_); @@ -141,16 +164,28 @@ void GuiSpellchecker::on_addPB_clicked() void GuiSpellchecker::on_ignorePB_clicked() { + dispatch(FuncRequest(LFUN_CHAR_FORWARD)); check(); } +void GuiSpellchecker::on_findNextPB_clicked() +{ + docstring const data = find2string( + qstring_to_ucs4(d->ui.wordED->text()), + true, true, true); + dispatch(FuncRequest(LFUN_WORD_FIND, data)); +} + + void GuiSpellchecker::on_replacePB_clicked() { docstring const replacement = qstring_to_ucs4(d->ui.replaceCO->currentText()); LYXERR(Debug::GUI, "Replace (" << replacement << ")"); BufferView * bv = const_cast(bufferview()); + if (!bv->cursor().inTexted()) + return; cap::replaceSelectionWithString(bv->cursor(), replacement, true); bv->buffer().markDirty(); // If we used an LFUN, we would not need that @@ -161,6 +196,17 @@ void GuiSpellchecker::on_replacePB_clicked() } +void GuiSpellchecker::on_replaceAllPB_clicked() +{ + docstring const data = replace2string( + qstring_to_ucs4(d->ui.replaceCO->currentText()), + qstring_to_ucs4(d->ui.wordED->text()), + true, true, true, true); + dispatch(FuncRequest(LFUN_WORD_REPLACE, data)); + check(); // continue spellchecking +} + + void GuiSpellchecker::updateSuggestions(docstring_list & words) { QString const suggestion = toqstr(d->word_.word()); @@ -169,13 +215,13 @@ void GuiSpellchecker::updateSuggestions(docstring_list & words) lw->clear(); if (words.empty()) { - on_suggestionsLW_changed(new QListWidgetItem(suggestion)); + on_suggestionsLW_itemClicked(new QListWidgetItem(suggestion)); return; } for (size_t i = 0; i != words.size(); ++i) lw->addItem(toqstr(words[i])); - on_suggestionsLW_changed(lw->item(0)); + on_suggestionsLW_itemClicked(lw->item(0)); lw->setCurrentRow(0); } @@ -221,7 +267,7 @@ void GuiSpellchecker::check() d->progress_ += progress; // end of document - if (from == to) { + if (from == doc_iterator_end(&buffer())) { showSummary(); return; }