Simplify some of the bibliography update code. There is really no reason

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
This commit is contained in:
Richard Heck 2010-12-03 20:08:04 +00:00
parent 66be58b074
commit 840f2baf91
9 changed files with 48 additions and 34 deletions

View 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;
}

View 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;

View 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.

View 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);
}
}

View 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);
///@}

View 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);
}

View 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
//@{

View 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();
}

View 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; }
///