]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiBibtex.cpp
amend d4f58c96b5d
[lyx.git] / src / frontends / qt / GuiBibtex.cpp
index 897224cfeea35390976ef80a2e136a45bf8ffdda..757c2c95e4094a0863a11bf6f8a6cd5dc0225842 100644 (file)
 #include "Validator.h"
 
 #include "ButtonPolicy.h"
+#include "FancyLineEdit.h"
 
 #include "frontends/alert.h"
 
 #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
@@ -63,10 +65,7 @@ GuiBibtex::GuiBibtex(GuiView & lv)
 
        // The filter bar
        filter_ = new FancyLineEdit(this);
-       filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
-       filter_->setButtonVisible(FancyLineEdit::Right, true);
-       filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
-       filter_->setAutoHideButton(FancyLineEdit::Right, true);
+       filter_->setClearButton(true);
        filter_->setPlaceholderText(qt_("All avail. databases"));
 
        filterBarL->addWidget(filter_, 0);
@@ -90,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,
@@ -107,13 +108,8 @@ GuiBibtex::GuiBibtex(GuiView & lv)
                this, SLOT(filterChanged(QString)));
        connect(filter_, SIGNAL(returnPressed()),
                this, SLOT(filterPressed()));
-#if (QT_VERSION < 0x050000)
-       connect(filter_, SIGNAL(downPressed()),
-               availableLV, SLOT(setFocus()));
-#else
        connect(filter_, &FancyLineEdit::downPressed,
-               availableLV, [=](){ focusAndHighlight(availableLV); });
-#endif
+               availableLV, [this](){ focusAndHighlight(availableLV); });
 
        availableLV->setToolTip(formatToolTip(qt_("This list consists of all databases that are indexed by LaTeX and thus are found without a file path. "
                                    "This is usually everything in the bib/ subdirectory of LaTeX's texmf tree. "
@@ -128,11 +124,7 @@ GuiBibtex::GuiBibtex(GuiView & lv)
        bc().addReadOnly(bibtocCB);
        bc().addReadOnly(bibEncodingCO);
 
-#if (QT_VERSION < 0x050000)
-       selectedLV->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
-#else
        selectedLV->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
-#endif
 
        // Always put the default encoding in the first position.
        bibEncodingCO->addItem(qt_("Document Encoding"), "default");
@@ -180,6 +172,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());
 }
 
 
@@ -242,6 +235,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<docstring> 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 =
@@ -269,7 +305,7 @@ void GuiBibtex::clearSelection()
 }
 
 
-void GuiBibtex::setSelectedBibs(QStringList const sl)
+void GuiBibtex::setSelectedBibs(QStringList const sl)
 {
        selected_model_.clear();
        QStringList headers;
@@ -353,6 +389,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)
@@ -453,7 +491,7 @@ void GuiBibtex::applyView()
 }
 
 
-QString GuiBibtex::browseBib(QString const & in_name) const
+QString GuiBibtex::browseBib(QString const & in_name)
 {
        QString const label1 = qt_("D&ocuments");
        QString const dir1 = toqstr(lyxrc.document_path);
@@ -463,7 +501,7 @@ QString GuiBibtex::browseBib(QString const & in_name) const
 }
 
 
-QString GuiBibtex::browseBst(QString const & in_name) const
+QString GuiBibtex::browseBst(QString const & in_name)
 {
        QString const label1 = qt_("D&ocuments");
        QString const dir1 = toqstr(lyxrc.document_path);
@@ -638,12 +676,10 @@ void GuiBibtex::dispatchParams()
 {
        std::string const lfun = InsetCommand::params2string(params_);
        dispatch(FuncRequest(getLfun(), lfun));
+       connectToNewInset();
 }
 
 
-Dialog * createGuiBibtex(GuiView & lv) { return new GuiBibtex(lv); }
-
-
 } // namespace frontend
 } // namespace lyx