#include <qpushbutton.h>
#include <qlabel.h>
+#include "ui/QCitationFindDialogBase.h"
#include "QCitationDialog.h"
#include "QCitation.h"
#include "support/lstrings.h"
form, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
form, SLOT(slotClose()));
+
+ add_ = new QCitationFindDialogBase(this, "", true);
+ connect(add_->previousPB, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(add_->nextPB, SIGNAL(clicked()), this, SLOT(next()));
+ connect(add_->availableLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
+ connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addCitation()));
+ connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
+ connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addCitation()));
+ connect(selectedLB, SIGNAL(returnPressed(QListBoxItem *)), form, SLOT(slotOK()));
}
return;
int const sel_nr = selectedLB->currentItem();
- int const avail_nr = availableLB->currentItem();
+ int const avail_nr = add_->availableLB->currentItem();
- addPB->setEnabled(avail_nr >= 0);
- delPB->setEnabled(sel_nr >= 0);
+ add_->addPB->setEnabled(avail_nr >= 0);
+ deletePB->setEnabled(sel_nr >= 0);
upPB->setEnabled(sel_nr > 0);
downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1));
}
}
infoML->setText(toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
+ setButtons();
+}
- vector<string>::const_iterator cit =
- std::find(form_->bibkeys.begin(),
- form_->bibkeys.end(), form_->citekeys[sel]);
- if (cit != form_->bibkeys.end()) {
- int const n = int(cit - form_->bibkeys.begin());
- availableLB->setSelected(n, true);
- availableLB->ensureCurrentVisible();
- }
- setButtons();
+void QCitationDialog::previous()
+{
+ find(biblio::BACKWARD);
+}
+
+
+void QCitationDialog::next()
+{
+ find(biblio::FORWARD);
}
void QCitationDialog::availableChanged()
{
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
- selectedLB->clearSelection();
- infoML->clear();
+ add_->infoML->clear();
- int const sel = availableLB->currentItem();
+ int const sel = add_->availableLB->currentItem();
if (sel < 0) {
setButtons();
return;
}
- infoML->setText(toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
-
- vector<string>::const_iterator cit =
- std::find(form_->citekeys.begin(), form_->citekeys.end(),
- form_->bibkeys[sel]);
-
- if (cit != form_->citekeys.end()) {
- int const n = int(cit - form_->citekeys.begin());
- selectedLB->setSelected(n, true);
- selectedLB->ensureCurrentVisible();
- }
+ add_->infoML->setText(toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
setButtons();
}
-void QCitationDialog::add()
+void QCitationDialog::addCitation()
{
- int const sel = availableLB->currentItem();
+ int const sel = add_->availableLB->currentItem();
- // Add the selected browser_bib key to browser_cite
- selectedLB->insertItem(toqstr(form_->bibkeys[sel]));
- form_->citekeys.push_back(form_->bibkeys[sel]);
+ if (sel < 0)
+ return;
+
+ // Add the selected browser_bib keys to browser_cite
+ // multiple selections are possible
+ for (unsigned int i = 0; i != add_->availableLB->count(); i++) {
+ if (add_->availableLB->isSelected(i)) {
+ // do not allow duplicates
+ if ((selectedLB->findItem(add_->availableLB->text(i))) == 0) {
+ selectedLB->insertItem(toqstr(form_->bibkeys[i]));
+ form_->citekeys.push_back(form_->bibkeys[i]);
+ }
+ }
+ }
int const n = int(form_->citekeys.size());
selectedLB->setSelected(n - 1, true);
form_->changed();
form_->fillStyles();
- availableLB->clearSelection();
setButtons();
}
form_->changed();
form_->fillStyles();
- availableLB->clearSelection();
setButtons();
}
-void QCitationDialog::previous()
-{
- doFind(biblio::BACKWARD);
-}
-
-
-void QCitationDialog::next()
+void QCitationDialog::add()
{
- doFind(biblio::FORWARD);
+ add_->exec();
}
}
-void QCitationDialog::doFind(biblio::Direction dir)
+void QCitationDialog::find(biblio::Direction dir)
{
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
- string const str = fromqstr(searchED->text());
- biblio::Search const type =
- searchTypeCB->isChecked() ?
- biblio::REGEX : biblio::SIMPLE;
+ biblio::Search const type = add_->searchTypeCB->isChecked()
+ ? biblio::REGEX : biblio::SIMPLE;
vector<string>::const_iterator start = form_->bibkeys.begin();
- int const sel = availableLB->currentItem();
+ int const sel = add_->availableLB->currentItem();
if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
start += sel;
else
start -= 1;
- bool const caseSensitive = searchCaseCB->isChecked();
+ bool const casesens = add_->searchCaseCB->isChecked();
+ string const str = fromqstr(add_->searchED->text());
vector<string>::const_iterator cit =
biblio::searchKeys(theMap, form_->bibkeys, str,
- start, type, dir, caseSensitive);
+ start, type, dir, casesens);
// not found. let's loop round
if (cit == form_->bibkeys.end()) {
else start = form_->bibkeys.end() - 1;
cit = biblio::searchKeys(theMap, form_->bibkeys, str,
- start, type, dir, caseSensitive);
+ start, type, dir, casesens);
if (cit == form_->bibkeys.end())
return;
}
// Update the display
- availableLB->setSelected(found, true);
- availableLB->ensureCurrentVisible();
+ add_->availableLB->setSelected(found, true);
+ add_->availableLB->ensureCurrentVisible();
}