]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiBibtex.cpp
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / GuiBibtex.cpp
index 7109bea2b185433b8eb85c2ed300df861b28a8a5..6d1c8c12a5056b4f97d0d4cc1a9210084e59f6fa 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "Buffer.h"
 #include "BufferParams.h"
+#include "CiteEnginesList.h"
+#include "Encoding.h"
 #include "FuncRequest.h"
 #include "LyXRC.h"
 #include "qt_helpers.h"
@@ -37,6 +39,7 @@
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
+#include <QDialogButtonBox>
 #include <QPushButton>
 #include <QListWidget>
 #include <QCheckBox>
@@ -56,11 +59,10 @@ GuiBibtex::GuiBibtex(GuiView & lv)
        setupUi(this);
 
        QDialog::setModal(true);
+       setWindowModality(Qt::WindowModal);
 
-       connect(okPB, SIGNAL(clicked()),
-               this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               this, SLOT(slotClose()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
        connect(stylePB, SIGNAL(clicked()),
                this, SLOT(browsePressed()));
        connect(deletePB, SIGNAL(clicked()),
@@ -81,19 +83,21 @@ GuiBibtex::GuiBibtex(GuiView & lv)
                this, SLOT(addPressed()));
        connect(rescanPB, SIGNAL(clicked()),
                this, SLOT(rescanClicked()));
+       connect(biblatexOptsLE, SIGNAL(textChanged(QString)),
+               this, SLOT(change_adaptor()));
+       connect(bibEncodingCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
 
        add_ = new GuiBibtexAddDialog(this);
        add_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
-       add_bc_.setOK(add_->addPB);
-       add_bc_.setCancel(add_->closePB);
+       add_bc_.setOK(add_->buttonBox->button(QDialogButtonBox::Ok));
+       add_bc_.setCancel(add_->buttonBox->button(QDialogButtonBox::Cancel));
        add_bc_.addCheckedLineEdit(add_->bibED, 0);
 
        connect(add_->bibED, SIGNAL(textChanged(QString)),
                this, SLOT(bibEDChanged()));
-       connect(add_->addPB, SIGNAL(clicked()),
-               this, SLOT(addDatabase()));
-       connect(add_->addPB, SIGNAL(clicked()),
-               add_, SLOT(accept()));
+       connect(add_->buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(addBBClicked(QAbstractButton *)));
        connect(add_->rescanPB, SIGNAL(clicked()),
                this, SLOT(rescanClicked()));
        connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
@@ -104,25 +108,58 @@ GuiBibtex::GuiBibtex(GuiView & lv)
                this, SLOT(availableChanged()));
        connect(add_->browsePB, SIGNAL(clicked()),
                this, SLOT(browseBibPressed()));
-       connect(add_->closePB, SIGNAL(clicked()),
-               add_, SLOT(reject()));
+
+       add_->bibLW->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. "
+                                   "If you want to reuse your own database, this is the place you should store it.")));
 
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setCancel(closePB);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
        bc().addReadOnly(databaseLW);
        bc().addReadOnly(stylePB);
        bc().addReadOnly(styleCB);
        bc().addReadOnly(bibtocCB);
        bc().addReadOnly(addBibPB);
+       bc().addReadOnly(bibEncodingCO);
        // Delete/Up/Down are handled with more conditions in
        // databaseChanged().
 
+       // Always put the default encoding in the first position.
+       bibEncodingCO->addItem(qt_("Document Encoding"), "default");
+       QMap<QString, QString> encodinglist;
+       for (auto const & encvar : encodings) {
+               if (!encvar.unsafe() && !encvar.guiName().empty())
+                       encodinglist.insert(qt_(encvar.guiName()), toqstr(encvar.name()));
+       }
+       QMap<QString, QString>::const_iterator it = encodinglist.constBegin();
+       while (it != encodinglist.constEnd()) {
+               bibEncodingCO->addItem(it.key(), it.value());
+               ++it;
+       }
+
        // Make sure the delete/up/down buttons are disabled if necessary.
        databaseChanged();
 }
 
 
+void GuiBibtex::addBBClicked(QAbstractButton * button)
+{
+       switch (add_->buttonBox->standardButton(button)) {
+       case QDialogButtonBox::Ok:
+               addDatabase();
+               add_->accept();
+               break;
+       case QDialogButtonBox::Cancel:
+               add_->reject();
+               break;
+       default:
+               break;
+       }
+}
+
+
 void GuiBibtex::bibEDChanged()
 {
        // Indicate to the button controller that the contents have
@@ -295,6 +332,12 @@ void GuiBibtex::availableChanged()
 void GuiBibtex::updateContents()
 {
        bool bibtopic = usingBibtopic();
+       bool biblatex = usingBiblatex();
+
+       if (biblatex)
+               setTitle(qt_("Biblatex Bibliography"));
+       else
+               setTitle(qt_("BibTeX Bibliography"));
 
        databaseLW->clear();
 
@@ -317,47 +360,63 @@ void GuiBibtex::updateContents()
        for (int i = 0; i != bibfiles.count(); ++i)
                add_->bibLW->addItem(changeExtension(bibfiles[i], ""));
 
-       QString bibstyle = styleFile();
+       QString const bibstyle = styleFile();
 
        bibtocCB->setChecked(bibtotoc() && !bibtopic);
        bibtocCB->setEnabled(!bibtopic);
 
-       if (!bibtopic && btPrintCO->count() == 3)
-               btPrintCO->removeItem(1);
-       else if (bibtopic && btPrintCO->count() < 3)
-               btPrintCO->insertItem(1, qt_("all uncited references", 0));
+       btPrintCO->clear();
+       btPrintCO->addItem(qt_("all cited references"), toqstr("btPrintCited"));
+       if (bibtopic)
+               btPrintCO->addItem(qt_("all uncited references"), toqstr("btPrintNotCited"));
+       btPrintCO->addItem(qt_("all references"), toqstr("btPrintAll"));
+       if (usingBiblatex() && !buffer().masterParams().multibib.empty())
+               btPrintCO->addItem(qt_("all reference units"), toqstr("bibbysection"));
 
        docstring btprint = params_["btprint"];
-       int btp = 0;
-       if ((bibtopic && btprint == "btPrintNotCited") ||
-          (!bibtopic && btprint == "btPrintAll"))
-               btp = 1;
-       else if (bibtopic && btprint == "btPrintAll")
-               btp = 2;
-
-       btPrintCO->setCurrentIndex(btp);
-
-       styleCB->clear();
-
-       int item_nr = -1;
+       if (btprint.empty())
+               // default
+               btprint = from_ascii("btPrintCited");
+       btPrintCO->setCurrentIndex(btPrintCO->findData(toqstr(btprint)));
+
+       docstring encoding = params_["encoding"];
+       if (encoding.empty())
+               // default
+               encoding = from_ascii("default");
+       bibEncodingCO->setCurrentIndex(bibEncodingCO->findData(toqstr(encoding)));
+
+       // Only useful for biblatex
+       biblatexOptsLA->setVisible(biblatex);
+       biblatexOptsLE->setVisible(biblatex);
+
+       // only useful for BibTeX
+       bstGB->setVisible(!biblatex);
+
+       if (!biblatex) {
+               styleCB->clear();
+
+               int item_nr = -1;
+
+               QStringList const str = bibStyles();
+               for (int i = 0; i != str.count(); ++i) {
+                       QString item = changeExtension(str[i], "");
+                       if (item == bibstyle)
+                               item_nr = i;
+                       styleCB->addItem(item);
+               }
 
-       QStringList str = bibStyles();
-       for (int i = 0; i != str.count(); ++i) {
-               QString item = changeExtension(str[i], "");
-               if (item == bibstyle)
-                       item_nr = i;
-               styleCB->addItem(item);
-       }
+               if (item_nr == -1 && !bibstyle.isEmpty()) {
+                       styleCB->addItem(bibstyle);
+                       item_nr = styleCB->count() - 1;
+               }
 
-       if (item_nr == -1 && !bibstyle.isEmpty()) {
-               styleCB->addItem(bibstyle);
-               item_nr = styleCB->count() - 1;
-       }
 
-       if (item_nr != -1)
-               styleCB->setCurrentIndex(item_nr);
-       else
-               styleCB->clearEditText();
+               if (item_nr != -1)
+                       styleCB->setCurrentIndex(item_nr);
+               else
+                       styleCB->clearEditText();
+       } else
+               biblatexOptsLE->setText(toqstr(params_["biblatexopts"]));
 }
 
 
@@ -392,35 +451,11 @@ void GuiBibtex::applyView()
                params_["options"] = bibstyle;
        }
 
-       int btp = btPrintCO->currentIndex();
-
-       if (usingBibtopic()) {
-               // bibtopic allows three kinds of sections:
-               // 1. sections that include all cited references of the database(s)
-               // 2. sections that include all uncited references of the database(s)
-               // 3. sections that include all references of the database(s), cited or not
-               switch (btp) {
-               case 0:
-                       params_["btprint"] = from_ascii("btPrintCited");
-                       break;
-               case 1:
-                       params_["btprint"] = from_ascii("btPrintNotCited");
-                       break;
-               case 2:
-                       params_["btprint"] = from_ascii("btPrintAll");
-                       break;
-               }
-       } else {
-               switch (btp) {
-               case 0:
-                       params_["btprint"] = docstring();
-                       break;
-               case 1:
-                       // use \nocite{*}
-                       params_["btprint"] = from_ascii("btPrintAll");
-                       break;
-               }               
-       }
+       params_["biblatexopts"] = qstring_to_ucs4(biblatexOptsLE->text());
+
+       params_["btprint"] = qstring_to_ucs4(btPrintCO->itemData(btPrintCO->currentIndex()).toString());
+
+       params_["encoding"] = qstring_to_ucs4(bibEncodingCO->itemData(bibEncodingCO->currentIndex()).toString());
 }
 
 
@@ -432,65 +467,68 @@ bool GuiBibtex::isValid()
 
 QString GuiBibtex::browseBib(QString const & in_name) const
 {
-       QString const label1 = qt_("Documents|#o#O");
+       QString const label1 = qt_("D&ocuments");
        QString const dir1 = toqstr(lyxrc.document_path);
        QStringList const filter(qt_("BibTeX Databases (*.bib)"));
-       return browseRelFile(in_name, bufferFilePath(),
+       return browseRelToParent(in_name, bufferFilePath(),
                qt_("Select a BibTeX database to add"), filter, false, label1, dir1);
 }
 
 
 QString GuiBibtex::browseBst(QString const & in_name) const
 {
-       QString const label1 = qt_("Documents|#o#O");
+       QString const label1 = qt_("D&ocuments");
        QString const dir1 = toqstr(lyxrc.document_path);
        QStringList const filter(qt_("BibTeX Styles (*.bst)"));
-       return browseRelFile(in_name, bufferFilePath(),
+       return browseRelToParent(in_name, bufferFilePath(),
                qt_("Select a BibTeX style"), filter, false, label1, dir1);
 }
 
 
 QStringList GuiBibtex::bibStyles() const
 {
-       QStringList data = texFileList("bstFiles.lst");
+       QStringList sdata = texFileList("bstFiles.lst");
        // test whether we have a valid list, otherwise run rescan
-       if (data.isEmpty()) {
+       if (sdata.isEmpty()) {
                rescanBibStyles();
-               data = texFileList("bstFiles.lst");
+               sdata = texFileList("bstFiles.lst");
        }
-       for (int i = 0; i != data.size(); ++i)
-               data[i] = onlyFileName(data[i]);
+       for (int i = 0; i != sdata.size(); ++i)
+               sdata[i] = onlyFileName(sdata[i]);
        // sort on filename only (no path)
-       data.sort();
-       return data;
+       sdata.sort();
+       return sdata;
 }
 
 
 QStringList GuiBibtex::bibFiles() const
 {
-       QStringList data = texFileList("bibFiles.lst");
+       QStringList sdata = texFileList("bibFiles.lst");
        // test whether we have a valid list, otherwise run rescan
-       if (data.isEmpty()) {
+       if (sdata.isEmpty()) {
                rescanBibStyles();
-               data = texFileList("bibFiles.lst");
+               sdata = texFileList("bibFiles.lst");
        }
-       for (int i = 0; i != data.size(); ++i)
-               data[i] = onlyFileName(data[i]);
+       for (int i = 0; i != sdata.size(); ++i)
+               sdata[i] = onlyFileName(sdata[i]);
        // sort on filename only (no path)
-       data.sort();
-       return data;
+       sdata.sort();
+       return sdata;
 }
 
 
 void GuiBibtex::rescanBibStyles() const
 {
-       rescanTexStyles();
+       if (usingBiblatex())
+               rescanTexStyles("bib");
+       else
+               rescanTexStyles("bst bib");
 }
 
 
 bool GuiBibtex::usingBibtopic() const
 {
-       return buffer().params().use_bibtopic;
+       return buffer().params().useBibtopic();
 }
 
 
@@ -500,26 +538,17 @@ bool GuiBibtex::bibtotoc() const
 }
 
 
+bool GuiBibtex::usingBiblatex() const
+{
+       return buffer().masterBuffer()->params().useBiblatex();
+}
+
+
 QString GuiBibtex::styleFile() const
 {
        // the different bibtex packages have (and need) their
        // own "plain" stylefiles
-       CiteEngine const engine = buffer().params().citeEngine();
-       QString defaultstyle;
-       switch (engine) {
-       case ENGINE_BASIC:
-               defaultstyle = "plain";
-               break;
-       case ENGINE_NATBIB_AUTHORYEAR:
-               defaultstyle = "plainnat";
-               break;
-       case ENGINE_NATBIB_NUMERICAL:
-               defaultstyle = "plainnat";
-               break;
-       case ENGINE_JURABIB:
-               defaultstyle = "jurabib";
-               break;
-       }
+       QString defaultstyle = toqstr(buffer().params().defaultBiblioStyle());
 
        QString bst = toqstr(params_["options"]);
        if (bibtotoc()){
@@ -545,16 +574,16 @@ QString GuiBibtex::styleFile() const
 }
 
 
-bool GuiBibtex::initialiseParams(std::string const & data)
+bool GuiBibtex::initialiseParams(std::string const & sdata)
 {
-       InsetCommand::string2params("bibtex", data, params_);
+       InsetCommand::string2params(sdata, params_);
        return true;
 }
 
 
 void GuiBibtex::dispatchParams()
 {
-       std::string const lfun = InsetCommand::params2string("bibtex", params_);
+       std::string const lfun = InsetCommand::params2string(params_);
        dispatch(FuncRequest(getLfun(), lfun));
 }