Some cleanup in InsetInclude:

* use the UpdateScope, introduced recently, to prevent the 'strange' calls to setParent which also causes the update mechanism to run,
* remove the buffer parameter of loadIfNeeded and all function,
* remove doubled code from getChildBuffer.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28919 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-03-26 00:48:32 +00:00
parent d697f88e1b
commit 74741ca5b9
4 changed files with 41 additions and 53 deletions

View File

@ -1368,10 +1368,10 @@ void Buffer::getLabelList(vector<docstring> & list) const
}
void Buffer::updateBibfilesCache() const
void Buffer::updateBibfilesCache(UpdateScope scope) const
{
// If this is a child document, use the parent's cache instead.
if (d->parent_buffer) {
if (d->parent_buffer && scope != UpdateChildOnly) {
d->parent_buffer->updateBibfilesCache();
return;
}
@ -1390,7 +1390,7 @@ void Buffer::updateBibfilesCache() const
static_cast<InsetInclude &>(*it);
inset.updateBibfilesCache();
support::FileNameList const & bibfiles =
inset.getBibfilesCache(*this);
inset.getBibfilesCache();
d->bibfilesCache_.insert(d->bibfilesCache_.end(),
bibfiles.begin(),
bibfiles.end());
@ -1407,15 +1407,15 @@ void Buffer::invalidateBibinfoCache()
}
support::FileNameList const & Buffer::getBibfilesCache() const
support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const
{
// If this is a child document, use the parent's cache instead.
if (d->parent_buffer)
if (d->parent_buffer && scope != UpdateChildOnly)
return d->parent_buffer->getBibfilesCache();
// We update the cache when first used instead of at loading time.
if (d->bibfilesCache_.empty())
const_cast<Buffer *>(this)->updateBibfilesCache();
const_cast<Buffer *>(this)->updateBibfilesCache(scope);
return d->bibfilesCache_;
}
@ -1968,7 +1968,7 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
InsetInclude const & inset =
static_cast<InsetInclude const &>(*iit->inset);
d->macro_lock = true;
Buffer * child = inset.loadIfNeeded(*this);
Buffer * child = inset.getChildBuffer();
d->macro_lock = false;
if (!child)
continue;

View File

@ -110,6 +110,12 @@ public:
timestamp_method, ///< Use timestamp, and checksum if timestamp has changed
};
///
enum UpdateScope {
UpdateMaster,
UpdateChildOnly
};
/// Constructor
explicit Buffer(std::string const & file, bool b = false);
@ -312,12 +318,13 @@ public:
/// Update the cache with all bibfiles in use (including bibfiles
/// of loaded child documents).
void updateBibfilesCache() const;
void updateBibfilesCache(UpdateScope scope = UpdateMaster) const;
///
void invalidateBibinfoCache();
/// Return the cache with all bibfiles in use (including bibfiles
/// of loaded child documents).
support::FileNameList const & getBibfilesCache() const;
support::FileNameList const &
getBibfilesCache(UpdateScope scope = UpdateMaster) const;
/// \return the bibliography information for this buffer's master,
/// or just for it, if it isn't a child.
BiblioInfo const & masterBibInfo() const;
@ -481,11 +488,6 @@ public:
// clear how to do it just for the individual pieces we need.
void setBuffersForInsets() const;
///
enum UpdateScope {
UpdateMaster,
UpdateChildOnly
};
///
void updateLabels(UpdateScope = UpdateMaster) const;
///
void updateLabels(ParIterator & parit) const;

View File

@ -365,24 +365,16 @@ docstring InsetInclude::screenLabel() const
}
Buffer * InsetInclude::getChildBuffer(Buffer const & buffer) const
Buffer * InsetInclude::getChildBuffer() const
{
InsetCommandParams const & p = params();
if (isVerbatim(p) || isListings(p))
return 0;
string const included_file = includedFilename(buffer, p).absFilename();
if (!isLyXFilename(included_file))
return 0;
Buffer * childBuffer = loadIfNeeded(buffer);
Buffer * childBuffer = loadIfNeeded();
// FIXME: recursive includes
return (childBuffer == &buffer) ? 0 : childBuffer;
return (childBuffer == &buffer()) ? 0 : childBuffer;
}
Buffer * InsetInclude::loadIfNeeded(Buffer const & parent) const
Buffer * InsetInclude::loadIfNeeded() const
{
// Don't try to load it again if we failed before.
if (failedtoload_)
@ -400,7 +392,7 @@ Buffer * InsetInclude::loadIfNeeded(Buffer const & parent) const
if (isVerbatim(p) || isListings(p))
return 0;
string const parent_filename = parent.absFileName();
string const parent_filename = buffer().absFileName();
FileName const included_file =
makeAbsPath(to_utf8(p["filename"]), onlyPath(parent_filename));
@ -429,7 +421,7 @@ Buffer * InsetInclude::loadIfNeeded(Buffer const & parent) const
// FIXME: Do something.
}
}
child->setParent(&parent);
child->setParent(&buffer());
// Cache the child buffer.
child_buffer_ = child;
return child;
@ -503,7 +495,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
isLyXFilename(included_file.absFilename())) {
//if it's a LyX file and we're inputting or including,
//try to load it so we can write the associated latex
if (!loadIfNeeded(buffer()))
if (!loadIfNeeded())
return false;
Buffer * tmp = theBufferList().getBuffer(included_file);
@ -663,7 +655,7 @@ int InsetInclude::docbook(odocstream & os, OutputParams const & runparams) const
string const exportfile = changeExtension(incfile, ".sgml");
DocFileName writefile(changeExtension(included_file, ".sgml"));
if (loadIfNeeded(buffer())) {
if (loadIfNeeded()) {
Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
string const mangled = writefile.mangledFilename();
@ -726,7 +718,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
// Here we must do the fun stuff...
// Load the file in the include if it needs
// to be loaded:
if (loadIfNeeded(buffer())) {
if (loadIfNeeded()) {
// a file got loaded
Buffer * const tmp = theBufferList().getBuffer(FileName(included_file));
// make sure the buffer isn't us
@ -748,7 +740,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
InsetIterator const & /*di*/) const
{
if (loadIfNeeded(buffer())) {
if (loadIfNeeded()) {
string const included_file = includedFilename(buffer(), params()).absFilename();
Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
BiblioInfo const & newkeys = tmp->localBibInfo();
@ -759,25 +751,19 @@ void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
void InsetInclude::updateBibfilesCache()
{
Buffer * const tmp = getChildBuffer(buffer());
if (tmp) {
tmp->setParent(0);
tmp->updateBibfilesCache();
tmp->setParent(&buffer());
}
Buffer const * const child = getChildBuffer();
if (child)
child->updateBibfilesCache(Buffer::UpdateChildOnly);
}
support::FileNameList const &
InsetInclude::getBibfilesCache(Buffer const & buffer) const
InsetInclude::getBibfilesCache() const
{
Buffer * const tmp = getChildBuffer(buffer);
if (tmp) {
tmp->setParent(0);
support::FileNameList const & cache = tmp->getBibfilesCache();
tmp->setParent(&buffer);
return cache;
}
Buffer const * const child = getChildBuffer();
if (child)
return child->getBibfilesCache(Buffer::UpdateChildOnly);
static support::FileNameList const empty;
return empty;
}
@ -925,7 +911,7 @@ void InsetInclude::addToToc(DocIterator const & cpit)
toc.push_back(TocItem(pit, 0, str));
return;
}
Buffer const * const childbuffer = getChildBuffer(buffer());
Buffer const * const childbuffer = getChildBuffer();
if (!childbuffer)
return;
@ -967,7 +953,7 @@ void InsetInclude::updateCommand()
void InsetInclude::updateLabels(ParIterator const & it)
{
Buffer const * const childbuffer = getChildBuffer(buffer());
Buffer const * const childbuffer = getChildBuffer();
if (childbuffer) {
childbuffer->updateLabels(Buffer::UpdateChildOnly);
return;

View File

@ -70,7 +70,7 @@ public:
* \param buffer the Buffer containing this inset.
*/
support::FileNameList const &
getBibfilesCache(Buffer const & buffer) const;
getBibfilesCache() const;
///
EDITABLE editable() const { return IS_EDITABLE; }
///
@ -97,10 +97,8 @@ public:
static bool isCompatibleCommand(std::string const & s);
///
docstring contextMenu(BufferView const & bv, int x, int y) const;
/// \return the child buffer if the file is a LyX doc and is loaded
Buffer * getChildBuffer(Buffer const & buffer) const;
/// \return loaded Buffer or zero if the file loading did not proceed.
Buffer * loadIfNeeded(Buffer const & parent) const;
/// \return the child buffer if the file is a LyX doc and could be loaded
Buffer * getChildBuffer() const;
protected:
InsetInclude(InsetInclude const &);
///
@ -115,6 +113,8 @@ private:
*/
void fileChanged() const;
/// \return loaded Buffer or zero if the file loading did not proceed.
Buffer * loadIfNeeded() const;
/// launch external application
void editIncluded(std::string const & file);
/// set the parameters