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 * Full author contact details are available in file CREDITS
16 #include "qt_helpers.h"
17 #include "controllers/ControlCitation.h"
20 #include <qcheckbox.h>
21 #include <qcombobox.h>
22 #include <qlineedit.h>
24 #include <qmultilineedit.h>
25 #include <qpushbutton.h>
28 #include "ui/QCitationFindDialogBase.h"
29 #include "QCitationDialog.h"
30 #include "QCitation.h"
31 #include "support/lstrings.h"
39 QCitationDialog::QCitationDialog(QCitation * form)
40 : QCitationDialogBase(0, 0, false, 0),
43 connect(restorePB, SIGNAL(clicked()),
44 form, SLOT(slotRestore()));
45 connect(okPB, SIGNAL(clicked()),
46 form, SLOT(slotOK()));
47 connect(applyPB, SIGNAL(clicked()),
48 form, SLOT(slotApply()));
49 connect(closePB, SIGNAL(clicked()),
50 form, SLOT(slotClose()));
52 add_ = new QCitationFindDialogBase(this, "", true);
53 connect(add_->previousPB, SIGNAL(clicked()), this, SLOT(previous()));
54 connect(add_->nextPB, SIGNAL(clicked()), this, SLOT(next()));
55 connect(add_->availableLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
56 connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addCitation()));
57 connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
58 connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addCitation()));
59 connect(selectedLB, SIGNAL(returnPressed(QListBoxItem *)), form, SLOT(slotOK()));
63 QCitationDialog::~QCitationDialog()
68 void QCitationDialog::setButtons()
70 if (form_->readOnly())
73 int const sel_nr = selectedLB->currentItem();
74 int const avail_nr = add_->availableLB->currentItem();
76 add_->addPB->setEnabled(avail_nr >= 0);
77 deletePB->setEnabled(sel_nr >= 0);
78 upPB->setEnabled(sel_nr > 0);
79 downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1));
83 void QCitationDialog::selectedChanged()
86 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
89 int const sel = selectedLB->currentItem();
95 infoML->setText(toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
100 void QCitationDialog::previous()
102 find(biblio::BACKWARD);
106 void QCitationDialog::next()
108 find(biblio::FORWARD);
112 void QCitationDialog::availableChanged()
114 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
115 add_->infoML->clear();
117 int const sel = add_->availableLB->currentItem();
123 add_->infoML->setText(toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
128 void QCitationDialog::addCitation()
130 int const sel = add_->availableLB->currentItem();
135 // Add the selected browser_bib keys to browser_cite
136 // multiple selections are possible
137 for (unsigned int i = 0; i != add_->availableLB->count(); i++) {
138 if (add_->availableLB->isSelected(i)) {
139 // do not allow duplicates
140 if ((selectedLB->findItem(add_->availableLB->text(i))) == 0) {
141 selectedLB->insertItem(toqstr(form_->bibkeys[i]));
142 form_->citekeys.push_back(form_->bibkeys[i]);
147 int const n = int(form_->citekeys.size());
148 selectedLB->setSelected(n - 1, true);
156 void QCitationDialog::del()
158 int const sel = selectedLB->currentItem();
160 // Remove the selected key from browser_cite
161 selectedLB->removeItem(sel);
162 form_->citekeys.erase(form_->citekeys.begin() + sel);
170 void QCitationDialog::up()
172 int const sel = selectedLB->currentItem();
174 // Move the selected key up one line
175 vector<string>::iterator it = form_->citekeys.begin() + sel;
176 string const tmp = *it;
178 selectedLB->removeItem(sel);
179 form_->citekeys.erase(it);
181 selectedLB->insertItem(toqstr(tmp), sel - 1);
182 selectedLB->setSelected(sel - 1, true);
183 form_->citekeys.insert(it - 1, tmp);
191 void QCitationDialog::down()
193 int const sel = selectedLB->currentItem();
195 // Move the selected key down one line
196 vector<string>::iterator it = form_->citekeys.begin() + sel;
197 string const tmp = *it;
199 selectedLB->removeItem(sel);
200 form_->citekeys.erase(it);
202 selectedLB->insertItem(toqstr(tmp), sel + 1);
203 selectedLB->setSelected(sel + 1, true);
204 form_->citekeys.insert(it + 1, tmp);
212 void QCitationDialog::add()
218 void QCitationDialog::changed_adaptor()
224 void QCitationDialog::find(biblio::Direction dir)
226 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
228 biblio::Search const type = add_->searchTypeCB->isChecked()
229 ? biblio::REGEX : biblio::SIMPLE;
231 vector<string>::const_iterator start = form_->bibkeys.begin();
232 int const sel = add_->availableLB->currentItem();
233 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
236 // Find the NEXT instance...
237 if (dir == biblio::FORWARD)
242 bool const casesens = add_->searchCaseCB->isChecked();
243 string const str = fromqstr(add_->searchED->text());
245 vector<string>::const_iterator cit =
246 biblio::searchKeys(theMap, form_->bibkeys, str,
247 start, type, dir, casesens);
249 // not found. let's loop round
250 if (cit == form_->bibkeys.end()) {
251 if (dir == biblio::FORWARD) {
252 start = form_->bibkeys.begin();
254 else start = form_->bibkeys.end() - 1;
256 cit = biblio::searchKeys(theMap, form_->bibkeys, str,
257 start, type, dir, casesens);
259 if (cit == form_->bibkeys.end())
263 int const found = int(cit - form_->bibkeys.begin());
268 // Update the display
269 add_->availableLB->setSelected(found, true);
270 add_->availableLB->ensureCurrentVisible();