]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiBibtex.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiBibtex.cpp
index 3b78e406a79a45a76ff3fcf2b6cce4fe2189f925..8680a384d286e96c63dd92f456788b606d86a933 100644 (file)
@@ -4,9 +4,9 @@
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
- * \author Herbert Voß
+ * \author Herbert Voß
  * \author Angus Leeming
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "Buffer.h"
 #include "BufferParams.h"
+#include "CiteEnginesList.h"
+#include "Encoding.h"
 #include "FuncRequest.h"
+#include "GuiApplication.h"
 #include "LyXRC.h"
 #include "qt_helpers.h"
 #include "Validator.h"
 
-#include "ui_BibtexAddUi.h"
-
 #include "ButtonPolicy.h"
 
 #include "frontends/alert.h"
@@ -37,6 +38,7 @@
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
+#include <QDialogButtonBox>
 #include <QPushButton>
 #include <QListWidget>
 #include <QCheckBox>
@@ -56,85 +58,147 @@ GuiBibtex::GuiBibtex(GuiView & lv)
        setupUi(this);
 
        QDialog::setModal(true);
+       setWindowModality(Qt::WindowModal);
+
+       // 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_->setPlaceholderText(qt_("All avail. databases"));
 
-       connect(okPB, SIGNAL(clicked()),
-               this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               this, SLOT(slotClose()));
+       filterBarL->addWidget(filter_, 0);
+       findKeysLA->setBuddy(filter_);
+
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
        connect(stylePB, SIGNAL(clicked()),
-               this, SLOT(browsePressed()));
-       connect(deletePB, SIGNAL(clicked()),
-               this, SLOT(deletePressed()));
-       connect(upPB, SIGNAL(clicked()),
-               this, SLOT(upPressed()));
-       connect(downPB, SIGNAL(clicked()),
-               this, SLOT(downPressed()));
+               this, SLOT(browseBstPressed()));
        connect(styleCB, SIGNAL(editTextChanged(QString)),
                this, SLOT(change_adaptor()));
-       connect(databaseLW, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
-               this, SLOT(databaseChanged()));
        connect(bibtocCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
        connect(btPrintCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
-       connect(addBibPB, SIGNAL(clicked()),
-               this, SLOT(addPressed()));
-
-       add_ = new GuiBibtexAddDialog(this);
-       add_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
-       add_bc_.setOK(add_->addPB);
-       add_bc_.setCancel(add_->closePB);
-       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_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
-               this, SLOT(addDatabase()));
-       connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
-               add_, SLOT(accept()));
-       connect(add_->bibLW, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
-               this, SLOT(availableChanged()));
-       connect(add_->browsePB, SIGNAL(clicked()),
+       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()));
+       connect(browseBibPB, SIGNAL(clicked()),
                this, SLOT(browseBibPressed()));
-       connect(add_->closePB, SIGNAL(clicked()),
-               add_, SLOT(reject()));
+
+       selected_model_.insertColumns(0, 1);
+       selectionManager = new GuiSelectionManager(this, availableLV, selectedLV,
+                       addBibPB, deletePB, upPB, downPB, &available_model_, &selected_model_);
+       connect(selectionManager, SIGNAL(selectionChanged()),
+               this, SLOT(databaseChanged()));
+       connect(selectionManager, SIGNAL(updateHook()),
+               this, SLOT(selUpdated()));
+       connect(selectionManager, SIGNAL(okHook()),
+               this, SLOT(on_buttonBox_accepted()));
+
+       connect(filter_, SIGNAL(rightButtonClicked()),
+               this, SLOT(resetFilter()));
+       connect(filter_, SIGNAL(textEdited(QString)),
+               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->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().addReadOnly(databaseLW);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
        bc().addReadOnly(stylePB);
        bc().addReadOnly(styleCB);
        bc().addReadOnly(bibtocCB);
-       bc().addReadOnly(addBibPB);
-       // Delete/Up/Down are handled with more conditions in
-       // databaseChanged().
+       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");
+       for (auto const & encvar : encodings) {
+               if (!encvar.unsafe() && !encvar.guiName().empty())
+                       encodings_.insert(qt_(encvar.guiName()), toqstr(encvar.name()));
+       }
+       QMap<QString, QString>::const_iterator it = encodings_.constBegin();
+       while (it != encodings_.constEnd()) {
+               bibEncodingCO->addItem(it.key(), it.value());
+               ++it;
+       }
 
-       // Make sure the delete/up/down buttons are disabled if necessary.
-       databaseChanged();
+       setFocusProxy(filter_);
 }
 
 
-void GuiBibtex::bibEDChanged()
+void GuiBibtex::init()
 {
-       // Indicate to the button controller that the contents have
-       // changed. The actual test of validity is carried out by
-       // the checkedLineEdit.
-       add_bc_.setValid(true);
+       all_bibs_ = bibFiles(false);
+       available_model_.setStringList(all_bibs_);
+
+       QString bibs = toqstr(params_["bibfiles"]);
+       if (bibs.isEmpty())
+               selected_bibs_.clear();
+       else
+               selected_bibs_ = bibs.split(",");
+       setSelectedBibs(selected_bibs_);
+
+       buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
+       buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+       selectionManager->update();
 }
 
 
 void GuiBibtex::change_adaptor()
 {
+       setButtons();
+       changed();
+}
+
+
+void GuiBibtex::setButtons()
+{
+       int const srows = selectedLV->model()->rowCount();
+       buttonBox->button(QDialogButtonBox::Apply)->setEnabled(srows > 0);
+       buttonBox->button(QDialogButtonBox::Ok)->setEnabled(srows > 0);
+}
+
+
+void GuiBibtex::selUpdated()
+{
+       selectionManager->update();
+       editPB->setEnabled(deletePB->isEnabled());
        changed();
 }
 
 
-void GuiBibtex::browsePressed()
+void GuiBibtex::on_buttonBox_accepted()
+{
+       applyView();
+       clearSelection();
+       hide();
+}
+
+
+void GuiBibtex::browseBstPressed()
 {
        QString const file = browseBst(QString());
 
@@ -143,7 +207,7 @@ void GuiBibtex::browsePressed()
 
        QString const filen = changeExtension(file, "");
        bool present = false;
-       unsigned int pres = 0;
+       int pres = 0;
 
        for (int i = 0; i != styleCB->count(); ++i) {
                if (styleCB->itemText(i) == filen) {
@@ -168,185 +232,178 @@ void GuiBibtex::browseBibPressed()
                return;
 
        QString const f = changeExtension(file, "");
-       bool present = false;
-
-       for (int i = 0; i < add_->bibLW->count(); ++i) {
-               if (add_->bibLW->item(i)->text() == f)
-                       present = true;
-       }
 
-       if (!present) {
-               add_->bibLW->addItem(f);
+       if (!selected_bibs_.contains(f)) {
+               selected_bibs_.append(f);
+               setSelectedBibs(selected_bibs_);
                changed();
        }
-
-       add_->bibED->setText(f);
-}
-
-
-void GuiBibtex::addPressed()
-{
-       add_bc_.setValid(false);
-       add_->exec();
 }
 
 
-void GuiBibtex::addDatabase()
+void GuiBibtex::on_editPB_clicked()
 {
-       int const sel = add_->bibLW->currentRow();
-       QString const file = add_->bibED->text().trimmed();
-
-       if (sel < 0 && file.isEmpty())
+       QModelIndexList selIdx =
+               selectedLV->selectionModel()->selectedIndexes();
+       if (selIdx.isEmpty())
                return;
-
-       // Add the selected browser_bib keys to browser_database
-       // multiple selections are possible
-       for (int i = 0; i != add_->bibLW->count(); ++i) {
-               QListWidgetItem * const item = add_->bibLW->item(i);
-               if (add_->bibLW->isItemSelected(item)) {
-                       add_->bibLW->setItemSelected(item, false);
-                       QList<QListWidgetItem *> matches =
-                               databaseLW->findItems(item->text(), Qt::MatchExactly);
-                       if (matches.empty()) {
-                               QString label = item->text();
-                               QListWidgetItem * db = new QListWidgetItem(label);
-                               db->setFlags(db->flags() | Qt::ItemIsSelectable);
-                               databaseLW->addItem(db);
-                       }
-               }
-       }
-
-       if (!file.isEmpty()) {
-               add_->bibED->clear();
-               QString const f = changeExtension(file, "");
-               QList<QListWidgetItem *> matches =
-                       databaseLW->findItems(f, Qt::MatchExactly);
-               if (matches.empty()) {
-                       QListWidgetItem * db = new QListWidgetItem(f);
-                       db->setFlags(db->flags() | Qt::ItemIsSelectable);
-                       databaseLW->addItem(db);
-               }
-       }
-
-       databaseChanged();
-       changed();
+       QModelIndex idx = selIdx.first();
+       QString sel = idx.data().toString();
+       FuncRequest fr(LFUN_INSET_EDIT, fromqstr(sel));
+       dispatch(fr);
 }
 
 
-void GuiBibtex::deletePressed()
+void GuiBibtex::rescanClicked()
 {
-       QListWidgetItem *cur = databaseLW->takeItem(databaseLW->currentRow());
-       if (cur) {
-               delete cur;
-               databaseChanged();
-               changed();
-       }
+       rescanBibStyles();
+       updateContents();
 }
 
 
-void GuiBibtex::upPressed()
+void GuiBibtex::clearSelection()
 {
-       int row = databaseLW->currentRow();
-       QListWidgetItem *cur = databaseLW->takeItem(row);
-       databaseLW->insertItem(row - 1, cur);
-       databaseLW->setCurrentItem(cur);
-       changed();
+       selected_bibs_.clear();
+       setSelectedBibs(selected_bibs_);
 }
 
 
-void GuiBibtex::downPressed()
+void GuiBibtex::setSelectedBibs(QStringList const sl)
 {
-       int row = databaseLW->currentRow();
-       QListWidgetItem *cur = databaseLW->takeItem(row);
-       databaseLW->insertItem(row + 1, cur);
-       databaseLW->setCurrentItem(cur);
-       changed();
+       selected_model_.clear();
+       QStringList headers;
+       headers << qt_("Database")
+               << qt_("File Encoding");
+       selected_model_.setHorizontalHeaderLabels(headers);
+       bool const moreencs = usingBiblatex() && sl.count() > 1;
+       selectedLV->setColumnHidden(1, !moreencs);
+       selectedLV->verticalHeader()->setVisible(false);
+       selectedLV->horizontalHeader()->setVisible(moreencs);
+       if (moreencs) {
+               bibEncodingLA->setText(qt_("General E&ncoding:"));
+               bibEncodingCO->setToolTip(qt_("If your bibliography databases use a different "
+                                             "encoding than the LyX document, specify it here. "
+                                             "If indivivual databases have different encodings, "
+                                             "you can set it in the list above."));
+       } else {
+               bibEncodingLA->setText(qt_("E&ncoding:"));
+               bibEncodingCO->setToolTip(qt_("If your bibliography databases use a different "
+                                             "encoding than the LyX document, specify it here"));
+       }
+       QStringList::const_iterator it  = sl.begin();
+       QStringList::const_iterator end = sl.end();
+       for (int i = 0; it != end; ++it, ++i) {
+               QStandardItem * si = new QStandardItem();
+               si->setData(*it);
+               si->setText(*it);
+               si->setToolTip(*it);
+               si->setEditable(false);
+               selected_model_.insertRow(i, si);
+               QComboBox * cb = new QComboBox;
+               cb->addItem(qt_("General Encoding"), "general");
+               cb->addItem(qt_("Document Encoding"), "auto");
+               QMap<QString, QString>::const_iterator it = encodings_.constBegin();
+               while (it != encodings_.constEnd()) {
+                       cb->addItem(it.key(), it.value());
+                       ++it;
+               }
+               cb->setToolTip(qt_("If this bibliography database uses a different "
+                                  "encoding than specified below, set it here"));
+               selectedLV->setIndexWidget(selected_model_.index(i, 1), cb);
+       }
+       editPB->setEnabled(deletePB->isEnabled());
 }
 
 
-void GuiBibtex::databaseChanged()
+QStringList GuiBibtex::selectedBibs()
 {
-       bool readOnly = isBufferReadonly();
-       int count = databaseLW->count();
-       int row = databaseLW->currentRow();
-       deletePB->setEnabled(!readOnly && row != -1);
-       upPB->setEnabled(!readOnly && count > 1 && row > 0);
-       downPB->setEnabled(!readOnly && count > 1 && row < count - 1);
+       QStringList res;
+       for (int i = 0; i != selected_model_.rowCount(); ++i) {
+               QStandardItem const * item = selected_model_.item(i);
+               if (item)
+                       res.append(item->text());
+       }
+       return res;
 }
 
 
-void GuiBibtex::availableChanged()
+void GuiBibtex::databaseChanged()
 {
-       add_bc_.setValid(true);
+       selected_bibs_ = selectedBibs();
+       setSelectedBibs(selected_bibs_);
 }
 
 
 void GuiBibtex::updateContents()
 {
        bool bibtopic = usingBibtopic();
+       bool biblatex = usingBiblatex();
 
-       databaseLW->clear();
-
-       docstring bibs = params_["bibfiles"];
-       docstring bib;
-
-       while (!bibs.empty()) {
-               bibs = split(bibs, bib, ',');
-               bib = trim(bib);
-               if (!bib.empty()) {
-                       QListWidgetItem * db = new QListWidgetItem(toqstr(bib));
-                       db->setFlags(db->flags() | Qt::ItemIsSelectable);
-                       databaseLW->addItem(db);
-               }
-       }
-
-       add_->bibLW->clear();
-
-       QStringList bibfiles = bibFiles();
-       for (int i = 0; i != bibfiles.count(); ++i)
-               add_->bibLW->addItem(changeExtension(bibfiles[i], ""));
+       if (biblatex)
+               setTitle(qt_("Biblatex Bibliography"));
+       else
+               setTitle(qt_("BibTeX Bibliography"));
 
-       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);
+       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);
+               }
 
-       styleCB->clear();
+               if (item_nr == -1 && !bibstyle.isEmpty()) {
+                       styleCB->addItem(bibstyle);
+                       item_nr = styleCB->count() - 1;
+               }
 
-       int item_nr = -1;
 
-       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)
+                       styleCB->setCurrentIndex(item_nr);
+               else
+                       styleCB->clearEditText();
+       } else
+               biblatexOptsLE->setText(toqstr(params_["biblatexopts"]));
 
-       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();
+       setFileEncodings(getVectorFromString(params_["file_encodings"], from_ascii("\t")));
+       editPB->setEnabled(deletePB->isEnabled());
 }
 
 
@@ -354,11 +411,11 @@ void GuiBibtex::applyView()
 {
        docstring dbs;
 
-       unsigned int maxCount = databaseLW->count();
-       for (unsigned int i = 0; i < maxCount; i++) {
+       int maxCount = selected_bibs_.count();
+       for (int i = 0; i < maxCount; i++) {
                if (i != 0)
                        dbs += ',';
-               QString item = databaseLW->item(i)->text();
+               QString item = selected_bibs_.at(i);
                docstring bibfile = qstring_to_ucs4(item);
                dbs += bibfile;
        }
@@ -381,105 +438,145 @@ 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());
 
-bool GuiBibtex::isValid()
-{
-       return databaseLW->count() != 0;
+       params_["encoding"] = qstring_to_ucs4(bibEncodingCO->itemData(bibEncodingCO->currentIndex()).toString());
+
+       if (usingBiblatex())
+               params_["file_encodings"] = getStringFromVector(getFileEncodings(), from_ascii("\t"));
 }
 
 
 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 GuiBibtex::bibFiles(bool const extension) 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] = extension ? onlyFileName(sdata[i])
+                                    : changeExtension(onlyFileName(sdata[i]), "");
        // sort on filename only (no path)
-       data.sort();
-       return data;
+       sdata.sort();
+       return sdata;
+}
+
+
+vector<docstring> GuiBibtex::getFileEncodings()
+{
+       vector<docstring> res;
+       for (int i = 0; i != selected_model_.rowCount(); ++i) {
+               QStandardItem const * key = selected_model_.item(i, 0);
+               QComboBox * cb = qobject_cast<QComboBox*>(selectedLV->indexWidget(selected_model_.index(i, 1)));
+               QString fenc = cb ? cb->itemData(cb->currentIndex()).toString() : QString();
+               if (key && !key->text().isEmpty() && !fenc.isEmpty() && fenc != "general")
+                       res.push_back(qstring_to_ucs4(key->text()) + " " + qstring_to_ucs4(fenc));
+       }
+       return res;
+}
+
+
+void GuiBibtex::setFileEncodings(vector<docstring> const m)
+{
+       for (docstring const & s: m) {
+               docstring key;
+               QString enc = toqstr(split(s, key, ' '));
+               QModelIndexList qmil =
+                               selected_model_.match(selected_model_.index(0, 0),
+                                                    Qt::DisplayRole, toqstr(key), 1,
+                                                    Qt::MatchFlags(Qt::MatchExactly | Qt::MatchWrap));
+               if (!qmil.empty()) {
+                       QComboBox * cb = qobject_cast<QComboBox*>(selectedLV->indexWidget(selected_model_.index(qmil.front().row(), 1)));
+                       cb->setCurrentIndex(cb->findData(enc));
+               }
+       }
 }
 
 
 void GuiBibtex::rescanBibStyles() const
 {
-       rescanTexStyles();
+       if (usingBiblatex())
+               rescanTexStyles("bib");
+       else
+               rescanTexStyles("bst bib");
+}
+
+
+void GuiBibtex::findText(QString const & text)
+{
+       QStringList const result = bibFiles(false).filter(text);
+       available_model_.setStringList(result);
+}
+
+
+void GuiBibtex::filterChanged(const QString & text)
+{
+       if (!text.isEmpty()) {
+               findText(filter_->text());
+               return;
+       }
+       findText(filter_->text());
+       filter_->setFocus();
+}
+
+
+void GuiBibtex::filterPressed()
+{
+       findText(filter_->text());
+}
+
+
+void GuiBibtex::resetFilter()
+{
+       filter_->setText(QString());
+       findText(filter_->text());
 }
 
 
+
 bool GuiBibtex::usingBibtopic() const
 {
-       return buffer().params().use_bibtopic;
+       return buffer().params().useBibtopic();
 }
 
 
@@ -489,26 +586,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()){
@@ -534,25 +622,25 @@ 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_);
+       init();
        return true;
 }
 
 
 void GuiBibtex::dispatchParams()
 {
-       std::string const lfun = InsetCommand::params2string("bibtex", params_);
+       std::string const lfun = InsetCommand::params2string(params_);
        dispatch(FuncRequest(getLfun(), lfun));
 }
 
 
-
 Dialog * createGuiBibtex(GuiView & lv) { return new GuiBibtex(lv); }
 
 
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiBibtex_moc.cpp"
+#include "moc_GuiBibtex.cpp"