2003-02-08 19:18:01 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Changes.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2003-02-08 19:18:01 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author John Levon
|
2006-10-21 14:34:05 +00:00
|
|
|
* \author Michael Gerz
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-08 19:18:01 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Record changes in a paragraph.
|
2003-02-08 19:18:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Changes.h"
|
2007-05-08 17:46:03 +00:00
|
|
|
#include "Author.h"
|
2008-09-30 11:06:34 +00:00
|
|
|
#include "Buffer.h"
|
2007-05-08 17:46:03 +00:00
|
|
|
#include "BufferParams.h"
|
2009-10-12 16:22:05 +00:00
|
|
|
#include "Encoding.h"
|
2007-05-08 17:46:03 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2009-10-12 16:22:05 +00:00
|
|
|
#include "OutputParams.h"
|
2008-09-30 11:06:34 +00:00
|
|
|
#include "Paragraph.h"
|
|
|
|
#include "TocBackend.h"
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2008-09-30 11:06:34 +00:00
|
|
|
#include "support/gettext.h"
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2009-10-12 16:22:05 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include "frontends/alert.h"
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-11-27 23:09:06 +00:00
|
|
|
#include <ostream>
|
2006-10-26 19:00:28 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2007-07-17 17:40:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2006-10-26 19:00:28 +00:00
|
|
|
/*
|
|
|
|
* Class Change has a changetime field that specifies the exact time at which
|
|
|
|
* a specific change was made. The change time is used as a guidance for the
|
|
|
|
* user while editing his document. Presently, it is not considered for LaTeX
|
2006-10-29 21:48:23 +00:00
|
|
|
* export.
|
|
|
|
* When merging two adjacent changes, the changetime is not considered,
|
|
|
|
* only the equality of the change type and author is checked (in method
|
|
|
|
* isSimilarTo(...)). If two changes are in fact merged (in method merge()),
|
2007-05-28 22:27:45 +00:00
|
|
|
* the later change time is preserved.
|
2006-10-26 19:00:28 +00:00
|
|
|
*/
|
2003-09-09 17:25:35 +00:00
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
bool Change::isSimilarTo(Change const & change) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
2007-11-01 22:17:22 +00:00
|
|
|
if (type != change.type)
|
2006-10-26 19:00:28 +00:00
|
|
|
return false;
|
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
if (type == Change::UNCHANGED)
|
2006-10-26 19:00:28 +00:00
|
|
|
return true;
|
|
|
|
|
2006-10-29 21:48:23 +00:00
|
|
|
return author == change.author;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-09 20:47:32 +00:00
|
|
|
Color Change::color() const
|
2008-09-22 15:30:26 +00:00
|
|
|
{
|
2009-02-09 20:47:32 +00:00
|
|
|
Color color = Color_none;
|
2008-09-22 15:30:26 +00:00
|
|
|
switch (author % 5) {
|
|
|
|
case 0:
|
|
|
|
color = Color_changedtextauthor1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
color = Color_changedtextauthor2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
color = Color_changedtextauthor3;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
color = Color_changedtextauthor4;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
color = Color_changedtextauthor5;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-09 20:47:32 +00:00
|
|
|
|
|
|
|
if (deleted())
|
|
|
|
color.mergeColor = Color_deletedtextmodifier;
|
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-29 21:48:23 +00:00
|
|
|
bool operator==(Change const & l, Change const & r)
|
|
|
|
{
|
2007-11-01 22:17:22 +00:00
|
|
|
if (l.type != r.type)
|
2007-01-08 23:28:41 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// two changes of type UNCHANGED are always equal
|
2007-11-01 22:17:22 +00:00
|
|
|
if (l.type == Change::UNCHANGED)
|
2007-01-08 23:28:41 +00:00
|
|
|
return true;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
return l.author == r.author && l.changetime == r.changetime;
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
bool operator!=(Change const & l, Change const & r)
|
|
|
|
{
|
|
|
|
return !(l == r);
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
bool operator==(Changes::Range const & r1, Changes::Range const & r2)
|
|
|
|
{
|
2003-03-04 09:27:27 +00:00
|
|
|
return r1.start == r2.start && r1.end == r2.end;
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(Changes::Range const & r1, Changes::Range const & r2)
|
|
|
|
{
|
|
|
|
return !(r1 == r2);
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
bool Changes::Range::intersects(Range const & r) const
|
|
|
|
{
|
2006-10-20 14:31:54 +00:00
|
|
|
return r.start < end && r.end > start; // end itself is not in the range!
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
|
|
|
2006-10-19 07:12:48 +00:00
|
|
|
void Changes::set(Change const & change, pos_type const pos)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
set(change, pos, pos + 1);
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
void Changes::set(Change const & change, pos_type const start, pos_type const end)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
2007-04-01 15:09:08 +00:00
|
|
|
if (change.type != Change::UNCHANGED) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, "setting change (type: " << change.type
|
2007-11-29 09:00:28 +00:00
|
|
|
<< ", author: " << change.author
|
|
|
|
<< ", time: " << long(change.changetime)
|
2007-11-15 20:04:51 +00:00
|
|
|
<< ") in range (" << start << ", " << end << ")");
|
2003-03-12 02:34:46 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
Range const newRange(start, end);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
ChangeTable::iterator it = table_.begin();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
for (; it != table_.end(); ) {
|
|
|
|
// current change starts like or follows new change
|
|
|
|
if (it->range.start >= start) {
|
2003-02-08 19:18:01 +00:00
|
|
|
break;
|
2006-10-21 14:34:05 +00:00
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
// new change intersects with existing change
|
|
|
|
if (it->range.end > start) {
|
|
|
|
pos_type oldEnd = it->range.end;
|
|
|
|
it->range.end = start;
|
2007-04-01 15:09:08 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, " cutting tail of type " << it->change.type
|
2007-04-01 15:09:08 +00:00
|
|
|
<< " resulting in range (" << it->range.start << ", "
|
2007-11-15 20:04:51 +00:00
|
|
|
<< it->range.end << ")");
|
2007-04-01 15:09:08 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
++it;
|
|
|
|
if (oldEnd >= end) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, " inserting tail in range ("
|
|
|
|
<< end << ", " << oldEnd << ")");
|
2006-10-21 14:34:05 +00:00
|
|
|
it = table_.insert(it, ChangeRange((it-1)->change, Range(end, oldEnd)));
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
++it;
|
2003-03-12 02:34:46 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
if (change.type != Change::UNCHANGED) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, " inserting change");
|
2006-10-21 14:34:05 +00:00
|
|
|
it = table_.insert(it, ChangeRange(change, Range(start, end)));
|
2003-02-08 19:18:01 +00:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
for (; it != table_.end(); ) {
|
|
|
|
// new change 'contains' existing change
|
|
|
|
if (newRange.contains(it->range)) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, " removing subrange ("
|
|
|
|
<< it->range.start << ", " << it->range.end << ")");
|
2006-10-21 14:34:05 +00:00
|
|
|
it = table_.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-10-21 14:34:05 +00:00
|
|
|
// new change precedes existing change
|
2007-11-01 22:17:22 +00:00
|
|
|
if (it->range.start >= end)
|
2006-10-21 14:34:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// new change intersects with existing change
|
|
|
|
it->range.start = end;
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, " cutting head of type "
|
2007-04-01 15:09:08 +00:00
|
|
|
<< it->change.type << " resulting in range ("
|
2007-11-15 20:04:51 +00:00
|
|
|
<< end << ", " << it->range.end << ")");
|
2006-10-21 14:34:05 +00:00
|
|
|
break; // no need for another iteration
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
merge();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::erase(pos_type const pos)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, "Erasing change at position " << pos);
|
2006-10-21 15:36:04 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
ChangeTable::iterator it = table_.begin();
|
|
|
|
ChangeTable::iterator end = table_.end();
|
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
2006-10-21 15:36:04 +00:00
|
|
|
// range (pos,pos+x) becomes (pos,pos+x-1)
|
2007-11-01 22:17:22 +00:00
|
|
|
if (it->range.start > pos)
|
2006-10-21 15:36:04 +00:00
|
|
|
--(it->range.start);
|
|
|
|
// range (pos-x,pos) stays (pos-x,pos)
|
2007-11-01 22:17:22 +00:00
|
|
|
if (it->range.end > pos)
|
2006-10-21 15:36:04 +00:00
|
|
|
--(it->range.end);
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-10-21 15:36:04 +00:00
|
|
|
merge();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Changes::insert(Change const & change, lyx::pos_type pos)
|
|
|
|
{
|
2007-04-01 15:09:08 +00:00
|
|
|
if (change.type != Change::UNCHANGED) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, "Inserting change of type " << change.type
|
|
|
|
<< " at position " << pos);
|
2006-10-21 15:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ChangeTable::iterator it = table_.begin();
|
|
|
|
ChangeTable::iterator end = table_.end();
|
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
// range (pos,pos+x) becomes (pos+1,pos+x+1)
|
2007-11-01 22:17:22 +00:00
|
|
|
if (it->range.start >= pos)
|
2006-10-21 15:36:04 +00:00
|
|
|
++(it->range.start);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2006-10-21 15:36:04 +00:00
|
|
|
// range (pos-x,pos) stays as it is
|
2007-11-01 22:17:22 +00:00
|
|
|
if (it->range.end > pos)
|
2006-10-21 15:36:04 +00:00
|
|
|
++(it->range.end);
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
2006-10-21 15:36:04 +00:00
|
|
|
|
|
|
|
set(change, pos, pos + 1); // set will call merge
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-07 18:13:25 +00:00
|
|
|
Change const & Changes::lookup(pos_type const pos) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
2007-01-07 18:13:25 +00:00
|
|
|
static Change const noChange = Change(Change::UNCHANGED);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
ChangeTable::const_iterator it = table_.begin();
|
2005-01-05 20:21:27 +00:00
|
|
|
ChangeTable::const_iterator const end = table_.end();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it->range.contains(pos))
|
|
|
|
return it->change;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-01-07 18:13:25 +00:00
|
|
|
return noChange;
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2009-08-04 22:50:36 +00:00
|
|
|
bool Changes::isDeleted(pos_type start, pos_type end) const
|
2009-05-14 22:21:05 +00:00
|
|
|
{
|
|
|
|
ChangeTable::const_iterator it = table_.begin();
|
|
|
|
ChangeTable::const_iterator const itend = table_.end();
|
|
|
|
|
|
|
|
for (; it != itend; ++it) {
|
|
|
|
if (it->range.contains(Range(start, end))) {
|
|
|
|
LYXERR(Debug::CHANGES, "range ("
|
|
|
|
<< start << ", " << end << ") fully contains ("
|
|
|
|
<< it->range.start << ", " << it->range.end
|
|
|
|
<< ") of type " << it->change.type);
|
|
|
|
return it->change.type == Change::DELETED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-20 15:27:11 +00:00
|
|
|
bool Changes::isChanged(pos_type const start, pos_type const end) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
ChangeTable::const_iterator it = table_.begin();
|
2005-01-05 20:21:27 +00:00
|
|
|
ChangeTable::const_iterator const itend = table_.end();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
for (; it != itend; ++it) {
|
2006-10-21 16:01:45 +00:00
|
|
|
if (it->range.intersects(Range(start, end))) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, "found intersection of range ("
|
2007-04-01 15:09:08 +00:00
|
|
|
<< start << ", " << end << ") with ("
|
|
|
|
<< it->range.start << ", " << it->range.end
|
2007-11-15 20:04:51 +00:00
|
|
|
<< ") of type " << it->change.type);
|
2003-02-08 19:18:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
void Changes::merge()
|
|
|
|
{
|
|
|
|
ChangeTable::iterator it = table_.begin();
|
|
|
|
|
|
|
|
while (it != table_.end()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, "found change of type " << it->change.type
|
2007-04-01 15:09:08 +00:00
|
|
|
<< " and range (" << it->range.start << ", " << it->range.end
|
2007-11-15 20:04:51 +00:00
|
|
|
<< ")");
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (it->range.start == it->range.end) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES, "removing empty range for pos "
|
|
|
|
<< it->range.start);
|
2003-03-12 02:34:46 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
table_.erase(it);
|
|
|
|
// start again
|
|
|
|
it = table_.begin();
|
|
|
|
continue;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (it + 1 == table_.end())
|
|
|
|
break;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
if (it->change.isSimilarTo((it + 1)->change)
|
|
|
|
&& it->range.end == (it + 1)->range.start) {
|
|
|
|
LYXERR(Debug::CHANGES, "merging ranges (" << it->range.start << ", "
|
2007-04-01 15:09:08 +00:00
|
|
|
<< it->range.end << ") and (" << (it + 1)->range.start << ", "
|
2007-11-15 20:04:51 +00:00
|
|
|
<< (it + 1)->range.end << ")");
|
2007-04-01 15:09:08 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
(it + 1)->range.start = it->range.start;
|
2007-12-12 19:28:07 +00:00
|
|
|
(it + 1)->change.changetime = max(it->change.changetime,
|
2007-05-28 22:27:45 +00:00
|
|
|
(it + 1)->change.changetime);
|
2003-02-08 19:18:01 +00:00
|
|
|
table_.erase(it);
|
|
|
|
// start again
|
|
|
|
it = table_.begin();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2009-10-12 16:22:05 +00:00
|
|
|
namespace {
|
2009-10-13 07:30:46 +00:00
|
|
|
docstring getLaTeXMarkup(docstring const & macro, docstring const & author,
|
|
|
|
docstring const & chgTime,
|
2009-10-12 16:22:05 +00:00
|
|
|
OutputParams const & runparams)
|
|
|
|
{
|
|
|
|
if (macro.empty())
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
static docstring warned_author = docstring();
|
|
|
|
docstring uncodable_author = warned_author;
|
|
|
|
odocstringstream ods;
|
|
|
|
|
|
|
|
ods << macro;
|
|
|
|
// convert utf8 author name to something representable
|
|
|
|
// in the current encoding
|
|
|
|
docstring author_latexed;
|
|
|
|
for (size_t n = 0; n < author.size(); ++n) {
|
|
|
|
try {
|
2012-03-25 13:36:00 +00:00
|
|
|
author_latexed += runparams.encoding->latexChar(author[n]).first;
|
2009-10-12 16:22:05 +00:00
|
|
|
} catch (EncodingException & /* e */) {
|
|
|
|
if (runparams.dryrun) {
|
|
|
|
ods << "<" << _("LyX Warning: ")
|
|
|
|
<< _("uncodable character") << " '";
|
|
|
|
ods.put(author[n]);
|
|
|
|
ods << "'>";
|
|
|
|
} else {
|
2009-12-05 23:18:21 +00:00
|
|
|
LYXERR0("Omitting uncodable character '"
|
2009-10-12 16:22:05 +00:00
|
|
|
<< docstring(1, author[n])
|
|
|
|
<< "' in change author name!");
|
|
|
|
uncodable_author = author;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ods << author_latexed << "}{" << chgTime << "}{";
|
|
|
|
|
|
|
|
// warn user (once) if we found uncodable glyphs.
|
|
|
|
if (uncodable_author != warned_author) {
|
|
|
|
frontend::Alert::warning(_("Uncodable character in author name"),
|
|
|
|
support::bformat(_("The author name '%1$s',\n"
|
|
|
|
"used for change tracking, contains glyphs that cannot be\n"
|
|
|
|
"represented in the current encoding. The respective glyphs\n"
|
2009-12-05 23:18:21 +00:00
|
|
|
"will be omitted in the exported LaTeX file.\n\n"
|
2010-03-10 15:09:44 +00:00
|
|
|
"Choose an appropriate document encoding (such as utf8)\n"
|
2009-10-12 16:22:05 +00:00
|
|
|
"or change the spelling of the author name."), uncodable_author));
|
|
|
|
warned_author = uncodable_author;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
} //namespace anon
|
|
|
|
|
|
|
|
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams,
|
2009-10-12 16:22:05 +00:00
|
|
|
Change const & oldChange, Change const & change,
|
|
|
|
OutputParams const & runparams)
|
2003-03-04 09:27:27 +00:00
|
|
|
{
|
2007-05-08 17:46:03 +00:00
|
|
|
if (!bparams.outputChanges || oldChange == change)
|
2003-02-08 19:18:01 +00:00
|
|
|
return 0;
|
2005-04-26 11:12:20 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
int column = 0;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-05-08 17:46:03 +00:00
|
|
|
if (oldChange.type != Change::UNCHANGED) {
|
2009-10-12 16:22:05 +00:00
|
|
|
// close \lyxadded or \lyxdeleted
|
|
|
|
os << '}';
|
2007-05-08 17:46:03 +00:00
|
|
|
column++;
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-05-08 17:46:03 +00:00
|
|
|
docstring chgTime;
|
|
|
|
chgTime += ctime(&change.changetime);
|
2009-10-12 16:22:05 +00:00
|
|
|
// remove trailing '\n'
|
|
|
|
chgTime.erase(chgTime.end() - 1);
|
|
|
|
|
|
|
|
docstring macro_beg;
|
|
|
|
if (change.type == Change::DELETED)
|
|
|
|
macro_beg = from_ascii("\\lyxdeleted{");
|
|
|
|
else if (change.type == Change::INSERTED)
|
|
|
|
macro_beg = from_ascii("\\lyxadded{");
|
|
|
|
|
|
|
|
docstring str = getLaTeXMarkup(macro_beg,
|
|
|
|
bparams.authors().get(change.author).name(),
|
|
|
|
chgTime, runparams);
|
|
|
|
|
|
|
|
os << str;
|
|
|
|
column += str.size();
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
return column;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-23 20:08:05 +00:00
|
|
|
void Changes::lyxMarkChange(ostream & os, BufferParams const & bparams, int & column,
|
2005-01-05 20:21:27 +00:00
|
|
|
Change const & old, Change const & change)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
if (old == change)
|
|
|
|
return;
|
|
|
|
|
|
|
|
column = 0;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2010-11-17 16:13:59 +00:00
|
|
|
int const buffer_id = bparams.authors().get(change.author).bufferId();
|
2009-07-23 20:08:05 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
switch (change.type) {
|
|
|
|
case Change::UNCHANGED:
|
|
|
|
os << "\n\\change_unchanged\n";
|
|
|
|
break;
|
|
|
|
|
2010-11-17 16:13:59 +00:00
|
|
|
case Change::DELETED:
|
2009-07-23 20:08:05 +00:00
|
|
|
os << "\n\\change_deleted " << buffer_id
|
2006-10-26 19:00:28 +00:00
|
|
|
<< " " << change.changetime << "\n";
|
2003-02-08 19:18:01 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-17 16:13:59 +00:00
|
|
|
case Change::INSERTED:
|
2009-07-23 20:08:05 +00:00
|
|
|
os << "\n\\change_inserted " << buffer_id
|
2006-10-26 19:00:28 +00:00
|
|
|
<< " " << change.changetime << "\n";
|
2003-02-08 19:18:01 +00:00
|
|
|
break;
|
2005-01-05 20:21:27 +00:00
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2007-07-09 20:52:34 +00:00
|
|
|
void Changes::checkAuthors(AuthorList const & authorList)
|
|
|
|
{
|
|
|
|
ChangeTable::const_iterator it = table_.begin();
|
|
|
|
ChangeTable::const_iterator endit = table_.end();
|
|
|
|
for ( ; it != endit ; ++it)
|
|
|
|
if (it->change.type != Change::UNCHANGED)
|
2007-11-01 22:17:22 +00:00
|
|
|
authorList.get(it->change.author).setUsed(true);
|
2007-07-09 20:52:34 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 11:06:34 +00:00
|
|
|
|
|
|
|
void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer) const
|
|
|
|
{
|
|
|
|
if (table_.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Toc & change_list = buffer.tocBackend().toc("change");
|
|
|
|
AuthorList const & author_list = buffer.params().authors();
|
|
|
|
DocIterator dit = cdit;
|
|
|
|
|
|
|
|
ChangeTable::const_iterator it = table_.begin();
|
|
|
|
ChangeTable::const_iterator const itend = table_.end();
|
|
|
|
for (; it != itend; ++it) {
|
|
|
|
docstring str;
|
|
|
|
switch (it->change.type) {
|
|
|
|
case Change::UNCHANGED:
|
|
|
|
continue;
|
|
|
|
case Change::DELETED:
|
|
|
|
// 0x2702 is a scissors symbol in the Dingbats unicode group.
|
|
|
|
str.push_back(0x2702);
|
|
|
|
break;
|
|
|
|
case Change::INSERTED:
|
2008-10-03 22:58:29 +00:00
|
|
|
// 0x270d is the hand writting symbol in the Dingbats unicode group.
|
2008-09-30 11:06:34 +00:00
|
|
|
str.push_back(0x270d);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dit.pos() = it->range.start;
|
2008-10-03 19:53:53 +00:00
|
|
|
Paragraph const & par = dit.paragraph();
|
2008-10-03 19:57:13 +00:00
|
|
|
str += " " + par.asString(it->range.start, min(par.size(), it->range.end));
|
2008-10-03 23:16:51 +00:00
|
|
|
if (it->range.end > par.size())
|
|
|
|
// the end of paragraph symbol from the Punctuation group
|
|
|
|
str.push_back(0x204B);
|
2008-09-30 11:06:34 +00:00
|
|
|
docstring const & author = author_list.get(it->change.author).name();
|
2008-09-30 12:34:36 +00:00
|
|
|
Toc::iterator it = change_list.item(0, author);
|
2008-09-30 11:06:34 +00:00
|
|
|
if (it == change_list.end()) {
|
|
|
|
change_list.push_back(TocItem(dit, 0, author));
|
2010-04-26 00:43:08 +00:00
|
|
|
change_list.push_back(TocItem(dit, 1, str,
|
|
|
|
support::wrapParas(str, 4)));
|
2008-09-30 11:26:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (++it; it != change_list.end(); ++it) {
|
|
|
|
if (it->depth() == 0 && it->str() != author)
|
|
|
|
break;
|
2008-09-30 11:06:34 +00:00
|
|
|
}
|
2010-04-26 00:43:08 +00:00
|
|
|
change_list.insert(it, TocItem(dit, 1, str,
|
|
|
|
support::wrapParas(str, 4)));
|
2008-09-30 11:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|