]> git.lyx.org Git - lyx.git/commitdiff
Routines for calculating numerical labels for BibTeX citations.
authorRichard Heck <rgheck@comcast.net>
Fri, 8 Jan 2010 18:19:13 +0000 (18:19 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 8 Jan 2010 18:19:13 +0000 (18:19 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32891 a592a061-630c-0410-9148-cb99ea01b6c8

src/BiblioInfo.cpp
src/BiblioInfo.h

index d8297d03036c31210b40ca014a2dfff5d530f77e..bb9b27f7feab4b11993cedc35dcd0454ee5df9cd 100644 (file)
@@ -26,6 +26,7 @@
 #include "insets/InsetBibtex.h"
 #include "insets/InsetInclude.h"
 
 #include "insets/InsetBibtex.h"
 #include "insets/InsetInclude.h"
 
+#include "support/convert.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
@@ -657,6 +658,26 @@ void BiblioInfo::collectCitedEntries(Buffer const & buf)
 }
 
 
 }
 
 
+void BiblioInfo::makeCitationLabels(Buffer const & buf)
+{
+       collectCitedEntries(buf);
+       // FIXME It'd be nice to do author-year as well as numerical
+       // and maybe even some other sorts of labels.
+       vector<docstring>::const_iterator it = cited_entries_.begin();
+       vector<docstring>::const_iterator const en = cited_entries_.end();
+       int keynumber = 0;
+       for (; it != en; ++it) {
+               map<docstring, BibTeXInfo>::iterator const biit = bimap_.find(*it);
+               // this shouldn't happen, but...
+               if (biit == bimap_.end())
+                       continue;
+               BibTeXInfo & entry = biit->second;
+               docstring const key = convert<docstring>(++keynumber);
+               entry.setCiteKey(key);
+       }
+}
+
+
 //////////////////////////////////////////////////////////////////////
 //
 // CitationStyle
 //////////////////////////////////////////////////////////////////////
 //
 // CitationStyle
index 0cb21fc0cbbc7b2dd6a2521c96f950aca2b5fa74..658a4ad02731da25504714e90a3eb009a56827a6 100644 (file)
@@ -91,6 +91,10 @@ public:
        ///
        docstring const & key() const { return bib_key_; }
        ///
        ///
        docstring const & key() const { return bib_key_; }
        ///
+       docstring citeKey() const { return cite_key_; }
+       ///
+       void setCiteKey(docstring const & k) { cite_key_ = k; }
+       ///
        docstring entryType() const { return entry_type_; }
        /// 
        bool isBibTeX() const { return is_bibtex_; }
        docstring entryType() const { return entry_type_; }
        /// 
        bool isBibTeX() const { return is_bibtex_; }
@@ -114,6 +118,9 @@ private:
        docstring entry_type_;
        /// a cache for getInfo()
        mutable docstring info_;
        docstring entry_type_;
        /// a cache for getInfo()
        mutable docstring info_;
+       /// key to use when citing this entry 
+       /// currently used only by XHTML output routines
+       docstring cite_key_;
        /// our map: <field, value>
        std::map <docstring, docstring> bimap_;
 };
        /// our map: <field, value>
        std::map <docstring, docstring> bimap_;
 };
@@ -176,6 +183,8 @@ public:
        /// the last name of the author.
        std::vector<docstring> const & citedEntries() const { return cited_entries_; }
        ///
        /// the last name of the author.
        std::vector<docstring> const & citedEntries() const { return cited_entries_; }
        ///
+       void makeCitationLabels(Buffer const & buf);
+       ///
        const_iterator begin() const { return bimap_.begin(); }
        ///
        void clear() { bimap_.clear(); }
        const_iterator begin() const { return bimap_.begin(); }
        ///
        void clear() { bimap_.clear(); }