From 4f8cfca1170926df08f86b1cc6eccf4c9f2e3fd1 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sat, 5 Dec 2020 20:27:46 +0100 Subject: [PATCH] Update handling of read-only for Thesaurus Remove dummy calls to ButtonController::addReadOnly(). Properly disable stuff for read-only documents. Streamline code. --- src/frontends/qt/GuiThesaurus.cpp | 39 ++++++++++++------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/frontends/qt/GuiThesaurus.cpp b/src/frontends/qt/GuiThesaurus.cpp index 2e80137019..eef37ebfa5 100644 --- a/src/frontends/qt/GuiThesaurus.cpp +++ b/src/frontends/qt/GuiThesaurus.cpp @@ -88,8 +88,6 @@ GuiThesaurus::GuiThesaurus(GuiView & lv) bc().setCancel(buttonBox->button(QDialogButtonBox::Close)); bc().setApply(replacePB, true); - bc().addReadOnly(replaceED); - bc().addReadOnly(replacePB); bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); setFocusProxy(entryCO); @@ -188,32 +186,25 @@ void GuiThesaurus::updateLists() Thesaurus::Meanings meanings = getMeanings(WordLangTuple(qstring_to_ucs4(entryCO->currentText()), language)); - for (Thesaurus::Meanings::const_iterator cit = meanings.begin(); - cit != meanings.end(); ++cit) { + for (auto const & meaning_p : meanings) { QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV); - i->setText(0, toqstr(cit->first)); + i->setText(0, toqstr(meaning_p.first)); meaningsTV->expandItem(i); - for (vector::const_iterator cit2 = cit->second.begin(); - cit2 != cit->second.end(); ++cit2) { - QTreeWidgetItem * i2 = new QTreeWidgetItem(i); - i2->setText(0, toqstr(*cit2)); - } - meaningsTV->setEnabled(true); - lookupPB->setEnabled(true); - bool const readonly = isBufferReadonly(); - replaceED->setEnabled(!readonly); - replacePB->setEnabled(!readonly); + for (docstring const & word : meaning_p.second) { + QTreeWidgetItem * i2 = new QTreeWidgetItem(i); + i2->setText(0, toqstr(word)); + } } - if (meanings.empty()) { - if (!thesaurus.thesaurusAvailable(lang_code)) { - QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV); - i->setText(0, qt_("No thesaurus available for this language!")); - meaningsTV->setEnabled(false); - lookupPB->setEnabled(false); - replaceED->setEnabled(false); - replacePB->setEnabled(false); - } + meaningsTV->setEnabled(!meanings.empty()); + lookupPB->setEnabled(!meanings.empty()); + selectionLA->setEnabled(!meanings.empty() && !isBufferReadonly()); + replaceED->setEnabled(!meanings.empty() && !isBufferReadonly()); + replacePB->setEnabled(!meanings.empty() && !isBufferReadonly()); + + if (meanings.empty() && !thesaurus.thesaurusAvailable(lang_code)) { + QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV); + i->setText(0, qt_("No thesaurus available for this language!")); } meaningsTV->setUpdatesEnabled(true);