3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
15 #pragma implementation
18 #include "support/lstrings.h"
20 #include "ControlBibtex.h"
24 #include "support/filetools.h" // ChangeExtension
25 #include "support/lstrings.h" // getVectorFromString
27 #include <qlineedit.h>
28 #include <qcombobox.h>
29 #include <qpushbutton.h>
31 #include <qcheckbox.h>
33 #include "QBibtexDialog.h"
39 typedef Qt2CB<ControlBibtex, Qt2DB<QBibtexDialog> > base_class;
43 : base_class(_("BibTeX"))
48 void QBibtex::build_dialog()
50 dialog_.reset(new QBibtexDialog(this));
52 bc().setOK(dialog_->okPB);
53 bc().setCancel(dialog_->closePB);
54 bc().addReadOnly(dialog_->databaseLB);
55 bc().addReadOnly(dialog_->databasePB);
56 bc().addReadOnly(dialog_->stylePB);
57 bc().addReadOnly(dialog_->styleCB);
58 bc().addReadOnly(dialog_->bibtocCB);
59 bc().addReadOnly(dialog_->databasePB);
60 bc().addReadOnly(dialog_->deletePB);
64 void QBibtex::update_contents()
66 dialog_->databaseLB->clear();
68 string bibs(controller().params().getContents());
71 while (!bibs.empty()) {
72 bibs = split(bibs, bib, ',');
75 dialog_->databaseLB->insertItem(bib.c_str());
78 string bibtotoc = "bibtotoc";
79 string bibstyle(controller().params().getOptions().c_str());
82 if (prefixIs(bibstyle, bibtotoc)) {
83 dialog_->bibtocCB->setChecked(true);
86 if (contains(bibstyle,','))
87 bibstyle = split(bibstyle, bibtotoc, ',');
91 dialog_->bibtocCB->setChecked(false);
94 dialog_->styleCB->clear();
98 vector<string> const str = getVectorFromString(
99 controller().getBibStyles(), "\n");
100 for (vector<string>::const_iterator it = str.begin();
101 it != str.end(); ++it) {
102 string item(ChangeExtension(*it, ""));
103 if (item == bibstyle)
104 item_nr = int(it - str.begin());
105 dialog_->styleCB->insertItem(item.c_str());
109 dialog_->styleCB->insertItem(bibstyle.c_str());
110 item_nr = dialog_->styleCB->count() - 1;
113 dialog_->styleCB->setCurrentItem(item_nr);
117 void QBibtex::apply()
119 string dbs(dialog_->databaseLB->text(0).latin1());
121 unsigned int maxCount = dialog_->databaseLB->count();
122 for (unsigned int i = 1; i < maxCount; i++) {
124 dbs += dialog_->databaseLB->text(i).latin1();
127 controller().params().setContents(dbs);
129 string const bibstyle(dialog_->styleCB->currentText().latin1());
130 bool const bibtotoc(dialog_->bibtocCB->isChecked());
132 if (bibtotoc && (!bibstyle.empty())) {
133 // both bibtotoc and style
134 controller().params().setOptions("bibtotoc," + bibstyle);
135 } else if (bibtotoc) {
136 // bibtotoc and no style
137 controller().params().setOptions("bibtotoc");
139 // only style. An empty one is valid, because some
140 // documentclasses have an own \bibliographystyle{}
142 controller().params().setOptions(bibstyle);
147 bool QBibtex::isValid()
149 return dialog_->databaseLB->count() != 0;