X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffrontends%2Fqt2%2FQCitation.C;h=85183bccf3ac57eef4b16f846050e70804bec6c6;hb=4c6e0fe4226ce3b55d13726977f1e579f17c2ad1;hp=03fcd326c64c000033028cb9659832d5e3d2c76a;hpb=814b8194510a5607638f81b10c939723835c1145;p=lyx.git diff --git a/src/frontends/qt2/QCitation.C b/src/frontends/qt2/QCitation.C index 03fcd326c6..85183bccf3 100644 --- a/src/frontends/qt2/QCitation.C +++ b/src/frontends/qt2/QCitation.C @@ -6,15 +6,12 @@ * \author Angus Leeming * \author Kalle Dalheimer * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include -#ifdef __GNUG__ -#pragma implementation -#endif - +#include "ui/QCitationFindDialogBase.h" #include "QCitationDialog.h" #include "QCitation.h" @@ -24,28 +21,24 @@ #include #include #include +#include -#include "QtLyXView.h" #include "Qt2BC.h" #include "ControlCitation.h" -#include "debug.h" -#include "gettext.h" +#include "qt_helpers.h" #include "support/lstrings.h" -#include "helper_funcs.h" +using namespace lyx::support; using std::find; -using std::max; -using std::min; -using std::pair; -using std::sort; + using std::vector; -typedef Qt2CB > base_class; +typedef QController > base_class; -QCitation::QCitation() - : base_class(_("Citation")) +QCitation::QCitation(Dialog & parent) + : base_class(parent, _("LyX: Citation Reference")) {} @@ -64,7 +57,7 @@ void QCitation::apply() controller().params().setCmdName(command); controller().params().setContents(getStringFromVector(citekeys)); - string const after = dialog_->textAfterED->text().latin1(); + string const after = fromqstr(dialog_->textAfterED->text()); controller().params().setOptions(after); } @@ -74,7 +67,7 @@ void QCitation::hide() citekeys.clear(); bibkeys.clear(); - Qt2Base::hide(); + QDialogView::hide(); } @@ -82,48 +75,66 @@ void QCitation::build_dialog() { dialog_.reset(new QCitationDialog(this)); - dialog_->searchTypeCB->setChecked(false); - dialog_->searchCaseCB->setChecked(false); - // Manage the ok, apply, restore and cancel/close buttons - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - bc().setRestore(dialog_->restorePB); - - bc().addReadOnly(dialog_->addPB); - bc().addReadOnly(dialog_->delPB); - bc().addReadOnly(dialog_->upPB); - bc().addReadOnly(dialog_->downPB); - bc().addReadOnly(dialog_->citationStyleCO); - bc().addReadOnly(dialog_->forceuppercaseCB); - bc().addReadOnly(dialog_->fulllistCB); + bcview().setOK(dialog_->okPB); + bcview().setApply(dialog_->applyPB); + bcview().setCancel(dialog_->closePB); + bcview().setRestore(dialog_->restorePB); + + bcview().addReadOnly(dialog_->addPB); + bcview().addReadOnly(dialog_->deletePB); + bcview().addReadOnly(dialog_->upPB); + bcview().addReadOnly(dialog_->downPB); + bcview().addReadOnly(dialog_->citationStyleCO); + bcview().addReadOnly(dialog_->forceuppercaseCB); + bcview().addReadOnly(dialog_->fulllistCB); // add when enabled ! - //bc().addReadOnly(dialog_->textBeforeED); - bc().addReadOnly(dialog_->textAfterED); + //bcview().addReadOnly(dialog_->textBeforeED); + bcview().addReadOnly(dialog_->textAfterED); } void QCitation::fillStyles() { - // style - string key; + if (citekeys.empty()) { + dialog_->citationStyleCO->setEnabled(false); + dialog_->citationStyleLA->setEnabled(false); + return; + } - if (!citekeys.empty()) - key = citekeys[0]; + int const orig = dialog_->citationStyleCO->currentItem(); dialog_->citationStyleCO->clear(); + + int curr = dialog_->selectedLB->currentItem(); + if (curr < 0) + curr = 0; + + string key = citekeys[curr]; + vector const & sty = controller().getCiteStrings(key); + bool const natbib = controller().usingNatbib(); + dialog_->citationStyleCO->setEnabled(!sty.empty() && natbib); + dialog_->citationStyleLA->setEnabled(!sty.empty() && natbib); + for (vector::const_iterator it = sty.begin(); it != sty.end(); ++it) { - dialog_->citationStyleCO->insertItem(it->c_str()); + dialog_->citationStyleCO->insertItem(toqstr(*it)); } + + if (orig != -1 && orig < dialog_->citationStyleCO->count()) + dialog_->citationStyleCO->setCurrentItem(orig); } void QCitation::updateStyle() { + bool const natbib = controller().usingNatbib(); + + dialog_->fulllistCB->setEnabled(natbib); + dialog_->forceuppercaseCB->setEnabled(natbib); + string const & command = controller().params().getCmdName(); // Find the style of the citekeys @@ -144,11 +155,6 @@ void QCitation::updateStyle() dialog_->fulllistCB->setChecked(cs.full); dialog_->forceuppercaseCB->setChecked(cs.forceUCase); } - - bool const natbib = controller().usingNatbib(); - dialog_->citationStyleCO->setEnabled(natbib); - dialog_->fulllistCB->setEnabled(natbib); - dialog_->forceuppercaseCB->setEnabled(natbib); } @@ -156,27 +162,25 @@ void QCitation::update_contents() { // Make the list of all available bibliography keys bibkeys = biblio::getKeys(controller().bibkeysInfo()); - updateBrowser(dialog_->bibLB, bibkeys); + updateBrowser(dialog_->add_->availableLB, bibkeys); // Ditto for the keys cited in this inset citekeys = getVectorFromString(controller().params().getContents()); - updateBrowser(dialog_->citeLB, citekeys); + updateBrowser(dialog_->selectedLB, citekeys); // No keys have been selected yet, so... dialog_->infoML->clear(); - setBibButtons(OFF); - setCiteButtons(OFF); + dialog_->setButtons(); - dialog_->textAfterED->setText(controller().params().getOptions().c_str()); + dialog_->textAfterED->setText(toqstr(controller().params().getOptions())); fillStyles(); - updateStyle(); } void QCitation::updateBrowser(QListBox * browser, - vector const & keys) const + vector const & keys) const { browser->clear(); @@ -185,26 +189,6 @@ void QCitation::updateBrowser(QListBox * browser, string const key = trim(*it); // FIXME: why the .empty() test ? if (!key.empty()) - browser->insertItem(key.c_str()); + browser->insertItem(toqstr(key)); } } - - -void QCitation::setBibButtons(State status) const -{ - dialog_->addPB->setEnabled((status == ON)); -} - - -void QCitation::setCiteButtons(State status) const -{ - int const sel = dialog_->citeLB->currentItem(); - int const maxline = dialog_->citeLB->count() - 1; - bool const activate = (status == ON); - bool const activate_up = (activate && sel != 0); - bool const activate_down = (activate && sel != maxline); - - dialog_->delPB->setEnabled(activate); - dialog_->upPB->setEnabled(activate_up); - dialog_->downPB->setEnabled(activate_down); -}