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()));
62 QCitationDialog::~QCitationDialog()
67 void QCitationDialog::setButtons()
69 if (form_->readOnly())
72 int const sel_nr = selectedLB->currentItem();
73 int const avail_nr = add_->availableLB->currentItem();
75 add_->addPB->setEnabled(avail_nr >= 0);
76 deletePB->setEnabled(sel_nr >= 0);
77 upPB->setEnabled(sel_nr > 0);
78 downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1));
82 void QCitationDialog::selectedChanged()
85 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
88 int const sel = selectedLB->currentItem();
94 infoML->setText(toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
99 void QCitationDialog::previous()
101 find(biblio::BACKWARD);
105 void QCitationDialog::next()
107 find(biblio::FORWARD);
111 void QCitationDialog::availableChanged()
113 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
114 add_->infoML->clear();
116 int const sel = add_->availableLB->currentItem();
122 add_->infoML->setText(toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
127 void QCitationDialog::addCitation()
129 int const sel = add_->availableLB->currentItem();
134 // Add the selected browser_bib key to browser_cite
135 selectedLB->insertItem(toqstr(form_->bibkeys[sel]));
136 form_->citekeys.push_back(form_->bibkeys[sel]);
138 int const n = int(form_->citekeys.size());
139 selectedLB->setSelected(n - 1, true);
147 void QCitationDialog::del()
149 int const sel = selectedLB->currentItem();
151 // Remove the selected key from browser_cite
152 selectedLB->removeItem(sel);
153 form_->citekeys.erase(form_->citekeys.begin() + sel);
161 void QCitationDialog::up()
163 int const sel = selectedLB->currentItem();
165 // Move the selected key up one line
166 vector<string>::iterator it = form_->citekeys.begin() + sel;
167 string const tmp = *it;
169 selectedLB->removeItem(sel);
170 form_->citekeys.erase(it);
172 selectedLB->insertItem(toqstr(tmp), sel - 1);
173 selectedLB->setSelected(sel - 1, true);
174 form_->citekeys.insert(it - 1, tmp);
182 void QCitationDialog::down()
184 int const sel = selectedLB->currentItem();
186 // Move the selected key down one line
187 vector<string>::iterator it = form_->citekeys.begin() + sel;
188 string const tmp = *it;
190 selectedLB->removeItem(sel);
191 form_->citekeys.erase(it);
193 selectedLB->insertItem(toqstr(tmp), sel + 1);
194 selectedLB->setSelected(sel + 1, true);
195 form_->citekeys.insert(it + 1, tmp);
203 void QCitationDialog::add()
209 void QCitationDialog::changed_adaptor()
215 void QCitationDialog::find(biblio::Direction dir)
217 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
219 biblio::Search const type = add_->searchTypeCB->isChecked()
220 ? biblio::REGEX : biblio::SIMPLE;
222 vector<string>::const_iterator start = form_->bibkeys.begin();
223 int const sel = add_->availableLB->currentItem();
224 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
227 // Find the NEXT instance...
228 if (dir == biblio::FORWARD)
233 bool const casesens = add_->searchCaseCB->isChecked();
234 string const str = fromqstr(add_->searchED->text());
236 vector<string>::const_iterator cit =
237 biblio::searchKeys(theMap, form_->bibkeys, str,
238 start, type, dir, casesens);
240 // not found. let's loop round
241 if (cit == form_->bibkeys.end()) {
242 if (dir == biblio::FORWARD) {
243 start = form_->bibkeys.begin();
245 else start = form_->bibkeys.end() - 1;
247 cit = biblio::searchKeys(theMap, form_->bibkeys, str,
248 start, type, dir, casesens);
250 if (cit == form_->bibkeys.end())
254 int const found = int(cit - form_->bibkeys.begin());
259 // Update the display
260 add_->availableLB->setSelected(found, true);
261 add_->availableLB->ensureCurrentVisible();