On 05/16/2011 04:50 AM, Jean-Marc Lasgouttes wrote: > Le 16/05/2011 00:00, Richard Heck a écrit : >> I've tested this a bit and it seems to work. Additional testing and >> comments would be welcome. > > The patch would be welcome too ;) > Doh.
Richard
>From 8314392962c042a18c95ac630869ec4421ac9876 Mon Sep 17 00:00:00 2001 From: Richard Heck <rgh...@lyx.org> Date: Sun, 15 May 2011 16:39:18 -0400 Subject: [PATCH] Fix problem first reported by Diego: If you try to view a child document, the macros declared in the parent do not work. This is because we were cloning only the child, which then didn't have a parent. The solution is to clone the whole structure, starting with the master document. --- src/Buffer.cpp | 24 ++++++++++++++++++++++-- src/Buffer.h | 4 ++++ src/frontends/qt4/GuiView.cpp | 3 ++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 9d102ac..b87b119 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -427,7 +427,22 @@ Buffer::~Buffer() Buffer * Buffer::clone() const { + BufferMap bufmap; + masterBuffer()->clone(bufmap); + BufferMap::iterator it = bufmap.find(this); + LASSERT(it != bufmap.end(), return 0); + return it->second; +} + + +void Buffer::clone(BufferMap & bufmap) const +{ + // have we already been cloned? + if (bufmap.find(this) != bufmap.end()) + return; + Buffer * buffer_clone = new Buffer(fileName().absFileName(), false, this); + bufmap[this] = buffer_clone; buffer_clone->d->macro_lock = true; buffer_clone->d->children_positions.clear(); // FIXME (Abdel 09/01/2010): this is too complicated. The whole children_positions and @@ -440,7 +455,12 @@ Buffer * Buffer::clone() const DocIterator dit = it->second.clone(buffer_clone); dit.setBuffer(buffer_clone); Buffer * child = const_cast<Buffer *>(it->first); - Buffer * child_clone = child->clone(); + + child->clone(bufmap); + BufferMap::iterator it = bufmap.find(child); + LASSERT(it != bufmap.end(), continue); + Buffer * child_clone = it->second; + Inset * inset = dit.nextInset(); LASSERT(inset && inset->lyxCode() == INCLUDE_CODE, continue); InsetInclude * inset_inc = static_cast<InsetInclude *>(inset); @@ -449,7 +469,7 @@ Buffer * Buffer::clone() const buffer_clone->setChild(dit, child_clone); } buffer_clone->d->macro_lock = false; - return buffer_clone; + return; } diff --git a/src/Buffer.h b/src/Buffer.h index b5c34b3..9701f31 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -211,6 +211,10 @@ public: int readHeader(Lexer & lex); private: + /// + typedef std::map<Buffer const *, Buffer *> BufferMap; + /// + void clone(BufferMap &) const; /// save timestamp and checksum of the given file. void saveCheckSum() const; /// read a new file diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 683982a..46a3cf2 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2944,7 +2944,8 @@ docstring GuiView::GuiViewPrivate::runAndDestroy(const T& func, Buffer const * o buffer->params().maintain_unincluded_children && !buffer->params().getIncludedChildren().empty(); bool const success = func(format, update_unincluded); - delete buffer; + Buffer * mbuf = const_cast<Buffer *>(buffer->masterBuffer()); + delete mbuf; busyBuffers.remove(orig); if (msg == "preview") { return success -- 1.7.4.4