2 * \file QCitationDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Kalle Dalheimer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "QCitationDialog.h"
16 #include "ui/QCitationFindDialogBase.h"
17 #include "QCitation.h"
18 #include "qt_helpers.h"
20 #include "controllers/ControlCitation.h"
21 #include "controllers/ButtonController.h"
23 #include <qcheckbox.h>
24 #include <qlineedit.h>
26 #include <qmultilineedit.h>
27 #include <qpushbutton.h>
37 QCitationDialog::QCitationDialog(QCitation * form)
38 : QCitationDialogBase(0, 0, false, 0),
41 connect(restorePB, SIGNAL(clicked()),
42 form, SLOT(slotRestore()));
43 connect(okPB, SIGNAL(clicked()),
44 form, SLOT(slotOK()));
45 connect(applyPB, SIGNAL(clicked()),
46 form, SLOT(slotApply()));
47 connect(closePB, SIGNAL(clicked()),
48 form, SLOT(slotClose()));
50 add_ = new QCitationFindDialogBase(this, "", true);
51 connect(add_->previousPB, SIGNAL(clicked()), this, SLOT(previous()));
52 connect(add_->nextPB, SIGNAL(clicked()), this, SLOT(next()));
53 connect(add_->availableLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
54 connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addCitation()));
55 connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
56 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addCitation()));
57 connect(selectedLB, SIGNAL(returnPressed(QListBoxItem *)), form, SLOT(slotOK()));
61 QCitationDialog::~QCitationDialog()
66 void QCitationDialog::setButtons()
68 if (form_->readOnly())
71 int const sel_nr = selectedLB->currentItem();
72 int const avail_nr = add_->availableLB->currentItem();
74 add_->addPB->setEnabled(avail_nr >= 0);
75 deletePB->setEnabled(sel_nr >= 0);
76 upPB->setEnabled(sel_nr > 0);
77 downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1));
81 void QCitationDialog::openFind()
83 if (form_->readOnly())
86 if (isVisible() && selectedLB->count() == 0
87 && add_->availableLB->count() != 0){
88 // open the find dialog
90 // and let the user press ok after a selection
91 if (selectedLB->count() != 0)
97 void QCitationDialog::selectedChanged()
100 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
103 int const sel = selectedLB->currentItem();
111 toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
116 void QCitationDialog::previous()
118 find(biblio::BACKWARD);
122 void QCitationDialog::next()
124 find(biblio::FORWARD);
128 void QCitationDialog::availableChanged()
130 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
131 add_->infoML->clear();
133 int const sel = add_->availableLB->currentItem();
140 add_->infoML->setText(
141 toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
146 void QCitationDialog::addCitation()
148 int const sel = add_->availableLB->currentItem();
153 // Add the selected browser_bib keys to browser_cite
154 // multiple selections are possible
155 for (unsigned int i = 0; i != add_->availableLB->count(); i++) {
156 if (add_->availableLB->isSelected(i)) {
157 // do not allow duplicates
158 if ((selectedLB->findItem(add_->availableLB->text(i))) == 0) {
159 selectedLB->insertItem(toqstr(form_->bibkeys[i]));
160 form_->citekeys.push_back(form_->bibkeys[i]);
165 int const n = int(form_->citekeys.size());
166 selectedLB->setSelected(n - 1, true);
174 void QCitationDialog::del()
176 int const sel = selectedLB->currentItem();
178 // Remove the selected key from browser_cite
179 selectedLB->removeItem(sel);
180 form_->citekeys.erase(form_->citekeys.begin() + sel);
188 void QCitationDialog::up()
190 int const sel = selectedLB->currentItem();
192 BOOST_ASSERT(sel > 0);
194 // Move the selected key up one line
195 string const tmp = form_->citekeys[sel];
197 selectedLB->removeItem(sel);
198 swap(form_->citekeys[sel - 1], form_->citekeys[sel]);
200 selectedLB->insertItem(toqstr(tmp), sel - 1);
201 selectedLB->setSelected(sel - 1, true);
209 void QCitationDialog::down()
211 int const sel = selectedLB->currentItem();
213 BOOST_ASSERT(sel < (int)form_->citekeys.size());
215 // Move the selected key down one line
216 string const tmp = form_->citekeys[sel];
218 selectedLB->removeItem(sel);
219 swap(form_->citekeys[sel + 1], form_->citekeys[sel]);
221 selectedLB->insertItem(toqstr(tmp), sel + 1);
222 selectedLB->setSelected(sel + 1, true);
230 void QCitationDialog::add()
236 void QCitationDialog::changed_adaptor()
242 void QCitationDialog::find(biblio::Direction dir)
244 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
246 biblio::Search const type = add_->searchTypeCB->isChecked()
247 ? biblio::REGEX : biblio::SIMPLE;
249 vector<string>::const_iterator start = form_->bibkeys.begin();
250 int const sel = add_->availableLB->currentItem();
251 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
254 // Find the NEXT instance...
255 if (dir == biblio::FORWARD)
258 bool const casesens = add_->searchCaseCB->isChecked();
259 string const str = fromqstr(add_->searchED->text());
261 vector<string>::const_iterator cit =
262 biblio::searchKeys(theMap, form_->bibkeys, str,
263 start, type, dir, casesens);
265 // not found. let's loop round
266 if (cit == form_->bibkeys.end()) {
267 if (dir == biblio::FORWARD) {
268 start = form_->bibkeys.begin();
270 else start = form_->bibkeys.end() - 1;
272 cit = biblio::searchKeys(theMap, form_->bibkeys, str,
273 start, type, dir, casesens);
275 if (cit == form_->bibkeys.end())
279 int const found = int(cit - form_->bibkeys.begin());
284 // Update the display
285 // note that we have multi selection mode!
286 add_->availableLB->setSelected(sel, false);
287 add_->availableLB->setSelected(found, true);
288 add_->availableLB->setCurrentItem(found);
289 add_->availableLB->ensureCurrentVisible();
292 } // namespace frontend