]> 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 04f23d554d24f2949fd8764c437ec00df67373ec..6d1c8c12a5056b4f97d0d4cc1a9210084e59f6fa 100644 (file)
@@ -18,6 +18,7 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "CiteEnginesList.h"
+#include "Encoding.h"
 #include "FuncRequest.h"
 #include "LyXRC.h"
 #include "qt_helpers.h"
@@ -38,6 +39,7 @@
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
+#include <QDialogButtonBox>
 #include <QPushButton>
 #include <QListWidget>
 #include <QCheckBox>
@@ -57,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()),
@@ -84,19 +85,19 @@ GuiBibtex::GuiBibtex(GuiView & lv)
                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 *)),
@@ -107,29 +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
@@ -349,14 +379,18 @@ void GuiBibtex::updateContents()
                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
-       styleCB->setVisible(!biblatex);
-       styleLA->setVisible(!biblatex);
-       stylePB->setVisible(!biblatex);
+       bstGB->setVisible(!biblatex);
 
        if (!biblatex) {
                styleCB->clear();
@@ -420,6 +454,8 @@ void GuiBibtex::applyView()
        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());
 }
 
 
@@ -431,7 +467,7 @@ 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 browseRelToParent(in_name, bufferFilePath(),
@@ -441,7 +477,7 @@ QString GuiBibtex::browseBib(QString const & in_name) const
 
 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 browseRelToParent(in_name, bufferFilePath(),
@@ -451,33 +487,33 @@ QString GuiBibtex::browseBst(QString const & in_name) const
 
 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;
 }
 
 
@@ -538,9 +574,9 @@ QString GuiBibtex::styleFile() const
 }
 
 
-bool GuiBibtex::initialiseParams(std::string const & data)
+bool GuiBibtex::initialiseParams(std::string const & sdata)
 {
-       InsetCommand::string2params(data, params_);
+       InsetCommand::string2params(sdata, params_);
        return true;
 }