2001-08-26 03:20:52 +00:00
|
|
|
/**
|
|
|
|
* \file QBibtexDialog.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-08-26 03:20:52 +00:00
|
|
|
*
|
2002-09-24 13:57:09 +00:00
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-08-26 03:20:52 +00:00
|
|
|
*/
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include <config.h>
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "ControlBibtex.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
2002-07-22 14:04:38 +00:00
|
|
|
#include "support/lyxalgo.h" // eliminate_duplicates
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
#include <qwidget.h>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qcombobox.h>
|
2002-12-17 17:28:04 +00:00
|
|
|
#include <qlineedit.h>
|
2001-08-26 03:20:52 +00:00
|
|
|
#include <qlistbox.h>
|
|
|
|
#include <qcheckbox.h>
|
|
|
|
#include <qfiledialog.h>
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
#include "QBibtexDialog.h"
|
|
|
|
#include "QBibtex.h"
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
QBibtexDialog::QBibtexDialog(QBibtex * form)
|
|
|
|
: QBibtexDialogBase(0, 0, false, 0),
|
|
|
|
form_(form)
|
|
|
|
{
|
|
|
|
connect(okPB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotOK()));
|
|
|
|
connect(closePB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotClose()));
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
void QBibtexDialog::change_adaptor()
|
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::browsePressed()
|
|
|
|
{
|
2002-12-17 17:28:04 +00:00
|
|
|
QString const file =
|
2002-07-23 13:12:55 +00:00
|
|
|
QFileDialog::getOpenFileName(QString::null,
|
2002-12-17 20:37:13 +00:00
|
|
|
qt_("BibTeX style files (*.bst)"),
|
2002-07-23 13:12:55 +00:00
|
|
|
this,
|
|
|
|
0,
|
2002-12-17 20:37:13 +00:00
|
|
|
qt_("Select a BibTeX style"));
|
2001-08-27 01:19:32 +00:00
|
|
|
if (!file.isNull()) {
|
2003-02-14 13:52:32 +00:00
|
|
|
string const filen = ChangeExtension(fromqstr(file), "");
|
|
|
|
bool present = false;
|
|
|
|
int pres = 0;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i != styleCB->count(); i++) {
|
|
|
|
if (fromqstr(styleCB->text(i)) == filen) {
|
|
|
|
present = true;
|
|
|
|
pres = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!present)
|
|
|
|
styleCB->insertItem(toqstr(filen),0);
|
|
|
|
|
|
|
|
styleCB->setCurrentItem(pres);
|
2001-08-26 03:20:52 +00:00
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-17 17:28:04 +00:00
|
|
|
void QBibtexDialog::browseBibPressed()
|
2001-08-26 03:20:52 +00:00
|
|
|
{
|
2002-12-17 17:28:04 +00:00
|
|
|
QString const file = QFileDialog::getOpenFileName(QString::null,
|
2002-12-17 20:37:13 +00:00
|
|
|
qt_("BibTeX database files (*.bib)"), this, 0, qt_("Select a BibTeX database to add"));
|
|
|
|
|
2001-08-27 20:41:45 +00:00
|
|
|
if (!file.isNull()) {
|
2002-12-17 20:37:13 +00:00
|
|
|
string const f = ChangeExtension(fromqstr(file), "");
|
2002-07-22 14:04:38 +00:00
|
|
|
bool present = false;
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
for (unsigned int i = 0; i != databaseLB->count(); i++) {
|
|
|
|
if (fromqstr(databaseLB->text(i)) == f)
|
|
|
|
present = true;
|
2002-07-22 14:04:38 +00:00
|
|
|
}
|
2002-12-17 20:37:13 +00:00
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
if (!present) {
|
2002-12-17 20:37:13 +00:00
|
|
|
databaseLB->insertItem(toqstr(f));
|
2002-07-22 14:04:38 +00:00
|
|
|
form_->changed();
|
|
|
|
}
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-17 17:28:04 +00:00
|
|
|
void QBibtexDialog::addPressed()
|
|
|
|
{
|
|
|
|
QString const file = addBibED->text();
|
|
|
|
if (!file.isNull()) {
|
|
|
|
string const f = ChangeExtension(file.latin1(), "");
|
|
|
|
bool present = false;
|
|
|
|
for(unsigned int i = 0; i != databaseLB->count(); ++i) {
|
|
|
|
if (databaseLB->text(i).latin1() == f)
|
|
|
|
present = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!present) {
|
|
|
|
databaseLB->insertItem(f.c_str());
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-27 20:41:45 +00:00
|
|
|
void QBibtexDialog::deletePressed()
|
|
|
|
{
|
|
|
|
databaseLB->removeItem(databaseLB->currentItem());
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
void QBibtexDialog::styleChanged(QString const & sel)
|
2001-08-26 03:20:52 +00:00
|
|
|
{
|
2002-07-23 13:12:55 +00:00
|
|
|
styleCB->insertItem(sel,0);
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-27 20:41:45 +00:00
|
|
|
void QBibtexDialog::databaseChanged()
|
|
|
|
{
|
|
|
|
deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
void QBibtexDialog::closeEvent(QCloseEvent *e)
|
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|