Fix bug #7499. The problem here is that there was no way for the

inset to know that the BibTeX data had changed. So we introduce a
Buffer-wide variable that we can query for that information.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38619 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2011-05-07 23:02:53 +00:00
parent ed67b9a6b5
commit 33ee5c9ae8
4 changed files with 38 additions and 14 deletions

View File

@ -257,6 +257,10 @@ public:
mutable bool bibfile_cache_valid_; mutable bool bibfile_cache_valid_;
/// Cache of timestamps of .bib files /// Cache of timestamps of .bib files
map<FileName, time_t> bibfile_status_; map<FileName, time_t> bibfile_status_;
/// Indicates whether the bibinfo has changed since the last time
/// we ran updateBuffer(), i.e., whether citation labels may need
/// to be updated.
mutable bool cite_labels_valid_;
mutable RefCache ref_cache_; mutable RefCache ref_cache_;
@ -329,8 +333,8 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
read_only(readonly_), filename(file), file_fully_loaded(false), read_only(readonly_), filename(file), file_fully_loaded(false),
toc_backend(owner), macro_lock(false), timestamp_(0), toc_backend(owner), macro_lock(false), timestamp_(0),
checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false), checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
bibfile_cache_valid_(false), cloned_buffer_(cloned_buffer), bibfile_cache_valid_(false), cite_labels_valid_(false),
doing_export(false), parent_buffer(0) cloned_buffer_(cloned_buffer), doing_export(false), parent_buffer(0)
{ {
if (!cloned_buffer_) { if (!cloned_buffer_) {
temppath = createBufferTmpDir(); temppath = createBufferTmpDir();
@ -347,6 +351,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
bibinfo_cache_valid_ = cloned_buffer_->d->bibinfo_cache_valid_; bibinfo_cache_valid_ = cloned_buffer_->d->bibinfo_cache_valid_;
bibfile_cache_valid_ = cloned_buffer_->d->bibfile_cache_valid_; bibfile_cache_valid_ = cloned_buffer_->d->bibfile_cache_valid_;
bibfile_status_ = cloned_buffer_->d->bibfile_status_; bibfile_status_ = cloned_buffer_->d->bibfile_status_;
cite_labels_valid_ = cloned_buffer_->d->cite_labels_valid_;
} }
@ -1771,12 +1776,14 @@ void Buffer::updateBibfilesCache(UpdateScope scope) const
} }
d->bibfile_cache_valid_ = true; d->bibfile_cache_valid_ = true;
d->bibinfo_cache_valid_ = false; d->bibinfo_cache_valid_ = false;
d->cite_labels_valid_ = false;
} }
void Buffer::invalidateBibinfoCache() const void Buffer::invalidateBibinfoCache() const
{ {
d->bibinfo_cache_valid_ = false; d->bibinfo_cache_valid_ = false;
d->cite_labels_valid_ = false;
// also invalidate the cache for the parent buffer // also invalidate the cache for the parent buffer
Buffer const * const pbuf = d->parent(); Buffer const * const pbuf = d->parent();
if (pbuf) if (pbuf)
@ -1788,6 +1795,7 @@ void Buffer::invalidateBibfileCache() const
{ {
d->bibfile_cache_valid_ = false; d->bibfile_cache_valid_ = false;
d->bibinfo_cache_valid_ = false; d->bibinfo_cache_valid_ = false;
d->cite_labels_valid_ = false;
// also invalidate the cache for the parent buffer // also invalidate the cache for the parent buffer
Buffer const * const pbuf = d->parent(); Buffer const * const pbuf = d->parent();
if (pbuf) if (pbuf)
@ -1837,6 +1845,7 @@ void Buffer::checkIfBibInfoCacheIsValid() const
time_t prevw = d->bibfile_status_[*ei]; time_t prevw = d->bibfile_status_[*ei];
if (lastw != prevw) { if (lastw != prevw) {
d->bibinfo_cache_valid_ = false; d->bibinfo_cache_valid_ = false;
d->cite_labels_valid_ = false;
d->bibfile_status_[*ei] = lastw; d->bibfile_status_[*ei] = lastw;
} }
} }
@ -1887,6 +1896,12 @@ void Buffer::addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const
} }
bool Buffer::citeLabelsValid() const
{
return masterBuffer()->d->cite_labels_valid_;
}
bool Buffer::isDepClean(string const & name) const bool Buffer::isDepClean(string const & name) const
{ {
DepClean::const_iterator const it = d->dep_clean.find(name); DepClean::const_iterator const it = d->dep_clean.find(name);
@ -4015,6 +4030,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
return; return;
d->bibinfo_cache_valid_ = true; d->bibinfo_cache_valid_ = true;
d->cite_labels_valid_ = true;
cbuf.tocBackend().update(); cbuf.tocBackend().update();
if (scope == UpdateMaster) if (scope == UpdateMaster)
cbuf.structureChanged(); cbuf.structureChanged();

View File

@ -461,6 +461,8 @@ public:
/// add a single piece of bibliography info to our cache /// add a single piece of bibliography info to our cache
void addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const; void addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const;
/// ///
bool citeLabelsValid() const;
///
void getLabelList(std::vector<docstring> &) const; void getLabelList(std::vector<docstring> &) const;
/// ///

View File

@ -19,6 +19,8 @@
#include "BufferParams.h" #include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
#include "DispatchResult.h" #include "DispatchResult.h"
#include "FuncCode.h"
#include "FuncRequest.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "output_xhtml.h" #include "output_xhtml.h"
#include "ParIterator.h" #include "ParIterator.h"
@ -99,6 +101,14 @@ bool InsetCitation::isCompatibleCommand(string const & cmd)
} }
void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
{
if (cmd.action() == LFUN_INSET_MODIFY)
cache.recalculate = true;
InsetCommand::doDispatch(cur, cmd);
}
docstring InsetCitation::toolTip(BufferView const & bv, int, int) const docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
{ {
Buffer const & buf = bv.buffer(); Buffer const & buf = bv.buffer();
@ -459,11 +469,10 @@ docstring InsetCitation::screenLabel() const
void InsetCitation::updateBuffer(ParIterator const &, UpdateType) void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
{ {
CiteEngine const engine = buffer().params().citeEngine(); if (!cache.recalculate && buffer().citeLabelsValid())
if (cache.params == params() && cache.engine == engine)
return; return;
// The label has changed, so we have to re-create it. // The label may have changed, so we have to re-create it.
docstring const glabel = generateLabel(); docstring const glabel = generateLabel();
unsigned int const maxLabelChars = 45; unsigned int const maxLabelChars = 45;
@ -474,8 +483,7 @@ void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
label += "..."; label += "...";
} }
cache.engine = engine; cache.recalculate = false;
cache.params = params();
cache.generated_label = glabel; cache.generated_label = glabel;
cache.screen_label = label; cache.screen_label = label;
} }

View File

@ -41,6 +41,8 @@ public:
/// ///
docstring toolTip(BufferView const & bv, int x, int y) const; docstring toolTip(BufferView const & bv, int x, int y) const;
/// ///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
InsetCode lyxCode() const { return CITE_CODE; } InsetCode lyxCode() const { return CITE_CODE; }
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
@ -102,14 +104,10 @@ private:
static ParamInfo param_info_; static ParamInfo param_info_;
/// ///
class Cache { struct Cache {
public: Cache() : recalculate(true) {};
/// ///
Cache() : engine(ENGINE_BASIC), params(CITE_CODE) {} bool recalculate;
///
CiteEngine engine;
///
InsetCommandParams params;
/// ///
docstring generated_label; docstring generated_label;
/// ///