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"
|
2005-05-16 09:14:18 +00:00
|
|
|
|
|
|
|
#include "checkedwidgets.h"
|
|
|
|
#include "Qt2BC.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2005-05-16 09:14:18 +00:00
|
|
|
#include "validators.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2004-08-08 13:17:22 +00:00
|
|
|
#include "controllers/ControlBibtex.h"
|
2005-05-16 09:14:18 +00:00
|
|
|
#include "controllers/ButtonPolicies.h"
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "support/filetools.h"
|
2005-05-16 09:14:18 +00:00
|
|
|
#include "support/lstrings.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
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;
|
2005-05-16 09:14:18 +00:00
|
|
|
using lyx::support::trim;
|
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);
|
2005-05-16 09:14:18 +00:00
|
|
|
Qt2BC * bcview = new Qt2BC(add_bc_);
|
|
|
|
add_bc_.view(bcview);
|
|
|
|
add_bc_.bp(new OkCancelPolicy);
|
|
|
|
|
|
|
|
bcview->setOK(add_->addPB);
|
|
|
|
bcview->setCancel(add_->closePB);
|
|
|
|
|
|
|
|
add_->bibED->setValidator(new PathValidator(false, add_->bibED));
|
|
|
|
addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
|
|
|
|
|
|
|
|
connect(add_->bibED, SIGNAL(textChanged(const QString&)),
|
|
|
|
this, SLOT(bibEDChanged()));
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QBibtexDialog::~QBibtexDialog()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::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);
|
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
|
|
|
{
|
2005-05-16 09:14:18 +00:00
|
|
|
string const file = trim(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-16 09:14:18 +00:00
|
|
|
|
2002-12-17 17:28:04 +00:00
|
|
|
void QBibtexDialog::addPressed()
|
|
|
|
{
|
2003-04-12 03:08:08 +00:00
|
|
|
add_->exec();
|
2005-05-16 09:14:18 +00:00
|
|
|
add_bc_.valid(false);
|
2003-04-12 03:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::addDatabase()
|
|
|
|
{
|
2003-07-21 09:08:14 +00:00
|
|
|
int const sel = add_->bibLB->currentItem();
|
2005-05-31 22:06:07 +00:00
|
|
|
string const file = trim(fromqstr(add_->bibED->text()));
|
2003-04-12 03:08:08 +00:00
|
|
|
|
2005-05-31 22:06:07 +00:00
|
|
|
if (sel < 0 && file.empty())
|
2003-07-21 09:08:14 +00:00
|
|
|
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
|
|
|
|
2005-05-31 22:06:07 +00:00
|
|
|
if (!file.empty()) {
|
|
|
|
QString const f = toqstr(ChangeExtension(file, ""));
|
2003-07-21 09:08:14 +00:00
|
|
|
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
|