}
-bool getTokenValue(string const & str, char const * token, Change::Type & change)
+bool getTokenValue(string const & str, char const * token, Change & change, BufferParams bp)
{
- // set the length to be zero() as default as this it should be if not
+ // set the change to be Change() as default as this it should be if not
// in the file format.
- change = Change::UNCHANGED;
+ change = Change();
string tmp;
if (getTokenValue(str, token, tmp)) {
- if (tmp == "inserted") {
- change = Change::INSERTED;
+ vector<string> const changedata = getVectorFromString(tmp, " ");
+ if (changedata.size() != 3) {
+ Alert::warning(_("Change tracking data incomplete"),
+ _("Change tracking information for tabular row/column "
+ "is incomplete. I will ignore this.\n"));
+ return false;
+ }
+ BufferParams::AuthorMap const & am = bp.author_map_;
+ int aid = convert<int>(changedata[1]);
+ if (am.find(aid) == am.end()) {
+ // FIXME Use ErrorList
+ Alert::warning(_("Change tracking author index missing"),
+ bformat(_("A change tracking author information for index "
+ "%1$d is missing. This can happen after a wrong "
+ "merge by a version control system. In this case, "
+ "either fix the merge, or have this information "
+ "missing until the corresponding tracked changes "
+ "are merged or this user edits the file again.\n"),
+ aid));
+ bp.addAuthor(Author(aid));
+ }
+ istringstream is(changedata[2]);
+ time_t ct;
+ is >> ct;
+ if (changedata[0] == "inserted") {
+ change = Change(Change::INSERTED, am.find(aid)->second, ct);
return true;
- } else if (tmp == "deleted") {
- change = Change::DELETED;
+ } else if (changedata[0] == "deleted") {
+ change = Change(Change::DELETED, am.find(aid)->second, ct);
return true;
}
}
return value.zero() ? string() : write_attribute(name, value.asString());
}
-template <>
-string const write_attribute(string const & name, Change::Type const & type)
+string const write_attribute(string const & name, Change const & change, BufferParams const bp)
{
- if (type == Change::INSERTED)
- return write_attribute(name, from_ascii("inserted"));
- else if (type == Change::DELETED)
- return write_attribute(name, from_ascii("deleted"));
+ odocstringstream ods;
+ if (change.inserted())
+ ods << from_ascii("inserted");
+ else if (change.deleted())
+ ods << from_ascii("deleted");
+ if (change.changed()) {
+ ods << " " << bp.authors().get(change.author).bufferId()
+ << " " << change.changetime;
+ return write_attribute(name, ods.str());
+ }
return string();
}
endlastfoot(false),
newpage(false),
caption(false),
- change(Change::UNCHANGED)
+ change(Change())
{}
valignment(LYX_VALIGN_TOP),
width(0),
varwidth(false),
- change(Change::UNCHANGED)
+ change(Change())
{
}
}
}
if (ct)
- row_info[row].change = Change::DELETED;
+ row_info[row].change.setDeleted();
else {
row_info.erase(row_info.begin() + row);
cell_info.erase(cell_info.begin() + row);
if (buffer().params().track_changes)
cellInfo(i).inset->setChange(Change(Change::INSERTED));
}
- if (buffer().params().track_changes)
- row_info[row + 1].change = Change::INSERTED;
+ if (buffer().params().track_changes) {
+ row_info[row + 1].change.setInserted();
+ }
}
cell_info[r].erase(cell_info[r].begin() + col);
}
if (ct)
- column_info[col].change = Change::DELETED;
+ column_info[col].change.setDeleted();
else
column_info.erase(column_info.begin() + col);
updateIndexes();
cellInfo(i).inset->setChange(Change(Change::INSERTED));
}
if (buffer().params().track_changes)
- column_info[col + 1].change = Change::INSERTED;
+ column_info[col + 1].change.setInserted();
}
<< write_attribute("alignment", column_info[c].alignment);
if (column_info[c].alignment == LYX_ALIGN_DECIMAL)
os << write_attribute("decimal_point", column_info[c].decimal_point);
- os << write_attribute("change", column_info[c].change)
+ os << write_attribute("change", column_info[c].change, buffer().params())
<< write_attribute("valignment", column_info[c].valignment)
<< write_attribute("width", column_info[c].p_width.asString())
<< write_attribute("varwidth", column_info[c].varwidth)
os << write_attribute("interlinespace", def);
else
os << write_attribute("interlinespace", row_info[r].interline_space);
- os << write_attribute("change", row_info[r].change)
+ os << write_attribute("change", row_info[r].change, buffer().params())
<< write_attribute("endhead", row_info[r].endhead)
<< write_attribute("endfirsthead", row_info[r].endfirsthead)
<< write_attribute("endfoot", row_info[r].endfoot)
getTokenValue(line, "width", column_info[c].p_width);
getTokenValue(line, "special", column_info[c].align_special);
getTokenValue(line, "varwidth", column_info[c].varwidth);
- getTokenValue(line, "change", column_info[c].change);
+ getTokenValue(line, "change", column_info[c].change, buffer().params());
}
for (row_type i = 0; i < nrows(); ++i) {
getTokenValue(line, "endlastfoot", row_info[i].endlastfoot);
getTokenValue(line, "newpage", row_info[i].newpage);
getTokenValue(line, "caption", row_info[i].caption);
- getTokenValue(line, "change", row_info[i].change);
+ getTokenValue(line, "change", row_info[i].change, buffer().params());
for (col_type j = 0; j < ncols(); ++j) {
l_getline(is, line);
if (!prefixIs(line, "<cell")) {
// Colour the frame if rows/columns are added or deleted
Color colour = Color_tabularline;
- if (tabular.column_info[col].change != Change::UNCHANGED
- || tabular.row_info[row].change != Change::UNCHANGED)
+ if (tabular.column_info[col].change.changed()
+ || tabular.row_info[row].change.changed())
colour = InsetTableCell(*tabular.cellInset(cell)).paragraphs().front().lookupChange(0).color();
// Top
if (ct && cs == 0 && ce == tabular.ncols() - 1) {
// whole row selected
if (act == LFUN_CHANGE_ACCEPT) {
- if (tabular.row_info[r].change == Change::INSERTED)
- tabular.row_info[r].change = Change::UNCHANGED;
- else if (tabular.row_info[r].change == Change::DELETED) {
+ if (tabular.row_info[r].change.inserted())
+ tabular.row_info[r].change.setUnchanged();
+ else if (tabular.row_info[r].change.deleted()) {
tabular.deleteRow(r, true);
--re;
continue;
}
} else {
- if (tabular.row_info[r].change == Change::DELETED)
- tabular.row_info[r].change = Change::UNCHANGED;
- else if (tabular.row_info[r].change == Change::INSERTED) {
+ if (tabular.row_info[r].change.deleted())
+ tabular.row_info[r].change.setUnchanged();
+ else if (tabular.row_info[r].change.inserted()) {
tabular.deleteRow(r, true);
--re;
continue;
if (ct && rs == 0 && re == tabular.nrows() - 1) {
// whole col selected
if (act == LFUN_CHANGE_ACCEPT) {
- if (tabular.column_info[c].change == Change::INSERTED)
- tabular.column_info[c].change = Change::UNCHANGED;
- else if (tabular.column_info[c].change == Change::DELETED) {
+ if (tabular.column_info[c].change.inserted())
+ tabular.column_info[c].change.setUnchanged();
+ else if (tabular.column_info[c].change.deleted()) {
tabular.deleteColumn(c, true);
--ce;
continue;
}
} else {
- if (tabular.column_info[c].change == Change::DELETED)
- tabular.column_info[c].change = Change::UNCHANGED;
- else if (tabular.column_info[c].change == Change::INSERTED) {
+ if (tabular.column_info[c].change.deleted())
+ tabular.column_info[c].change.setUnchanged();
+ else if (tabular.column_info[c].change.inserted()) {
tabular.deleteColumn(c, true);
--ce;
continue;
case LFUN_CHANGE_PREVIOUS: {
// BufferView::dispatch has already moved the cursor, we just
// need to select here if we have a changed row or column
- if (tabular.row_info[tabular.cellRow(cur.idx())].change != Change::UNCHANGED) {
+ if (tabular.row_info[tabular.cellRow(cur.idx())].change.changed()) {
// select row
cur.idx() = tabular.getFirstCellInRow(tabular.cellRow(cur.idx()));
cur.pit() = 0;
bvcur = cur;
rowselect_ = true;
}
- else if (tabular.column_info[tabular.cellColumn(cur.idx())].change != Change::UNCHANGED) {
+ else if (tabular.column_info[tabular.cellColumn(cur.idx())].change.changed()) {
// select column
cur.idx() = tabular.cellIndex(0, tabular.cellColumn(cur.idx()));
cur.pit() = 0;
col_type cs, ce;
getSelection(cur, rs, re, cs, ce);
for (row_type r = rs; r <= re; ++r) {
- if (tabular.row_info[r].change != Change::UNCHANGED) {
+ if (tabular.row_info[r].change.changed()) {
status.setEnabled(true);
return true;
}
for (col_type c = cs; c <= ce; ++c) {
- if (tabular.column_info[c].change != Change::UNCHANGED) {
+ if (tabular.column_info[c].change.changed()) {
status.setEnabled(true);
return true;
}
}
}
} else {
- if (tabular.row_info[tabular.cellRow(cur.idx())].change != Change::UNCHANGED) {
+ if (tabular.row_info[tabular.cellRow(cur.idx())].change.changed()) {
status.setEnabled(true);
return true;
}
- else if (tabular.column_info[tabular.cellColumn(cur.idx())].change != Change::UNCHANGED) {
+ else if (tabular.column_info[tabular.cellColumn(cur.idx())].change.changed()) {
status.setEnabled(true);
return true;
}
for (idx_type idx = 0; idx < nargs(); ++idx)
cell(idx)->acceptChanges();
for (row_type row = 0; row < tabular.nrows(); ++row) {
- if (tabular.row_info[row].change == Change::INSERTED)
- tabular.row_info[row].change = Change::UNCHANGED;
- else if (tabular.row_info[row].change == Change::DELETED)
+ if (tabular.row_info[row].change.inserted())
+ tabular.row_info[row].change.setUnchanged();
+ else if (tabular.row_info[row].change.deleted())
tabular.deleteRow(row, true);
}
for (col_type col = 0; col < tabular.ncols(); ++col) {
- if (tabular.column_info[col].change == Change::INSERTED)
- tabular.column_info[col].change = Change::UNCHANGED;
- else if (tabular.column_info[col].change == Change::DELETED)
+ if (tabular.column_info[col].change.inserted())
+ tabular.column_info[col].change.setUnchanged();
+ else if (tabular.column_info[col].change.deleted())
tabular.deleteColumn(col, true);
}
}
for (idx_type idx = 0; idx < nargs(); ++idx)
cell(idx)->rejectChanges();
for (row_type row = 0; row < tabular.nrows(); ++row) {
- if (tabular.row_info[row].change == Change::DELETED)
- tabular.row_info[row].change = Change::UNCHANGED;
- else if (tabular.row_info[row].change == Change::INSERTED)
+ if (tabular.row_info[row].change.deleted())
+ tabular.row_info[row].change.setUnchanged();
+ else if (tabular.row_info[row].change.inserted())
tabular.deleteRow(row, true);
}
for (col_type col = 0; col < tabular.ncols(); ++col) {
- if (tabular.column_info[col].change == Change::DELETED)
- tabular.column_info[col].change = Change::UNCHANGED;
- else if (tabular.column_info[col].change == Change::INSERTED)
+ if (tabular.column_info[col].change.deleted())
+ tabular.column_info[col].change.setUnchanged();
+ else if (tabular.column_info[col].change.inserted())
tabular.deleteColumn(col, true);
}
}