X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt2%2FQCitationDialog.C;h=4a188b647c4dbc082203f3b701d5c20635c1dc98;hb=ce044d86c4e9363d6c20f98327ce13a90b13d7d7;hp=74d45f960c56523383f06794369793918f1921b0;hpb=da4456f2aab5c449886cfb40ff6a141d347c92d1;p=lyx.git diff --git a/src/frontends/qt2/QCitationDialog.C b/src/frontends/qt2/QCitationDialog.C index 74d45f960c..4a188b647c 100644 --- a/src/frontends/qt2/QCitationDialog.C +++ b/src/frontends/qt2/QCitationDialog.C @@ -10,16 +10,12 @@ #include -#ifdef __GNUG__ -#pragma implementation -#endif #include -#include "gettext.h" +#include "qt_helpers.h" #include "controllers/ControlCitation.h" -#include "LyXView.h" -#include "buffer.h" +#include "debug.h" #include #include @@ -27,7 +23,9 @@ #include #include #include +#include +#include "ui/QCitationFindDialogBase.h" #include "QCitationDialog.h" #include "QCitation.h" #include "support/lstrings.h" @@ -35,6 +33,8 @@ using std::vector; using std::find; using std::max; +using std::endl; + QCitationDialog::QCitationDialog(QCitation * form) : QCitationDialogBase(0, 0, false, 0), @@ -48,14 +48,15 @@ QCitationDialog::QCitationDialog(QCitation * form) form, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); - connect(searchED, SIGNAL(returnPressed()), - this, SLOT(slotNextClicked())); - - textBeforeED->setText(_("Not yet supported")); - textBeforeED->setReadOnly(true); - textBeforeED->setFocusPolicy(QWidget::NoFocus); - citationStyleCO->setEnabled(false); - citationStyleCO->setFocusPolicy(QWidget::NoFocus); + + 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())); } @@ -64,189 +65,153 @@ QCitationDialog::~QCitationDialog() } -void QCitationDialog::slotBibSelected(int sel) +void QCitationDialog::setButtons() { - slotBibHighlighted(sel); - if (form_->readOnly()) return; - slotAddClicked(); + int const sel_nr = selectedLB->currentItem(); + int const avail_nr = add_->availableLB->currentItem(); + + 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)); } -void QCitationDialog::slotBibHighlighted(int sel) +void QCitationDialog::selectedChanged() { + form_->fillStyles(); biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); + infoML->clear(); - citeLB->clearSelection(); - - // FIXME: why would this happen ? - if (sel < 0 || sel >= (int)form_->bibkeys.size()) { + int const sel = selectedLB->currentItem(); + if (sel < 0) { + setButtons(); return; } - // Put into browser_info the additional info associated with - // the selected browser_bib key - infoML->clear(); + infoML->setText(toqstr(biblio::getInfo(theMap, form_->citekeys[sel]))); + setButtons(); +} - infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str()); - // Highlight the selected browser_bib key in browser_cite if - // present - vector::const_iterator cit = - std::find(form_->citekeys.begin(), form_->citekeys.end(), - form_->bibkeys[sel]); +void QCitationDialog::previous() +{ + find(biblio::BACKWARD); +} - if (cit != form_->citekeys.end()) { - int const n = int(cit - form_->citekeys.begin()); - citeLB->setSelected(n, true); - citeLB->setTopItem(n); - } - if (!form_->readOnly()) { - if (cit != form_->citekeys.end()) { - form_->setBibButtons(QCitation::OFF); - form_->setCiteButtons(QCitation::ON); - } else { - form_->setBibButtons(QCitation::ON); - form_->setCiteButtons(QCitation::OFF); - } - } +void QCitationDialog::next() +{ + find(biblio::FORWARD); } -void QCitationDialog::slotCiteHighlighted(int sel) +void QCitationDialog::availableChanged() { biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); + add_->infoML->clear(); - // FIXME: why would this happen ? - if (sel < 0 || sel >= (int)form_->citekeys.size()) { + int const sel = add_->availableLB->currentItem(); + if (sel < 0) { + setButtons(); return; } - if (!form_->readOnly()) { - form_->setBibButtons(QCitation::OFF); - form_->setCiteButtons(QCitation::ON); - } - - // Highlight the selected browser_cite key in browser_bib - 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()); - bibLB->setSelected(n, true); - bibLB->setTopItem(n); - - // Put into browser_info the additional info associated - // with the selected browser_cite key - infoML->clear(); - infoML->setText(biblio::getInfo(theMap, form_->citekeys[sel]).c_str()); - } + add_->infoML->setText(toqstr(biblio::getInfo(theMap, form_->bibkeys[sel]))); + setButtons(); } -void QCitationDialog::slotAddClicked() +void QCitationDialog::addCitation() { - int const sel = bibLB->currentItem(); + int const sel = add_->availableLB->currentItem(); - // FIXME: why ? - if (sel < 0 || sel >= (int)form_->bibkeys.size()) { + if (sel < 0) return; - } - // Add the selected browser_bib key to browser_cite - citeLB->insertItem(form_->bibkeys[sel].c_str()); - form_->citekeys.push_back(form_->bibkeys[sel]); + // 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()); - citeLB->setSelected(n - 1, true); + selectedLB->setSelected(n - 1, true); - slotBibHighlighted(sel); - form_->setBibButtons(QCitation::OFF); - form_->setCiteButtons(QCitation::ON); form_->changed(); + form_->fillStyles(); + setButtons(); } -void QCitationDialog::slotDelClicked() +void QCitationDialog::del() { - int const sel = citeLB->currentItem(); - - // FIXME: why ? - if (sel < 0 || sel >= (int)form_->citekeys.size()) { - return; - } + int const sel = selectedLB->currentItem(); // Remove the selected key from browser_cite - citeLB->removeItem(sel); + selectedLB->removeItem(sel); form_->citekeys.erase(form_->citekeys.begin() + sel); - form_->setBibButtons(QCitation::ON); - form_->setCiteButtons(QCitation::OFF); form_->changed(); + form_->fillStyles(); + setButtons(); } -void QCitationDialog::slotUpClicked() +void QCitationDialog::up() { - int const sel = citeLB->currentItem(); - - // FIXME: why ? - if (sel < 1 || sel >= (int)form_->citekeys.size()) { - return; - } + int const sel = selectedLB->currentItem(); // Move the selected key up one line vector::iterator it = form_->citekeys.begin() + sel; string const tmp = *it; - citeLB->removeItem(sel); + selectedLB->removeItem(sel); form_->citekeys.erase(it); - citeLB->insertItem(tmp.c_str(), sel - 1); - citeLB->setSelected(sel - 1, true); + selectedLB->insertItem(toqstr(tmp), sel - 1); + selectedLB->setSelected(sel - 1, true); form_->citekeys.insert(it - 1, tmp); - form_->setCiteButtons(QCitation::ON); + form_->changed(); + form_->fillStyles(); + setButtons(); } -void QCitationDialog::slotDownClicked() +void QCitationDialog::down() { - int const sel = citeLB->currentItem(); - - // FIXME: ? - if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) { - return; - } + int const sel = selectedLB->currentItem(); // Move the selected key down one line vector::iterator it = form_->citekeys.begin() + sel; string const tmp = *it; - citeLB->removeItem(sel); + selectedLB->removeItem(sel); form_->citekeys.erase(it); - citeLB->insertItem(tmp.c_str(), sel + 1); - citeLB->setSelected(sel + 1, true); + selectedLB->insertItem(toqstr(tmp), sel + 1); + selectedLB->setSelected(sel + 1, true); form_->citekeys.insert(it + 1, tmp); - form_->setCiteButtons(QCitation::ON); - form_->changed(); -} - -void QCitationDialog::slotPreviousClicked() -{ - doFind(biblio::BACKWARD); + form_->changed(); + form_->fillStyles(); + setButtons(); } -void QCitationDialog::slotNextClicked() +void QCitationDialog::add() { - doFind(biblio::FORWARD); + add_->exec(); } @@ -256,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 = searchED->text().latin1(); - 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 = bibLB->currentItem(); + int const sel = add_->availableLB->currentItem(); if (sel >= 0 && sel <= int(form_->bibkeys.size()-1)) start += sel; @@ -276,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()) { @@ -290,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; @@ -302,8 +266,6 @@ void QCitationDialog::doFind(biblio::Direction dir) } // Update the display - int const top = max(found - 5, 1); - bibLB->setTopItem(top); - bibLB->setSelected(found, true); - slotBibHighlighted(0); + add_->availableLB->setSelected(found, true); + add_->availableLB->ensureCurrentVisible(); }