#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "bufferlist.h"
#include "lyx_main.h"
#include "lastfiles.h"
#include "frontends/LyXView.h"
#include "vc-backend.h"
#include "TextCache.h"
-#include "lyxtextclasslist.h"
+#include "lyxlex.h"
#include "frontends/Alert.h"
#include "support/lyxfunctional.h"
#include "support/LAssert.h"
+#include <boost/bind.hpp>
+#include "BoostFormat.h"
+
#include <cassert>
#include <algorithm>
#include <functional>
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)
{}
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());
}
}
- if (!unsaved.empty() && lyxrc.exit_confirmation) {
- return Alert::askQuestion(_("Some documents were not saved:"),
- unsaved, _("Exit anyway?"));
- }
-
return true;
}
+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->paragraph && !buf->isLyxClean() && !quitting) {
- if (buf->getUser())
- buf->getUser()->owner()->prohibitInput();
+ if (!buf->paragraphs.empty() && !buf->isClean() && !quitting) {
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();
void BufferList::emergencyWriteAll()
{
for_each(bstore.begin(), bstore.end(),
- lyx::void_class_fun(*this, &BufferList::emergencyWrite));
+ boost::bind(&BufferList::emergencyWrite, this, _1));
}
// 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.
string s = buf->fileName();
s += ".emergency";
lyxerr << " " << s << endl;
- if (buf->writeFile(s, true)) {
- buf->markLyxClean();
+ if (buf->writeFile(s)) {
+ buf->markClean();
lyxerr << _(" Save seems successful. Phew.") << endl;
return;
} else {
// 2) In HOME directory.
string s = AddName(GetEnvPath("HOME"), buf->fileName());
s += ".emergency";
- lyxerr << " " << s << endl;
- if (buf->writeFile(s, true)) {
- buf->markLyxClean();
+ lyxerr << ' ' << s << endl;
+ if (buf->writeFile(s)) {
+ buf->markClean();
lyxerr << _(" Save seems successful. Phew.") << endl;
return;
}
// drive letter on OS/2
s = AddName(MakeAbsPath("/tmp/"), buf->fileName());
s += ".emergency";
- lyxerr << " " << s << endl;
- if (buf->writeFile(s, true)) {
- buf->markLyxClean();
+ lyxerr << ' ' << s << endl;
+ if (buf->writeFile(s)) {
+ buf->markClean();
lyxerr << _(" Save seems successful. Phew.") << endl;
return;
}
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";
// 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);
+ 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()) {
LyXLex lex(0, 0);
lex.setFile(tname);
if (lex.isOK()) {
- if (b->readFile(lex)) {
+ if (b->readFile(lex, tname)) {
templateok = true;
}
}
Alert::alert(_("Error!"), _("Unable to open template"),
MakeDisplayPath(tname));
// no template, start with empty buffer
- b->paragraph = new Paragraph;
- b->paragraph->layout(textclasslist[b->params.textclass].defaultLayoutName());
+ 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(textclasslist[b->params.textclass].defaultLayoutName());
+ b->paragraphs.set(new Paragraph);
+ b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
}
- if (!lyxrc.new_ask_filename && !isNamed) {
+ if (!isNamed) {
b->setUnnamed();
b->setFileName(name);
}
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));
+ }
+}