]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Whitespace.
[lyx.git] / src / Buffer.cpp
index 080eee73ad70f319121004566958fb456bb2dea7..74582bc90437a47b831d8da59c33871f4f3cef01 100644 (file)
@@ -289,8 +289,12 @@ Buffer::~Buffer()
        // loop over children
        Impl::BufferPositionMap::iterator it = d->children_positions.begin();
        Impl::BufferPositionMap::iterator end = d->children_positions.end();
-       for (; it != end; ++it)
-               theBufferList().releaseChild(this, const_cast<Buffer *>(it->first));
+       for (; it != end; ++it) {
+               Buffer * child = const_cast<Buffer *>(it->first);
+               // The child buffer might have been closed already.
+               if (theBufferList().isLoaded(child))
+                       theBufferList().releaseChild(this, child);
+       }
 
        // clear references to children in macro tables
        d->children_positions.clear();
@@ -590,15 +594,22 @@ bool Buffer::readDocument(Lexer & lex)
                if (isLyXFilename(master_file.absFilename())) {
                        Buffer * master = 
                                checkAndLoadLyXFile(master_file, true);
-                       // set master as master buffer, but only if we are
-                       // a real child
-                       if (master && master->isChild(this))
-                               d->parent_buffer = master;
-                       else
-                               LYXERR0("The master '" 
-                                       << params().master 
-                                       << "' assigned to this document does not include "
-                                       "this document. Ignoring the master assignment.");
+                       if (master) {
+                               // set master as master buffer, but only
+                               // if we are a real child
+                               if (master->isChild(this))
+                                       setParent(master);
+                               // if the master is not fully loaded
+                               // it is probably just loading this
+                               // child. No warning needed then.
+                               else if (master->isFullyLoaded())
+                                       LYXERR0("The master '"
+                                               << params().master
+                                               << "' assigned to this document '"
+                                               << absFileName()
+                                               << "' does not include "
+                                               "this document. Ignoring the master assignment.");
+                       }
                }
        }
 
@@ -1754,6 +1765,25 @@ DocIterator Buffer::firstChildPosition(Buffer const * child)
 }
 
 
+std::vector<Buffer *> Buffer::getChildren() const
+{
+       std::vector<Buffer *> clist;
+       // loop over children
+       Impl::BufferPositionMap::iterator it = d->children_positions.begin();
+       Impl::BufferPositionMap::iterator end = d->children_positions.end();
+       for (; it != end; ++it) {
+               Buffer * child = const_cast<Buffer *>(it->first);
+               clist.push_back(child);
+               // there might be grandchildren
+               std::vector<Buffer *> glist = child->getChildren();
+               for (vector<Buffer *>::const_iterator git = glist.begin();
+                    git != glist.end(); ++git)
+                       clist.push_back(*git);
+       }
+       return clist;
+}
+
+
 template<typename M>
 typename M::iterator greatest_below(M & m, typename M::key_type const & x)
 {
@@ -2276,6 +2306,12 @@ void Buffer::resetAutosaveTimers() const
 }
 
 
+bool Buffer::hasGuiDelegate() const
+{
+       return gui_;
+}
+
+
 void Buffer::setGuiDelegate(frontend::GuiBufferDelegate * gui)
 {
        gui_ = gui;
@@ -2708,6 +2744,10 @@ void Buffer::updateLabels(bool childonly) const
                if (master != this) {
                        bufToUpdate.insert(this);
                        master->updateLabels(false);
+                       // Do this here in case the master has no gui associated with it. Then, 
+                       // the TocModel is not updated and TocModel::toc_ is invalid (bug 5699).
+                       if (!master->gui_)
+                               structureChanged();     
 
                        // was buf referenced from the master (i.e. not in bufToUpdate anymore)?
                        if (bufToUpdate.find(this) == bufToUpdate.end())
@@ -2723,7 +2763,6 @@ void Buffer::updateLabels(bool childonly) const
 
        // update all caches
        clearReferenceCache();
-       inset().setBuffer(const_cast<Buffer &>(*this));
        updateMacros();
 
        Buffer & cbuf = const_cast<Buffer &>(*this);