]> git.lyx.org Git - lyx.git/blobdiff - src/BufferList.cpp
lyx2lyx/lyx_1_6.py: fixes for r26882 as promised
[lyx.git] / src / BufferList.cpp
index 4512cae4abdd8e5fc521f3089f217b90425f8f12..4f7c4e0ac4a2f34001420b28c19409b66dcb1180 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "support/ExceptionMessage.h"
 #include "support/debug.h"
+#include "support/FileName.h"
+#include "support/FileNameList.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -49,6 +51,15 @@ BufferList::BufferList()
 {}
 
 
+BufferList::~BufferList()
+{
+       BufferStorage::iterator it = binternal.begin();
+       BufferStorage::iterator end = binternal.end();
+       for (; it != end; ++it)
+               delete (*it);
+}
+
+
 bool BufferList::empty() const
 {
        return bstore.empty();
@@ -108,8 +119,12 @@ Buffer * BufferList::newBuffer(string const & s, bool const ronly)
                }
        }
        tmpbuf->params().useClassDefaults();
-       LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size());
-       bstore.push_back(tmpbuf.get());
+       if (tmpbuf->fileName().extension() == "internal") {
+               binternal.push_back(tmpbuf.get());
+       } else {
+               LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size());
+               bstore.push_back(tmpbuf.get());
+       }
        return tmpbuf.release();
 }
 
@@ -121,12 +136,13 @@ void BufferList::closeAll()
 }
 
 
-vector<string> const BufferList::getFileNames() const
+FileNameList const & BufferList::fileNames() const
 {
-       vector<string> nvec;
+       static FileNameList nvec;
+       nvec.clear();
        transform(bstore.begin(), bstore.end(),
                  back_inserter(nvec),
-                 boost::bind(&Buffer::absFileName, _1));
+                 boost::bind(&Buffer::fileName, _1));
        return nvec;
 }
 
@@ -165,10 +181,8 @@ Buffer * BufferList::next(Buffer const * buf) const
                                                bstore.end(), buf);
        LASSERT(it != bstore.end(), /**/);
        ++it;
-       if (it == bstore.end())
-               return bstore.front();
-       else
-               return *it;
+       Buffer * nextbuf = (it == bstore.end()) ? bstore.front() : *it;
+       return nextbuf;
 }
 
 
@@ -181,10 +195,9 @@ Buffer * BufferList::previous(Buffer const * buf) const
        BufferStorage::const_iterator it = find(bstore.begin(),
                                                bstore.end(), buf);
        LASSERT(it != bstore.end(), /**/);
-       if (it == bstore.begin())
-               return bstore.back();
-       else
-               return *(it - 1);
+
+       Buffer * previousbuf = (it == bstore.begin()) ? bstore.back() : *(it - 1);
+       return previousbuf;
 }
 
 
@@ -273,13 +286,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 +301,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;
 }
 
@@ -324,11 +329,11 @@ void BufferList::setCurrentAuthor(docstring const & name, docstring const & emai
 }
 
 
-int BufferList::bufferNum(string const & name) const
+int BufferList::bufferNum(FileName const & fname) const
 {
-       vector<string> buffers = getFileNames();
-       vector<string>::const_iterator cit =
-               find(buffers.begin(), buffers.end(), name);
+       FileNameList const & buffers = fileNames();
+       FileNameList::const_iterator cit =
+               find(buffers.begin(), buffers.end(), fname);
        if (cit == buffers.end())
                return 0;
        return int(cit - buffers.begin());