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 "controllers/ControlBibtex.h"
19 #include "support/filetools.h"
21 #include <qpushbutton.h>
22 #include <qcombobox.h>
23 #include <qlineedit.h>
26 using lyx::support::ChangeExtension;
33 QBibtexDialog::QBibtexDialog(QBibtex * form)
34 : QBibtexDialogBase(0, 0, false, 0),
37 connect(okPB, SIGNAL(clicked()),
38 form, SLOT(slotOK()));
39 connect(closePB, SIGNAL(clicked()),
40 form, SLOT(slotClose()));
42 add_ = new QBibtexAddDialogBase(this, "", true);
43 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
44 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
45 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addDatabase()));
46 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
47 connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
48 connect(add_->browsePB, SIGNAL(clicked()), this, SLOT(browseBibPressed()));
52 void QBibtexDialog::change_adaptor()
58 void QBibtexDialog::browsePressed()
60 string const file = form_->controller().browseBst("");
63 string const filen = ChangeExtension(file, "");
65 unsigned int pres = 0;
67 for (int i = 0; i != styleCB->count(); ++i) {
68 if (fromqstr(styleCB->text(i)) == filen) {
75 styleCB->insertItem(toqstr(filen),0);
77 styleCB->setCurrentItem(pres);
83 void QBibtexDialog::browseBibPressed()
85 string const file = form_->controller().browseBib("");
88 string const f = ChangeExtension(file, "");
91 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
92 if (fromqstr(add_->bibLB->text(i)) == f)
97 add_->bibLB->insertItem(toqstr(f));
101 add_->bibED->setText(toqstr(f));
105 void QBibtexDialog::addPressed()
111 void QBibtexDialog::addDatabase()
113 int const sel = add_->bibLB->currentItem();
114 QString const file = add_->bibED->text();
116 if (sel < 0 && file.isNull())
119 // Add the selected browser_bib keys to browser_database
120 // multiple selections are possible
121 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
122 if (add_->bibLB->isSelected(i)) {
123 // do not allow duplicates
124 if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
125 databaseLB->insertItem(add_->bibLB->text(i));
129 if (!file.isEmpty()) {
130 QString const f = toqstr(ChangeExtension(fromqstr(file), ""));
131 if ((databaseLB->findItem(f)) == 0)
132 databaseLB->insertItem(f);
139 void QBibtexDialog::deletePressed()
141 databaseLB->removeItem(databaseLB->currentItem());
146 void QBibtexDialog::databaseChanged()
148 deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
152 void QBibtexDialog::availableChanged()
158 void QBibtexDialog::closeEvent(QCloseEvent *e)
164 } // namespace frontend