From: Richard Heck Date: Fri, 3 Dec 2010 19:29:46 +0000 (+0000) Subject: Proper fix now for bug #6846. The idea, due to JMarc, is to collect X-Git-Tag: 2.0.0~1531 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=66be58b074976c527c855626ce741023aac1363b;p=features.git Proper fix now for bug #6846. The idea, due to JMarc, is to collect bibliography information in updateBuffer(), rather than doing a wholly separate traversal. We still do a separate traversal in two cases, as a full updateBuffer() call just isn't needed there. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36696 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index c840564574..505dcddf95 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1809,8 +1809,21 @@ BiblioInfo const & Buffer::masterBibInfo() const } +BiblioInfo & Buffer::masterBibInfo() +{ + Buffer * tmp = const_cast(masterBuffer()); + if (tmp != this) + return tmp->masterBibInfo(); + return d->bibinfo_; +} + + bool Buffer::isBibInfoCacheValid() const { + // use the master's cache + Buffer const * const tmp = masterBuffer(); + if (tmp != this) + return tmp->isBibInfoCacheValid(); return d->bibinfo_cache_valid_; } @@ -3845,7 +3858,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const // do this only if we are the top-level Buffer if (master == this) - reloadBibInfoCache(); + checkIfBibInfoCacheIsValid(); // keep the buffers to be children in this set. If the call from the // master comes back we can see which of them were actually seen (i.e. diff --git a/src/Buffer.h b/src/Buffer.h index 355ff33289..4d30212611 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -445,12 +445,16 @@ public: /// whether the cache is valid. If so, we do nothing. If not, then we /// reload all the BibTeX info. /// Note that this operates on the master document. + /// Normally, this is done (more cheaply) in updateBuffer(), but there are + /// times when we need to force it to be done and don't need a full buffer + /// update. This is in GuiCitation and in changeRefsIfUnique() now. void reloadBibInfoCache() const; /// Was the cache valid the last time we checked? bool isBibInfoCacheValid() const; /// \return the bibliography information for this buffer's master, /// or just for it, if it isn't a child. BiblioInfo const & masterBibInfo() const; + BiblioInfo & masterBibInfo(); /// void fillWithBibKeys(BiblioInfo & keys) const; /// diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index a685ca0cac..5da4751038 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -334,6 +334,14 @@ void InsetBibitem::updateBuffer(ParIterator const & it, UpdateType utype) } else { autolabel_ = from_ascii("??"); } + if (!buffer().isBibInfoCacheValid()) { + BiblioInfo bi = buffer().masterBibInfo(); + docstring const key = getParam("key"); + BibTeXInfo keyvalmap(false); + keyvalmap.label(bibLabel()); + keyvalmap[from_ascii("ref")] = it.paragraph().asString(); + bi[key] = keyvalmap; + } } diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 8f1af04f50..daff111998 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -234,6 +234,15 @@ static string normalizeName(Buffer const & buffer, } +void InsetBibtex::updateBuffer(ParIterator const &, UpdateType) +{ + if (buffer().isBibInfoCacheValid()) + return; + BiblioInfo & bi = buffer().masterBibInfo(); + fillWithBibKeys(bi); +} + + int InsetBibtex::latex(odocstream & os, OutputParams const & runparams) const { // the sequence of the commands: @@ -669,9 +678,14 @@ namespace { } -// This method returns a comma separated list of Bibtex entries void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist, InsetIterator const & /*di*/) const +{ + fillWithBibKeys(keylist); +} + + +void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist) const { // This bibtex parser is a first step to parse bibtex files // more precisely. diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h index 5ede7aaa45..ec6ed3a707 100644 --- a/src/insets/InsetBibtex.h +++ b/src/insets/InsetBibtex.h @@ -52,6 +52,8 @@ public: /// int latex(odocstream &, OutputParams const &) const; /// + void updateBuffer(ParIterator const &, UpdateType); + /// void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const; /// void validate(LaTeXFeatures &) const; @@ -78,6 +80,8 @@ private: getBibTeXPath(docstring const & filename, Buffer const & buf); /// void editDatabases() const; + /// + void fillWithBibKeys(BiblioInfo &) const; /// \name Private functions inherited from Inset class //@{