]> git.lyx.org Git - lyx.git/blobdiff - src/BufferList.cpp
* GuiToolbar.cpp:
[lyx.git] / src / BufferList.cpp
index c95616907a2f6cb9069eba5f97be1f34fceac521..4512cae4abdd8e5fc521f3089f217b90425f8f12 100644 (file)
@@ -29,7 +29,7 @@
 #include "support/lstrings.h"
 #include "support/Package.h"
 
-#include <boost/assert.hpp>
+#include "support/lassert.h"
 #include <boost/bind.hpp>
 
 #include <algorithm>
@@ -81,12 +81,12 @@ BufferList::const_iterator BufferList::end() const
 
 void BufferList::release(Buffer * buf)
 {
-       BOOST_ASSERT(buf);
+       LASSERT(buf, /**/);
        BufferStorage::iterator const it =
                find(bstore.begin(), bstore.end(), buf);
        if (it != bstore.end()) {
                Buffer * tmp = (*it);
-               BOOST_ASSERT(tmp);
+               LASSERT(tmp, /**/);
                bstore.erase(it);
                delete tmp;
        }
@@ -157,13 +157,13 @@ Buffer * BufferList::getBuffer(unsigned int choice)
 
 Buffer * BufferList::next(Buffer const * buf) const
 {
-       BOOST_ASSERT(buf);
+       LASSERT(buf, /**/);
 
        if (bstore.empty())
                return 0;
        BufferStorage::const_iterator it = find(bstore.begin(),
                                                bstore.end(), buf);
-       BOOST_ASSERT(it != bstore.end());
+       LASSERT(it != bstore.end(), /**/);
        ++it;
        if (it == bstore.end())
                return bstore.front();
@@ -174,13 +174,13 @@ Buffer * BufferList::next(Buffer const * buf) const
 
 Buffer * BufferList::previous(Buffer const * buf) const
 {
-       BOOST_ASSERT(buf);
+       LASSERT(buf, /**/);
 
        if (bstore.empty())
                return 0;
        BufferStorage::const_iterator it = find(bstore.begin(),
                                                bstore.end(), buf);
-       BOOST_ASSERT(it != bstore.end());
+       LASSERT(it != bstore.end(), /**/);
        if (it == bstore.begin())
                return bstore.back();
        else
@@ -285,7 +285,7 @@ bool BufferList::exists(string const & s) const
 
 bool BufferList::isLoaded(Buffer const * b) const
 {
-       BOOST_ASSERT(b);
+       LASSERT(b, /**/);
        BufferStorage::const_iterator cit =
                find(bstore.begin(), bstore.end(), b);
        return cit != bstore.end();
@@ -335,4 +335,28 @@ int BufferList::bufferNum(string const & name) const
 }
 
 
+bool BufferList::releaseChild(Buffer * parent, Buffer * child)
+{
+       LASSERT(parent, return false);
+       LASSERT(child, return false);
+       LASSERT(parent->isChild(child), return false);
+
+       // Child document has a different parent, don't close it.
+       if (child->parent() != parent)
+               return false;
+
+       BufferStorage::iterator it = bstore.begin();
+       BufferStorage::iterator end = bstore.end();
+       for (; it != end; ++it) {
+               Buffer * buf = *it;
+               if (buf != parent && buf->isChild(child)) {
+                       child->setParent(0);
+                       return false;
+               }
+       }
+       release(child);
+       return true;
+}
+
+
 } // namespace lyx