X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBuffer.cpp;h=a068ecfe3a9c9e502cac0801395b4aaf56f09a83;hb=0b17cb113523fb23c43064709e9b6606fe80914c;hp=ba77061463c56c7176f0dbf685adb2d8172648e1;hpb=06445c964e1d6ca9e405f4f2b787df21283e27f7;p=lyx.git diff --git a/src/Buffer.cpp b/src/Buffer.cpp index ba77061463..a068ecfe3a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -127,7 +127,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 398; // uwestoehr: support for \mathscr +int const LYX_FORMAT = 400; // uwestoehr: support for \rule typedef map DepClean; typedef map > RefCache; @@ -255,7 +255,9 @@ public: /// A cache for bibliography info mutable BiblioInfo bibinfo_; /// whether the bibinfo cache is valid - bool bibinfo_cache_valid_; + mutable bool bibinfo_cache_valid_; + /// whether the bibfile cache is valid + mutable bool bibfile_cache_valid_; /// Cache of timestamps of .bib files map bibfile_status_; @@ -277,12 +279,19 @@ public: parent_buffer = 0; return parent_buffer; } + /// void setParent(Buffer const * pb) { - if (!cloned_buffer_ - && parent_buffer && pb && parent_buffer != pb) + if (parent_buffer == pb) + // nothing to do + return; + if (!cloned_buffer_ && parent_buffer && pb) LYXERR0("Warning: a buffer should not have two parents!"); parent_buffer = pb; + if (!cloned_buffer_ && parent_buffer) { + parent_buffer->invalidateBibfileCache(); + parent_buffer->invalidateBibinfoCache(); + } } /// If non zero, this buffer is a clone of existing buffer \p cloned_buffer_ @@ -323,7 +332,8 @@ 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), - cloned_buffer_(cloned_buffer), doing_export(false), parent_buffer(0) + bibfile_cache_valid_(false), cloned_buffer_(cloned_buffer), + doing_export(false), parent_buffer(0) { if (!cloned_buffer_) { temppath = createBufferTmpDir(); @@ -338,6 +348,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_, bibfiles_cache_ = cloned_buffer_->d->bibfiles_cache_; bibinfo_ = cloned_buffer_->d->bibinfo_; bibinfo_cache_valid_ = cloned_buffer_->d->bibinfo_cache_valid_; + bibfile_cache_valid_ = cloned_buffer_->d->bibfile_cache_valid_; bibfile_status_ = cloned_buffer_->d->bibfile_status_; } @@ -1573,7 +1584,6 @@ void Buffer::writeLyXHTMLSource(odocstream & os, LaTeXFeatures features(*this, params(), runparams); validate(features); updateBuffer(UpdateMaster, OutputUpdate); - checkBibInfoCache(); d->bibinfo_.makeCitationLabels(*this); updateMacros(); updateMacroInstances(); @@ -1695,6 +1705,7 @@ void Buffer::getLabelList(vector & list) const void Buffer::updateBibfilesCache(UpdateScope scope) const { + // FIXME This is probably unnecssary, given where we call this. // If this is a child document, use the parent's cache instead. Buffer const * const pbuf = d->parent(); if (pbuf && scope != UpdateChildOnly) { @@ -1714,35 +1725,54 @@ void Buffer::updateBibfilesCache(UpdateScope scope) const } else if (it->lyxCode() == INCLUDE_CODE) { InsetInclude & inset = static_cast(*it); - inset.updateBibfilesCache(); + Buffer const * const incbuf = inset.getChildBuffer(); + if (!incbuf) + continue; support::FileNameList const & bibfiles = - inset.getBibfilesCache(); - d->bibfiles_cache_.insert(d->bibfiles_cache_.end(), - bibfiles.begin(), - bibfiles.end()); + incbuf->getBibfilesCache(UpdateChildOnly); + if (!bibfiles.empty()) { + d->bibfiles_cache_.insert(d->bibfiles_cache_.end(), + bibfiles.begin(), + bibfiles.end()); + } } } - // the bibinfo cache is now invalid + d->bibfile_cache_valid_ = true; d->bibinfo_cache_valid_ = false; } -void Buffer::invalidateBibinfoCache() +void Buffer::invalidateBibinfoCache() const { d->bibinfo_cache_valid_ = false; + // also invalidate the cache for the parent buffer + Buffer const * const pbuf = d->parent(); + if (pbuf) + pbuf->invalidateBibinfoCache(); } -support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const +void Buffer::invalidateBibfileCache() const { - // If this is a child document, use the parent's cache instead. + d->bibfile_cache_valid_ = false; + d->bibinfo_cache_valid_ = false; + // also invalidate the cache for the parent buffer Buffer const * const pbuf = d->parent(); - if (pbuf && scope != UpdateChildOnly) + if (pbuf) + pbuf->invalidateBibfileCache(); +} + + +support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const +{ + // FIXME This is probably unnecessary, given where we call this. + // If this is a child document, use the master's cache instead. + Buffer const * const pbuf = masterBuffer(); + if (pbuf != this && scope != UpdateChildOnly) return pbuf->getBibfilesCache(); - // We update the cache when first used instead of at loading time. - if (d->bibfiles_cache_.empty()) - const_cast(this)->updateBibfilesCache(scope); + if (!d->bibfile_cache_valid_) + this->updateBibfilesCache(scope); return d->bibfiles_cache_; } @@ -1750,28 +1780,28 @@ support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const BiblioInfo const & Buffer::masterBibInfo() const { - // if this is a child document and the parent is already loaded - // use the parent's list instead [ale990412] Buffer const * const tmp = masterBuffer(); - LASSERT(tmp, /**/); if (tmp != this) return tmp->masterBibInfo(); - return localBibInfo(); -} - - -BiblioInfo const & Buffer::localBibInfo() const -{ return d->bibinfo_; } void Buffer::checkBibInfoCache() const { - support::FileNameList const & bibfilesCache = getBibfilesCache(); + // use the master's cache + Buffer const * const tmp = masterBuffer(); + if (tmp != this) { + tmp->checkBibInfoCache(); + return; + } + + // this will also reload the cache if it is invalid + support::FileNameList const & bibfiles_cache = getBibfilesCache(); + // compare the cached timestamps with the actual ones. - support::FileNameList::const_iterator ei = bibfilesCache.begin(); - support::FileNameList::const_iterator en = bibfilesCache.end(); + support::FileNameList::const_iterator ei = bibfiles_cache.begin(); + support::FileNameList::const_iterator en = bibfiles_cache.end(); for (; ei != en; ++ ei) { time_t lastw = ei->lastModified(); time_t prevw = d->bibfile_status_[*ei]; @@ -1780,13 +1810,20 @@ void Buffer::checkBibInfoCache() const d->bibfile_status_[*ei] = lastw; } } - + + // if not valid, then reload the info if (!d->bibinfo_cache_valid_) { d->bibinfo_.clear(); - for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) - it->fillWithBibKeys(d->bibinfo_, it); + fillWithBibKeys(d->bibinfo_); d->bibinfo_cache_valid_ = true; - } + } +} + + +void Buffer::fillWithBibKeys(BiblioInfo & keys) const +{ + for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) + it->fillWithBibKeys(keys, it); } @@ -2364,6 +2401,7 @@ void Buffer::markClean() const // if the .lyx file has been saved, we don't need an // autosave d->bak_clean = true; + d->undo_.markDirty(); } @@ -3686,7 +3724,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const DocumentClass const & textclass = master->params().documentClass(); // do this only if we are the top-level Buffer - if (scope != UpdateMaster || master == this) + if (master == this) checkBibInfoCache(); // keep the buffers to be children in this set. If the call from the @@ -3995,7 +4033,9 @@ int Buffer::spellCheck(DocIterator & from, DocIterator & to, if (from == end) break; to = from; - if (from.paragraph().spellCheck(from.pos(), to.pos(), wl, suggestions)) { + from.paragraph().spellCheck(); + SpellChecker::Result res = from.paragraph().spellCheck(from.pos(), to.pos(), wl, suggestions); + if (SpellChecker::misspelled(res)) { word_lang = wl; break; }