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"
|
2008-04-20 09:24:14 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#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
|
|
|
|
|
|
|
#include "ui_BibtexAddUi.h"
|
2007-04-25 08:42:22 +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
|
|
|
|
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);
|
|
|
|
|
|
|
|
connect(okPB, SIGNAL(clicked()),
|
2007-09-05 20:33:29 +00:00
|
|
|
this, SLOT(slotOK()));
|
2007-04-25 08:42:22 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()),
|
2007-09-05 20:33:29 +00:00
|
|
|
this, SLOT(slotClose()));
|
2007-04-25 08:42:22 +00:00
|
|
|
connect(stylePB, SIGNAL(clicked()),
|
2007-08-31 05:53:55 +00:00
|
|
|
this, SLOT(browsePressed()));
|
2007-04-25 08:42:22 +00:00
|
|
|
connect(deletePB, SIGNAL(clicked()),
|
2007-08-31 05:53:55 +00:00
|
|
|
this, SLOT(deletePressed()));
|
2008-01-12 09:30:21 +00:00
|
|
|
connect(upPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(upPressed()));
|
|
|
|
connect(downPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(downPressed()));
|
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()));
|
2008-01-13 21:35:48 +00:00
|
|
|
connect(databaseLW, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
|
2007-08-31 05:53:55 +00:00
|
|
|
this, SLOT(databaseChanged()));
|
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()));
|
2007-04-25 08:42:22 +00:00
|
|
|
connect(addBibPB, SIGNAL(clicked()),
|
2007-08-31 05:53:55 +00:00
|
|
|
this, SLOT(addPressed()));
|
2008-12-02 08:46:59 +00:00
|
|
|
connect(rescanPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(rescanClicked()));
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
add_ = new GuiBibtexAddDialog(this);
|
2007-09-02 07:53:07 +00:00
|
|
|
add_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
|
2007-09-03 05:59:32 +00:00
|
|
|
add_bc_.setOK(add_->addPB);
|
|
|
|
add_bc_.setCancel(add_->closePB);
|
|
|
|
add_bc_.addCheckedLineEdit(add_->bibED, 0);
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2007-10-28 16:32:20 +00:00
|
|
|
connect(add_->bibED, SIGNAL(textChanged(QString)),
|
2007-04-25 08:42:22 +00:00
|
|
|
this, SLOT(bibEDChanged()));
|
|
|
|
connect(add_->addPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(addDatabase()));
|
|
|
|
connect(add_->addPB, SIGNAL(clicked()),
|
|
|
|
add_, SLOT(accept()));
|
2008-12-02 08:46:59 +00:00
|
|
|
connect(add_->rescanPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(rescanClicked()));
|
2007-04-25 08:42:22 +00:00
|
|
|
connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
|
|
|
|
this, SLOT(addDatabase()));
|
|
|
|
connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
|
|
|
|
add_, SLOT(accept()));
|
2008-01-13 21:35:48 +00:00
|
|
|
connect(add_->bibLW, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
|
2007-04-25 08:42:22 +00:00
|
|
|
this, SLOT(availableChanged()));
|
|
|
|
connect(add_->browsePB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(browseBibPressed()));
|
|
|
|
connect(add_->closePB, SIGNAL(clicked()),
|
|
|
|
add_, SLOT(reject()));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
|
|
|
|
bc().setOK(okPB);
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
bc().addReadOnly(databaseLW);
|
|
|
|
bc().addReadOnly(stylePB);
|
|
|
|
bc().addReadOnly(styleCB);
|
|
|
|
bc().addReadOnly(bibtocCB);
|
|
|
|
bc().addReadOnly(addBibPB);
|
2008-01-12 11:49:49 +00:00
|
|
|
// Delete/Up/Down are handled with more conditions in
|
|
|
|
// databaseChanged().
|
2008-01-12 09:30:21 +00:00
|
|
|
|
|
|
|
// Make sure the delete/up/down buttons are disabled if necessary.
|
|
|
|
databaseChanged();
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::bibEDChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
// Indicate to the button controller that the contents have
|
|
|
|
// changed. The actual test of validity is carried out by
|
|
|
|
// the checkedLineEdit.
|
2007-09-03 05:59:32 +00:00
|
|
|
add_bc_.setValid(true);
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::change_adaptor()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::browsePressed()
|
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;
|
|
|
|
unsigned int pres = 0;
|
|
|
|
|
|
|
|
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, "");
|
2008-03-06 00:07:19 +00:00
|
|
|
bool present = false;
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
for (int i = 0; i < add_->bibLW->count(); ++i) {
|
|
|
|
if (add_->bibLW->item(i)->text() == f)
|
|
|
|
present = true;
|
|
|
|
}
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
if (!present) {
|
|
|
|
add_->bibLW->addItem(f);
|
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
2008-03-06 00:07:19 +00:00
|
|
|
|
|
|
|
add_->bibED->setText(f);
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::addPressed()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2007-09-03 05:59:32 +00:00
|
|
|
add_bc_.setValid(false);
|
2007-04-25 08:42:22 +00:00
|
|
|
add_->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::addDatabase()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
int const sel = add_->bibLW->currentRow();
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const file = add_->bibED->text().trimmed();
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
if (sel < 0 && file.isEmpty())
|
2007-04-25 08:42:22 +00:00
|
|
|
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);
|
2008-01-08 17:02:09 +00:00
|
|
|
if (matches.empty()) {
|
|
|
|
QString label = item->text();
|
|
|
|
QListWidgetItem * db = new QListWidgetItem(label);
|
2008-04-19 15:52:35 +00:00
|
|
|
db->setFlags(db->flags() | Qt::ItemIsSelectable);
|
2008-01-08 17:02:09 +00:00
|
|
|
databaseLW->addItem(db);
|
|
|
|
}
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
if (!file.isEmpty()) {
|
2007-04-25 08:42:22 +00:00
|
|
|
add_->bibED->clear();
|
2008-03-08 07:59:47 +00:00
|
|
|
QString const f = changeExtension(file, "");
|
2007-04-25 08:42:22 +00:00
|
|
|
QList<QListWidgetItem *> matches =
|
|
|
|
databaseLW->findItems(f, Qt::MatchExactly);
|
2008-01-08 17:02:09 +00:00
|
|
|
if (matches.empty()) {
|
|
|
|
QListWidgetItem * db = new QListWidgetItem(f);
|
2008-04-19 15:52:35 +00:00
|
|
|
db->setFlags(db->flags() | Qt::ItemIsSelectable);
|
2008-01-10 23:39:58 +00:00
|
|
|
databaseLW->addItem(db);
|
2008-01-08 17:02:09 +00:00
|
|
|
}
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
2008-01-12 15:41:40 +00:00
|
|
|
databaseChanged();
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::deletePressed()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2008-01-12 09:30:21 +00:00
|
|
|
QListWidgetItem *cur = databaseLW->takeItem(databaseLW->currentRow());
|
|
|
|
if (cur) {
|
|
|
|
delete cur;
|
2008-01-12 15:41:40 +00:00
|
|
|
databaseChanged();
|
2008-01-12 09:30:21 +00:00
|
|
|
changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiBibtex::upPressed()
|
|
|
|
{
|
|
|
|
int row = databaseLW->currentRow();
|
2008-01-12 15:41:40 +00:00
|
|
|
QListWidgetItem *cur = databaseLW->takeItem(row);
|
|
|
|
databaseLW->insertItem(row - 1, cur);
|
2008-01-12 09:30:21 +00:00
|
|
|
databaseLW->setCurrentItem(cur);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-12 09:30:21 +00:00
|
|
|
void GuiBibtex::downPressed()
|
|
|
|
{
|
|
|
|
int row = databaseLW->currentRow();
|
2008-01-12 15:41:40 +00:00
|
|
|
QListWidgetItem *cur = databaseLW->takeItem(row);
|
|
|
|
databaseLW->insertItem(row + 1, cur);
|
2008-01-12 09:30:21 +00:00
|
|
|
databaseLW->setCurrentItem(cur);
|
|
|
|
changed();
|
|
|
|
}
|
|
|
|
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-12-02 08:46:59 +00:00
|
|
|
void GuiBibtex::rescanClicked()
|
|
|
|
{
|
|
|
|
rescanBibStyles();
|
|
|
|
updateContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::databaseChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2008-01-13 21:35:48 +00:00
|
|
|
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);
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
void GuiBibtex::availableChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2007-09-03 05:59:32 +00:00
|
|
|
add_bc_.setValid(true);
|
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();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
databaseLW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 18:40:01 +00:00
|
|
|
docstring bibs = params_["bibfiles"];
|
2006-10-20 13:53:43 +00:00
|
|
|
docstring bib;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
while (!bibs.empty()) {
|
|
|
|
bibs = split(bibs, bib, ',');
|
|
|
|
bib = trim(bib);
|
2008-01-08 17:02:09 +00:00
|
|
|
if (!bib.empty()) {
|
|
|
|
QListWidgetItem * db = new QListWidgetItem(toqstr(bib));
|
2008-04-19 15:52:35 +00:00
|
|
|
db->setFlags(db->flags() | Qt::ItemIsSelectable);
|
2008-01-08 17:02:09 +00:00
|
|
|
databaseLW->addItem(db);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
add_->bibLW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
QStringList bibfiles = bibFiles();
|
|
|
|
for (int i = 0; i != bibfiles.count(); ++i)
|
|
|
|
add_->bibLW->addItem(changeExtension(bibfiles[i], ""));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
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
|
|
|
|
2007-12-28 16:56:57 +00:00
|
|
|
if (!bibtopic && btPrintCO->count() == 3)
|
|
|
|
btPrintCO->removeItem(1);
|
|
|
|
else if (bibtopic && btPrintCO->count() < 3)
|
|
|
|
btPrintCO->insertItem(1, qt_("all uncited references", 0));
|
|
|
|
|
2012-05-01 17:02:10 +00:00
|
|
|
docstring const & btprint = params_["btprint"];
|
2006-03-05 17:24:44 +00:00
|
|
|
int btp = 0;
|
2007-12-28 16:56:57 +00:00
|
|
|
if ((bibtopic && btprint == "btPrintNotCited") ||
|
|
|
|
(!bibtopic && btprint == "btPrintAll"))
|
2006-03-05 17:24:44 +00:00
|
|
|
btp = 1;
|
2007-12-28 16:56:57 +00:00
|
|
|
else if (bibtopic && btprint == "btPrintAll")
|
2006-03-05 17:24:44 +00:00
|
|
|
btp = 2;
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
btPrintCO->setCurrentIndex(btp);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
styleCB->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
int item_nr = -1;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2012-05-01 17:02:10 +00:00
|
|
|
QStringList const str = bibStyles();
|
2008-03-08 07:59:47 +00:00
|
|
|
for (int i = 0; i != str.count(); ++i) {
|
|
|
|
QString item = changeExtension(str[i], "");
|
2006-03-05 17:24:44 +00:00
|
|
|
if (item == bibstyle)
|
2008-03-08 07:59:47 +00:00
|
|
|
item_nr = i;
|
|
|
|
styleCB->addItem(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
if (item_nr == -1 && !bibstyle.isEmpty()) {
|
|
|
|
styleCB->addItem(bibstyle);
|
2007-09-05 20:33:29 +00:00
|
|
|
item_nr = styleCB->count() - 1;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item_nr != -1)
|
2007-09-05 20:33:29 +00:00
|
|
|
styleCB->setCurrentIndex(item_nr);
|
2006-03-05 17:24:44 +00:00
|
|
|
else
|
2007-09-05 20:33:29 +00:00
|
|
|
styleCB->clearEditText();
|
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
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
unsigned int maxCount = databaseLW->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 += ',';
|
2008-03-29 15:39:19 +00:00
|
|
|
QString item = databaseLW->item(i)->text();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
int btp = btPrintCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-28 16:56:57 +00:00
|
|
|
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;
|
2011-12-03 22:15:11 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 09:55:21 +00:00
|
|
|
bool GuiBibtex::isValid()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
return databaseLW->count() != 0;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 09:55:21 +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
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const label1 = qt_("Documents|#o#O");
|
|
|
|
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
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const label1 = qt_("Documents|#o#O");
|
|
|
|
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
|
|
|
{
|
2008-03-08 07:59:47 +00:00
|
|
|
QStringList data = texFileList("bstFiles.lst");
|
|
|
|
// test whether we have a valid list, otherwise run rescan
|
|
|
|
if (data.isEmpty()) {
|
2007-10-06 09:55:21 +00:00
|
|
|
rescanBibStyles();
|
2008-03-08 07:59:47 +00:00
|
|
|
data = texFileList("bstFiles.lst");
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
2008-03-08 07:59:47 +00:00
|
|
|
for (int i = 0; i != data.size(); ++i)
|
2010-04-21 01:19:28 +00:00
|
|
|
data[i] = onlyFileName(data[i]);
|
2007-10-06 09:55:21 +00:00
|
|
|
// sort on filename only (no path)
|
2008-03-08 07:59:47 +00:00
|
|
|
data.sort();
|
|
|
|
return data;
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-08 07:59:47 +00:00
|
|
|
QStringList GuiBibtex::bibFiles() const
|
2007-10-06 09:55:21 +00:00
|
|
|
{
|
2008-03-08 07:59:47 +00:00
|
|
|
QStringList data = texFileList("bibFiles.lst");
|
|
|
|
// test whether we have a valid list, otherwise run rescan
|
|
|
|
if (data.isEmpty()) {
|
2007-10-06 09:55:21 +00:00
|
|
|
rescanBibStyles();
|
2008-03-08 07:59:47 +00:00
|
|
|
data = texFileList("bibFiles.lst");
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
2008-03-08 07:59:47 +00:00
|
|
|
for (int i = 0; i != data.size(); ++i)
|
2010-04-21 01:19:28 +00:00
|
|
|
data[i] = onlyFileName(data[i]);
|
2007-10-06 09:55:21 +00:00
|
|
|
// sort on filename only (no path)
|
2008-03-08 07:59:47 +00:00
|
|
|
data.sort();
|
|
|
|
return data;
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiBibtex::rescanBibStyles() const
|
|
|
|
{
|
2012-05-01 16:54:17 +00:00
|
|
|
rescanTexStyles("bst bib");
|
2007-10-06 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiBibtex::usingBibtopic() const
|
|
|
|
{
|
|
|
|
return buffer().params().use_bibtopic;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-20 09:24:14 +00:00
|
|
|
bool GuiBibtex::initialiseParams(std::string const & data)
|
|
|
|
{
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(data, params_);
|
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"
|