3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Kalle Dalheimer
9 * Full author contact details are available in file CREDITS.
15 #include "ui/QCitationFindDialogBase.h"
16 #include "QCitationDialog.h"
17 #include "QCitation.h"
19 #include <qcheckbox.h>
20 #include <qcombobox.h>
21 #include <qlineedit.h>
23 #include <qmultilineedit.h>
24 #include <qpushbutton.h>
28 #include "ControlCitation.h"
29 #include "qt_helpers.h"
30 #include "support/lstrings.h"
32 using lyx::support::getStringFromVector;
33 using lyx::support::getVectorFromString;
34 using lyx::support::trim;
41 typedef QController<ControlCitation, QView<QCitationDialog> > base_class;
43 QCitation::QCitation(Dialog & parent)
44 : base_class(parent, _("LyX: Citation Reference"))
48 void QCitation::apply()
50 vector<biblio::CiteStyle> const & styles =
51 ControlCitation::getCiteStyles();
53 int const choice = dialog_->citationStyleCO->currentItem();
54 bool const full = dialog_->fulllistCB->isChecked();
55 bool const force = dialog_->forceuppercaseCB->isChecked();
57 string const command =
58 biblio::getCiteCommand(styles[choice], full, force);
60 controller().params().setCmdName(command);
61 controller().params().setContents(getStringFromVector(citekeys));
63 string const after = fromqstr(dialog_->textAfterED->text());
64 controller().params().setOptions(after);
71 void QCitation::hide()
81 void QCitation::build_dialog()
83 dialog_.reset(new QCitationDialog(this));
85 // Manage the ok, apply, restore and cancel/close buttons
86 bcview().setOK(dialog_->okPB);
87 bcview().setApply(dialog_->applyPB);
88 bcview().setCancel(dialog_->closePB);
89 bcview().setRestore(dialog_->restorePB);
91 bcview().addReadOnly(dialog_->addPB);
92 bcview().addReadOnly(dialog_->deletePB);
93 bcview().addReadOnly(dialog_->upPB);
94 bcview().addReadOnly(dialog_->downPB);
95 bcview().addReadOnly(dialog_->citationStyleCO);
96 bcview().addReadOnly(dialog_->forceuppercaseCB);
97 bcview().addReadOnly(dialog_->fulllistCB);
99 //bcview().addReadOnly(dialog_->textBeforeED);
100 bcview().addReadOnly(dialog_->textAfterED);
106 void QCitation::fillStyles()
108 if (citekeys.empty()) {
109 dialog_->citationStyleCO->setEnabled(false);
110 dialog_->citationStyleLA->setEnabled(false);
114 int const orig = dialog_->citationStyleCO->currentItem();
116 dialog_->citationStyleCO->clear();
118 int curr = dialog_->selectedLB->currentItem();
122 string key = citekeys[curr];
124 vector<string> const & sty = controller().getCiteStrings(key);
126 bool const natbib = controller().usingNatbib();
127 dialog_->citationStyleCO->setEnabled(!sty.empty() && natbib);
128 dialog_->citationStyleLA->setEnabled(!sty.empty() && natbib);
130 for (vector<string>::const_iterator it = sty.begin();
131 it != sty.end(); ++it) {
132 dialog_->citationStyleCO->insertItem(toqstr(*it));
135 if (orig != -1 && orig < dialog_->citationStyleCO->count())
136 dialog_->citationStyleCO->setCurrentItem(orig);
140 void QCitation::updateStyle()
142 bool const natbib = controller().usingNatbib();
144 dialog_->fulllistCB->setEnabled(natbib);
145 dialog_->forceuppercaseCB->setEnabled(natbib);
147 string const & command = controller().params().getCmdName();
149 // Find the style of the citekeys
150 vector<biblio::CiteStyle> const & styles =
151 ControlCitation::getCiteStyles();
152 biblio::CitationStyle cs = biblio::getCitationStyle(command);
154 vector<biblio::CiteStyle>::const_iterator cit =
155 find(styles.begin(), styles.end(), cs.style);
157 // restore the latest natbib style
158 if (style_ >= 0 && style_ < dialog_->citationStyleCO->count())
159 dialog_->citationStyleCO->setCurrentItem(style_);
161 dialog_->citationStyleCO->setCurrentItem(0);
162 dialog_->fulllistCB->setChecked(false);
163 dialog_->forceuppercaseCB->setChecked(false);
165 if (cit != styles.end()) {
166 int const i = int(cit - styles.begin());
167 dialog_->citationStyleCO->setCurrentItem(i);
168 dialog_->fulllistCB->setChecked(cs.full);
169 dialog_->forceuppercaseCB->setChecked(cs.forceUCase);
174 void QCitation::update_contents()
176 // Make the list of all available bibliography keys
177 bibkeys = biblio::getKeys(controller().bibkeysInfo());
178 updateBrowser(dialog_->add_->availableLB, bibkeys);
180 // Ditto for the keys cited in this inset
181 citekeys = getVectorFromString(controller().params().getContents());
182 updateBrowser(dialog_->selectedLB, citekeys);
184 // No keys have been selected yet, so...
185 dialog_->infoML->clear();
186 dialog_->setButtons();
188 dialog_->textAfterED->setText(toqstr(controller().params().getOptions()));
193 // open the find dialog if nothing has been selected (yet)
194 // the bool prevents that this is also done after "apply"
200 void QCitation::updateBrowser(QListBox * browser,
201 vector<string> const & keys) const
205 for (vector<string>::const_iterator it = keys.begin();
206 it < keys.end(); ++it) {
207 string const key = trim(*it);
208 // FIXME: why the .empty() test ?
210 browser->insertItem(toqstr(key));