2 * \file QBibtexDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 #include "qt_helpers.h"
16 #include "support/filetools.h"
18 #include <qpushbutton.h>
19 #include <qcombobox.h>
20 #include <qlineedit.h>
22 #include <qfiledialog.h>
24 #include "ui/QBibtexAddDialogBase.h"
25 #include "QBibtexDialog.h"
29 using namespace lyx::support;
31 QBibtexDialog::QBibtexDialog(QBibtex * form)
32 : QBibtexDialogBase(0, 0, false, 0),
35 connect(okPB, SIGNAL(clicked()),
36 form, SLOT(slotOK()));
37 connect(closePB, SIGNAL(clicked()),
38 form, SLOT(slotClose()));
40 add_ = new QBibtexAddDialogBase(this, "", true);
41 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
42 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
43 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addDatabase()));
44 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
45 connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
46 connect(add_->browsePB, SIGNAL(clicked()), this, SLOT(browseBibPressed()));
50 void QBibtexDialog::change_adaptor()
56 void QBibtexDialog::browsePressed()
59 QFileDialog::getOpenFileName(QString::null,
60 qt_("BibTeX style files (*.bst)"),
63 qt_("Select a BibTeX style"));
65 string const filen = ChangeExtension(fromqstr(file), "");
67 unsigned int pres = 0;
69 for (int i = 0; i != styleCB->count(); ++i) {
70 if (fromqstr(styleCB->text(i)) == filen) {
77 styleCB->insertItem(toqstr(filen),0);
79 styleCB->setCurrentItem(pres);
85 void QBibtexDialog::browseBibPressed()
87 QString const file = QFileDialog::getOpenFileName(QString::null,
88 qt_("BibTeX database files (*.bib)"), add_, 0, qt_("Select a BibTeX database to add"));
91 string const f = ChangeExtension(fromqstr(file), "");
94 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
95 if (fromqstr(add_->bibLB->text(i)) == f)
100 add_->bibLB->insertItem(toqstr(f));
104 add_->bibED->setText(toqstr(f));
108 void QBibtexDialog::addPressed()
114 void QBibtexDialog::addDatabase()
116 int const sel = add_->bibLB->currentItem();
117 QString const file = add_->bibED->text();
119 if (sel < 0 && file.isNull())
122 // Add the selected browser_bib keys to browser_database
123 // multiple selections are possible
124 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
125 if (add_->bibLB->isSelected(i)) {
126 // do not allow duplicates
127 if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
128 databaseLB->insertItem(add_->bibLB->text(i));
132 if (!file.isEmpty()) {
133 QString const f = toqstr(ChangeExtension(fromqstr(file), ""));
134 if ((databaseLB->findItem(f)) == 0)
135 databaseLB->insertItem(f);
142 void QBibtexDialog::deletePressed()
144 databaseLB->removeItem(databaseLB->currentItem());
149 void QBibtexDialog::databaseChanged()
151 deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
155 void QBibtexDialog::availableChanged()
161 void QBibtexDialog::closeEvent(QCloseEvent *e)