#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"
-#include "support/assert.h"
+#include "support/lassert.h"
#include <boost/bind.hpp>
#include <algorithm>
}
-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;
}
}
-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;
}
}
+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