X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiThesaurus.cpp;h=c28fdf113e9f1ab5960df05d1b68b7ed174d3826;hb=1f10969bb5c5f36017bf5ba8671381b09945cf57;hp=083ed2eac0d7d07102a1475d2bf1bd3ea7a41add;hpb=df4814e0267789ce84802d69aa6725395517ca9b;p=lyx.git diff --git a/src/frontends/qt4/GuiThesaurus.cpp b/src/frontends/qt4/GuiThesaurus.cpp index 083ed2eac0..c28fdf113e 100644 --- a/src/frontends/qt4/GuiThesaurus.cpp +++ b/src/frontends/qt4/GuiThesaurus.cpp @@ -22,12 +22,14 @@ #include "FuncRequest.h" #include "Language.h" #include "lyxfind.h" +#include "WordLangTuple.h" #include "support/debug.h" #include "support/gettext.h" #include "support/lstrings.h" #include +#include #include #include #include @@ -77,6 +79,11 @@ GuiThesaurus::GuiThesaurus(GuiView & lv) // FIXME: it would be nice if sorting was enabled/disabled via a checkbox. language_model->sort(0); languageCO->setModel(language_model); + languageCO->setModelColumn(2); + + //bug #8138 + if (entryCO->completer()) + entryCO->completer()->setCompletionMode(QCompleter::PopupCompletion); bc().setCancel(closePB); bc().setApply(replacePB); @@ -85,7 +92,16 @@ GuiThesaurus::GuiThesaurus(GuiView & lv) bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); } - +void GuiThesaurus::checkStatus() +{ + if (!isBufferAvailable()) { + // deactivate the thesaurus if we have no buffer + enableView(false); + return; + } + updateView(); +} + void GuiThesaurus::change_adaptor() { changed(); @@ -105,17 +121,20 @@ void GuiThesaurus::selectionChanged() return; QString item = meaningsTV->currentItem()->text(col); - // cut out the classification in brackets - // (as in "hominid (generic term)") - // FIXME: not ideal yet. We need to cut off classifications - // at the beginning as well - // (as in "(noun) man" and "(noun) male (generic term)") + // cut out the classification in brackets: + // "hominid (generic term)" -> "hominid" QRegExp re("^([^\\(\\)]+)\\b\\(?.*\\)?.*$"); + // This is for items with classifications at the beginning: + // "(noun) man" -> "man"; "(noun) male (generic term)" -> "male" + QRegExp rex("^(\\(.+\\))\\s*([^\\(\\)]+)\\s*\\(?.*\\)?.*$"); int pos = re.indexIn(item); if (pos > -1) item = re.cap(1).trimmed(); + pos = rex.indexIn(item); + if (pos > -1) + item = rex.cap(2).trimmed(); replaceED->setText(item); - replacePB->setEnabled(true); + replacePB->setEnabled(!isBufferReadonly()); changed(); } @@ -129,15 +148,18 @@ void GuiThesaurus::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/) void GuiThesaurus::selectionClicked(QTreeWidgetItem * item, int col) { QString str = item->text(col); - // cut out the classification in brackets - // (as in "hominid (generic term)") - // FIXME: not ideal yet. We need to cut off classifications - // at the beginning as well - // (as in "(noun) man" and "(noun) male (generic term)") + // cut out the classification in brackets: + // "hominid (generic term)" -> "hominid" QRegExp re("^([^\\(\\)]+)\\b\\(?.*\\)?.*$"); + // This is for items with classifications at the beginning: + // "(noun) man" -> "man"; "(noun) male (generic term)" -> "male" + QRegExp rex("^(\\(.+\\))\\s*([^\\(\\)]+)\\s*\\(?.*\\)?.*$"); int pos = re.indexIn(str); if (pos > -1) str = re.cap(1).trimmed(); + pos = rex.indexIn(str); + if (pos > -1) + str = rex.cap(2).trimmed(); entryCO->insertItem(0, str); entryCO->setCurrentIndex(0); @@ -149,15 +171,19 @@ void GuiThesaurus::selectionClicked(QTreeWidgetItem * item, int col) void GuiThesaurus::updateLists() { meaningsTV->clear(); + + if (entryCO->currentText().isEmpty()) + return; + meaningsTV->setUpdatesEnabled(false); QString const lang = languageCO->itemData( languageCO->currentIndex()).toString(); - docstring const lang_code = - from_ascii(lyx::languages.getLanguage(fromqstr(lang))->code()); + Language * language = const_cast(lyx::languages.getLanguage(fromqstr(lang))); + docstring const lang_code = from_ascii(language->code()); Thesaurus::Meanings meanings = - getMeanings(qstring_to_ucs4(entryCO->currentText()), lang_code); + getMeanings(WordLangTuple(qstring_to_ucs4(entryCO->currentText()), language)); for (Thesaurus::Meanings::const_iterator cit = meanings.begin(); cit != meanings.end(); ++cit) { @@ -171,8 +197,9 @@ void GuiThesaurus::updateLists() } meaningsTV->setEnabled(true); lookupPB->setEnabled(true); - replaceED->setEnabled(true); - replacePB->setEnabled(true); + bool const readonly = isBufferReadonly(); + replaceED->setEnabled(!readonly); + replacePB->setEnabled(!readonly); } if (meanings.empty()) { @@ -241,7 +268,7 @@ void GuiThesaurus::replace(docstring const & newstr) * deletion/change ! */ docstring const data = - replace2string(text_, newstr, + replace2string(newstr, text_, true, // case sensitive true, // match word false, // all words @@ -250,11 +277,10 @@ void GuiThesaurus::replace(docstring const & newstr) } -Thesaurus::Meanings const & GuiThesaurus::getMeanings(docstring const & str, - docstring const & lang) +Thesaurus::Meanings const & GuiThesaurus::getMeanings(WordLangTuple const & wl) { - if (str != laststr_) - meanings_ = thesaurus.lookup(str, lang); + if (wl.word() != laststr_) + meanings_ = thesaurus.lookup(wl); return meanings_; }