X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt2%2FQCitationDialog.C;h=4a188b647c4dbc082203f3b701d5c20635c1dc98;hb=ce044d86c4e9363d6c20f98327ce13a90b13d7d7;hp=aeaaae23c4ec8685676896df8c98da9689750bc6;hpb=6dac02d3bbbb3327ea2f92c37cd6ce8fd91f3462;p=lyx.git diff --git a/src/frontends/qt2/QCitationDialog.C b/src/frontends/qt2/QCitationDialog.C index aeaaae23c4..4a188b647c 100644 --- a/src/frontends/qt2/QCitationDialog.C +++ b/src/frontends/qt2/QCitationDialog.C @@ -1,240 +1,235 @@ /** * \file QCitationDialog.C - * Copyright 2001 the LyX Team - * Read the file COPYING + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * \author Kalle Dalheimer + * \author Kalle Dalheimer + * + * Full author contact details are available in file CREDITS */ #include - -#include "QCitationDialog.h" -#include "Dialogs.h" -#include "QCitation.h" + + +#include + +#include "qt_helpers.h" #include "controllers/ControlCitation.h" +#include "debug.h" #include +#include #include #include #include #include - -#include "QtLyXView.h" +#include -#include -#include "buffer.h" +#include "ui/QCitationFindDialogBase.h" +#include "QCitationDialog.h" +#include "QCitation.h" +#include "support/lstrings.h" using std::vector; using std::find; using std::max; +using std::endl; -QCitationDialog::QCitationDialog(QCitation * form, QWidget * parent, const char * name, bool modal, WFlags fl) - : QCitationDialogBase(parent, name, modal, fl), + +QCitationDialog::QCitationDialog(QCitation * form) + : QCitationDialogBase(0, 0, false, 0), form_(form) { - connect(okPB, SIGNAL(clicked()), - form, SLOT(slotOK())); - connect(cancelPB, SIGNAL(clicked()), - form, SLOT(slotCancel())); connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore())); + connect(okPB, SIGNAL(clicked()), + form, SLOT(slotOK())); connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply())); - connect(searchED, SIGNAL(returnPressed()), - form, SLOT(slotNextClicked())); + 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())); } - + QCitationDialog::~QCitationDialog() { } -void QCitationDialog::slotBibSelected( int sel ) +void QCitationDialog::setButtons() { - biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); + if (form_->readOnly()) + return; - citeLB->clearSelection(); + int const sel_nr = selectedLB->currentItem(); + int const avail_nr = add_->availableLB->currentItem(); - // FIXME: why would this happen ? - if (sel < 0 || sel >= (int)form_->bibkeys.size()) { + 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::selectedChanged() +{ + form_->fillStyles(); + biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); + infoML->clear(); + + 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_->controller().isReadonly()) { - 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::slotCiteSelected(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_->controller().isReadonly()) { - 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_->bibkeys[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); - 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(); + form_->fillStyles(); + setButtons(); } -void QCitationDialog::slotPreviousClicked() +void QCitationDialog::add() { - doFind(biblio::BACKWARD); + add_->exec(); } -void QCitationDialog::slotNextClicked() +void QCitationDialog::changed_adaptor() { - doFind(biblio::FORWARD); + form_->changed(); } -void QCitationDialog::doFind(biblio::Direction const 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; @@ -244,14 +239,25 @@ void QCitationDialog::doFind(biblio::Direction const dir) else start -= 1; - bool const caseSensitive = searchCaseCB->isChecked(); - - vector::const_iterator const cit = + 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()) { - return; + if (dir == biblio::FORWARD) { + start = form_->bibkeys.begin(); + } + else start = form_->bibkeys.end() - 1; + + cit = biblio::searchKeys(theMap, form_->bibkeys, str, + start, type, dir, casesens); + + if (cit == form_->bibkeys.end()) + return; } int const found = int(cit - form_->bibkeys.begin()); @@ -260,26 +266,6 @@ void QCitationDialog::doFind(biblio::Direction const dir) } // Update the display - int const top = max(found - 5, 1); - bibLB->setTopItem(top); - bibLB->setSelected(found, true); - slotBibSelected(0); -} - - -void QCitationDialog::slotCitationStyleSelected( int ) -{ - form_->changed(); -} - - -void QCitationDialog::slotTextBeforeReturn() -{ - form_->changed(); -} - - -void QCitationDialog::slotTextAfterReturn() -{ - form_->changed(); + add_->availableLB->setSelected(found, true); + add_->availableLB->ensureCurrentVisible(); }