3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
16 #include "QBibtexDialog.h"
17 #include "ui/QBibtexAddUi.h"
19 #include "qt_helpers.h"
20 #include "validators.h"
24 #include "controllers/ControlBibtex.h"
26 #include "support/filetools.h" // changeExtension
27 #include "support/lstrings.h"
29 #include <QPushButton>
30 #include <QListWidget>
34 using lyx::support::changeExtension;
35 using lyx::support::split;
36 using lyx::support::trim;
44 typedef QController<ControlBibtex, QView<QBibtexDialog> > base_class;
46 QBibtex::QBibtex(Dialog & parent)
47 : base_class(parent, _("BibTeX Bibliography"))
52 void QBibtex::build_dialog()
54 dialog_.reset(new QBibtexDialog(this));
56 bcview().setOK(dialog_->okPB);
57 bcview().setCancel(dialog_->closePB);
58 bcview().addReadOnly(dialog_->databaseLW);
59 bcview().addReadOnly(dialog_->stylePB);
60 bcview().addReadOnly(dialog_->styleCB);
61 bcview().addReadOnly(dialog_->bibtocCB);
62 bcview().addReadOnly(dialog_->addBibPB);
63 bcview().addReadOnly(dialog_->deletePB);
67 void QBibtex::update_contents()
69 PathValidator * path_validator =
70 getPathValidator(dialog_->add_->bibED);
72 path_validator->setChecker(kernel().docType(), lyxrc);
74 bool bibtopic = controller().usingBibtopic();
76 dialog_->databaseLW->clear();
78 string bibs(controller().params().getContents());
81 while (!bibs.empty()) {
82 bibs = split(bibs, bib, ',');
85 dialog_->databaseLW->addItem(toqstr(bib));
88 dialog_->add_->bibLW->clear();
90 vector<string> bib_str;
91 controller().getBibFiles(bib_str);
92 for (vector<string>::const_iterator it = bib_str.begin();
93 it != bib_str.end(); ++it) {
94 string bibItem(changeExtension(*it, ""));
95 dialog_->add_->bibLW->addItem(toqstr(bibItem));
98 string bibstyle(controller().getStylefile());
100 dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
101 dialog_->bibtocCB->setEnabled(!bibtopic);
103 string btprint(controller().params().getSecOptions());
105 if (btprint == "btPrintNotCited")
107 else if (btprint == "btPrintAll")
110 dialog_->btPrintCO->setCurrentIndex(btp);
111 dialog_->btPrintCO->setEnabled(bibtopic);
113 dialog_->styleCB->clear();
118 controller().getBibStyles(str);
119 for (vector<string>::const_iterator it = str.begin();
120 it != str.end(); ++it) {
121 string item(changeExtension(*it, ""));
122 if (item == bibstyle)
123 item_nr = int(it - str.begin());
124 dialog_->styleCB->addItem(toqstr(item));
127 if (item_nr == -1 && !bibstyle.empty()) {
128 dialog_->styleCB->addItem(toqstr(bibstyle));
129 item_nr = dialog_->styleCB->count() - 1;
133 dialog_->styleCB->setCurrentIndex(item_nr);
135 dialog_->styleCB->clearEditText();
139 void QBibtex::apply()
141 string dbs(fromqstr(dialog_->databaseLW->item(0)->text()));
143 unsigned int maxCount = dialog_->databaseLW->count();
144 for (unsigned int i = 1; i < maxCount; i++) {
146 dbs += fromqstr(dialog_->databaseLW->item(i)->text());
149 controller().params().setContents(dbs);
151 string const bibstyle(fromqstr(dialog_->styleCB->currentText()));
152 bool const bibtotoc(dialog_->bibtocCB->isChecked());
154 if (bibtotoc && (!bibstyle.empty())) {
155 // both bibtotoc and style
156 controller().params().setOptions("bibtotoc," + bibstyle);
157 } else if (bibtotoc) {
158 // bibtotoc and no style
159 controller().params().setOptions("bibtotoc");
161 // only style. An empty one is valid, because some
162 // documentclasses have an own \bibliographystyle{}
164 controller().params().setOptions(bibstyle);
167 // bibtopic allows three kinds of sections:
168 // 1. sections that include all cited references of the database(s)
169 // 2. sections that include all uncited references of the database(s)
170 // 3. sections that include all references of the database(s), cited or not
171 int btp = dialog_->btPrintCO->currentIndex();
175 controller().params().setSecOptions("btPrintCited");
178 controller().params().setSecOptions("btPrintNotCited");
181 controller().params().setSecOptions("btPrintAll");
185 if (!controller().usingBibtopic())
186 controller().params().setSecOptions("");
190 bool QBibtex::isValid()
192 return dialog_->databaseLW->count() != 0;
195 } // namespace frontend