]> git.lyx.org Git - lyx.git/blobdiff - src/BufferList.cpp
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / src / BufferList.cpp
index 2348ac610348b28d96634f877a79a87bfefa7962..9a5c4e1c27bef836a145ebcb156c64c14a497c2c 100644 (file)
@@ -92,13 +92,15 @@ BufferList::const_iterator BufferList::end() const
 
 void BufferList::release(Buffer * buf)
 {
-       LASSERT(buf, /**/);
+       // We may leak here, but we probably do not need to
+       // shut down.
+       LASSERT(buf, return);
        BufferStorage::iterator const it =
                find(bstore.begin(), bstore.end(), buf);
        if (it != bstore.end()) {
                Buffer * tmp = (*it);
-               LASSERT(tmp, /**/);
                bstore.erase(it);
+               LASSERT(tmp, return);
                delete tmp;
        }
 }
@@ -128,9 +130,9 @@ Buffer * BufferList::newBuffer(string const & s)
 
 Buffer * BufferList::createNewBuffer(string const & s)
 {
-       auto_ptr<Buffer> tmpbuf;
+       unique_ptr<Buffer> tmpbuf;
        try {
-               tmpbuf.reset(new Buffer(s));
+               tmpbuf = make_unique<Buffer>(s);
        } catch (ExceptionMessage const & message) {
                if (message.type_ == ErrorException) {
                        Alert::error(message.title_, message.details_);
@@ -152,10 +154,9 @@ void BufferList::closeAll()
 }
 
 
-FileNameList const & BufferList::fileNames() const
+FileNameList BufferList::fileNames() const
 {
-       static FileNameList nvec;
-       nvec.clear();
+       FileNameList nvec;
        BufferStorage::const_iterator it = bstore.begin();
        BufferStorage::const_iterator end = bstore.end();
        for (; it != end; ++it) {
@@ -192,13 +193,14 @@ Buffer * BufferList::getBuffer(unsigned int choice)
 
 Buffer * BufferList::next(Buffer const * buf) const
 {
-       LASSERT(buf, /**/);
+       // Something is wrong, but we can probably survive it.
+       LASSERT(buf, return 0);
 
        if (bstore.empty())
                return 0;
        BufferStorage::const_iterator it = 
                        find(bstore.begin(), bstore.end(), buf);
-       LASSERT(it != bstore.end(), /**/);
+       LASSERT(it != bstore.end(), return 0);
        ++it;
        Buffer * nextbuf = (it == bstore.end()) ? bstore.front() : *it;
        return nextbuf;
@@ -207,13 +209,14 @@ Buffer * BufferList::next(Buffer const * buf) const
 
 Buffer * BufferList::previous(Buffer const * buf) const
 {
-       LASSERT(buf, /**/);
+       // Something is wrong, but we can probably survive it.
+       LASSERT(buf, return 0);
 
        if (bstore.empty())
                return 0;
        BufferStorage::const_iterator it = 
                        find(bstore.begin(), bstore.end(), buf);
-       LASSERT(it != bstore.end(), /**/);
+       LASSERT(it != bstore.end(), return 0);
 
        Buffer * previousbuf = (it == bstore.begin()) ? bstore.back() : *(it - 1);
        return previousbuf;
@@ -264,6 +267,28 @@ bool BufferList::exists(FileName const & fname) const
 }
 
 
+bool BufferList::isOthersChild(Buffer * parent, Buffer * child)
+{
+       LASSERT(parent, return false);
+       LASSERT(child, return false);
+       LASSERT(parent->isChild(child), return false);
+       
+       // Does child document have a different parent?
+       Buffer const * parent_ = child->parent();
+       if (parent_ && parent_ != parent)
+               return true;
+       
+       BufferStorage::iterator it = bstore.begin();
+       BufferStorage::iterator end = bstore.end();
+       for (; it != end; ++it) {
+               Buffer * buf = *it;
+               if (buf != parent && buf->isChild(child))
+                       return true;
+       }
+       return false;
+}
+
+
 namespace {
 
 struct equivalent_to : public binary_function<FileName, FileName, bool>
@@ -341,9 +366,18 @@ void BufferList::recordCurrentAuthor(Author const & author)
 }
 
 
+void BufferList::updatePreviews()
+{
+       BufferStorage::iterator it = bstore.begin();
+       BufferStorage::iterator end = bstore.end();
+       for (; it != end; ++it)
+               (*it)->updatePreviews();
+}
+
+
 int BufferList::bufferNum(FileName const & fname) const
 {
-       FileNameList const & buffers = fileNames();
+       FileNameList const buffers(fileNames());
        FileNameList::const_iterator cit =
                find(buffers.begin(), buffers.end(), fname);
        if (cit == buffers.end())
@@ -352,31 +386,6 @@ int BufferList::bufferNum(FileName const & fname) 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.
-       Buffer const * parent_ = child->parent();
-       if (parent_ && 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;
-}
-
-
 void BufferList::changed(bool update_metrics) const
 {
        BufferStorage::const_iterator it = bstore.begin();