]> git.lyx.org Git - lyx.git/blobdiff - src/BufferList.cpp
BufferList::getBuffer(): migrate to FileName.
[lyx.git] / src / BufferList.cpp
index 692101d0c8e507ec660f81b8771c50e54c7e94a0..edb7885a12e90671a55e5c1dcd595c36ddd9239e 100644 (file)
@@ -25,6 +25,7 @@
 #include "support/ExceptionMessage.h"
 #include "support/debug.h"
 #include "support/filetools.h"
+#include "support/FileName.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/Package.h"
@@ -273,13 +274,9 @@ docstring BufferList::emergencyWrite(Buffer * buf)
 }
 
 
-bool BufferList::exists(string const & s) const
+bool BufferList::exists(FileName const & fname) const
 {
-       return find_if(bstore.begin(), bstore.end(),
-                      bind(equal_to<string>(),
-                           bind(&Buffer::absFileName, _1),
-                           s))
-               != bstore.end();
+       return getBuffer(fname) != 0;
 }
 
 
@@ -292,14 +289,10 @@ bool BufferList::isLoaded(Buffer const * b) const
 }
 
 
-Buffer * BufferList::getBuffer(string const & s)
+Buffer * BufferList::getBuffer(support::FileName const & fname) const
 {
-       BufferStorage::iterator it =
-               find_if(bstore.begin(), bstore.end(),
-                       bind(equal_to<string>(),
-                            bind(&Buffer::absFileName, _1),
-                            s));
-
+       BufferStorage::const_iterator it = find_if(bstore.begin(), bstore.end(),
+               bind(equal_to<FileName>(), bind(&Buffer::fileName, _1), fname));
        return it != bstore.end() ? (*it) : 0;
 }
 
@@ -335,4 +328,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