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"
17 #include "checkedwidgets.h"
19 #include "qt_helpers.h"
20 #include "validators.h"
22 #include "controllers/ControlBibtex.h"
23 #include "controllers/ButtonPolicies.h"
25 #include "support/filetools.h"
26 #include "support/lstrings.h"
28 #include <qpushbutton.h>
29 #include <qcombobox.h>
30 #include <qlineedit.h>
33 using lyx::support::ChangeExtension;
34 using lyx::support::trim;
41 QBibtexDialog::QBibtexDialog(QBibtex * form)
42 : QBibtexDialogBase(0, 0, false, 0),
45 connect(okPB, SIGNAL(clicked()),
46 form, SLOT(slotOK()));
47 connect(closePB, SIGNAL(clicked()),
48 form, SLOT(slotClose()));
50 add_ = new QBibtexAddDialogBase(this, "", true);
51 Qt2BC * bcview = new Qt2BC(add_bc_);
53 add_bc_.bp(new OkCancelPolicy);
55 bcview->setOK(add_->addPB);
56 bcview->setCancel(add_->closePB);
58 add_->bibED->setValidator(new PathValidator(false, add_->bibED));
59 addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
61 connect(add_->bibED, SIGNAL(textChanged(const QString&)),
62 this, SLOT(bibEDChanged()));
63 connect(add_->addPB, SIGNAL(clicked()),
64 this, SLOT(addDatabase()));
65 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)),
66 this, SLOT(addDatabase()));
67 connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)),
68 add_, SLOT(accept()));
69 connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)),
70 this, SLOT(availableChanged()));
71 connect(add_->browsePB, SIGNAL(clicked()),
72 this, SLOT(browseBibPressed()));
76 QBibtexDialog::~QBibtexDialog()
80 void QBibtexDialog::bibEDChanged()
82 // Indicate to the button controller that the contents have
83 // changed. The actual test of validity is carried out by
84 // the checkedLineEdit.
89 void QBibtexDialog::change_adaptor()
95 void QBibtexDialog::browsePressed()
97 string const file = form_->controller().browseBst("");
100 string const filen = ChangeExtension(file, "");
101 bool present = false;
102 unsigned int pres = 0;
104 for (int i = 0; i != styleCB->count(); ++i) {
105 if (fromqstr(styleCB->text(i)) == filen) {
112 styleCB->insertItem(toqstr(filen),0);
114 styleCB->setCurrentItem(pres);
120 void QBibtexDialog::browseBibPressed()
122 string const file = trim(form_->controller().browseBib(""));
125 string const f = ChangeExtension(file, "");
126 bool present = false;
128 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
129 if (fromqstr(add_->bibLB->text(i)) == f)
134 add_->bibLB->insertItem(toqstr(f));
138 add_->bibED->setText(toqstr(f));
143 void QBibtexDialog::addPressed()
146 add_bc_.valid(false);
150 void QBibtexDialog::addDatabase()
152 int const sel = add_->bibLB->currentItem();
153 string const file = trim(fromqstr(add_->bibED->text()));
155 if (sel < 0 && file.empty())
158 // Add the selected browser_bib keys to browser_database
159 // multiple selections are possible
160 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
161 if (add_->bibLB->isSelected(i)) {
162 // do not allow duplicates
163 if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
164 databaseLB->insertItem(add_->bibLB->text(i));
169 QString const f = toqstr(ChangeExtension(file, ""));
170 if ((databaseLB->findItem(f)) == 0)
171 databaseLB->insertItem(f);
178 void QBibtexDialog::deletePressed()
180 databaseLB->removeItem(databaseLB->currentItem());
185 void QBibtexDialog::databaseChanged()
187 deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
191 void QBibtexDialog::availableChanged()
197 void QBibtexDialog::closeEvent(QCloseEvent *e)
203 } // namespace frontend