2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiBibtex.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Herbert Voß
|
2007-10-06 09:55:21 +00:00
|
|
|
* \author Angus Leeming
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiBibtex.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2017-01-08 08:39:46 +00:00
|
|
|
#include "CiteEnginesList.h"
|
2018-07-07 13:25:35 +00:00
|
|
|
#include "Encoding.h"
|
2008-04-20 09:24:14 +00:00
|
|
|
#include "FuncRequest.h"
|
2018-08-11 10:17:42 +00:00
|
|
|
#include "GuiApplication.h"
|
2008-04-20 09:24:14 +00:00
|
|
|
#include "LyXRC.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "Validator.h"
|
2008-04-20 09:24:14 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
#include "ButtonPolicy.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-13 17:19:36 +00:00
|
|
|
#include "frontends/alert.h"
|
|
|
|
|
2008-03-29 15:39:19 +00:00
|
|
|
#include "insets/InsetBibtex.h"
|
|
|
|
|
2012-06-28 18:52:20 +00:00
|
|
|
#include "support/debug.h"
|
2008-03-13 17:19:36 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
2008-04-20 03:08:11 +00:00
|
|
|
#include "support/FileName.h"
|
2006-04-09 08:42:58 +00:00
|
|
|
#include "support/filetools.h" // changeExtension
|
2008-02-05 12:43:19 +00:00
|
|
|
#include "support/gettext.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-10-06 09:55:21 +00:00
|
|
|
|
2018-07-08 14:35:38 +00:00
|
|
|
#include <QDialogButtonBox>
|
2006-05-02 19:17:59 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QCheckBox>
|
2007-04-25 08:42:22 +00:00
|
|
|
#include <QLineEdit>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiBibtex::GuiBibtex(GuiView & lv)
|
2008-04-20 09:24:14 +00:00
|
|
|
: GuiDialog(lv, "bibtex", qt_("BibTeX Bibliography")),
|
|
|
|
params_(insetCode("bibtex"))
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-04-25 08:42:22 +00:00
|
|
|
QDialog::setModal(true);
|
2017-09-12 09:05:42 +00:00
|
|
|
setWindowModality(Qt::WindowModal);
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
// 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"));
|
|
|
|
|
|
|
|
filterBarL->addWidget(filter_, 0);
|
|
|
|
findKeysLA->setBuddy(filter_);
|
|
|
|
|
2018-07-08 14:35:38 +00:00
|
|
|
connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
|
|
|
|
this, SLOT(slotButtonBox(QAbstractButton *)));
|
2007-04-25 08:42:22 +00:00
|
|
|
connect(stylePB, SIGNAL(clicked()),
|
2018-08-11 10:17:42 +00:00
|
|
|
this, SLOT(browseBstPressed()));
|
2007-10-06 09:55:21 +00:00
|
|
|
connect(styleCB, SIGNAL(editTextChanged(QString)),
|
2007-08-31 05:53:55 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-04-25 08:42:22 +00:00
|
|
|
connect(bibtocCB, SIGNAL(clicked()),
|
2007-08-31 05:53:55 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-04-25 08:42:22 +00:00
|
|
|
connect(btPrintCO, SIGNAL(activated(int)),
|
2007-08-31 05:53:55 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2008-12-02 08:46:59 +00:00
|
|
|
connect(rescanPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(rescanClicked()));
|
2017-01-08 08:39:46 +00:00
|
|
|
connect(biblatexOptsLE, SIGNAL(textChanged(QString)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2018-07-07 13:25:35 +00:00
|
|
|
connect(bibEncodingCO, SIGNAL(activated(int)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2018-08-11 10:17:42 +00:00
|
|
|
connect(browseBibPB, SIGNAL(clicked()),
|
2007-04-25 08:42:22 +00:00
|
|
|
this, SLOT(browseBibPressed()));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2019-03-29 14:45:55 +00:00
|
|
|
selected_model_.insertColumns(0, 1);
|
2018-08-11 10:17:42 +00:00
|
|
|
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. "
|
2017-01-13 08:07:44 +00:00
|
|
|
"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.")));
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
|
2018-07-08 14:35:38 +00:00
|
|
|
bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
|
|
|
|
bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
|
|
|
|
bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().addReadOnly(stylePB);
|
|
|
|
bc().addReadOnly(styleCB);
|
|
|
|
bc().addReadOnly(bibtocCB);
|
2018-07-07 13:25:35 +00:00
|
|
|
bc().addReadOnly(bibEncodingCO);
|
2008-01-12 09:30:21 +00:00
|
|
|
|
2019-03-29 14:45:55 +00:00
|
|
|
#if (QT_VERSION < 0x050000)
|
|
|
|
selectedLV->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
|
|
|
|
#else
|
|
|
|
selectedLV->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
#endif
|
|
|
|
|
2018-07-07 13:25:35 +00:00
|
|
|
// 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())
|
2019-03-29 14:45:55 +00:00
|
|
|
encodings_.insert(qt_(encvar.guiName()), toqstr(encvar.name()));
|
2018-07-07 13:25:35 +00:00
|
|
|
}
|
2019-03-29 14:45:55 +00:00
|
|
|
QMap<QString, QString>::const_iterator it = encodings_.constBegin();
|
|
|
|
while (it != encodings_.constEnd()) {
|
2018-07-07 13:25:35 +00:00
|
|
|
bibEncodingCO->addItem(it.key(), it.value());
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
setFocusProxy(filter_);
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
void GuiBibtex::init()
|
2018-07-08 14:35:38 +00:00
|
|
|
{
|
2018-08-11 10:17:42 +00:00
|
|
|
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();
|
2018-07-08 14:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
void GuiBibtex::change_adaptor()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2018-08-11 10:17:42 +00:00
|
|
|
setButtons();
|
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
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()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2018-08-11 10:17:42 +00:00
|
|
|
selectionManager->update();
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
void GuiBibtex::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
applyView();
|
|
|
|
clearSelection();
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiBibtex::browseBstPressed()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const file = browseBst(QString());
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
if (file.isEmpty())
|
|
|
|
return;
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
QString const filen = changeExtension(file, "");
|
2008-03-06 00:07:19 +00:00
|
|
|
bool present = false;
|
2019-03-29 14:45:55 +00:00
|
|
|
int pres = 0;
|
2008-03-06 00:07:19 +00:00
|
|
|
|
|
|
|
for (int i = 0; i != styleCB->count(); ++i) {
|
|
|
|
if (styleCB->itemText(i) == filen) {
|
|
|
|
present = true;
|
|
|
|
pres = i;
|
|
|
|
}
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
2008-03-06 00:07:19 +00:00
|
|
|
|
|
|
|
if (!present)
|
|
|
|
styleCB->insertItem(0, filen);
|
|
|
|
|
|
|
|
styleCB->setCurrentIndex(pres);
|
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::browseBibPressed()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const file = browseBib(QString()).trimmed();
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
if (file.isEmpty())
|
|
|
|
return;
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
QString const f = changeExtension(file, "");
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
if (!selected_bibs_.contains(f)) {
|
|
|
|
selected_bibs_.append(f);
|
|
|
|
setSelectedBibs(selected_bibs_);
|
2008-03-06 00:07:19 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
void GuiBibtex::rescanClicked()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2018-08-11 10:17:42 +00:00
|
|
|
rescanBibStyles();
|
|
|
|
updateContents();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
void GuiBibtex::clearSelection()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2018-08-11 10:17:42 +00:00
|
|
|
selected_bibs_.clear();
|
|
|
|
setSelectedBibs(selected_bibs_);
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
void GuiBibtex::setSelectedBibs(QStringList const sl)
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2018-08-11 10:17:42 +00:00
|
|
|
selected_model_.clear();
|
2019-03-29 14:45:55 +00:00
|
|
|
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"));
|
|
|
|
}
|
2018-08-11 10:17:42 +00:00
|
|
|
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);
|
2019-03-29 14:45:55 +00:00
|
|
|
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);
|
2008-01-12 09:30:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
QStringList GuiBibtex::selectedBibs()
|
2008-01-12 09:30:21 +00:00
|
|
|
{
|
2018-08-11 10:17:42 +00:00
|
|
|
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;
|
2008-12-02 08:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::databaseChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2018-08-11 10:17:42 +00:00
|
|
|
QString const item = selectionManager->getSelectedIndex().data().toString();
|
|
|
|
if (!selected_bibs_.contains(item)) {
|
|
|
|
selected_bibs_.append(item);
|
|
|
|
} else
|
|
|
|
selected_bibs_ = selectedBibs();
|
|
|
|
setSelectedBibs(selected_bibs_);
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-06 09:55:21 +00:00
|
|
|
bool bibtopic = usingBibtopic();
|
2017-01-08 08:39:46 +00:00
|
|
|
bool biblatex = usingBiblatex();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2017-09-10 08:57:48 +00:00
|
|
|
if (biblatex)
|
|
|
|
setTitle(qt_("Biblatex Bibliography"));
|
|
|
|
else
|
|
|
|
setTitle(qt_("BibTeX Bibliography"));
|
|
|
|
|
2012-05-01 17:02:10 +00:00
|
|
|
QString const bibstyle = styleFile();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
bibtocCB->setChecked(bibtotoc() && !bibtopic);
|
2007-09-05 20:33:29 +00:00
|
|
|
bibtocCB->setEnabled(!bibtopic);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2017-02-04 11:02:00 +00:00
|
|
|
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"));
|
2007-12-28 16:56:57 +00:00
|
|
|
|
2017-09-10 08:51:42 +00:00
|
|
|
docstring btprint = params_["btprint"];
|
|
|
|
if (btprint.empty())
|
|
|
|
// default
|
|
|
|
btprint = from_ascii("btPrintCited");
|
|
|
|
btPrintCO->setCurrentIndex(btPrintCO->findData(toqstr(btprint)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2018-07-07 13:25:35 +00:00
|
|
|
docstring encoding = params_["encoding"];
|
|
|
|
if (encoding.empty())
|
|
|
|
// default
|
|
|
|
encoding = from_ascii("default");
|
|
|
|
bibEncodingCO->setCurrentIndex(bibEncodingCO->findData(toqstr(encoding)));
|
|
|
|
|
2017-01-08 08:39:46 +00:00
|
|
|
// Only useful for biblatex
|
|
|
|
biblatexOptsLA->setVisible(biblatex);
|
|
|
|
biblatexOptsLE->setVisible(biblatex);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2017-01-08 08:39:46 +00:00
|
|
|
// only useful for BibTeX
|
2018-07-08 10:13:47 +00:00
|
|
|
bstGB->setVisible(!biblatex);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2017-01-08 08:39:46 +00:00
|
|
|
if (!biblatex) {
|
|
|
|
styleCB->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2017-01-08 08:39:46 +00:00
|
|
|
int item_nr = -1;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2017-01-08 08:39:46 +00:00
|
|
|
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"]));
|
2019-03-29 14:45:55 +00:00
|
|
|
|
|
|
|
setFileEncodings(getVectorFromString(params_["file_encodings"], from_ascii("\t")));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-03-13 17:19:36 +00:00
|
|
|
docstring dbs;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
unsigned int maxCount = selected_bibs_.count();
|
2008-03-13 17:19:36 +00:00
|
|
|
for (unsigned int i = 0; i < maxCount; i++) {
|
2008-04-19 15:52:35 +00:00
|
|
|
if (i != 0)
|
2008-03-13 17:19:36 +00:00
|
|
|
dbs += ',';
|
2018-08-11 10:17:42 +00:00
|
|
|
QString item = selected_bibs_.at(i);
|
2008-03-29 15:39:19 +00:00
|
|
|
docstring bibfile = qstring_to_ucs4(item);
|
|
|
|
dbs += bibfile;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2008-03-13 17:19:36 +00:00
|
|
|
params_["bibfiles"] = dbs;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 18:40:01 +00:00
|
|
|
docstring const bibstyle = qstring_to_ucs4(styleCB->currentText());
|
|
|
|
bool const bibtotoc = bibtocCB->isChecked();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
if (bibtotoc && !bibstyle.empty()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
// both bibtotoc and style
|
2007-10-07 18:40:01 +00:00
|
|
|
params_["options"] = "bibtotoc," + bibstyle;
|
2006-03-05 17:24:44 +00:00
|
|
|
} else if (bibtotoc) {
|
|
|
|
// bibtotoc and no style
|
2007-10-07 18:40:01 +00:00
|
|
|
params_["options"] = from_ascii("bibtotoc");
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
|
|
|
// only style. An empty one is valid, because some
|
|
|
|
// documentclasses have an own \bibliographystyle{}
|
|
|
|
// command!
|
2007-10-07 18:40:01 +00:00
|
|
|
params_["options"] = bibstyle;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 08:39:46 +00:00
|
|
|
params_["biblatexopts"] = qstring_to_ucs4(biblatexOptsLE->text());
|
|
|
|
|
2017-02-04 11:02:00 +00:00
|
|
|
params_["btprint"] = qstring_to_ucs4(btPrintCO->itemData(btPrintCO->currentIndex()).toString());
|
2018-07-07 13:25:35 +00:00
|
|
|
|
|
|
|
params_["encoding"] = qstring_to_ucs4(bibEncodingCO->itemData(bibEncodingCO->currentIndex()).toString());
|
2019-03-29 14:45:55 +00:00
|
|
|
|
|
|
|
if (usingBiblatex())
|
|
|
|
params_["file_encodings"] = getStringFromVector(getFileEncodings(), from_ascii("\t"));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
QString GuiBibtex::browseBib(QString const & in_name) const
|
2007-10-06 09:55:21 +00:00
|
|
|
{
|
2017-12-20 10:36:32 +00:00
|
|
|
QString const label1 = qt_("D&ocuments");
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const dir1 = toqstr(lyxrc.document_path);
|
2008-04-20 19:56:01 +00:00
|
|
|
QStringList const filter(qt_("BibTeX Databases (*.bib)"));
|
2011-06-01 13:18:08 +00:00
|
|
|
return browseRelToParent(in_name, bufferFilePath(),
|
2008-03-06 00:07:19 +00:00
|
|
|
qt_("Select a BibTeX database to add"), filter, false, label1, dir1);
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
QString GuiBibtex::browseBst(QString const & in_name) const
|
2007-10-06 09:55:21 +00:00
|
|
|
{
|
2017-12-20 10:36:32 +00:00
|
|
|
QString const label1 = qt_("D&ocuments");
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const dir1 = toqstr(lyxrc.document_path);
|
2008-04-20 19:56:01 +00:00
|
|
|
QStringList const filter(qt_("BibTeX Styles (*.bst)"));
|
2011-06-01 13:18:08 +00:00
|
|
|
return browseRelToParent(in_name, bufferFilePath(),
|
2008-03-06 00:07:19 +00:00
|
|
|
qt_("Select a BibTeX style"), filter, false, label1, dir1);
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
QStringList GuiBibtex::bibStyles() const
|
2007-10-06 09:55:21 +00:00
|
|
|
{
|
2017-12-16 14:45:38 +00:00
|
|
|
QStringList sdata = texFileList("bstFiles.lst");
|
2008-03-08 07:59:47 +00:00
|
|
|
// test whether we have a valid list, otherwise run rescan
|
2017-12-16 14:45:38 +00:00
|
|
|
if (sdata.isEmpty()) {
|
2007-10-06 09:55:21 +00:00
|
|
|
rescanBibStyles();
|
2017-12-16 14:45:38 +00:00
|
|
|
sdata = texFileList("bstFiles.lst");
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
2017-12-16 14:45:38 +00:00
|
|
|
for (int i = 0; i != sdata.size(); ++i)
|
|
|
|
sdata[i] = onlyFileName(sdata[i]);
|
2007-10-06 09:55:21 +00:00
|
|
|
// sort on filename only (no path)
|
2017-12-16 14:45:38 +00:00
|
|
|
sdata.sort();
|
|
|
|
return sdata;
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
QStringList GuiBibtex::bibFiles(bool const extension) const
|
2007-10-06 09:55:21 +00:00
|
|
|
{
|
2017-12-16 14:45:38 +00:00
|
|
|
QStringList sdata = texFileList("bibFiles.lst");
|
2008-03-08 07:59:47 +00:00
|
|
|
// test whether we have a valid list, otherwise run rescan
|
2017-12-16 14:45:38 +00:00
|
|
|
if (sdata.isEmpty()) {
|
2007-10-06 09:55:21 +00:00
|
|
|
rescanBibStyles();
|
2017-12-16 14:45:38 +00:00
|
|
|
sdata = texFileList("bibFiles.lst");
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
2017-12-16 14:45:38 +00:00
|
|
|
for (int i = 0; i != sdata.size(); ++i)
|
2018-08-11 10:17:42 +00:00
|
|
|
sdata[i] = extension ? onlyFileName(sdata[i])
|
|
|
|
: changeExtension(onlyFileName(sdata[i]), "");
|
2007-10-06 09:55:21 +00:00
|
|
|
// sort on filename only (no path)
|
2017-12-16 14:45:38 +00:00
|
|
|
sdata.sort();
|
|
|
|
return sdata;
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-29 14:45:55 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::rescanBibStyles() const
|
|
|
|
{
|
2017-01-08 08:39:46 +00:00
|
|
|
if (usingBiblatex())
|
|
|
|
rescanTexStyles("bib");
|
|
|
|
else
|
|
|
|
rescanTexStyles("bst bib");
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-11 10:17:42 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
bool GuiBibtex::usingBibtopic() const
|
|
|
|
{
|
2017-01-15 14:40:20 +00:00
|
|
|
return buffer().params().useBibtopic();
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiBibtex::bibtotoc() const
|
|
|
|
{
|
2007-10-07 18:40:01 +00:00
|
|
|
return prefixIs(to_utf8(params_["options"]), "bibtotoc");
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-08 08:39:46 +00:00
|
|
|
bool GuiBibtex::usingBiblatex() const
|
|
|
|
{
|
2017-01-12 11:19:14 +00:00
|
|
|
return buffer().masterBuffer()->params().useBiblatex();
|
2017-01-08 08:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
QString GuiBibtex::styleFile() const
|
2007-10-06 09:55:21 +00:00
|
|
|
{
|
|
|
|
// the different bibtex packages have (and need) their
|
|
|
|
// own "plain" stylefiles
|
2012-03-01 00:41:30 +00:00
|
|
|
QString defaultstyle = toqstr(buffer().params().defaultBiblioStyle());
|
2007-10-06 09:55:21 +00:00
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
QString bst = toqstr(params_["options"]);
|
2007-10-06 09:55:21 +00:00
|
|
|
if (bibtotoc()){
|
|
|
|
// bibstyle exists?
|
2008-03-08 07:59:47 +00:00
|
|
|
int pos = bst.indexOf(',');
|
|
|
|
if (pos != -1) {
|
|
|
|
// FIXME: check
|
|
|
|
// docstring bibtotoc = from_ascii("bibtotoc");
|
|
|
|
// bst = split(bst, bibtotoc, ',');
|
2008-04-28 12:57:41 +00:00
|
|
|
bst = bst.mid(pos + 1);
|
2008-03-08 07:59:47 +00:00
|
|
|
} else {
|
|
|
|
bst.clear();
|
|
|
|
}
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// propose default style file for new insets
|
|
|
|
// existing insets might have (legally) no bst files
|
|
|
|
// (if the class already provides a style)
|
2008-03-08 07:59:47 +00:00
|
|
|
if (bst.isEmpty() && params_["bibfiles"].empty())
|
2007-10-06 09:55:21 +00:00
|
|
|
bst = defaultstyle;
|
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
return bst;
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-16 14:45:38 +00:00
|
|
|
bool GuiBibtex::initialiseParams(std::string const & sdata)
|
2008-04-20 09:24:14 +00:00
|
|
|
{
|
2017-12-16 14:45:38 +00:00
|
|
|
InsetCommand::string2params(sdata, params_);
|
2018-08-11 10:17:42 +00:00
|
|
|
init();
|
2008-04-20 09:24:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiBibtex::dispatchParams()
|
|
|
|
{
|
2010-10-29 00:25:28 +00:00
|
|
|
std::string const lfun = InsetCommand::params2string(params_);
|
2008-04-20 09:24:14 +00:00
|
|
|
dispatch(FuncRequest(getLfun(), lfun));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiBibtex(GuiView & lv) { return new GuiBibtex(lv); }
|
2007-10-06 09:55:21 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiBibtex.cpp"
|