#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "bufferlist.h"
#include "lyx_main.h"
#include "lastfiles.h"
#include "support/LAssert.h"
#include <boost/bind.hpp>
+#include "BoostFormat.h"
#include <cassert>
#include <algorithm>
extern BufferView * current_view;
-//
-// Class BufferStorage
-//
-
-void BufferStorage::release(Buffer * buf)
-{
- lyx::Assert(buf);
- Container::iterator it = find(container.begin(), container.end(), buf);
- if (it != container.end()) {
- // Make sure that we don't store a LyXText in
- // the textcache that points to the buffer
- // we just deleted.
- Buffer * tmp = (*it);
- container.erase(it);
- textcache.removeAllWithBuffer(tmp);
- delete tmp;
- }
-}
-
-
-Buffer * BufferStorage::newBuffer(string const & s, bool ronly)
-{
- Buffer * tmpbuf = new Buffer(s, ronly);
- tmpbuf->params.useClassDefaults();
- lyxerr[Debug::INFO] << "Assigning to buffer "
- << container.size() << endl;
- container.push_back(tmpbuf);
- return tmpbuf;
-}
-
-
-//
-// Class BufferList
-//
BufferList::BufferList()
- : state_(BufferList::OK)
{}
}
+void BufferList::release(Buffer * buf)
+{
+ lyx::Assert(buf);
+ BufferStorage::iterator it = find(bstore.begin(), bstore.end(), buf);
+ if (it != bstore.end()) {
+ // Make sure that we don't store a LyXText in
+ // the textcache that points to the buffer
+ // we just deleted.
+ Buffer * tmp = (*it);
+ bstore.erase(it);
+ textcache.removeAllWithBuffer(tmp);
+ delete tmp;
+ }
+}
+
+
+Buffer * BufferList::newBuffer(string const & s, bool ronly)
+{
+ Buffer * tmpbuf = new Buffer(s, ronly);
+ tmpbuf->params.useClassDefaults();
+ lyxerr[Debug::INFO] << "Assigning to buffer "
+ << bstore.size() << endl;
+ bstore.push_back(tmpbuf);
+ return tmpbuf;
+}
+
+
void BufferList::closeAll()
{
- state_ = BufferList::CLOSING;
// Since we are closing we can just as well delete all
// in the textcache this will also speed the closing/quiting up a bit.
textcache.clear();
while (!bstore.empty()) {
close(bstore.front());
}
- state_ = BufferList::OK;
}
{
lyx::Assert(buf);
- // CHECK
- // Trace back why we need to use buf->getUser here.
- // Perhaps slight rewrite is in order? (Lgb)
-
- if (buf->getUser())
- buf->getUser()->insetUnlock();
-
if (!buf->paragraphs.empty() && !buf->isClean() && !quitting) {
- if (buf->getUser())
- buf->getUser()->owner()->prohibitInput();
string fname;
if (buf->isUnnamed())
fname = OnlyFilename(buf->fileName());
lastfiles->newFile(buf->fileName());
reask = false;
} else {
- if (buf->getUser())
- buf->getUser()->owner()->allowInput();
return false;
}
break;
reask = false;
break;
case 3: // Cancel
- if (buf->getUser())
- buf->getUser()->owner()->allowInput();
return false;
}
}
- if (buf->getUser())
- buf->getUser()->owner()->allowInput();
}
- bstore.release(buf);
+ release(buf);
return true;
}
}
-int BufferList::unlockInset(UpdatableInset * inset)
-{
- lyx::Assert(inset);
-
- BufferStorage::iterator it = bstore.begin();
- BufferStorage::iterator end = bstore.end();
- for (; it != end; ++it) {
- if ((*it)->getUser()
- && (*it)->getUser()->theLockingInset() == inset) {
- (*it)->getUser()->insetUnlock();
- return 0;
- }
- }
- return 1;
-}
-
-
void BufferList::updateIncludedTeXfiles(string const & mastertmpdir)
{
BufferStorage::iterator it = bstore.begin();
string const doc = buf->isUnnamed()
? OnlyFilename(buf->fileName()) : buf->fileName();
-
- lyxerr << _("LyX: Attempting to save document ") << doc << endl;
+#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.
// 2) In HOME directory.
string s = AddName(GetEnvPath("HOME"), buf->fileName());
s += ".emergency";
- lyxerr << " " << s << endl;
+ lyxerr << ' ' << s << endl;
if (buf->writeFile(s)) {
buf->markClean();
lyxerr << _(" Save seems successful. Phew.") << endl;
// drive letter on OS/2
s = AddName(MakeAbsPath("/tmp/"), buf->fileName());
s += ".emergency";
- lyxerr << " " << s << endl;
+ lyxerr << ' ' << s << endl;
if (buf->writeFile(s)) {
buf->markClean();
lyxerr << _(" Save seems successful. Phew.") << endl;
return 0;
}
- Buffer * b = bstore.newBuffer(s, ronly);
+ Buffer * b = newBuffer(s, ronly);
// Check if emergency save file exists and is newer.
e += OnlyFilename(s) + ".emergency";
if (b->readFile(lex, ts))
return b;
else {
- bstore.release(b);
+ release(b);
return 0;
}
}
Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
{
// get a free buffer
- Buffer * b = bstore.newBuffer(name);
+ Buffer * b = newBuffer(name);
// use defaults.lyx as a default template if it exists.
if (tname.empty()) {
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));
+ }
+}