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
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* 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
|
|
|
|
2004-05-20 09:36:28 +00:00
|
|
|
#include "QBibtexDialog.h"
|
|
|
|
#include "ui/QBibtexAddDialogBase.h"
|
|
|
|
#include "QBibtex.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2004-08-08 13:17:22 +00:00
|
|
|
#include "controllers/ControlBibtex.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
#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>
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::ChangeExtension;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
QBibtexDialog::QBibtexDialog(QBibtex * form)
|
2004-06-02 20:13:18 +00:00
|
|
|
: QBibtexDialogBase(0, 0, false, 0),
|
2001-08-26 03:20:52 +00:00
|
|
|
form_(form)
|
|
|
|
{
|
|
|
|
connect(okPB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotOK()));
|
|
|
|
connect(closePB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotClose()));
|
2003-04-12 03:08:08 +00:00
|
|
|
|
|
|
|
add_ = new QBibtexAddDialogBase(this, "", true);
|
|
|
|
connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
|
|
|
|
connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
|
|
|
|
connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addDatabase()));
|
|
|
|
connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
|
|
|
|
connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
|
|
|
|
connect(add_->browsePB, SIGNAL(clicked()), this, SLOT(browseBibPressed()));
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2004-08-08 13:17:22 +00:00
|
|
|
string const file = form_->controller().browseBst("");
|
|
|
|
|
|
|
|
if (!file.empty()) {
|
|
|
|
string const filen = ChangeExtension(file, "");
|
2003-02-14 13:52:32 +00:00
|
|
|
bool present = false;
|
2003-02-14 17:23:50 +00:00
|
|
|
unsigned int pres = 0;
|
2003-02-14 13:52:32 +00:00
|
|
|
|
2003-06-20 14:03:49 +00:00
|
|
|
for (int i = 0; i != styleCB->count(); ++i) {
|
2003-02-14 13:52:32 +00:00
|
|
|
if (fromqstr(styleCB->text(i)) == filen) {
|
|
|
|
present = true;
|
|
|
|
pres = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-25 13:35:26 +00:00
|
|
|
if (!present)
|
2003-02-14 13:52:32 +00:00
|
|
|
styleCB->insertItem(toqstr(filen),0);
|
2003-02-25 13:35:26 +00:00
|
|
|
|
2003-02-14 13:52:32 +00:00
|
|
|
styleCB->setCurrentItem(pres);
|
2001-08-26 03:20:52 +00:00
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-12 03:08:08 +00:00
|
|
|
|
2002-12-17 17:28:04 +00:00
|
|
|
void QBibtexDialog::browseBibPressed()
|
2001-08-26 03:20:52 +00:00
|
|
|
{
|
2004-08-08 13:17:22 +00:00
|
|
|
string const file = form_->controller().browseBib("");
|
2002-12-17 20:37:13 +00:00
|
|
|
|
2004-08-08 13:17:22 +00:00
|
|
|
if (!file.empty()) {
|
|
|
|
string const f = ChangeExtension(file, "");
|
2002-07-22 14:04:38 +00:00
|
|
|
bool present = false;
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2003-04-12 03:08:08 +00:00
|
|
|
for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
|
|
|
|
if (fromqstr(add_->bibLB->text(i)) == f)
|
2002-12-17 20:37:13 +00:00
|
|
|
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) {
|
2003-04-12 03:08:08 +00:00
|
|
|
add_->bibLB->insertItem(toqstr(f));
|
2002-07-22 14:04:38 +00:00
|
|
|
form_->changed();
|
|
|
|
}
|
2003-04-12 03:08:08 +00:00
|
|
|
|
|
|
|
add_->bibED->setText(toqstr(f));
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-17 17:28:04 +00:00
|
|
|
void QBibtexDialog::addPressed()
|
|
|
|
{
|
2003-04-12 03:08:08 +00:00
|
|
|
add_->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::addDatabase()
|
|
|
|
{
|
2003-07-21 09:08:14 +00:00
|
|
|
int const sel = add_->bibLB->currentItem();
|
2003-04-12 03:08:08 +00:00
|
|
|
QString const file = add_->bibED->text();
|
|
|
|
|
2003-07-21 09:08:14 +00:00
|
|
|
if (sel < 0 && file.isNull())
|
|
|
|
return;
|
2002-12-17 17:28:04 +00:00
|
|
|
|
2003-07-21 09:08:14 +00:00
|
|
|
// Add the selected browser_bib keys to browser_database
|
|
|
|
// multiple selections are possible
|
|
|
|
for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
|
|
|
|
if (add_->bibLB->isSelected(i)) {
|
|
|
|
// do not allow duplicates
|
|
|
|
if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
|
|
|
|
databaseLB->insertItem(add_->bibLB->text(i));
|
2002-12-17 17:28:04 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-21 09:08:14 +00:00
|
|
|
|
|
|
|
if (!file.isEmpty()) {
|
|
|
|
QString const f = toqstr(ChangeExtension(fromqstr(file), ""));
|
|
|
|
if ((databaseLB->findItem(f)) == 0)
|
|
|
|
databaseLB->insertItem(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
form_->changed();
|
2002-12-17 17:28:04 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2003-04-12 03:08:08 +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
|
|
|
|
2003-04-12 03:08:08 +00:00
|
|
|
|
|
|
|
void QBibtexDialog::databaseChanged()
|
2001-08-26 03:20:52 +00:00
|
|
|
{
|
2003-04-12 03:08:08 +00:00
|
|
|
deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2003-04-12 03:08:08 +00:00
|
|
|
void QBibtexDialog::availableChanged()
|
2001-08-27 20:41:45 +00:00
|
|
|
{
|
2003-07-21 09:08:14 +00:00
|
|
|
form_->changed();
|
2001-08-27 20:41:45 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|