X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt2%2FQCitationDialog.C;h=4a188b647c4dbc082203f3b701d5c20635c1dc98;hb=ce044d86c4e9363d6c20f98327ce13a90b13d7d7;hp=214cb54c21267ad78eb9d6b6afdaf2d6103f1621;hpb=4d6c6daf4e49d7c0d9ec8bf357e72b1340c8bd96;p=lyx.git diff --git a/src/frontends/qt2/QCitationDialog.C b/src/frontends/qt2/QCitationDialog.C index 214cb54c21..4a188b647c 100644 --- a/src/frontends/qt2/QCitationDialog.C +++ b/src/frontends/qt2/QCitationDialog.C @@ -25,6 +25,7 @@ #include #include +#include "ui/QCitationFindDialogBase.h" #include "QCitationDialog.h" #include "QCitation.h" #include "support/lstrings.h" @@ -47,6 +48,15 @@ QCitationDialog::QCitationDialog(QCitation * form) 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())); } @@ -61,10 +71,10 @@ void QCitationDialog::setButtons() 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)); } @@ -83,54 +93,56 @@ void QCitationDialog::selectedChanged() } infoML->setText(toqstr(biblio::getInfo(theMap, form_->citekeys[sel]))); + setButtons(); +} - vector::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::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); @@ -172,7 +184,6 @@ void QCitationDialog::up() form_->changed(); form_->fillStyles(); - availableLB->clearSelection(); setButtons(); } @@ -194,20 +205,13 @@ void QCitationDialog::down() form_->changed(); form_->fillStyles(); - availableLB->clearSelection(); setButtons(); } -void QCitationDialog::previous() -{ - doFind(biblio::BACKWARD); -} - - -void QCitationDialog::next() +void QCitationDialog::add() { - doFind(biblio::FORWARD); + add_->exec(); } @@ -217,17 +221,15 @@ void QCitationDialog::changed_adaptor() } -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::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; @@ -237,11 +239,12 @@ void QCitationDialog::doFind(biblio::Direction dir) else start -= 1; - bool const caseSensitive = searchCaseCB->isChecked(); + bool const casesens = add_->searchCaseCB->isChecked(); + string const str = fromqstr(add_->searchED->text()); vector::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()) { @@ -251,7 +254,7 @@ void QCitationDialog::doFind(biblio::Direction dir) 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; @@ -263,6 +266,6 @@ void QCitationDialog::doFind(biblio::Direction dir) } // Update the display - availableLB->setSelected(found, true); - availableLB->ensureCurrentVisible(); + add_->availableLB->setSelected(found, true); + add_->availableLB->ensureCurrentVisible(); }