2 * \file QCitationDialog.C
3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
14 #include "controllers/ControlCitation.h"
18 #include <qcheckbox.h>
19 #include <qcombobox.h>
20 #include <qlineedit.h>
22 #include <qmultilineedit.h>
23 #include <qpushbutton.h>
25 #include "QCitationDialog.h"
31 QCitationDialog::QCitationDialog(QCitation * form)
32 : QCitationDialogBase(0, 0, false, 0),
35 connect(restorePB, SIGNAL(clicked()),
36 form, SLOT(slotRestore()));
37 connect(okPB, SIGNAL(clicked()),
38 form, SLOT(slotOK()));
39 connect(applyPB, SIGNAL(clicked()),
40 form, SLOT(slotApply()));
41 connect(closePB, SIGNAL(clicked()),
42 form, SLOT(slotClose()));
43 connect(searchED, SIGNAL(returnPressed()),
44 this, SLOT(slotNextClicked()));
46 textBeforeED->setText(_("Not yet supported"));
47 textBeforeED->setReadOnly(true);
48 textBeforeED->setFocusPolicy(QWidget::NoFocus);
49 citationStyleCO->setEnabled(false);
50 citationStyleCO->setFocusPolicy(QWidget::NoFocus);
54 QCitationDialog::~QCitationDialog()
59 void QCitationDialog::slotBibSelected(int sel)
61 slotBibHighlighted(sel);
63 if (form_->readOnly())
70 void QCitationDialog::slotBibHighlighted(int sel)
72 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
74 citeLB->clearSelection();
76 // FIXME: why would this happen ?
77 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
81 // Put into browser_info the additional info associated with
82 // the selected browser_bib key
85 infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
87 // Highlight the selected browser_bib key in browser_cite if
89 vector<string>::const_iterator cit =
90 std::find(form_->citekeys.begin(), form_->citekeys.end(),
93 if (cit != form_->citekeys.end()) {
94 int const n = int(cit - form_->citekeys.begin());
95 citeLB->setSelected(n, true);
96 citeLB->setTopItem(n);
99 if (!form_->readOnly()) {
100 if (cit != form_->citekeys.end()) {
101 form_->setBibButtons(QCitation::OFF);
102 form_->setCiteButtons(QCitation::ON);
104 form_->setBibButtons(QCitation::ON);
105 form_->setCiteButtons(QCitation::OFF);
111 void QCitationDialog::slotCiteHighlighted(int sel)
113 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
115 // FIXME: why would this happen ?
116 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
120 if (!form_->readOnly()) {
121 form_->setBibButtons(QCitation::OFF);
122 form_->setCiteButtons(QCitation::ON);
125 // Highlight the selected browser_cite key in browser_bib
126 vector<string>::const_iterator cit =
127 std::find(form_->bibkeys.begin(),
128 form_->bibkeys.end(), form_->citekeys[sel]);
130 if (cit != form_->bibkeys.end()) {
131 int const n = int(cit - form_->bibkeys.begin());
132 bibLB->setSelected(n, true);
133 bibLB->setTopItem(n);
135 // Put into browser_info the additional info associated
136 // with the selected browser_cite key
138 infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
143 void QCitationDialog::slotAddClicked()
145 int const sel = bibLB->currentItem();
148 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
152 // Add the selected browser_bib key to browser_cite
153 citeLB->insertItem(form_->bibkeys[sel].c_str());
154 form_->citekeys.push_back(form_->bibkeys[sel]);
156 int const n = int(form_->citekeys.size());
157 citeLB->setSelected(n - 1, true);
159 form_->setBibButtons(QCitation::OFF);
160 form_->setCiteButtons(QCitation::ON);
165 void QCitationDialog::slotDelClicked()
167 int const sel = citeLB->currentItem();
170 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
174 // Remove the selected key from browser_cite
175 citeLB->removeItem(sel);
176 form_->citekeys.erase(form_->citekeys.begin() + sel);
178 form_->setBibButtons(QCitation::ON);
179 form_->setCiteButtons(QCitation::OFF);
184 void QCitationDialog::slotUpClicked()
186 int const sel = citeLB->currentItem();
189 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
193 // Move the selected key up one line
194 vector<string>::iterator it = form_->citekeys.begin() + sel;
195 string const tmp = *it;
197 citeLB->removeItem(sel);
198 form_->citekeys.erase(it);
200 citeLB->insertItem(tmp.c_str(), sel - 1);
201 citeLB->setSelected(sel - 1, true);
202 form_->citekeys.insert(it - 1, tmp);
203 form_->setCiteButtons(QCitation::ON);
208 void QCitationDialog::slotDownClicked()
210 int const sel = citeLB->currentItem();
213 if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
217 // Move the selected key down one line
218 vector<string>::iterator it = form_->citekeys.begin() + sel;
219 string const tmp = *it;
221 citeLB->removeItem(sel);
222 form_->citekeys.erase(it);
224 citeLB->insertItem(tmp.c_str(), sel + 1);
225 citeLB->setSelected(sel + 1, true);
226 form_->citekeys.insert(it + 1, tmp);
227 form_->setCiteButtons(QCitation::ON);
232 void QCitationDialog::slotPreviousClicked()
234 doFind(biblio::BACKWARD);
238 void QCitationDialog::slotNextClicked()
240 doFind(biblio::FORWARD);
244 void QCitationDialog::doFind(biblio::Direction dir)
246 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
247 string const str = searchED->text().latin1();
249 biblio::Search const type =
250 searchTypeCB->isChecked() ?
251 biblio::REGEX : biblio::SIMPLE;
253 vector<string>::const_iterator start = form_->bibkeys.begin();
254 int const sel = bibLB->currentItem();
255 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
258 // Find the NEXT instance...
259 if (dir == biblio::FORWARD)
264 bool const caseSensitive = searchCaseCB->isChecked();
266 vector<string>::const_iterator cit =
267 biblio::searchKeys(theMap, form_->bibkeys, str,
268 start, type, dir, caseSensitive);
270 // FIXME: should work ...
271 if (cit == form_->bibkeys.end()) {
272 // not found. let's loop round
273 if (dir == biblio::FORWARD)
274 start = form_->bibkeys.begin();
276 start = form_->bibkeys.end();
278 cit = biblio::searchKeys(theMap, form_->bibkeys, str,
279 start, type, dir, caseSensitive);
281 if (cit == form_->bibkeys.end())
285 int const found = int(cit - form_->bibkeys.begin());
290 // Update the display
291 int const top = max(found - 5, 1);
292 bibLB->setTopItem(top);
293 bibLB->setSelected(found, true);
294 slotBibHighlighted(0);