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 key to browser_cite
136 selectedLB->insertItem(toqstr(form_->bibkeys[sel]));
137 form_->citekeys.push_back(form_->bibkeys[sel]);
139 int const n = int(form_->citekeys.size());
140 selectedLB->setSelected(n - 1, true);
148 void QCitationDialog::del()
150 int const sel = selectedLB->currentItem();
152 // Remove the selected key from browser_cite
153 selectedLB->removeItem(sel);
154 form_->citekeys.erase(form_->citekeys.begin() + sel);
162 void QCitationDialog::up()
164 int const sel = selectedLB->currentItem();
166 // Move the selected key up one line
167 vector<string>::iterator it = form_->citekeys.begin() + sel;
168 string const tmp = *it;
170 selectedLB->removeItem(sel);
171 form_->citekeys.erase(it);
173 selectedLB->insertItem(toqstr(tmp), sel - 1);
174 selectedLB->setSelected(sel - 1, true);
175 form_->citekeys.insert(it - 1, tmp);
183 void QCitationDialog::down()
185 int const sel = selectedLB->currentItem();
187 // Move the selected key down one line
188 vector<string>::iterator it = form_->citekeys.begin() + sel;
189 string const tmp = *it;
191 selectedLB->removeItem(sel);
192 form_->citekeys.erase(it);
194 selectedLB->insertItem(toqstr(tmp), sel + 1);
195 selectedLB->setSelected(sel + 1, true);
196 form_->citekeys.insert(it + 1, tmp);
204 void QCitationDialog::add()
210 void QCitationDialog::changed_adaptor()
216 void QCitationDialog::find(biblio::Direction dir)
218 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
220 biblio::Search const type = add_->searchTypeCB->isChecked()
221 ? biblio::REGEX : biblio::SIMPLE;
223 vector<string>::const_iterator start = form_->bibkeys.begin();
224 int const sel = add_->availableLB->currentItem();
225 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
228 // Find the NEXT instance...
229 if (dir == biblio::FORWARD)
234 bool const casesens = add_->searchCaseCB->isChecked();
235 string const str = fromqstr(add_->searchED->text());
237 vector<string>::const_iterator cit =
238 biblio::searchKeys(theMap, form_->bibkeys, str,
239 start, type, dir, casesens);
241 // not found. let's loop round
242 if (cit == form_->bibkeys.end()) {
243 if (dir == biblio::FORWARD) {
244 start = form_->bibkeys.begin();
246 else start = form_->bibkeys.end() - 1;
248 cit = biblio::searchKeys(theMap, form_->bibkeys, str,
249 start, type, dir, casesens);
251 if (cit == form_->bibkeys.end())
255 int const found = int(cit - form_->bibkeys.begin());
260 // Update the display
261 add_->availableLB->setSelected(found, true);
262 add_->availableLB->ensureCurrentVisible();