]> git.lyx.org Git - features.git/commitdiff
Fix bug #7499. The problem here is that there was no way for the
authorRichard Heck <rgheck@comcast.net>
Tue, 29 Nov 2011 19:45:27 +0000 (19:45 +0000)
committerRichard Heck <rgheck@comcast.net>
Tue, 29 Nov 2011 19:45:27 +0000 (19:45 +0000)
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/branches/BRANCH_2_0_X@40307 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/insets/InsetCitation.cpp
src/insets/InsetCitation.h
status.20x

index 3767a8eb35c7f4e47b42ab91cc6abfc28c4542b7..709bc0ac17c0b604797e695f3805a4d64b50b8c6 100644 (file)
@@ -261,6 +261,10 @@ public:
        mutable bool bibfile_cache_valid_;
        /// Cache of timestamps of .bib files
        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_;
 
@@ -335,8 +339,9 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
          read_only(readonly_), filename(file), file_fully_loaded(false),
          toc_backend(owner), macro_lock(false), timestamp_(0),
          checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
-               bibfile_cache_valid_(false), cloned_buffer_(cloned_buffer),
-               clone_list_(0), doing_export(false), parent_buffer(0)
+         bibfile_cache_valid_(false), cite_labels_valid_(false),
+         cloned_buffer_(cloned_buffer), clone_list_(0), doing_export(false),
+         parent_buffer(0)
 {
        if (!cloned_buffer_) {
                temppath = createBufferTmpDir();
@@ -354,6 +359,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
        bibfile_cache_valid_ = cloned_buffer_->d->bibfile_cache_valid_;
        bibfile_status_ = cloned_buffer_->d->bibfile_status_;
        unnamed = cloned_buffer_->d->unnamed;
+       cite_labels_valid_ = cloned_buffer_->d->cite_labels_valid_;
 }
 
 
@@ -1838,12 +1844,14 @@ void Buffer::updateBibfilesCache(UpdateScope scope) const
        }
        d->bibfile_cache_valid_ = true;
        d->bibinfo_cache_valid_ = false;
+       d->cite_labels_valid_ = false;
 }
 
 
 void Buffer::invalidateBibinfoCache() const
 {
        d->bibinfo_cache_valid_ = false;
+       d->cite_labels_valid_ = false;
        // also invalidate the cache for the parent buffer
        Buffer const * const pbuf = d->parent();
        if (pbuf)
@@ -1855,6 +1863,7 @@ void Buffer::invalidateBibfileCache() const
 {
        d->bibfile_cache_valid_ = false;
        d->bibinfo_cache_valid_ = false;
+       d->cite_labels_valid_ = false;
        // also invalidate the cache for the parent buffer
        Buffer const * const pbuf = d->parent();
        if (pbuf)
@@ -1904,6 +1913,7 @@ void Buffer::checkIfBibInfoCacheIsValid() const
                time_t prevw = d->bibfile_status_[*ei];
                if (lastw != prevw) {
                        d->bibinfo_cache_valid_ = false;
+                       d->cite_labels_valid_ = false;
                        d->bibfile_status_[*ei] = lastw;
                }
        }
@@ -1954,6 +1964,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
 {
        DepClean::const_iterator const it = d->dep_clean.find(name);
@@ -3953,6 +3969,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
                return;
 
        d->bibinfo_cache_valid_ = true;
+       d->cite_labels_valid_ = true;
        cbuf.tocBackend().update();
        if (scope == UpdateMaster)
                cbuf.structureChanged();
index 50c02b4dc6e4c86bf3db8b1c2cc7c6de15ee9347..d230ec158eb2685678b57df77d4e7401d048d6fc 100644 (file)
@@ -460,6 +460,8 @@ public:
        /// add a single piece of bibliography info to our cache
        void addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const;
        ///
+       bool citeLabelsValid() const;
+       ///
        void getLabelList(std::vector<docstring> &) const;
 
        ///
index 7780f24a8d09c721b3cede8b6ac4fd1787ad68b9..6f9035c5b9f4606d07f8323428d7beb0587cbef7 100644 (file)
@@ -19,6 +19,8 @@
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "DispatchResult.h"
+#include "FuncCode.h"
+#include "FuncRequest.h"
 #include "LaTeXFeatures.h"
 #include "output_xhtml.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
 {
        Buffer const & buf = bv.buffer();
@@ -459,11 +469,10 @@ docstring InsetCitation::screenLabel() const
 
 void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
 {
-       CiteEngine const engine = buffer().params().citeEngine();
-       if (cache.params == params() && cache.engine == engine)
+       if (!cache.recalculate && buffer().citeLabelsValid())
                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();
 
        unsigned int const maxLabelChars = 45;
@@ -474,8 +483,7 @@ void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
                label += "...";
        }
 
-       cache.engine  = engine;
-       cache.params = params();
+       cache.recalculate = false;
        cache.generated_label = glabel;
        cache.screen_label = label;
 }
index 49104924cd2d00f0cc31a8e56640ee2b322f0680..6eb0da03fc52c540c7d0fa3d88b15d4d14653bcd 100644 (file)
@@ -41,6 +41,8 @@ public:
        ///
        docstring toolTip(BufferView const & bv, int x, int y) const;
        ///
+       void doDispatch(Cursor & cur, FuncRequest & cmd);
+       ///
        InsetCode lyxCode() const { return CITE_CODE; }
        ///
        void latex(otexstream &, OutputParams const &) const;
@@ -102,14 +104,10 @@ private:
        static ParamInfo param_info_;
 
        ///
-       class Cache {
-       public:
-               ///
-               Cache() : engine(ENGINE_BASIC), params(CITE_CODE) {}
-               ///
-               CiteEngine engine;
+       struct Cache {
+               Cache() : recalculate(true) {};
                ///
-               InsetCommandParams params;
+               bool recalculate;
                ///
                docstring generated_label;
                ///
index b35aa478ed1cfa8a5c3d5c13b1a7dd17159e7f14..4c67e0a35a9ccaeb35877c904f0ffb05a1e358ba 100644 (file)
@@ -49,6 +49,7 @@ What's new
 
 * USER INTERFACE
 
+- Update citation labels when the BibTeX file changes (bug 7499).
 
 * ADVANCED FIND AND REPLACE