]> 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 edb7885a12e90671a55e5c1dcd595c36ddd9239e..4f7c4e0ac4a2f34001420b28c19409b66dcb1180 100644 (file)
@@ -24,8 +24,9 @@
 
 #include "support/ExceptionMessage.h"
 #include "support/debug.h"
-#include "support/filetools.h"
 #include "support/FileName.h"
+#include "support/FileNameList.h"
+#include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/Package.h"
@@ -50,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();
@@ -109,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();
 }
 
@@ -122,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;
 }
 
@@ -166,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;
 }
 
 
@@ -182,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;
 }
 
 
@@ -317,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());