]> git.lyx.org Git - features.git/commitdiff
Simplify some of the bibliography update code. There is really no reason
authorRichard Heck <rgheck@comcast.net>
Fri, 3 Dec 2010 20:08:04 +0000 (20:08 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 3 Dec 2010 20:08:04 +0000 (20:08 +0000)
to be passing the BiblioInfo structure around this way. (That's an old
holdover.) That lets us get rid of the non-const masterBibInfo() again.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36697 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/insets/Inset.h
src/insets/InsetBibitem.cpp
src/insets/InsetBibitem.h
src/insets/InsetBibtex.cpp
src/insets/InsetBibtex.h
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h

index 505dcddf956a80084aa5cc2a46992aa471f67ac8..3884c0c0576da6fab7bbd249c7f5bcc4bd88094a 100644 (file)
@@ -1809,15 +1809,6 @@ BiblioInfo const & Buffer::masterBibInfo() const
 }
 
 
-BiblioInfo & Buffer::masterBibInfo()
-{
-       Buffer * tmp = const_cast<Buffer *>(masterBuffer());
-       if (tmp != this)
-               return tmp->masterBibInfo();
-       return d->bibinfo_;
-}
-
-
 bool Buffer::isBibInfoCacheValid() const
 {
        // use the master's cache
@@ -1866,15 +1857,33 @@ void Buffer::reloadBibInfoCache() const
                return;
 
        d->bibinfo_.clear();
-       fillWithBibKeys(d->bibinfo_);
+       collectBibKeys();
        d->bibinfo_cache_valid_ = true;
 }
 
 
-void Buffer::fillWithBibKeys(BiblioInfo & keys) const
+void Buffer::collectBibKeys() const
 {
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
-               it->fillWithBibKeys(keys, it);
+               it->collectBibKeys(it);
+}
+
+
+void Buffer::addBiblioInfo(BiblioInfo const & bi) const
+{
+       Buffer const * tmp = masterBuffer();
+       BiblioInfo & masterbi = (tmp == this) ?
+               d->bibinfo_ : tmp->d->bibinfo_;
+       masterbi.mergeBiblioInfo(bi);
+}
+
+
+void Buffer::addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const
+{
+       Buffer const * tmp = masterBuffer();
+       BiblioInfo & masterbi = (tmp == this) ?
+               d->bibinfo_ : tmp->d->bibinfo_;
+       masterbi[key] = bi;
 }
 
 
index 4d3021261109288a009fe863e4716bf73b41fd0c..a13f0c5db0c671b1d6acfcf70c26e98a6fb5c718 100644 (file)
@@ -28,6 +28,7 @@
 namespace lyx {
 
 class BiblioInfo;
+class BibTeXInfo;
 class BufferParams;
 class DispatchResult;
 class DocIterator;
@@ -454,9 +455,12 @@ public:
        /// \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;
+       /// collect bibliography info from the various insets in this buffer.
+       void collectBibKeys() const;
+       /// add some BiblioInfo to our cache
+       void addBiblioInfo(BiblioInfo const & bi) const;
+       /// add a single piece of bibliography info to our cache
+       void addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const;
        ///
        void getLabelList(std::vector<docstring> &) const;
 
index 85a1360c2c30fc1b7540a7779afa7a0eb1d850c8..965fa6279a44b86de35fecf6d0df4a255d8c1819 100644 (file)
@@ -489,8 +489,8 @@ public:
        /// Add an entry to the TocList
        /// pit is the ParConstIterator of the paragraph containing the inset
        virtual void addToToc(DocIterator const &) {}
-       /// Fill keys with BibTeX information
-       virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {}
+       /// Collect BibTeX information
+       virtual void collectBibKeys(InsetIterator const &) const {}
        /// Update the counters of this inset and of its contents.
        /// The boolean indicates whether we are preparing for output, e.g.,
        /// of XHTML.
index 5da47510386c94c929f67a3a7ebc9bfb8af314ee..0fbc516240bb69c59ec8d5659482112f59c66169 100644 (file)
@@ -308,7 +308,7 @@ docstring bibitemWidest(Buffer const & buffer, OutputParams const & runparams)
 }
 
 
-void InsetBibitem::fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const
+void InsetBibitem::collectBibKeys(InsetIterator const & it) const
 {
        docstring const key = getParam("key");
        BibTeXInfo keyvalmap(false);
@@ -316,7 +316,7 @@ void InsetBibitem::fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it)
        DocIterator doc_it(it); 
        doc_it.forwardPos();
        keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString();
-       keys[key] = keyvalmap;
+       buffer().addBibTeXInfo(key, keyvalmap);
 }
 
 
@@ -335,12 +335,11 @@ void InsetBibitem::updateBuffer(ParIterator const & it, UpdateType utype)
                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;
+               buffer().addBibTeXInfo(key, keyvalmap);
        }
 }
 
index 9231b3cb9b0f01ea7c464e6a089e9120fb01cf49..c28f66aa5206dec22ee30858cbdc0eab1156da05 100644 (file)
@@ -59,7 +59,7 @@ public:
        ///
        docstring xhtml(XHTMLStream &, OutputParams const &) const;
        ///
-       void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
+       void collectBibKeys(InsetIterator const &) const;
        /// update the counter of this inset
        void updateBuffer(ParIterator const &, UpdateType);
        ///@}
index daff1119983f5c9ed18b3790c1ba79c4f8939b58..dc022f1e242670cff834b56ed0bf9c2006a69b33 100644 (file)
@@ -238,8 +238,7 @@ void InsetBibtex::updateBuffer(ParIterator const &, UpdateType)
 {
        if (buffer().isBibInfoCacheValid())
                return;
-       BiblioInfo & bi = buffer().masterBibInfo();
-       fillWithBibKeys(bi);
+       parseBibTeXFiles();
 }
 
 
@@ -678,14 +677,13 @@ namespace {
 }
 
 
-void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist,
-       InsetIterator const & /*di*/) const
+void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/) const
 {
-       fillWithBibKeys(keylist);
+       parseBibTeXFiles();
 }
 
 
-void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist) const
+void InsetBibtex::parseBibTeXFiles() const
 {
        // This bibtex parser is a first step to parse bibtex files
        // more precisely.
@@ -705,6 +703,9 @@ void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist) const
        // We don't restrict keys to ASCII in LyX, since our own
        // InsetBibitem can generate non-ASCII keys, and nonstandard
        // 8bit clean bibtex forks exist.
+
+       BiblioInfo keylist;
+
        support::FileNameList const files = getBibFiles();
        support::FileNameList::const_iterator it = files.begin();
        support::FileNameList::const_iterator en = files.end();
@@ -870,6 +871,8 @@ void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist) const
                        } //< else (citation entry)
                } //< searching '@'
        } //< for loop over files
+
+       buffer().addBiblioInfo(keylist);
 }
 
 
index ec6ed3a7070e77693ef67f1722328d167f22646d..ea0cecfc142d4fc3a483a27d6330684a4e80c7e1 100644 (file)
@@ -54,7 +54,7 @@ public:
        ///
        void updateBuffer(ParIterator const &, UpdateType);
        ///
-       void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
+       void collectBibKeys(InsetIterator const &) const;
        ///
        void validate(LaTeXFeatures &) const;
        ///
@@ -81,7 +81,7 @@ private:
        ///
        void editDatabases() const;
        ///
-       void fillWithBibKeys(BiblioInfo &) const;
+       void parseBibTeXFiles() const;
 
        /// \name Private functions inherited from Inset class
        //@{
index 9464012614ab1c20e2aec8485c7d733799e38345..b852f4b2591a520eda0684a8a67c421ad3a725db 100644 (file)
@@ -844,13 +844,12 @@ void InsetInclude::validate(LaTeXFeatures & features) const
 }
 
 
-void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
-       InsetIterator const & /*di*/) const
+void InsetInclude::collectBibKeys(InsetIterator const & /*di*/) const
 {
        Buffer * child = loadIfNeeded();
        if (!child)
                return;
-       child->fillWithBibKeys(keys);
+       child->collectBibKeys();
 }
 
 
index 7860ac6510da29e44d6dc265aa3c43e858d9fcb7..565cf0ac7738145e039e608f8ddf3bca1cc08106 100644 (file)
@@ -83,7 +83,7 @@ public:
         *  \param keys the list of bibkeys in the child buffer.
         *  \param it not used here
         */
-       void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
+       void collectBibKeys(InsetIterator const &) const;
        ///
        bool hasSettings() const { return true; }
        ///