]> git.lyx.org Git - lyx.git/blobdiff - src/bufferlist.C
Fix natbib bug spotted by JMarc.
[lyx.git] / src / bufferlist.C
index 5d57c361704ac1bf219bc26b1a8052c14dd39b97..caba200f85ed7b21aae441818d0fb35b9ed3d4b9 100644 (file)
@@ -41,6 +41,9 @@
 #include "support/lyxfunctional.h"
 #include "support/LAssert.h"
 
+#include <boost/bind.hpp>
+#include "BoostFormat.h"
+
 #include <cassert>
 #include <algorithm>
 #include <functional>
@@ -141,7 +144,7 @@ bool BufferList::qwriteAll()
        BufferStorage::iterator it = bstore.begin();
        BufferStorage::iterator end = bstore.end();
        for (; it != end; ++it) {
-               if (!(*it)->isLyxClean()) {
+               if (!(*it)->isClean()) {
                        string fname;
                        if ((*it)->isUnnamed())
                                fname = OnlyFilename((*it)->fileName());
@@ -181,7 +184,7 @@ bool BufferList::close(Buffer * buf)
        if (buf->getUser())
                buf->getUser()->insetUnlock();
 
-       if (buf->paragraph && !buf->isLyxClean() && !quitting) {
+       if (!buf->paragraphs.empty() && !buf->isClean() && !quitting) {
                if (buf->getUser())
                        buf->getUser()->owner()->prohibitInput();
                string fname;
@@ -289,7 +292,7 @@ void BufferList::updateIncludedTeXfiles(string const & mastertmpdir)
 void BufferList::emergencyWriteAll()
 {
        for_each(bstore.begin(), bstore.end(),
-                lyx::void_class_fun(*this, &BufferList::emergencyWrite));
+                boost::bind(&BufferList::emergencyWrite, this, _1));
 }
 
 
@@ -301,13 +304,19 @@ void BufferList::emergencyWrite(Buffer * buf)
 
 
        // No need to save if the buffer has not changed.
-       if (buf->isLyxClean())
+       if (buf->isClean())
                return;
 
-       lyxerr << fmt(_("lyx: Attempting to save document %s as..."),
-                     buf->isUnnamed() ? OnlyFilename(buf->fileName()).c_str()
-                     : buf->fileName().c_str()) << endl;
+       string const doc = buf->isUnnamed()
+               ? OnlyFilename(buf->fileName()) : buf->fileName();
 
+#if USE_BOOST_FORMAT
+       lyxerr << boost::format(_("LyX: Attempting to save document %1$s"))
+               % doc
+              << endl;
+#else
+       lyxerr << _("LyX: Attempting to save document ") << doc << endl;
+#endif
        // We try to save three places:
 
        // 1) Same place as document. Unless it is an unnamed doc.
@@ -316,7 +325,7 @@ void BufferList::emergencyWrite(Buffer * buf)
                s += ".emergency";
                lyxerr << "  " << s << endl;
                if (buf->writeFile(s)) {
-                       buf->markLyxClean();
+                       buf->markClean();
                        lyxerr << _("  Save seems successful. Phew.") << endl;
                        return;
                } else {
@@ -327,9 +336,9 @@ void BufferList::emergencyWrite(Buffer * buf)
        // 2) In HOME directory.
        string s = AddName(GetEnvPath("HOME"), buf->fileName());
        s += ".emergency";
-       lyxerr << " " << s << endl;
+       lyxerr << ' ' << s << endl;
        if (buf->writeFile(s)) {
-               buf->markLyxClean();
+               buf->markClean();
                lyxerr << _("  Save seems successful. Phew.") << endl;
                return;
        }
@@ -341,9 +350,9 @@ void BufferList::emergencyWrite(Buffer * buf)
        // drive letter on OS/2
        s = AddName(MakeAbsPath("/tmp/"), buf->fileName());
        s += ".emergency";
-       lyxerr << " " << s << endl;
+       lyxerr << ' ' << s << endl;
        if (buf->writeFile(s)) {
-               buf->markLyxClean();
+               buf->markClean();
                lyxerr << _("  Save seems successful. Phew.") << endl;
                return;
        }
@@ -418,7 +427,7 @@ Buffer * BufferList::readFile(string const & s, bool ronly)
        // not sure if this is the correct place to begin LyXLex
        LyXLex lex(0, 0);
        lex.setFile(ts);
-       if (b->readFile(lex))
+       if (b->readFile(lex, ts))
                return b;
        else {
                bstore.release(b);
@@ -468,7 +477,7 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
                LyXLex lex(0, 0);
                lex.setFile(tname);
                if (lex.isOK()) {
-                       if (b->readFile(lex)) {
+                       if (b->readFile(lex, tname)) {
                                templateok = true;
                        }
                }
@@ -476,12 +485,12 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
                        Alert::alert(_("Error!"), _("Unable to open template"),
                                   MakeDisplayPath(tname));
                        // no template, start with empty buffer
-                       b->paragraph = new Paragraph;
-                       b->paragraph->layout(b->params.getLyXTextClass().defaultLayout());
+                       b->paragraphs.set(new Paragraph);
+                       b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
                }
        } else {  // start with empty buffer
-               b->paragraph = new Paragraph;
-                       b->paragraph->layout(b->params.getLyXTextClass().defaultLayout());
+               b->paragraphs.set(new Paragraph);
+               b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
        }
 
        if (!isNamed) {
@@ -560,3 +569,13 @@ Buffer * BufferList::loadLyXFile(string const & filename, bool tolastfiles)
 
        return b;
 }
+
+
+void BufferList::setCurrentAuthor(string const & name, string const & email)
+{
+       BufferStorage::iterator it = bstore.begin();
+       BufferStorage::iterator end = bstore.end();
+       for (; it != end; ++it) {
+               (*it)->authors().record(0, Author(name, email));
+       }
+}