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.
13 #include "QBibtexDialog.h"
14 #include "ui/QBibtexAddDialogBase.h"
16 #include "qt_helpers.h"
18 #include "support/filetools.h"
20 #include <qpushbutton.h>
21 #include <qcombobox.h>
22 #include <qlineedit.h>
24 #include <qfiledialog.h>
27 using lyx::support::ChangeExtension;
34 QBibtexDialog::QBibtexDialog(QBibtex * form)
35 : QBibtexDialogBase(qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget(), 0, false, 0),
38 connect(okPB, SIGNAL(clicked()),
39 form, SLOT(slotOK()));
40 connect(closePB, SIGNAL(clicked()),
41 form, SLOT(slotClose()));
43 add_ = new QBibtexAddDialogBase(this, "", true);
44 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
45 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
46 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addDatabase()));
47 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
48 connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
49 connect(add_->browsePB, SIGNAL(clicked()), this, SLOT(browseBibPressed()));
53 void QBibtexDialog::change_adaptor()
59 void QBibtexDialog::browsePressed()
62 QFileDialog::getOpenFileName(QString::null,
63 qt_("BibTeX style files (*.bst)"),
66 qt_("Select a BibTeX style"));
68 string const filen = ChangeExtension(fromqstr(file), "");
70 unsigned int pres = 0;
72 for (int i = 0; i != styleCB->count(); ++i) {
73 if (fromqstr(styleCB->text(i)) == filen) {
80 styleCB->insertItem(toqstr(filen),0);
82 styleCB->setCurrentItem(pres);
88 void QBibtexDialog::browseBibPressed()
90 QString const file = QFileDialog::getOpenFileName(QString::null,
91 qt_("BibTeX database files (*.bib)"), add_, 0, qt_("Select a BibTeX database to add"));
94 string const f = ChangeExtension(fromqstr(file), "");
97 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
98 if (fromqstr(add_->bibLB->text(i)) == f)
103 add_->bibLB->insertItem(toqstr(f));
107 add_->bibED->setText(toqstr(f));
111 void QBibtexDialog::addPressed()
117 void QBibtexDialog::addDatabase()
119 int const sel = add_->bibLB->currentItem();
120 QString const file = add_->bibED->text();
122 if (sel < 0 && file.isNull())
125 // Add the selected browser_bib keys to browser_database
126 // multiple selections are possible
127 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
128 if (add_->bibLB->isSelected(i)) {
129 // do not allow duplicates
130 if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
131 databaseLB->insertItem(add_->bibLB->text(i));
135 if (!file.isEmpty()) {
136 QString const f = toqstr(ChangeExtension(fromqstr(file), ""));
137 if ((databaseLB->findItem(f)) == 0)
138 databaseLB->insertItem(f);
145 void QBibtexDialog::deletePressed()
147 databaseLB->removeItem(databaseLB->currentItem());
152 void QBibtexDialog::databaseChanged()
154 deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
158 void QBibtexDialog::availableChanged()
164 void QBibtexDialog::closeEvent(QCloseEvent *e)
170 } // namespace frontend