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 "qt_helpers.h"
15 #include "support/filetools.h"
17 #include <qpushbutton.h>
18 #include <qcombobox.h>
19 #include <qlineedit.h>
21 #include <qfiledialog.h>
23 #include "ui/QBibtexAddDialogBase.h"
24 #include "QBibtexDialog.h"
27 using lyx::support::ChangeExtension;
30 QBibtexDialog::QBibtexDialog(QBibtex * form)
31 : QBibtexDialogBase(0, 0, false, 0),
34 connect(okPB, SIGNAL(clicked()),
35 form, SLOT(slotOK()));
36 connect(closePB, SIGNAL(clicked()),
37 form, SLOT(slotClose()));
39 add_ = new QBibtexAddDialogBase(this, "", true);
40 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
41 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
42 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addDatabase()));
43 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
44 connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
45 connect(add_->browsePB, SIGNAL(clicked()), this, SLOT(browseBibPressed()));
49 void QBibtexDialog::change_adaptor()
55 void QBibtexDialog::browsePressed()
58 QFileDialog::getOpenFileName(QString::null,
59 qt_("BibTeX style files (*.bst)"),
62 qt_("Select a BibTeX style"));
64 string const filen = ChangeExtension(fromqstr(file), "");
66 unsigned int pres = 0;
68 for (int i = 0; i != styleCB->count(); ++i) {
69 if (fromqstr(styleCB->text(i)) == filen) {
76 styleCB->insertItem(toqstr(filen),0);
78 styleCB->setCurrentItem(pres);
84 void QBibtexDialog::browseBibPressed()
86 QString const file = QFileDialog::getOpenFileName(QString::null,
87 qt_("BibTeX database files (*.bib)"), add_, 0, qt_("Select a BibTeX database to add"));
90 string const f = ChangeExtension(fromqstr(file), "");
93 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
94 if (fromqstr(add_->bibLB->text(i)) == f)
99 add_->bibLB->insertItem(toqstr(f));
103 add_->bibED->setText(toqstr(f));
107 void QBibtexDialog::addPressed()
113 void QBibtexDialog::addDatabase()
115 int const sel = add_->bibLB->currentItem();
116 QString const file = add_->bibED->text();
118 if (sel < 0 && file.isNull())
121 // Add the selected browser_bib keys to browser_database
122 // multiple selections are possible
123 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
124 if (add_->bibLB->isSelected(i)) {
125 // do not allow duplicates
126 if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
127 databaseLB->insertItem(add_->bibLB->text(i));
131 if (!file.isEmpty()) {
132 QString const f = toqstr(ChangeExtension(fromqstr(file), ""));
133 if ((databaseLB->findItem(f)) == 0)
134 databaseLB->insertItem(f);
141 void QBibtexDialog::deletePressed()
143 databaseLB->removeItem(databaseLB->currentItem());
148 void QBibtexDialog::databaseChanged()
150 deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
154 void QBibtexDialog::availableChanged()
160 void QBibtexDialog::closeEvent(QCloseEvent *e)