]> 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 b92bc8cbdc3cc0dddf2186d32b9a8ae1b78d7de6..6d1c8c12a5056b4f97d0d4cc1a9210084e59f6fa 100644 (file)
@@ -4,8 +4,9 @@
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
- * \author Herbert Voß
- * \author Jürgen Spitzmüller
+ * \author Herbert Voß
+ * \author Angus Leeming
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "GuiBibtex.h"
 
-#include "ui_BibtexAddUi.h"
-#include "Qt2BC.h"
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "CiteEnginesList.h"
+#include "Encoding.h"
+#include "FuncRequest.h"
+#include "LyXRC.h"
 #include "qt_helpers.h"
 #include "Validator.h"
-#include "LyXRC.h"
-#include "CheckedLineEdit.h"
 
-#include "controllers/ControlBibtex.h"
-#include "controllers/ButtonPolicy.h"
+#include "ui_BibtexAddUi.h"
+
+#include "ButtonPolicy.h"
+
+#include "frontends/alert.h"
 
+#include "insets/InsetBibtex.h"
+
+#include "support/debug.h"
+#include "support/ExceptionMessage.h"
+#include "support/FileName.h"
 #include "support/filetools.h" // changeExtension
+#include "support/gettext.h"
 #include "support/lstrings.h"
 
+#include <QDialogButtonBox>
 #include <QPushButton>
 #include <QListWidget>
 #include <QCheckBox>
-#include <QCloseEvent>
 #include <QLineEdit>
 
-#include "debug.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
-
-using std::vector;
-using std::string;
-
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
 
-using support::changeExtension;
-using support::split;
-using support::trim;
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// GuiBibtexDialog
-//
-/////////////////////////////////////////////////////////////////////
 
-GuiBibtexDialog::GuiBibtexDialog(GuiBibtex * form)
-       : form_(form)
+GuiBibtex::GuiBibtex(GuiView & lv)
+       : GuiDialog(lv, "bibtex", qt_("BibTeX Bibliography")),
+         params_(insetCode("bibtex"))
 {
        setupUi(this);
+
        QDialog::setModal(true);
+       setWindowModality(Qt::WindowModal);
 
-       connect(okPB, SIGNAL(clicked()),
-               form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
        connect(stylePB, SIGNAL(clicked()),
                this, SLOT(browsePressed()));
        connect(deletePB, SIGNAL(clicked()),
                this, SLOT(deletePressed()));
-       connect(styleCB, SIGNAL(editTextChanged (const QString &)),
+       connect(upPB, SIGNAL(clicked()),
+               this, SLOT(upPressed()));
+       connect(downPB, SIGNAL(clicked()),
+               this, SLOT(downPressed()));
+       connect(styleCB, SIGNAL(editTextChanged(QString)),
                this, SLOT(change_adaptor()));
-       connect(databaseLW, SIGNAL(itemSelectionChanged()),
+       connect(databaseLW, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
                this, SLOT(databaseChanged()));
        connect(bibtocCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
@@ -79,116 +81,163 @@ GuiBibtexDialog::GuiBibtexDialog(GuiBibtex * form)
                this, SLOT(change_adaptor()));
        connect(addBibPB, SIGNAL(clicked()),
                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 UiDialog<Ui::BibtexAddUi>(this, true);
-
-       Qt2BC * bcview = new Qt2BC(add_bc_);
-       add_bc_.view(bcview);
+       add_ = new GuiBibtexAddDialog(this);
        add_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
+       add_bc_.setOK(add_->buttonBox->button(QDialogButtonBox::Ok));
+       add_bc_.setCancel(add_->buttonBox->button(QDialogButtonBox::Cancel));
+       add_bc_.addCheckedLineEdit(add_->bibED, 0);
 
-       bcview->setOK(add_->addPB);
-       bcview->setCancel(add_->closePB);
-
-       addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
-
-       connect(add_->bibED, SIGNAL(textChanged(const QString &)),
+       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 *)),
                this, SLOT(addDatabase()));
        connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
                add_, SLOT(accept()));
-       connect(add_->bibLW, SIGNAL(itemSelectionChanged()),
+       connect(add_->bibLW, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
                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(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 GuiBibtexDialog::bibEDChanged()
+void GuiBibtex::bibEDChanged()
 {
        // Indicate to the button controller that the contents have
        // changed. The actual test of validity is carried out by
        // the checkedLineEdit.
-       add_bc_.valid(true);
+       add_bc_.setValid(true);
 }
 
 
-void GuiBibtexDialog::change_adaptor()
+void GuiBibtex::change_adaptor()
 {
-       form_->changed();
+       changed();
 }
 
 
-void GuiBibtexDialog::browsePressed()
+void GuiBibtex::browsePressed()
 {
-       docstring const file = form_->controller().browseBst(docstring());
-
-       if (!file.empty()) {
-               // FIXME UNICODE
-               docstring const filen = from_utf8(changeExtension(to_utf8(file), ""));
-               bool present = false;
-               unsigned int pres = 0;
-
-               for (int i = 0; i != styleCB->count(); ++i) {
-                       if (qstring_to_ucs4(styleCB->itemText(i)) == filen) {
-                               present = true;
-                               pres = i;
-                       }
-               }
+       QString const file = browseBst(QString());
+
+       if (file.isEmpty())
+               return;
 
-               if (!present)
-                       styleCB->insertItem(0, toqstr(filen));
+       QString const filen = changeExtension(file, "");
+       bool present = false;
+       unsigned int pres = 0;
 
-               styleCB->setCurrentIndex(pres);
-               form_->changed();
+       for (int i = 0; i != styleCB->count(); ++i) {
+               if (styleCB->itemText(i) == filen) {
+                       present = true;
+                       pres = i;
+               }
        }
+
+       if (!present)
+               styleCB->insertItem(0, filen);
+
+       styleCB->setCurrentIndex(pres);
+       changed();
 }
 
 
-void GuiBibtexDialog::browseBibPressed()
+void GuiBibtex::browseBibPressed()
 {
-       docstring const file = trim(form_->controller().browseBib(docstring()));
+       QString const file = browseBib(QString()).trimmed();
 
-       if (!file.empty()) {
-               // FIXME UNICODE
-               QString const f = toqstr(changeExtension(to_utf8(file), ""));
-               bool present = false;
+       if (file.isEmpty())
+               return;
 
-               for (int i = 0; i < add_->bibLW->count(); ++i) {
-                       if (add_->bibLW->item(i)->text() == f)
-                               present = true;
-               }
+       QString const f = changeExtension(file, "");
+       bool present = false;
 
-               if (!present) {
-                       add_->bibLW->addItem(f);
-                       form_->changed();
-               }
+       for (int i = 0; i < add_->bibLW->count(); ++i) {
+               if (add_->bibLW->item(i)->text() == f)
+                       present = true;
+       }
 
-               add_->bibED->setText(f);
+       if (!present) {
+               add_->bibLW->addItem(f);
+               changed();
        }
+
+       add_->bibED->setText(f);
 }
 
 
-void GuiBibtexDialog::addPressed()
+void GuiBibtex::addPressed()
 {
-       add_bc_.valid(false);
+       add_bc_.setValid(false);
        add_->exec();
 }
 
 
-void GuiBibtexDialog::addDatabase()
+void GuiBibtex::addDatabase()
 {
        int const sel = add_->bibLW->currentRow();
-       docstring const file = trim(qstring_to_ucs4(add_->bibED->text()));
+       QString const file = add_->bibED->text().trimmed();
 
-       if (sel < 0 && file.empty())
+       if (sel < 0 && file.isEmpty())
                return;
 
        // Add the selected browser_bib keys to browser_database
@@ -199,203 +248,351 @@ void GuiBibtexDialog::addDatabase()
                        add_->bibLW->setItemSelected(item, false);
                        QList<QListWidgetItem *> matches =
                                databaseLW->findItems(item->text(), Qt::MatchExactly);
-                       if (matches.empty())
-                               databaseLW->addItem(item->text());
+                       if (matches.empty()) {
+                               QString label = item->text();
+                               QListWidgetItem * db = new QListWidgetItem(label);
+                               db->setFlags(db->flags() | Qt::ItemIsSelectable);
+                               databaseLW->addItem(db);
+                       }
                }
        }
 
-       if (!file.empty()) {
+       if (!file.isEmpty()) {
                add_->bibED->clear();
-               QString const f = toqstr(from_utf8(changeExtension(to_utf8(file), "")));
+               QString const f = changeExtension(file, "");
                QList<QListWidgetItem *> matches =
                        databaseLW->findItems(f, Qt::MatchExactly);
-               if (matches.empty())
-                       databaseLW->addItem(f);
+               if (matches.empty()) {
+                       QListWidgetItem * db = new QListWidgetItem(f);
+                       db->setFlags(db->flags() | Qt::ItemIsSelectable);
+                       databaseLW->addItem(db);
+               }
        }
 
-       form_->changed();
+       databaseChanged();
+       changed();
 }
 
 
-void GuiBibtexDialog::deletePressed()
+void GuiBibtex::deletePressed()
 {
-       databaseLW->takeItem(databaseLW->currentRow());
-       form_->changed();
+       QListWidgetItem *cur = databaseLW->takeItem(databaseLW->currentRow());
+       if (cur) {
+               delete cur;
+               databaseChanged();
+               changed();
+       }
 }
 
 
-
-void GuiBibtexDialog::databaseChanged()
+void GuiBibtex::upPressed()
 {
-       deletePB->setEnabled(!form_->readOnly() && databaseLW->currentRow() != -1);
+       int row = databaseLW->currentRow();
+       QListWidgetItem *cur = databaseLW->takeItem(row);
+       databaseLW->insertItem(row - 1, cur);
+       databaseLW->setCurrentItem(cur);
+       changed();
 }
 
 
-void GuiBibtexDialog::availableChanged()
+void GuiBibtex::downPressed()
 {
-       add_bc_.valid(true);
+       int row = databaseLW->currentRow();
+       QListWidgetItem *cur = databaseLW->takeItem(row);
+       databaseLW->insertItem(row + 1, cur);
+       databaseLW->setCurrentItem(cur);
+       changed();
 }
 
 
-void GuiBibtexDialog::closeEvent(QCloseEvent *e)
+void GuiBibtex::rescanClicked()
 {
-       form_->slotWMHide();
-       e->accept();
+       rescanBibStyles();
+       updateContents();
 }
 
 
-/////////////////////////////////////////////////////////////////////
-//
-// QBibTex
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiBibtex::GuiBibtex(Dialog & parent)
-       : GuiView<GuiBibtexDialog>(parent, _("BibTeX Bibliography"))
+void GuiBibtex::databaseChanged()
 {
+       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);
 }
 
 
-void GuiBibtex::build_dialog()
+void GuiBibtex::availableChanged()
 {
-       dialog_.reset(new GuiBibtexDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->databaseLW);
-       bcview().addReadOnly(dialog_->stylePB);
-       bcview().addReadOnly(dialog_->styleCB);
-       bcview().addReadOnly(dialog_->bibtocCB);
-       bcview().addReadOnly(dialog_->addBibPB);
-       bcview().addReadOnly(dialog_->deletePB);
+       add_bc_.setValid(true);
 }
 
 
-void GuiBibtex::update_contents()
+void GuiBibtex::updateContents()
 {
-       bool bibtopic = controller().usingBibtopic();
+       bool bibtopic = usingBibtopic();
+       bool biblatex = usingBiblatex();
+
+       if (biblatex)
+               setTitle(qt_("Biblatex Bibliography"));
+       else
+               setTitle(qt_("BibTeX Bibliography"));
 
-       dialog_->databaseLW->clear();
+       databaseLW->clear();
 
-       docstring bibs(controller().params()["bibfiles"]);
+       docstring bibs = params_["bibfiles"];
        docstring bib;
 
        while (!bibs.empty()) {
                bibs = split(bibs, bib, ',');
                bib = trim(bib);
-               if (!bib.empty())
-                       dialog_->databaseLW->addItem(toqstr(bib));
+               if (!bib.empty()) {
+                       QListWidgetItem * db = new QListWidgetItem(toqstr(bib));
+                       db->setFlags(db->flags() | Qt::ItemIsSelectable);
+                       databaseLW->addItem(db);
+               }
        }
 
-       dialog_->add_->bibLW->clear();
+       add_->bibLW->clear();
 
-       vector<string> bib_str;
-       controller().getBibFiles(bib_str);
-       for (vector<string>::const_iterator it = bib_str.begin();
-               it != bib_str.end(); ++it) {
-               string bibItem(changeExtension(*it, ""));
-               dialog_->add_->bibLW->addItem(toqstr(bibItem));
-       }
+       QStringList bibfiles = bibFiles();
+       for (int i = 0; i != bibfiles.count(); ++i)
+               add_->bibLW->addItem(changeExtension(bibfiles[i], ""));
 
-       string bibstyle(controller().getStylefile());
+       QString const bibstyle = styleFile();
 
-       dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
-       dialog_->bibtocCB->setEnabled(!bibtopic);
+       bibtocCB->setChecked(bibtotoc() && !bibtopic);
+       bibtocCB->setEnabled(!bibtopic);
 
-       docstring btprint(controller().params()["btprint"]);
-       int btp = 0;
-       if (btprint == "btPrintNotCited")
-               btp = 1;
-       else if (btprint == "btPrintAll")
-               btp = 2;
+       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"));
 
-       dialog_->btPrintCO->setCurrentIndex(btp);
-       dialog_->btPrintCO->setEnabled(bibtopic);
+       docstring btprint = params_["btprint"];
+       if (btprint.empty())
+               // default
+               btprint = from_ascii("btPrintCited");
+       btPrintCO->setCurrentIndex(btPrintCO->findData(toqstr(btprint)));
 
-       dialog_->styleCB->clear();
+       docstring encoding = params_["encoding"];
+       if (encoding.empty())
+               // default
+               encoding = from_ascii("default");
+       bibEncodingCO->setCurrentIndex(bibEncodingCO->findData(toqstr(encoding)));
 
-       int item_nr(-1);
+       // Only useful for biblatex
+       biblatexOptsLA->setVisible(biblatex);
+       biblatexOptsLE->setVisible(biblatex);
 
-       vector<string> str;
-       controller().getBibStyles(str);
-       for (vector<string>::const_iterator it = str.begin();
-               it != str.end(); ++it) {
-               string item(changeExtension(*it, ""));
-               if (item == bibstyle)
-                       item_nr = int(it - str.begin());
-               dialog_->styleCB->addItem(toqstr(item));
-       }
+       // only useful for BibTeX
+       bstGB->setVisible(!biblatex);
 
-       if (item_nr == -1 && !bibstyle.empty()) {
-               dialog_->styleCB->addItem(toqstr(bibstyle));
-               item_nr = dialog_->styleCB->count() - 1;
-       }
+       if (!biblatex) {
+               styleCB->clear();
 
-       if (item_nr != -1)
-               dialog_->styleCB->setCurrentIndex(item_nr);
-       else
-               dialog_->styleCB->clearEditText();
+               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);
+               }
+
+               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();
+       } else
+               biblatexOptsLE->setText(toqstr(params_["biblatexopts"]));
 }
 
 
-void GuiBibtex::apply()
+void GuiBibtex::applyView()
 {
-       docstring dbs(qstring_to_ucs4(dialog_->databaseLW->item(0)->text()));
-
-       unsigned int maxCount = dialog_->databaseLW->count();
-       for (unsigned int i = 1; i < maxCount; i++) {
-               dbs += ',';
-               dbs += qstring_to_ucs4(dialog_->databaseLW->item(i)->text());
+       docstring dbs;
+
+       unsigned int maxCount = databaseLW->count();
+       for (unsigned int i = 0; i < maxCount; i++) {
+               if (i != 0)
+                       dbs += ',';
+               QString item = databaseLW->item(i)->text();
+               docstring bibfile = qstring_to_ucs4(item);
+               dbs += bibfile;
        }
 
-       controller().params()["bibfiles"] = dbs;
+       params_["bibfiles"] = dbs;
 
-       docstring const bibstyle(qstring_to_ucs4(dialog_->styleCB->currentText()));
-       bool const bibtotoc(dialog_->bibtocCB->isChecked());
+       docstring const bibstyle = qstring_to_ucs4(styleCB->currentText());
+       bool const bibtotoc = bibtocCB->isChecked();
 
-       if (bibtotoc && (!bibstyle.empty())) {
+       if (bibtotoc && !bibstyle.empty()) {
                // both bibtotoc and style
-               controller().params()["options"] = "bibtotoc," + bibstyle;
+               params_["options"] = "bibtotoc," + bibstyle;
        } else if (bibtotoc) {
                // bibtotoc and no style
-               controller().params()["options"] = from_ascii("bibtotoc");
+               params_["options"] = from_ascii("bibtotoc");
        } else {
                // only style. An empty one is valid, because some
                // documentclasses have an own \bibliographystyle{}
                // command!
-               controller().params()["options"] = bibstyle;
+               params_["options"] = bibstyle;
        }
 
-       // 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
-       int btp = dialog_->btPrintCO->currentIndex();
+       params_["biblatexopts"] = qstring_to_ucs4(biblatexOptsLE->text());
 
-       switch (btp) {
-       case 0:
-               controller().params()["btprint"] = from_ascii("btPrintCited");
-               break;
-       case 1:
-               controller().params()["btprint"] = from_ascii("btPrintNotCited");
-               break;
-       case 2:
-               controller().params()["btprint"] = from_ascii("btPrintAll");
-               break;
-       }
+       params_["btprint"] = qstring_to_ucs4(btPrintCO->itemData(btPrintCO->currentIndex()).toString());
 
-       if (!controller().usingBibtopic())
-               controller().params()["btprint"] = docstring();
+       params_["encoding"] = qstring_to_ucs4(bibEncodingCO->itemData(bibEncodingCO->currentIndex()).toString());
 }
 
 
 bool GuiBibtex::isValid()
 {
-       return dialog_->databaseLW->count() != 0;
+       return databaseLW->count() != 0;
+}
+
+
+QString GuiBibtex::browseBib(QString const & in_name) const
+{
+       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(),
+               qt_("Select a BibTeX database to add"), filter, false, label1, dir1);
+}
+
+
+QString GuiBibtex::browseBst(QString const & in_name) const
+{
+       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(),
+               qt_("Select a BibTeX style"), filter, false, label1, dir1);
 }
 
+
+QStringList GuiBibtex::bibStyles() const
+{
+       QStringList sdata = texFileList("bstFiles.lst");
+       // test whether we have a valid list, otherwise run rescan
+       if (sdata.isEmpty()) {
+               rescanBibStyles();
+               sdata = texFileList("bstFiles.lst");
+       }
+       for (int i = 0; i != sdata.size(); ++i)
+               sdata[i] = onlyFileName(sdata[i]);
+       // sort on filename only (no path)
+       sdata.sort();
+       return sdata;
+}
+
+
+QStringList GuiBibtex::bibFiles() const
+{
+       QStringList sdata = texFileList("bibFiles.lst");
+       // test whether we have a valid list, otherwise run rescan
+       if (sdata.isEmpty()) {
+               rescanBibStyles();
+               sdata = texFileList("bibFiles.lst");
+       }
+       for (int i = 0; i != sdata.size(); ++i)
+               sdata[i] = onlyFileName(sdata[i]);
+       // sort on filename only (no path)
+       sdata.sort();
+       return sdata;
+}
+
+
+void GuiBibtex::rescanBibStyles() const
+{
+       if (usingBiblatex())
+               rescanTexStyles("bib");
+       else
+               rescanTexStyles("bst bib");
+}
+
+
+bool GuiBibtex::usingBibtopic() const
+{
+       return buffer().params().useBibtopic();
+}
+
+
+bool GuiBibtex::bibtotoc() const
+{
+       return prefixIs(to_utf8(params_["options"]), "bibtotoc");
+}
+
+
+bool GuiBibtex::usingBiblatex() const
+{
+       return buffer().masterBuffer()->params().useBiblatex();
+}
+
+
+QString GuiBibtex::styleFile() const
+{
+       // the different bibtex packages have (and need) their
+       // own "plain" stylefiles
+       QString defaultstyle = toqstr(buffer().params().defaultBiblioStyle());
+
+       QString bst = toqstr(params_["options"]);
+       if (bibtotoc()){
+               // bibstyle exists?
+               int pos = bst.indexOf(',');
+               if (pos != -1) {
+                       // FIXME: check
+                       // docstring bibtotoc = from_ascii("bibtotoc");
+                       // bst = split(bst, bibtotoc, ',');
+                       bst = bst.mid(pos + 1);
+               } else {
+                       bst.clear();
+               }
+       }
+
+       // propose default style file for new insets
+       // existing insets might have (legally) no bst files
+       // (if the class already provides a style)
+       if (bst.isEmpty() && params_["bibfiles"].empty())
+               bst = defaultstyle;
+
+       return bst;
+}
+
+
+bool GuiBibtex::initialiseParams(std::string const & sdata)
+{
+       InsetCommand::string2params(sdata, params_);
+       return true;
+}
+
+
+void GuiBibtex::dispatchParams()
+{
+       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"