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>
36 QCitationDialog::QCitationDialog(QCitation * form)
37 : QCitationDialogBase(0, 0, false, 0),
40 connect(restorePB, SIGNAL(clicked()),
41 form, SLOT(slotRestore()));
42 connect(okPB, SIGNAL(clicked()),
43 form, SLOT(slotOK()));
44 connect(applyPB, SIGNAL(clicked()),
45 form, SLOT(slotApply()));
46 connect(closePB, SIGNAL(clicked()),
47 form, SLOT(slotClose()));
49 add_ = new QCitationFindDialogBase(this, "", true);
50 connect(add_->previousPB, SIGNAL(clicked()), this, SLOT(previous()));
51 connect(add_->nextPB, SIGNAL(clicked()), this, SLOT(next()));
52 connect(add_->availableLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
53 connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addCitation()));
54 connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
55 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addCitation()));
56 connect(selectedLB, SIGNAL(returnPressed(QListBoxItem *)), form, SLOT(slotOK()));
60 QCitationDialog::~QCitationDialog()
65 void QCitationDialog::setButtons()
67 if (form_->readOnly())
70 int const sel_nr = selectedLB->currentItem();
71 int const avail_nr = add_->availableLB->currentItem();
73 add_->addPB->setEnabled(avail_nr >= 0);
74 deletePB->setEnabled(sel_nr >= 0);
75 upPB->setEnabled(sel_nr > 0);
76 downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1));
80 void QCitationDialog::openFind()
82 if (form_->readOnly())
85 if (selectedLB->count() == 0 && add_->availableLB->count() != 0){
86 // open the find dialog
88 // and let the user press ok after a selection
89 if (selectedLB->count() != 0)
95 void QCitationDialog::selectedChanged()
98 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
101 int const sel = selectedLB->currentItem();
109 toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
114 void QCitationDialog::previous()
116 find(biblio::BACKWARD);
120 void QCitationDialog::next()
122 find(biblio::FORWARD);
126 void QCitationDialog::availableChanged()
128 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
129 add_->infoML->clear();
131 int const sel = add_->availableLB->currentItem();
138 add_->infoML->setText(
139 toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
144 void QCitationDialog::addCitation()
146 int const sel = add_->availableLB->currentItem();
151 // Add the selected browser_bib keys to browser_cite
152 // multiple selections are possible
153 for (unsigned int i = 0; i != add_->availableLB->count(); i++) {
154 if (add_->availableLB->isSelected(i)) {
155 // do not allow duplicates
156 if ((selectedLB->findItem(add_->availableLB->text(i))) == 0) {
157 selectedLB->insertItem(toqstr(form_->bibkeys[i]));
158 form_->citekeys.push_back(form_->bibkeys[i]);
163 int const n = int(form_->citekeys.size());
164 selectedLB->setSelected(n - 1, true);
172 void QCitationDialog::del()
174 int const sel = selectedLB->currentItem();
176 // Remove the selected key from browser_cite
177 selectedLB->removeItem(sel);
178 form_->citekeys.erase(form_->citekeys.begin() + sel);
186 void QCitationDialog::up()
188 int const sel = selectedLB->currentItem();
190 // Move the selected key up one line
191 vector<string>::iterator it = form_->citekeys.begin() + sel;
192 string const tmp = *it;
194 selectedLB->removeItem(sel);
195 form_->citekeys.erase(it);
197 selectedLB->insertItem(toqstr(tmp), sel - 1);
198 selectedLB->setSelected(sel - 1, true);
199 form_->citekeys.insert(it - 1, tmp);
207 void QCitationDialog::down()
209 int const sel = selectedLB->currentItem();
211 // Move the selected key down one line
212 vector<string>::iterator it = form_->citekeys.begin() + sel;
213 string const tmp = *it;
215 selectedLB->removeItem(sel);
216 form_->citekeys.erase(it);
218 selectedLB->insertItem(toqstr(tmp), sel + 1);
219 selectedLB->setSelected(sel + 1, true);
220 form_->citekeys.insert(it + 1, tmp);
228 void QCitationDialog::add()
234 void QCitationDialog::changed_adaptor()
240 void QCitationDialog::find(biblio::Direction dir)
242 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
244 biblio::Search const type = add_->searchTypeCB->isChecked()
245 ? biblio::REGEX : biblio::SIMPLE;
247 vector<string>::const_iterator start = form_->bibkeys.begin();
248 int const sel = add_->availableLB->currentItem();
249 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
252 // Find the NEXT instance...
253 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 add_->availableLB->setSelected(found, true);
286 add_->availableLB->ensureCurrentVisible();
289 } // namespace frontend