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 slotBibHighlighted(sel);
160 form_->setBibButtons(QCitation::OFF);
161 form_->setCiteButtons(QCitation::ON);
166 void QCitationDialog::slotDelClicked()
168 int const sel = citeLB->currentItem();
171 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
175 // Remove the selected key from browser_cite
176 citeLB->removeItem(sel);
177 form_->citekeys.erase(form_->citekeys.begin() + sel);
179 form_->setBibButtons(QCitation::ON);
180 form_->setCiteButtons(QCitation::OFF);
185 void QCitationDialog::slotUpClicked()
187 int const sel = citeLB->currentItem();
190 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
194 // Move the selected key up one line
195 vector<string>::iterator it = form_->citekeys.begin() + sel;
196 string const tmp = *it;
198 citeLB->removeItem(sel);
199 form_->citekeys.erase(it);
201 citeLB->insertItem(tmp.c_str(), sel - 1);
202 citeLB->setSelected(sel - 1, true);
203 form_->citekeys.insert(it - 1, tmp);
204 form_->setCiteButtons(QCitation::ON);
209 void QCitationDialog::slotDownClicked()
211 int const sel = citeLB->currentItem();
214 if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
218 // Move the selected key down one line
219 vector<string>::iterator it = form_->citekeys.begin() + sel;
220 string const tmp = *it;
222 citeLB->removeItem(sel);
223 form_->citekeys.erase(it);
225 citeLB->insertItem(tmp.c_str(), sel + 1);
226 citeLB->setSelected(sel + 1, true);
227 form_->citekeys.insert(it + 1, tmp);
228 form_->setCiteButtons(QCitation::ON);
233 void QCitationDialog::slotPreviousClicked()
235 doFind(biblio::BACKWARD);
239 void QCitationDialog::slotNextClicked()
241 doFind(biblio::FORWARD);
245 void QCitationDialog::doFind(biblio::Direction dir)
247 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
248 string const str = searchED->text().latin1();
250 biblio::Search const type =
251 searchTypeCB->isChecked() ?
252 biblio::REGEX : biblio::SIMPLE;
254 vector<string>::const_iterator start = form_->bibkeys.begin();
255 int const sel = bibLB->currentItem();
256 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
259 // Find the NEXT instance...
260 if (dir == biblio::FORWARD)
265 bool const caseSensitive = searchCaseCB->isChecked();
267 vector<string>::const_iterator cit =
268 biblio::searchKeys(theMap, form_->bibkeys, str,
269 start, type, dir, caseSensitive);
271 // not found. let's loop round
272 if (cit == form_->bibkeys.end()) {
273 if (dir == biblio::FORWARD) {
274 start = form_->bibkeys.begin();
276 else start = form_->bibkeys.end() - 1;
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);