2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QBibtexDialog.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "QBibtexDialog.h"
|
|
|
|
|
|
|
|
#include <QCloseEvent>
|
|
|
|
|
|
|
|
#include "checkedwidgets.h"
|
|
|
|
#include "Qt2BC.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "validators.h"
|
|
|
|
|
|
|
|
#include "controllers/ControlBibtex.h"
|
|
|
|
#include "controllers/ButtonPolicies.h"
|
|
|
|
|
2006-05-02 19:17:59 +00:00
|
|
|
#include "debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2006-05-02 19:17:59 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QLineEdit>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-09 08:42:58 +00:00
|
|
|
using lyx::support::changeExtension;
|
2006-03-05 17:24:44 +00:00
|
|
|
using lyx::support::trim;
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
|
|
QBibtexDialog::QBibtexDialog(QBibtex * form)
|
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2006-05-02 19:17:59 +00:00
|
|
|
QDialog::setModal(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(okPB, SIGNAL(clicked()),
|
2006-03-05 17:24:44 +00:00
|
|
|
form, SLOT(slotOK()));
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()),
|
2006-03-05 17:24:44 +00:00
|
|
|
form, SLOT(slotClose()));
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(stylePB, SIGNAL( clicked() ),
|
2006-05-02 19:17:59 +00:00
|
|
|
this, SLOT( browsePressed() ) );
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(deletePB, SIGNAL( clicked() ),
|
2006-05-02 19:17:59 +00:00
|
|
|
this, SLOT( deletePressed() ) );
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(styleCB, SIGNAL( textChanged(const QString&) ),
|
2006-05-02 19:17:59 +00:00
|
|
|
this, SLOT( change_adaptor() ) );
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(databaseLW, SIGNAL( selectionChanged() ),
|
2006-05-02 19:17:59 +00:00
|
|
|
this, SLOT( databaseChanged() ) );
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(bibtocCB, SIGNAL( toggled(bool) ),
|
2006-05-02 19:17:59 +00:00
|
|
|
this, SLOT( change_adaptor() ) );
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(btPrintCO, SIGNAL( activated(int) ),
|
2006-05-02 19:17:59 +00:00
|
|
|
this, SLOT( change_adaptor() ) );
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(addBibPB, SIGNAL( clicked() ),
|
2006-05-02 19:17:59 +00:00
|
|
|
this, SLOT( addPressed() ) );
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
add_ = new UiDialog<Ui::QBibtexAddUi>(this, true);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(add_->bibED, SIGNAL(textChanged(const QString&)),
|
2006-03-05 17:24:44 +00:00
|
|
|
this, SLOT(bibEDChanged()));
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(add_->addPB, SIGNAL(clicked()),
|
2006-03-05 17:24:44 +00:00
|
|
|
this, SLOT(addDatabase()));
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(add_->addPB, SIGNAL(clicked()),
|
2006-05-02 19:17:59 +00:00
|
|
|
add_, SLOT(accept()) );
|
|
|
|
connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
|
2006-03-05 17:24:44 +00:00
|
|
|
this, SLOT(addDatabase()));
|
2006-05-02 19:17:59 +00:00
|
|
|
connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
|
2006-03-05 17:24:44 +00:00
|
|
|
add_, SLOT(accept()));
|
2006-05-02 19:17:59 +00:00
|
|
|
connect(add_->bibLW, SIGNAL(itemChanged(QListWidgetItem *)),
|
2006-03-05 17:24:44 +00:00
|
|
|
this, SLOT(availableChanged()));
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(add_->browsePB, SIGNAL(clicked()),
|
2006-03-05 17:24:44 +00:00
|
|
|
this, SLOT(browseBibPressed()));
|
2006-05-04 07:31:46 +00:00
|
|
|
connect(add_->closePB, SIGNAL( clicked() ),
|
2006-05-02 19:17:59 +00:00
|
|
|
add_, SLOT( reject() ) );
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::change_adaptor()
|
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::browsePressed()
|
|
|
|
{
|
|
|
|
string const file = form_->controller().browseBst("");
|
|
|
|
|
|
|
|
if (!file.empty()) {
|
2006-04-09 08:42:58 +00:00
|
|
|
string const filen = changeExtension(file, "");
|
2006-03-05 17:24:44 +00:00
|
|
|
bool present = false;
|
|
|
|
unsigned int pres = 0;
|
|
|
|
|
|
|
|
for (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);
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::browseBibPressed()
|
|
|
|
{
|
|
|
|
string const file = trim(form_->controller().browseBib(""));
|
|
|
|
|
|
|
|
if (!file.empty()) {
|
2006-05-04 07:31:46 +00:00
|
|
|
QString const f = toqstr(changeExtension(file, ""));
|
2006-03-05 17:24:44 +00:00
|
|
|
bool present = false;
|
|
|
|
|
2006-05-02 19:17:59 +00:00
|
|
|
for (unsigned int i = 0; i != add_->bibLW->count(); i++) {
|
2006-05-04 07:31:46 +00:00
|
|
|
if (add_->bibLW->item(i)->text() == f)
|
2006-03-05 17:24:44 +00:00
|
|
|
present = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!present) {
|
2006-05-02 19:17:59 +00:00
|
|
|
add_->bibLW->addItem(toqstr(f));
|
2006-03-05 17:24:44 +00:00
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
add_->bibED->setText(toqstr(f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::addPressed()
|
|
|
|
{
|
|
|
|
add_->exec();
|
|
|
|
add_bc_.valid(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::addDatabase()
|
|
|
|
{
|
2006-05-02 19:17:59 +00:00
|
|
|
int const sel = add_->bibLW->currentRow();
|
2006-03-05 17:24:44 +00:00
|
|
|
string const file = trim(fromqstr(add_->bibED->text()));
|
|
|
|
|
|
|
|
if (sel < 0 && file.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Add the selected browser_bib keys to browser_database
|
|
|
|
// multiple selections are possible
|
2006-05-02 19:17:59 +00:00
|
|
|
for (unsigned 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);
|
|
|
|
if (matches.empty())
|
|
|
|
databaseLW->addItem(item->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file.empty()) {
|
2006-05-02 19:17:59 +00:00
|
|
|
add_->bibED->clear();
|
2006-04-09 08:42:58 +00:00
|
|
|
QString const f = toqstr(changeExtension(file, ""));
|
2006-05-02 19:17:59 +00:00
|
|
|
QList<QListWidgetItem *> matches =
|
|
|
|
databaseLW->findItems(f, Qt::MatchExactly);
|
|
|
|
if (matches.empty())
|
|
|
|
databaseLW->addItem(f);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::deletePressed()
|
|
|
|
{
|
2006-05-02 19:17:59 +00:00
|
|
|
databaseLW->takeItem(databaseLW->currentRow());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::databaseChanged()
|
|
|
|
{
|
2006-05-02 19:17:59 +00:00
|
|
|
deletePB->setEnabled(!form_->readOnly() && databaseLW->currentRow() != -1);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::availableChanged()
|
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtexDialog::closeEvent(QCloseEvent *e)
|
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2006-05-02 19:17:59 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|