]> git.lyx.org Git - lyx.git/blobdiff - src/bufferlist.C
* Replace all use of 'slashify_path' with 'internal_path'.
[lyx.git] / src / bufferlist.C
index 8c19a3928f1964ee365bb4087dfe25b96af19bd5..174dd2cc6e4ff1b75c7563962ac7d5f5d47fd577 100644 (file)
 #include "lyx_main.h"
 #include "output_latex.h"
 #include "paragraph.h"
+#include "ParagraphList_fwd.h"
 
 #include "frontends/Alert.h"
 
 #include "support/filetools.h"
-#include "support/lyxfunctional.h"
+#include "support/os.h"
 
 #include <boost/bind.hpp>
 
+#include <algorithm>
+#include <functional>
+
 using lyx::support::AddName;
 using lyx::support::bformat;
-using lyx::support::GetEnvPath;
 using lyx::support::MakeAbsPath;
 using lyx::support::MakeDisplayPath;
 using lyx::support::OnlyFilename;
@@ -43,12 +46,16 @@ using boost::bind;
 
 using std::auto_ptr;
 using std::endl;
+using std::equal_to;
 using std::find;
 using std::find_if;
 using std::for_each;
 using std::string;
 using std::vector;
+using std::back_inserter;
+using std::transform;
 
+namespace os = lyx::support::os;
 
 BufferList::BufferList()
 {}
@@ -194,8 +201,9 @@ bool BufferList::close(Buffer * buf, bool ask)
 vector<string> const BufferList::getFileNames() const
 {
        vector<string> nvec;
-       std::copy(bstore.begin(), bstore.end(),
-                 lyx::back_inserter_fun(nvec, &Buffer::fileName));
+       transform(bstore.begin(), bstore.end(),
+                 back_inserter(nvec),
+                 boost::bind(&Buffer::fileName, _1));
        return nvec;
 }
 
@@ -216,6 +224,35 @@ Buffer * BufferList::getBuffer(unsigned int choice)
 }
 
 
+Buffer * BufferList::next(Buffer const * buf) const
+{
+       if (bstore.empty())
+               return 0;
+       BufferStorage::const_iterator it = find(bstore.begin(),
+                                               bstore.end(), buf);
+       BOOST_ASSERT(it != bstore.end());
+       ++it;
+       if (it == bstore.end())
+               return bstore.front();
+       else
+               return *it;
+}
+
+
+Buffer * BufferList::previous(Buffer const * buf) const
+{
+       if (bstore.empty())
+               return 0;
+       BufferStorage::const_iterator it = find(bstore.begin(),
+                                               bstore.end(), buf);
+       BOOST_ASSERT(it != bstore.end());
+       if (it == bstore.begin())
+               return bstore.back();
+       else
+               return *(it - 1);
+}
+
+
 void BufferList::updateIncludedTeXfiles(string const & mastertmpdir,
                                        OutputParams const & runparams)
 {
@@ -273,7 +310,7 @@ void BufferList::emergencyWrite(Buffer * buf)
        }
 
        // 2) In HOME directory.
-       string s = AddName(GetEnvPath("HOME"), buf->fileName());
+       string s = AddName(os::homepath(), buf->fileName());
        s += ".emergency";
        lyxerr << ' ' << s << endl;
        if (buf->writeFile(s)) {
@@ -302,7 +339,9 @@ void BufferList::emergencyWrite(Buffer * buf)
 bool BufferList::exists(string const & s) const
 {
        return find_if(bstore.begin(), bstore.end(),
-                      lyx::compare_memfun(&Buffer::fileName, s))
+                      bind(equal_to<string>(),
+                           bind(&Buffer::fileName, _1),
+                           s))
                != bstore.end();
 }
 
@@ -320,7 +359,10 @@ Buffer * BufferList::getBuffer(string const & s)
 {
        BufferStorage::iterator it =
                find_if(bstore.begin(), bstore.end(),
-                       lyx::compare_memfun(&Buffer::fileName, s));
+                       bind(equal_to<string>(),
+                            bind(&Buffer::fileName, _1),
+                            s));
+
        return it != bstore.end() ? (*it) : 0;
 }