2003-02-08 19:18:01 +00:00
|
|
|
/**
|
|
|
|
* \file changes.C
|
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
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
#include "changes.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
#include "debug.h"
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-09-09 17:25:35 +00:00
|
|
|
#include <boost/assert.hpp>
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using lyx::pos_type;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-09-09 17:25:35 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
bool operator==(Change const & l, Change const & r)
|
|
|
|
{
|
|
|
|
return l.type == r.type && l.author == r.author
|
|
|
|
&& l.changetime == r.changetime;
|
|
|
|
}
|
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::contains(Range const & r) const
|
|
|
|
{
|
|
|
|
return r.start >= start && r.end <= end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Changes::Range::contained(Range const & r) const
|
|
|
|
{
|
|
|
|
return r.contains(*this);
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
bool Changes::Range::contains(pos_type const pos) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
return pos >= start && pos < end;
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-05-08 20:30:52 +00:00
|
|
|
bool Changes::Range::containsOrPrecedes(pos_type const pos) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
return pos >= start && pos <= end;
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
bool Changes::Range::intersects(Range const & r) const
|
|
|
|
{
|
|
|
|
return contained(r) || contains(r)
|
|
|
|
|| contains(r.start) || contains(r.end);
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
Changes::Changes(Change::Type const type)
|
2003-02-08 19:18:01 +00:00
|
|
|
: empty_type_(type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Changes::~Changes()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Changes::Changes(Changes const & c)
|
|
|
|
{
|
|
|
|
table_ = c.table_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::record(Change const change, pos_type const pos)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "record " << change.type
|
|
|
|
<< " at pos " << pos << " with total "
|
|
|
|
<< table_.size() << " changes." << endl;
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
switch (change.type) {
|
|
|
|
case Change::INSERTED:
|
|
|
|
add(change, pos);
|
|
|
|
break;
|
|
|
|
case Change::DELETED:
|
|
|
|
del(change, pos);
|
|
|
|
break;
|
|
|
|
case Change::UNCHANGED:
|
|
|
|
set(Change::UNCHANGED, pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-05 20:21:27 +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
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::set(Change::Type const type, pos_type const pos)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
set(type, pos, pos + 1);
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::set(Change::Type const type,
|
|
|
|
pos_type const start, pos_type const end)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
set(Change(type), start, end);
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::set(Change const change,
|
|
|
|
pos_type const start, pos_type const end)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
ChangeTable::iterator it = table_.begin();
|
|
|
|
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "changeset of " << change.type
|
|
|
|
<< " author " << change.author << " time " << change.changetime
|
|
|
|
<< " in range " << start << "," << end << endl;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
Range const new_range(start, end);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
// remove all sub-ranges
|
|
|
|
for (; it != table_.end();) {
|
|
|
|
if (new_range != it->range && it->range.contained(new_range)) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Removing subrange "
|
|
|
|
<< it->range.start << "," << it->range.end << endl;
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
it = table_.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
it = table_.begin();
|
2005-01-05 20:21:27 +00:00
|
|
|
ChangeTable::iterator const itend = table_.end();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
// find a super-range
|
|
|
|
for (; it != itend; ++it) {
|
|
|
|
if (it->range.contains(new_range))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it == itend) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Inserting change at end" << endl;
|
|
|
|
table_.push_back(ChangeRange(start, end, change));
|
|
|
|
merge();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change.type == it->change.type) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Change set already." << endl;
|
|
|
|
it->change = change;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChangeRange c(*it);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Using change of type " << c.change.type
|
|
|
|
<< " over " << c.range.start << "," << c.range.end << endl;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
|
|
// split head
|
2003-02-08 19:18:01 +00:00
|
|
|
if (c.range.start < start) {
|
|
|
|
it = table_.insert(it, ChangeRange(c.range.start, start, c.change));
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Splitting head of type " << c.change.type
|
|
|
|
<< " over " << c.range.start << "," << start << endl;
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reset this as new type
|
|
|
|
it->range.start = start;
|
|
|
|
it->range.end = end;
|
|
|
|
it->change = change;
|
|
|
|
lyxerr[Debug::CHANGES] << "Resetting to new change" << endl;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
// split tail
|
|
|
|
if (c.range.end > end) {
|
|
|
|
++it;
|
|
|
|
table_.insert(it, ChangeRange(end, c.range.end, c.change));
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Splitting tail of type " << c.change.type
|
|
|
|
<< " over " << end << "," << c.range.end << endl;
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check();
|
|
|
|
merge();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::erase(pos_type const pos)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
ChangeTable::iterator it = table_.begin();
|
|
|
|
ChangeTable::iterator end = table_.end();
|
|
|
|
|
|
|
|
bool found = false;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
for (; it != end; ++it) {
|
|
|
|
Range & range(it->range);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "era:Range of type " << it->change.type << " is "
|
|
|
|
<< it->range.start << "," << it->range.end << endl;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (range.contains(pos)) {
|
|
|
|
found = true;
|
|
|
|
--range.end;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
--range.start;
|
|
|
|
--range.end;
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
check();
|
2003-02-08 19:18:01 +00:00
|
|
|
merge();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::del(Change const change, ChangeTable::size_type const pos)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
// this case happens when building from .lyx
|
|
|
|
if (table_.empty()) {
|
|
|
|
set(change, pos);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
ChangeTable::iterator it = table_.begin();
|
|
|
|
|
|
|
|
for (; it != table_.end(); ++it) {
|
|
|
|
Range & range(it->range);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (range.contains(pos)) {
|
|
|
|
if (it->change.type != Change::INSERTED) {
|
|
|
|
set(change, pos);
|
|
|
|
} else {
|
|
|
|
erase(pos);
|
|
|
|
}
|
|
|
|
break;
|
2006-05-08 20:30:52 +00:00
|
|
|
} else if (range.containsOrPrecedes(pos) && it + 1 == table_.end()) {
|
2003-02-08 19:18:01 +00:00
|
|
|
// this case happens when building from .lyx
|
|
|
|
set(change, pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::add(Change const change, ChangeTable::size_type const pos)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
ChangeTable::iterator it = table_.begin();
|
|
|
|
ChangeTable::iterator end = table_.end();
|
|
|
|
|
|
|
|
bool found = false;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
for (; it != end; ++it) {
|
|
|
|
Range & range(it->range);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-05-08 20:30:52 +00:00
|
|
|
if (!found && range.containsOrPrecedes(pos)) {
|
2003-02-08 19:18:01 +00:00
|
|
|
found = true;
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Found range of "
|
|
|
|
<< range.start << "," << range.end << endl;
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
++range.end;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
++range.start;
|
|
|
|
++range.end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set(change, pos);
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2006-05-08 20:30:52 +00:00
|
|
|
Change const Changes::lookup(pos_type const pos) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
if (!table_.size()) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES))
|
|
|
|
lyxerr[Debug::CHANGES] << "Empty, type is " << empty_type_ << endl;
|
2003-02-08 19:18:01 +00:00
|
|
|
return Change(empty_type_);
|
|
|
|
}
|
2003-03-04 09:27:27 +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
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
check();
|
2005-01-05 20:21:27 +00:00
|
|
|
BOOST_ASSERT(false && "missing changes for pos");
|
2003-02-08 19:18:01 +00:00
|
|
|
return Change(Change::UNCHANGED);
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
bool Changes::isChange(pos_type const start, pos_type const end) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
if (!table_.size()) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES))
|
|
|
|
lyxerr[Debug::CHANGES] << "Empty, type is " << empty_type_ << endl;
|
2003-02-08 19:18:01 +00:00
|
|
|
return empty_type_ != Change::UNCHANGED;
|
|
|
|
}
|
2003-03-04 09:27:27 +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 itend = table_.end();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
for (; it != itend; ++it) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Looking for " << start << ","
|
|
|
|
<< end << " in " << it->range.start << ","
|
|
|
|
<< it->range.end << "of type " << it->change.type << endl;
|
|
|
|
}
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (it->range.intersects(Range(start, end))
|
|
|
|
&& it->change.type != Change::UNCHANGED) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Found intersection of "
|
|
|
|
<< start << "," << end << " with "
|
|
|
|
<< it->range.start << "," << it->range.end
|
|
|
|
<< " of type " << it->change.type << endl;
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
bool Changes::isChangeEdited(lyx::pos_type const start,
|
|
|
|
lyx::pos_type const end) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
if (!table_.size()) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES))
|
|
|
|
lyxerr[Debug::CHANGES] << "Empty, type is " << empty_type_ << endl;
|
2003-02-08 19:18:01 +00:00
|
|
|
return empty_type_ != Change::INSERTED;
|
|
|
|
}
|
2003-03-04 09:27:27 +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 itend = table_.end();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
for (; it != itend; ++it) {
|
|
|
|
if (it->range.intersects(Range(start, end ? end - 1 : 0))
|
|
|
|
&& it->change.type != Change::INSERTED) {
|
|
|
|
return true;
|
2003-03-04 09:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
void Changes::merge()
|
|
|
|
{
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES))
|
|
|
|
lyxerr[Debug::CHANGES] << "Starting merge" << endl;
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
ChangeTable::iterator it = table_.begin();
|
|
|
|
|
|
|
|
while (it != table_.end()) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Range of type " << it->change.type << " is "
|
|
|
|
<< it->range.start << "," << it->range.end << endl;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (it->range.start == it->range.end) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Removing empty range for pos "
|
|
|
|
<< it->range.start << endl;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (it->change == (it + 1)->change) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Merging equal ranges "
|
|
|
|
<< it->range.start << "," << it->range.end
|
|
|
|
<< " and " << (it + 1)->range.start << ","
|
|
|
|
<< (it + 1)->range.end << endl;
|
|
|
|
}
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
(it + 1)->range.start = it->range.start;
|
|
|
|
table_.erase(it);
|
|
|
|
// start again
|
|
|
|
it = table_.begin();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
lyxerr[Debug::CHANGES] << "Merge ended" << endl;
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
void Changes::check() const
|
|
|
|
{
|
|
|
|
ChangeTable::const_iterator it = table_.begin();
|
|
|
|
ChangeTable::const_iterator end = table_.end();
|
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
bool dont_assert = true;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
lyxerr[Debug::CHANGES] << "Changelist:" << endl;
|
|
|
|
for (; it != end; ++it) {
|
2003-03-12 02:34:46 +00:00
|
|
|
if (lyxerr.debugging(Debug::CHANGES)) {
|
|
|
|
lyxerr[Debug::CHANGES] << "Range of type " << it->change.type << " is "
|
|
|
|
<< it->range.start << "," << it->range.end << " author "
|
|
|
|
<< it->change.author << " time " << it->change.changetime << endl;
|
|
|
|
}
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (it + 1 == end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
Range const & range(it->range);
|
|
|
|
Range const & next((it + 1)->range);
|
|
|
|
if (range.end != next.start)
|
|
|
|
dont_assert = false;
|
|
|
|
}
|
2003-03-12 02:34:46 +00:00
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::CHANGES))
|
|
|
|
lyxerr[Debug::CHANGES] << "End" << endl;
|
|
|
|
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(dont_assert);
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
int Changes::latexMarkChange(std::ostream & os,
|
2005-01-24 17:12:19 +00:00
|
|
|
Change::Type const old, Change::Type const change,
|
|
|
|
bool const & output)
|
2003-03-04 09:27:27 +00:00
|
|
|
{
|
2005-01-24 17:12:19 +00:00
|
|
|
if (!output || old == 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
|
|
|
string const start("\\changestart{}");
|
|
|
|
string const end("\\changeend{}");
|
|
|
|
string const son("\\overstrikeon{}");
|
|
|
|
string const soff("\\overstrikeoff{}");
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
int column = 0;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (old == Change::DELETED) {
|
|
|
|
os << soff;
|
|
|
|
column += soff.length();
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
switch (change) {
|
|
|
|
case Change::UNCHANGED:
|
|
|
|
os << end;
|
|
|
|
column += end.length();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Change::DELETED:
|
|
|
|
if (old == Change::UNCHANGED) {
|
|
|
|
os << start;
|
|
|
|
column += start.length();
|
|
|
|
}
|
|
|
|
os << son;
|
|
|
|
column += son.length();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Change::INSERTED:
|
|
|
|
if (old == Change::UNCHANGED) {
|
|
|
|
os << start;
|
|
|
|
column += start.length();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
return column;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
void Changes::lyxMarkChange(std::ostream & os, int & column,
|
|
|
|
lyx::time_type const curtime,
|
|
|
|
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
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
switch (change.type) {
|
|
|
|
case Change::UNCHANGED:
|
|
|
|
os << "\n\\change_unchanged\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Change::DELETED: {
|
2005-01-05 20:21:27 +00:00
|
|
|
lyx::time_type t = change.changetime;
|
2003-02-08 19:18:01 +00:00
|
|
|
if (!t)
|
|
|
|
t = curtime;
|
|
|
|
os << "\n\\change_deleted " << change.author
|
|
|
|
<< " " << t << "\n";
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-05 20:21:27 +00:00
|
|
|
case Change::INSERTED: {
|
|
|
|
lyx::time_type t = change.changetime;
|
2003-02-08 19:18:01 +00:00
|
|
|
if (!t)
|
|
|
|
t = curtime;
|
|
|
|
os << "\n\\change_inserted " << change.author
|
|
|
|
<< " " << t << "\n";
|
|
|
|
break;
|
|
|
|
}
|
2005-01-05 20:21:27 +00:00
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|