#include "lyxtextclasslist.h"
#include "sgml.h"
#include "paragraph_funcs.h"
+#include "author.h"
#include "frontends/LyXView.h"
#include "support/FileInfo.h"
#include "support/lyxmanip.h"
#include "support/lyxalgo.h" // for lyx::count
+#include "support/lyxtime.h"
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>
namespace {
-const int LYX_FORMAT = 221;
+const int LYX_FORMAT = 222;
} // namespace anon
Buffer::Buffer(string const & file, bool ronly)
: niceFile(true), lyx_clean(true), bak_clean(true),
- unnamed(false), dep_clean(0), read_only(ronly),
+ unnamed(false), read_only(ronly),
filename_(file), users(0)
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
} else {
tmppath.erase();
}
+
+ // set initial author
+ authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
}
}
+AuthorList & Buffer::authors()
+{
+ return authorlist;
+}
+
+
/// Update window titles of all users
// Should work on a list
void Buffer::updateTitles() const
#endif
int unknown_layouts;
int unknown_tokens;
+vector<int> author_ids;
} // anon
// changed to be public and have one parameter
// if par = 0 normal behavior
// else insert behavior
-// Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
+// Returns false if "\the_end" is not read (Asger)
bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
{
unknown_layouts = 0;
unknown_tokens = 0;
+ author_ids.clear();
int pos = 0;
Paragraph::depth_type depth = 0;
}
+namespace {
+ // This stuff is, in the traditional LyX terminology, Super UGLY
+ // but this code is too b0rken to admit of a better solution yet
+ Change current_change;
+};
+
+
bool
Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
Paragraph *& first_par,
if (token[0] != '\\') {
for (string::const_iterator cit = token.begin();
cit != token.end(); ++cit) {
- par->insertChar(pos, (*cit), font);
+ par->insertChar(pos, (*cit), font, current_change);
++pos;
}
} else if (token == "\\layout") {
else {
par = new Paragraph(par);
par->layout(params.getLyXTextClass().defaultLayout());
+ if (params.tracking_changes)
+ par->trackChanges();
}
pos = 0;
par->layout(params.getLyXTextClass()[layoutname]);
lex.next();
string const next_token = lex.getString();
if (next_token == "\\-") {
- par->insertChar(pos, '-', font);
+ par->insertChar(pos, '-', font, current_change);
} else if (next_token == "~") {
- par->insertChar(pos, ' ', font);
+ par->insertChar(pos, ' ', font, current_change);
} else {
lex.printError("Token `$$Token' "
"is in free space "
} else {
Inset * inset = new InsetSpecialChar;
inset->read(this, lex);
- par->insertInset(pos, inset, font);
+ par->insertInset(pos, inset, font, current_change);
}
++pos;
} else if (token == "\\i") {
Inset * inset = new InsetLatexAccent;
inset->read(this, lex);
- par->insertInset(pos, inset, font);
+ par->insertInset(pos, inset, font, current_change);
++pos;
} else if (token == "\\backslash") {
- par->insertChar(pos, '\\', font);
+ par->insertChar(pos, '\\', font, current_change);
++pos;
} else if (token == "\\begin_deeper") {
++depth;
#if USE_BOOST_FORMAT
Alert::alert(_("Textclass error"),
boost::io::str(boost::format(_("The document uses an unknown textclass \"%1$s\".")) % lex.getString()),
- _("LyX will not be able to produce output correctly."));
+ _("-- substituting default."));
#else
Alert::alert(
_("Textclass error"),
_("The document uses an unknown textclass ")
+ lex.getString(),
- _("LyX will not be able to produce output correctly."));
+ _("-- substituting default."));
#endif
params.textclass = 0;
}
Alert::alert(_("Textclass Loading Error!"),
boost::io::str(boost::format(_("Can't load textclass %1$s")) %
params.getLyXTextClass().name()),
- _("-- substituting default"));
+ _("-- substituting default."));
#else
Alert::alert(_("Textclass Loading Error!"),
_("Can't load textclass ")
+ params.getLyXTextClass().name(),
- _("-- substituting default"));
+ _("-- substituting default."));
#endif
params.textclass = 0;
}
} else if (token == "\\use_numerical_citations") {
lex.nextToken();
params.use_numerical_citations = lex.getInteger();
+ } else if (token == "\\tracking_changes") {
+ lex.nextToken();
+ params.tracking_changes = lex.getInteger();
+ // mark the first paragraph
+ if (params.tracking_changes)
+ par->trackChanges();
+ } else if (token == "\\author") {
+ lex.nextToken();
+ istringstream ss(lex.getString());
+ Author a;
+ ss >> a;
+ int aid(authorlist.record(a));
+ lyxerr << "aid is " << aid << endl;
+ lyxerr << "listed aid is " << author_ids.size() << endl;
+ author_ids.push_back(authorlist.record(a));
} else if (token == "\\paperorientation") {
int tmpret = lex.findToken(string_orientation);
if (tmpret == -1)
par->params().labelWidthString(lex.getString());
// do not delete this token, it is still needed!
} else if (token == "\\newline") {
- par->insertChar(pos, Paragraph::META_NEWLINE, font);
+ par->insertChar(pos, Paragraph::META_NEWLINE, font, current_change);
++pos;
} else if (token == "\\LyXTable") {
Inset * inset = new InsetTabular(*this);
inset->read(this, lex);
- par->insertInset(pos, inset, font);
+ par->insertInset(pos, inset, font, current_change);
++pos;
} else if (token == "\\hfill") {
- par->insertChar(pos, Paragraph::META_HFILL, font);
+ par->insertChar(pos, Paragraph::META_HFILL, font, current_change);
++pos;
+ } else if (token == "\\change_unchanged") {
+ // Hack ! Needed for empty paragraphs :/
+ if (!pos)
+ par->cleanChanges();
+ current_change = Change(Change::UNCHANGED);
+ } else if (token == "\\change_inserted") {
+ lex.nextToken();
+ istringstream istr(lex.getString());
+ int aid;
+ lyx::time_type ct;
+ istr >> aid;
+ istr >> ct;
+ current_change = Change(Change::INSERTED, author_ids[aid], ct);
+ } else if (token == "\\change_deleted") {
+ lex.nextToken();
+ istringstream istr(lex.getString());
+ int aid;
+ lyx::time_type ct;
+ istr >> aid;
+ istr >> ct;
+ current_change = Change(Change::DELETED, author_ids[aid], ct);
} else if (token == "\\bibitem") { // ale970302
if (!par->bibkey) {
InsetCommandParams p("bibitem", "dummy");
} else if (*cit == '\t') {
if (!layout->free_spacing && !par->isFreeSpacing()) {
// tabs are like spaces here
- par->insertChar(pos, ' ', font);
+ par->insertChar(pos, ' ', font, current_change);
++pos;
space_inserted = true;
} else {
const pos_type nb = 8 - pos % 8;
for (pos_type a = 0; a < nb ; ++a) {
- par->insertChar(pos, ' ', font);
+ par->insertChar(pos, ' ', font, current_change);
++pos;
}
space_inserted = true;
}
if (inset) {
- par->insertInset(pos, inset, font);
+ par->insertInset(pos, inset, font, current_change);
++pos;
}
}
istringstream is(STRCONV(ret.second));
LyXLex tmplex(0, 0);
tmplex.setStream(is);
- return readFile(tmplex, string());
+ return readFile(tmplex, string(), par);
} else {
// This code is reached if lyx2lyx failed (for
// some reason) to change the file format of
// now write out the buffer paramters.
params.writeFile(ofs);
+ // if we're tracking, list all possible authors
+ if (params.tracking_changes) {
+ AuthorList::Authors::const_iterator it = authorlist.begin();
+ AuthorList::Authors::const_iterator end = authorlist.end();
+ for (; it != end; ++it) {
+ ofs << "\\author " << it->second << "\n";
+ }
+ }
+
Paragraph::depth_type depth = 0;
// this will write out all the paragraphs
preamble += "\\makeatother\n";
+ // dvipost settings come after everything else
+ if (params.tracking_changes) {
+ preamble += "\\dvipostlayout\n";
+ preamble += "\\dvipost{osstart color push Red}\n";
+ preamble += "\\dvipost{osend color pop}\n";
+ preamble += "\\dvipost{cbstart color push Blue}\n";
+ preamble += "\\dvipost{cbend color pop} \n";
+ }
+
os << preamble;
if (only_preamble)
{
LyXTextClass const & tclass = params.getLyXTextClass();
+ if (params.tracking_changes) {
+ features.require("dvipost");
+ features.require("color");
+ }
+
// AMS Style is at document level
if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
features.require("amsmath");
bool Buffer::isDepClean(string const & name) const
{
- DEPCLEAN * item = dep_clean;
- while (item && item->master != name)
- item = item->next;
- if (!item) return true;
- return item->clean;
+ DepClean::const_iterator it = dep_clean_.find(name);
+ if (it == dep_clean_.end())
+ return true;
+ return it->second;
}
void Buffer::markDepClean(string const & name)
{
- if (!dep_clean) {
- dep_clean = new DEPCLEAN;
- dep_clean->clean = true;
- dep_clean->master = name;
- dep_clean->next = 0;
- } else {
- DEPCLEAN * item = dep_clean;
- while (item && item->master != name)
- item = item->next;
- if (item) {
- item->clean = true;
- } else {
- item = new DEPCLEAN;
- item->clean = true;
- item->master = name;
- item->next = 0;
- }
- }
+ dep_clean_[name] = true;
}
updateTitles();
}
bak_clean = false;
- DEPCLEAN * tmp = dep_clean;
- while (tmp) {
- tmp->clean = false;
- tmp = tmp->next;
+
+ DepClean::iterator it = dep_clean_.begin();
+ DepClean::const_iterator const end = dep_clean_.end();
+
+ for (; it != end; ++it) {
+ it->second = false;
}
}