From b128f3de145fdf439ae3c8a9bad182fee0078a03 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 23 May 2014 10:59:12 -0400 Subject: [PATCH] Fix bug #9131 for stable branch. The real problem lies elsewhere, but it will require major surgery and, more importantly, a file format change. --- src/BiblioInfo.cpp | 37 +++++++++++++++++++++++-------- src/BiblioInfo.h | 19 ++++++++-------- src/frontends/qt4/GuiCitation.cpp | 7 +++--- src/frontends/qt4/GuiCitation.h | 2 +- src/frontends/qt4/Menus.cpp | 3 ++- src/insets/InsetCitation.cpp | 5 +++-- status.21x | 5 ++++- 7 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index a50a865318..ddd2486b1f 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -636,7 +636,8 @@ docstring const & BibTeXInfo::getInfo(BibTeXInfo const * const xref, docstring const BibTeXInfo::getLabel(BibTeXInfo const * const xref, Buffer const & buf, docstring const & format, bool richtext, - docstring before, docstring after, docstring dialog, bool next) const + docstring const & before, docstring const & after, + docstring const & dialog, bool next) const { docstring loclabel; @@ -872,10 +873,19 @@ docstring const BiblioInfo::getInfo(docstring const & key, } -docstring const BiblioInfo::getLabel(vector const & keys, - Buffer const & buf, string const & style, bool richtext, - docstring const & before, docstring const & after, docstring const & dialog) const +docstring const BiblioInfo::getLabel(vector keys, + Buffer const & buf, string const & style, bool for_xhtml, + size_t max_size, docstring const & before, docstring const & after, + docstring const & dialog) const { + // shorter makes no sense + LASSERT(max_size >= 16, max_size = 16); + + // we can't display more than 10 of these, anyway + bool const too_many_keys = keys.size() > 10; + if (too_many_keys) + keys.resize(10); + CiteEngineType const engine_type = buf.params().citeEngineType(); DocumentClass const & dc = buf.params().documentClass(); docstring const & format = from_utf8(dc.getCiteFormat(engine_type, style, "cite")); @@ -897,8 +907,17 @@ docstring const BiblioInfo::getLabel(vector const & keys, xrefptr = &(xrefit->second); } } - ret = data.getLabel(xrefptr, buf, ret, richtext, - before, after, dialog, key+1 != ken); + ret = data.getLabel(xrefptr, buf, ret, for_xhtml, + before, after, dialog, key + 1 != ken); + } + + if (ret.size() > max_size) { + ret.resize(max_size - 3); + ret += "..."; + } else if (too_many_keys) { + if (ret.size() > max_size - 3) + ret.resize(max_size - 3); + ret += "..."; } return ret; } @@ -915,8 +934,8 @@ bool BiblioInfo::isBibtex(docstring const & key) const vector const BiblioInfo::getCiteStrings( vector const & keys, vector const & styles, - Buffer const & buf, bool richtext, docstring const & before, - docstring const & after, docstring const & dialog) const + Buffer const & buf, docstring const & before, + docstring const & after, docstring const & dialog, size_t max_size) const { if (empty()) return vector(); @@ -925,7 +944,7 @@ vector const BiblioInfo::getCiteStrings( vector vec(styles.size()); for (size_t i = 0; i != vec.size(); ++i) { style = styles[i].cmd; - vec[i] = getLabel(keys, buf, style, richtext, before, after, dialog); + vec[i] = getLabel(keys, buf, style, false, max_size, before, after, dialog); } return vec; diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h index 1bd428c626..31c2b54b0f 100644 --- a/src/BiblioInfo.h +++ b/src/BiblioInfo.h @@ -19,9 +19,9 @@ #include "Citation.h" -#include #include #include +#include namespace lyx { @@ -67,7 +67,8 @@ public: /// \return formatted BibTeX data for a citation label docstring const getLabel(BibTeXInfo const * const xref, Buffer const & buf, docstring const & format, bool richtext, - docstring before, docstring after, docstring dialog, bool next = false) const; + const docstring & before, const docstring & after, + const docstring & dialog, bool next = false) const; /// const_iterator find(docstring const & f) const { return bimap_.find(f); } /// @@ -202,10 +203,9 @@ public: bool richtext = false) const; /// \return formatted BibTeX data for citation labels. /// Citation labels can have more than one key. - docstring const getLabel(std::vector const & keys, - Buffer const & buf, std::string const & style, bool richtext = false, - docstring const & before = docstring(), - docstring const & after = docstring(), + docstring const getLabel(std::vector keys, + Buffer const & buf, std::string const & style, bool for_xhtml, + size_t max_size, docstring const & before, docstring const & after, docstring const & dialog = docstring()) const; /// Is this a reference from a bibtex database /// or from a bibliography environment? @@ -214,10 +214,9 @@ public: /// list of keys, using either numerical or author-year style depending /// upon the active engine. std::vector const getCiteStrings(std::vector const & keys, - std::vector const & styles, Buffer const & buf, bool richtext = false, - docstring const & before = docstring(), - docstring const & after = docstring(), - docstring const & dialog = docstring()) const; + std::vector const & styles, Buffer const & buf, + docstring const & before, docstring const & after, docstring const & dialog, + size_t max_size) const; /// Collects the cited entries from buf. void collectCitedEntries(Buffer const & buf); /// 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 84c9c82557..1afc9b708c 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -250,7 +250,8 @@ void GuiCitation::updateStyles(BiblioInfo const & bi) if (!selectedLV->selectionModel()->selectedIndexes().empty()) curr = selectedLV->selectionModel()->selectedIndexes()[0].row(); - QStringList sty = citationStyles(bi); + static const size_t max_length = 80; + QStringList sty = citationStyles(bi, max_length); if (sty.isEmpty()) { // some error @@ -587,7 +588,7 @@ void GuiCitation::findKey(BiblioInfo const & bi, } -QStringList GuiCitation::citationStyles(BiblioInfo const & bi) +QStringList GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size) { docstring const before = qstring_to_ucs4(textBeforeED->text()); docstring const after = qstring_to_ucs4(textAfterED->text()); @@ -595,7 +596,7 @@ QStringList GuiCitation::citationStyles(BiblioInfo const & bi) vector styles = citeStyles_; // FIXME: pass a dictionary instead of individual before, after, dialog, etc. vector ret = bi.getCiteStrings(keys, styles, documentBuffer(), - false, before, after, from_utf8("dialog")); + before, after, from_utf8("dialog"), max_size); return to_qstring_list(ret); } diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h index 36675d02f5..153c631ba9 100644 --- a/src/frontends/qt4/GuiCitation.h +++ b/src/frontends/qt4/GuiCitation.h @@ -123,7 +123,7 @@ private: ); /// List of example cite strings - QStringList citationStyles(BiblioInfo const & bi); + QStringList citationStyles(BiblioInfo const & bi, size_t max_size); /// Set the Params variable for the Controller. void apply(int const choice, bool const full, bool const force, diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 110121c9f1..707251dfbb 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1554,9 +1554,10 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv) vector const keys = getVectorFromString(key); vector const citeStyleList = buf->params().citeStyles(); + static const size_t max_length = 40; vector citeStrings = buf->masterBibInfo().getCiteStrings(keys, citeStyleList, bv->buffer(), - false, before, after, from_utf8("dialog")); + before, after, from_utf8("dialog"), max_length); vector::const_iterator cit = citeStrings.begin(); vector::const_iterator end = citeStrings.end(); diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 96620c1412..801fe4e62b 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -33,6 +33,7 @@ #include "support/lstrings.h" #include +#include using namespace std; using namespace lyx::support; @@ -273,8 +274,8 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const buffer().params().documentClass().addCiteMacro("!textafter", to_utf8(after)); */ docstring label; - vector const keys = getVectorFromString(key); - label = biblist.getLabel(keys, buffer(), cite_type, for_xhtml, before, after); + vector keys = getVectorFromString(key); + label = biblist.getLabel(keys, buffer(), cite_type, for_xhtml, UINT_MAX, before, after); return label; } diff --git a/status.21x b/status.21x index 01e9cf2713..fd736226c0 100644 --- a/status.21x +++ b/status.21x @@ -119,7 +119,10 @@ What's new - Make selection by mouse drag more reliable in mathed (bug 9074). - Fix undo with many individual changes (e.g. with replace all) - (bug #7079). + (bug 7079). + +- Fix problem with display of citation information when a whole lot of + entries are cited at once (bug 9131). - Do not spellcheck "code" style in logical markup module. -- 2.39.5