diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index 1e2a1be769..a9f48e4457 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -1367,21 +1367,21 @@ bool BiblioInfo::isBibtex(docstring const & key) const } -vector const BiblioInfo::getCiteStrings( +BiblioInfo::CiteStringMap const BiblioInfo::getCiteStrings( vector const & keys, vector const & styles, Buffer const & buf, CiteItem const & ci) const { if (empty()) - return vector(); + return vector>(); string style; - vector vec(styles.size()); - for (size_t i = 0; i != vec.size(); ++i) { + CiteStringMap csm(styles.size()); + for (size_t i = 0; i != csm.size(); ++i) { style = styles[i].name; - vec[i] = getLabel(keys, buf, style, ci); + csm[i] = make_pair(from_ascii(style), getLabel(keys, buf, style, ci)); } - return vec; + return csm; } diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h index 791f9cf400..162cad19f2 100644 --- a/src/BiblioInfo.h +++ b/src/BiblioInfo.h @@ -222,10 +222,16 @@ public: /// Is this a reference from a bibtex database /// or from a bibliography environment? bool isBibtex(docstring const & key) const; + /// A vector holding a pair of lyx cite command and the respective + /// output for a given (list of) key(s). + typedef std::vector> CiteStringMap; /// Translates the available citation styles into strings for a given /// list of keys, using either numerical or author-year style depending - /// upon the active engine. - std::vector const getCiteStrings(std::vector const & keys, + /// upon the active engine. The function returns a CiteStringMap with the first + /// element being the lyx cite command, the second being the formatted + /// citation reference. + CiteStringMap const getCiteStrings( + std::vector const & keys, std::vector const & styles, Buffer const & buf, CiteItem const & ci) const; /// A list of BibTeX keys cited in the current document, sorted by diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index d5f1ebb28a..44e887e409 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -92,7 +92,7 @@ static vector to_docstring_vector(QStringList const & qlist) GuiCitation::GuiCitation(GuiView & lv) : DialogView(lv, "citation", qt_("Citation")), - style_(0), params_(insetCode("citation")) + style_(QString()), params_(insetCode("citation")) { setupUi(this); @@ -188,7 +188,7 @@ void GuiCitation::closeEvent(QCloseEvent * e) void GuiCitation::applyView() { int const choice = max(0, citationStyleCO->currentIndex()); - style_ = choice; + style_ = citationStyleCO->currentData().toString(); bool const full = starredCB->isChecked(); bool const force = forceuppercaseCB->isChecked(); @@ -258,7 +258,7 @@ void GuiCitation::updateControls(BiblioInfo const & bi) QModelIndex idx = selectionManager->getSelectedIndex(1); updateInfo(bi, idx); int i = citationStyleCO->currentIndex(); - if (i == -1) + if (i == -1 || i > int(citeStyles_.size())) i = 0; updateFormatting(citeStyles_[i]); selectionManager->update(); @@ -379,9 +379,9 @@ void GuiCitation::updateStyles(BiblioInfo const & bi) } static const size_t max_length = 80; - QStringList sty = citationStyles(bi, max_length); + BiblioInfo::CiteStringMap sty = citationStyles(bi, max_length); - if (sty.isEmpty()) { + if (sty.empty()) { // some error citationStyleCO->setEnabled(false); citationStyleLA->setEnabled(false); @@ -391,16 +391,20 @@ void GuiCitation::updateStyles(BiblioInfo const & bi) citationStyleCO->blockSignals(true); - // save old index - int const curindex = citationStyleCO->currentIndex(); - int const oldIndex = (curindex < 0) ? style_ : curindex; + // save old style selection + QString const curdata = citationStyleCO->currentData().toString(); + QString const olddata = (curdata.isEmpty()) ? style_ : curdata; citationStyleCO->clear(); - citationStyleCO->insertItems(0, sty); + BiblioInfo::CiteStringMap::const_iterator cit = sty.begin(); + BiblioInfo::CiteStringMap::const_iterator end = sty.end(); + for (int ii = 1; cit != end; ++cit, ++ii) + citationStyleCO->addItem(toqstr(cit->second), toqstr(cit->first)); citationStyleCO->setEnabled(true); citationStyleLA->setEnabled(true); - // restore old index - if (oldIndex != -1 && oldIndex < citationStyleCO->count()) - citationStyleCO->setCurrentIndex(oldIndex); + // restore old style selection + int const i = citationStyleCO->findData(olddata); + if (i != -1) + citationStyleCO->setCurrentIndex(i); citationStyleCO->blockSignals(false); } @@ -855,7 +859,7 @@ void GuiCitation::findKey(BiblioInfo const & bi, } -QStringList GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size) +BiblioInfo::CiteStringMap GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size) { vector const keys = to_docstring_vector(cited_keys_); vector styles = citeStyles_; @@ -891,8 +895,8 @@ QStringList GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size) ci.isQualified = qualified; ci.pretexts = pres; ci.posttexts = posts; - vector ret = bi.getCiteStrings(keys, styles, documentBuffer(), ci); - return to_qstring_list(ret); + BiblioInfo::CiteStringMap ret = bi.getCiteStrings(keys, styles, documentBuffer(), ci); + return ret; } @@ -1068,7 +1072,7 @@ void GuiCitation::restoreSession() regexp_->setChecked(settings.value(sessionKey() + "/regex").toBool()); casesense_->setChecked(settings.value(sessionKey() + "/casesensitive").toBool()); instant_->setChecked(settings.value(sessionKey() + "/autofind", true).toBool()); - style_ = settings.value(sessionKey() + "/citestyle").toInt(); + style_ = settings.value(sessionKey() + "/citestyle").toString(); literal_ = settings.value(sessionKey() + "/literal", false).toBool(); updateFilterHint(); } diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h index db88ca9d44..5f093cc21d 100644 --- a/src/frontends/qt4/GuiCitation.h +++ b/src/frontends/qt4/GuiCitation.h @@ -21,6 +21,7 @@ #include "insets/InsetCommandParams.h" +#include "BiblioInfo.h" #include "Citation.h" #include @@ -141,8 +142,9 @@ private: bool reset = false //< whether to reset and search all keys ); - /// List of example cite strings - QStringList citationStyles(BiblioInfo const & bi, size_t max_size); + /// List of example cite strings and their correlating lyx name + BiblioInfo::CiteStringMap citationStyles(BiblioInfo const & bi, + size_t max_size); /// Set the Params variable for the Controller. void applyParams(int const choice, bool const full, bool const force, @@ -180,7 +182,7 @@ private: QAction * instant_; /// last used citation style - int style_; + QString style_; /// last set value for literal /// this is used only for new citations bool literal_; diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index faab339001..627ec4c4c9 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1592,14 +1592,14 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv) ci.isQualified = qualified; ci.pretexts = pres; ci.posttexts = posts; - vector citeStrings = + BiblioInfo::CiteStringMap citeStrings = buf->masterBibInfo().getCiteStrings(keys, citeStyleList, bv->buffer(), ci); - vector::const_iterator cit = citeStrings.begin(); - vector::const_iterator end = citeStrings.end(); + BiblioInfo::CiteStringMap::const_iterator cit = citeStrings.begin(); + BiblioInfo::CiteStringMap::const_iterator end = citeStrings.end(); for (int ii = 1; cit != end; ++cit, ++ii) { - docstring label = *cit; + docstring label = cit->second; CitationStyle cs = citeStyleList[ii - 1]; cs.forceUpperCase &= force; cs.hasStarredVersion &= star;