]> git.lyx.org Git - features.git/commitdiff
Backport fix for #7593 to branch.
authorRichard Heck <rgheck@comcast.net>
Mon, 5 Sep 2011 19:25:15 +0000 (19:25 +0000)
committerRichard Heck <rgheck@comcast.net>
Mon, 5 Sep 2011 19:25:15 +0000 (19:25 +0000)
=====

Original log:

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. As a side effect, we only clone each child once.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39599 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/frontends/qt4/GuiView.cpp
status.20x

index 8849c7b3d0483921cd5a013738c0cdd36c619fe4..06174697e56490477fb20ca99d16a8d3934ffb3c 100644 (file)
@@ -422,7 +422,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
@@ -435,7 +450,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);
@@ -444,7 +464,7 @@ Buffer * Buffer::clone() const
                buffer_clone->setChild(dit, child_clone);
        }
        buffer_clone->d->macro_lock = false;
-       return buffer_clone;
+       return;
 }
 
 
index 5472f741dee80801eb9fc9cbc25f9e2ea3d23c96..01e300e41a622f50275f47beb082aa582ba462d3 100644 (file)
@@ -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
index abcbe30ec8530f79d3a2044fe41e710b203eef55..d3c45676e49a186160aed4ac4ca0021e7c5f74ab 100644 (file)
@@ -2951,7 +2951,11 @@ 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;
+
+       // the cloning operation will have produced a clone of the entire set of
+       // documents, starting from the master. so we must delete those.
+       Buffer * mbuf = const_cast<Buffer *>(buffer->masterBuffer());
+       delete mbuf;
        busyBuffers.remove(orig);
        if (msg == "preview") {
                return success
index b6eb2151724ee1c7cd066db3322ac839453c051d..07a4ca1412f1c43925a473c590b9ca7b1e22ed81 100644 (file)
@@ -44,6 +44,9 @@ What's new
 
 - Fix ASCII export for branch inset (bug 7720).
 
+- Fix regression where parent macros were not displayed in a viewed child
+  (bug 7593).
+
 
 * USER INTERFACE