From 8fa7e27e7ef78f3529be63c5c98c6ad4beb541ef Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 19 Feb 2022 14:09:59 +0100 Subject: [PATCH] child documents: allow inheritance of bibliography file list (#4427) --- src/Buffer.h | 8 +++--- src/frontends/qt/GuiBibtex.cpp | 49 +++++++++++++++++++++++++++++++++ src/frontends/qt/GuiBibtex.h | 3 ++ src/frontends/qt/ui/BibtexUi.ui | 14 ++++++++-- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index 332ef86404..0d79ffaff4 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -784,6 +784,10 @@ public: void registerBibfiles(docstring_list const & bf) const; /// support::FileName getBibfilePath(docstring const & bibid) const; + /// Return the list with all bibfiles in use (including bibfiles + /// of loaded child documents). + docstring_list const & + getBibfiles(UpdateScope scope = UpdateMaster) const; /// routines for dealing with possible self-inclusion void pushIncludedBuffer(Buffer const * buf) const; @@ -807,10 +811,6 @@ private: /// last time we loaded the cache. Note that this does NOT update the /// cached information. void checkIfBibInfoCacheIsValid() const; - /// Return the list with all bibfiles in use (including bibfiles - /// of loaded child documents). - docstring_list const & - getBibfiles(UpdateScope scope = UpdateMaster) const; /// void collectChildren(ListOfBuffers & children, bool grand_children) const; diff --git a/src/frontends/qt/GuiBibtex.cpp b/src/frontends/qt/GuiBibtex.cpp index 64bb987137..3c71884246 100644 --- a/src/frontends/qt/GuiBibtex.cpp +++ b/src/frontends/qt/GuiBibtex.cpp @@ -34,6 +34,7 @@ #include "insets/InsetBibtex.h" #include "support/debug.h" +#include "support/docstring_list.h" #include "support/ExceptionMessage.h" #include "support/FileName.h" #include "support/filetools.h" // changeExtension @@ -88,6 +89,8 @@ GuiBibtex::GuiBibtex(GuiView & lv) this, SLOT(change_adaptor())); connect(browseBibPB, SIGNAL(clicked()), this, SLOT(browseBibPressed())); + connect(inheritPB, SIGNAL(clicked()), + this, SLOT(inheritPressed())); selected_model_.insertColumns(0, 1); selectionManager = new GuiSelectionManager(this, availableLV, selectedLV, @@ -178,6 +181,7 @@ void GuiBibtex::setButtons() int const srows = selectedLV->model()->rowCount(); buttonBox->button(QDialogButtonBox::Apply)->setEnabled(srows > 0); buttonBox->button(QDialogButtonBox::Ok)->setEnabled(srows > 0); + inheritPB->setEnabled(hasInherits()); } @@ -240,6 +244,49 @@ void GuiBibtex::browseBibPressed() } +bool GuiBibtex::hasInherits() +{ + if (!buffer().parent()) + return false; + + docstring_list const mbibs = buffer().masterBuffer()->getBibfiles(); + if (mbibs.empty()) + return false; + + for (auto const & f : mbibs) { + if (!selected_bibs_.contains(toqstr(f))) + return true; + } + return false; +} + + +void GuiBibtex::inheritPressed() +{ + docstring_list const mbibs = buffer().masterBuffer()->getBibfiles(); + bool chng = false; + vector nfe; + for (auto const & f : mbibs) { + if (!selected_bibs_.contains(toqstr(f))) { + selected_bibs_.append(toqstr(f)); + setSelectedBibs(selected_bibs_); + string enc; + if (usingBiblatex()) { + string const bfe = buffer().masterParams().bibFileEncoding(to_utf8(f)); + if (!bfe.empty()) + nfe.push_back(f + " " + from_utf8(bfe)); + } + chng = true; + } + } + if (chng) { + if (!nfe.empty()) + setFileEncodings(nfe); + change_adaptor(); + } +} + + void GuiBibtex::on_editPB_clicked() { QModelIndexList selIdx = @@ -351,6 +398,8 @@ void GuiBibtex::updateContents() bibtocCB->setChecked((bibtotoc() && !bibtopic) || hasbibintoc); bibtocCB->setEnabled(!bibtopic && !hasbibintoc); + inheritPB->setEnabled(hasInherits()); + btPrintCO->clear(); btPrintCO->addItem(qt_("all cited references"), toqstr("btPrintCited")); if (bibtopic) diff --git a/src/frontends/qt/GuiBibtex.h b/src/frontends/qt/GuiBibtex.h index 2258ec9d16..5d54be7554 100644 --- a/src/frontends/qt/GuiBibtex.h +++ b/src/frontends/qt/GuiBibtex.h @@ -40,6 +40,7 @@ private Q_SLOTS: void on_buttonBox_accepted(); void browseBstPressed(); void browseBibPressed(); + void inheritPressed(); void on_editPB_clicked(); void databaseChanged(); void rescanClicked(); @@ -99,6 +100,8 @@ private: void dispatchParams() override; /// bool isBufferDependent() const override { return true; } + /// Is his a child which can inherit bibs from its master? + bool hasInherits(); private: /// diff --git a/src/frontends/qt/ui/BibtexUi.ui b/src/frontends/qt/ui/BibtexUi.ui index ac41646afd..ab2769d9ac 100644 --- a/src/frontends/qt/ui/BibtexUi.ui +++ b/src/frontends/qt/ui/BibtexUi.ui @@ -6,8 +6,8 @@ 0 0 - 523 - 617 + 542 + 702 @@ -85,6 +85,16 @@ + + + + Inherit bibliography databases from the master document + + + &Inherit from Master + + +