From 1b5f5e58ed43aeca64ad11af6a493a49699d1b2e Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Wed, 11 Oct 2006 20:01:32 +0000 Subject: [PATCH] Change tracking: * src/paragraph.h: remove enum ChangeTracking; remove default parameters for insertChar and insertInset * src/BufferView.h: constify getCurrentChange() * src/changes.h: make Change constructor explicit * src/insets/*.C: * src/*.C: adjust accordingly; add FIXMEs git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15302 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 2 +- src/BufferView.h | 2 +- src/CutAndPaste.C | 5 +++-- src/buffer.C | 9 ++++++--- src/changes.h | 2 +- src/insets/insettext.C | 3 ++- src/paragraph.C | 3 ++- src/paragraph.h | 18 ++++-------------- src/paragraph_funcs.C | 20 +++++++++++++------- src/rowpainter.C | 3 ++- src/text.C | 36 +++++++++++++++++++++++------------- src/text2.C | 9 ++++++--- 12 files changed, 64 insertions(+), 48 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index af1c147400..fe2d180398 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -501,7 +501,7 @@ void BufferView::setCursorFromScrollbar() } -Change const BufferView::getCurrentChange() +Change const BufferView::getCurrentChange() const { if (!cursor_.selection()) return Change(Change::UNCHANGED); diff --git a/src/BufferView.h b/src/BufferView.h index 9f8ae09cad..2481c286ba 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -128,7 +128,7 @@ public: void saveSavedPositions(); /// return the current change at the cursor - Change const getCurrentChange(); + Change const getCurrentChange() const; /// return the lyxtext we are using LyXText * getLyXText(); diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 2a5b52b9fb..61dbaca38d 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -321,7 +321,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params, // FIXME: Change tracking (MG) bool const merge = !params.trackChanges || pars[pit].lookupChange(pars[pit].size()) == - Change::INSERTED; + Change(Change::INSERTED); pos_type const left = ( pit == startpit ? startpos : 0 ); pos_type const right = ( pit == endpit ? endpos : pars[pit].size() + 1 ); @@ -677,7 +677,8 @@ void replaceSelectionWithString(LCursor & cur, string const & str, bool backward string::const_iterator cit = str.begin(); string::const_iterator end = str.end(); for (; cit != end; ++cit, ++pos) - par.insertChar(pos, (*cit), font); + // FIXME: change tracking (MG) + par.insertChar(pos, (*cit), font, Change(Change::INSERTED)); // Cut the selection cutSelection(cur, true, false); diff --git a/src/buffer.C b/src/buffer.C index 473075ff7f..a783755e67 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -529,13 +529,15 @@ void Buffer::insertStringAsLines(ParagraphList & pars, } else if (*cit == '\t') { if (!par.isFreeSpacing()) { // tabs are like spaces here - par.insertChar(pos, ' ', font); + // FIXME: change tracking (MG) + par.insertChar(pos, ' ', font, Change(Change::INSERTED)); ++pos; space_inserted = true; } else { const pos_type n = 8 - pos % 8; for (pos_type i = 0; i < n; ++i) { - par.insertChar(pos, ' ', font); + // FIXME: change tracking (MG) + par.insertChar(pos, ' ', font, Change(Change::INSERTED)); ++pos; } space_inserted = true; @@ -547,7 +549,8 @@ void Buffer::insertStringAsLines(ParagraphList & pars, */ } else { // just insert the character - par.insertChar(pos, *cit, font); + // FIXME: change tracking (MG) + par.insertChar(pos, *cit, font, Change(Change::INSERTED)); ++pos; space_inserted = (*cit == ' '); } diff --git a/src/changes.h b/src/changes.h index dabfdf80e8..516c9c5269 100644 --- a/src/changes.h +++ b/src/changes.h @@ -30,7 +30,7 @@ public: DELETED // deleted text }; - Change(Type t = UNCHANGED, int a = 0, lyx::time_type ct = 0) + explicit Change(Type t, int a = 0, lyx::time_type ct = 0) : type(t), author(a), changetime(ct) {} Type type; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index f104bd6312..33c041ce42 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -334,7 +334,8 @@ void InsetText::setText(docstring const & data, LyXFont const & font) clear(); Paragraph & first = paragraphs().front(); for (unsigned int i = 0; i < data.length(); ++i) - first.insertChar(i, data[i], font); + // FIXME: change tracking (MG) + first.insertChar(i, data[i], font, Change(Change::INSERTED)); } diff --git a/src/paragraph.C b/src/paragraph.C index 7abffd2ea2..bbb47f5548 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -259,7 +259,8 @@ void Paragraph::insert(pos_type start, string const & str, LyXFont const & font) { for (size_t i = 0, n = str.size(); i != n ; ++i) - insertChar(start + i, str[i], font); + // FIXME: change tracking (MG) + insertChar(start + i, str[i], font, Change(Change::INSERTED)); } diff --git a/src/paragraph.h b/src/paragraph.h index df46cb4b40..b2b0763dda 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -72,15 +72,6 @@ public: //META_INSET = 1 // as in trunk META_INSET = 0x200001 // above 0x10ffff, for ucs-4 }; - enum ChangeTracking - { - /// Change tracking is "on" in this buffer - trackingOn, - /// Change tracking is "off" in this buffer - trackingOff, - /// Change tracking is "unknown" in this buffer - trackingUnknown - }; /// typedef lyx::char_type value_type; /// @@ -307,17 +298,16 @@ public: void insert(lyx::pos_type pos, std::string const & str, LyXFont const & font); /// - void insertChar(lyx::pos_type pos, value_type c, - Change change = Change::INSERTED); + void insertChar(lyx::pos_type pos, value_type c, Change change); /// void insertChar(lyx::pos_type pos, value_type c, - LyXFont const &, Change change = Change::INSERTED); + LyXFont const &, Change change); /// void insertInset(lyx::pos_type pos, InsetBase * inset, - Change change = Change::INSERTED); + Change change); /// void insertInset(lyx::pos_type pos, InsetBase * inset, - LyXFont const &, Change change = Change::INSERTED); + LyXFont const &, Change change); /// bool insetAllowed(InsetBase_code code); /// diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 26abd74759..9b58b9a1be 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -116,7 +116,8 @@ void breakParagraph(BufferParams const & bparams, for (pos_type i = pos, j = pos; i <= pos_end; ++i) { Change::Type change = par.lookupChange(i).type; if (moveItem(par, *tmp, bparams, i, j - pos)) { - tmp->setChange(j - pos, change); + // FIXME: change tracking (MG) + tmp->setChange(j - pos, Change(change)); ++j; } } @@ -180,18 +181,20 @@ void breakParagraphConservative(BufferParams const & bparams, for (pos_type i = pos, j = pos; i <= pos_end; ++i) { Change::Type change = par.lookupChange(i).type; - if (moveItem(par, tmp, bparams, i, j - pos, change)) + // FIXME: change tracking (MG) + if (moveItem(par, tmp, bparams, i, j - pos, Change(change))) ++j; } // Move over end-of-par change attr - tmp.setChange(tmp.size(), par.lookupChange(par.size()).type); + // FIXME: change tracking (MG) + tmp.setChange(tmp.size(), Change(par.lookupChange(par.size()).type)); // If tracking changes, set all the text that is to be // erased to Type::INSERTED. for (pos_type k = pos_end; k >= pos; --k) { if (bparams.trackChanges) // FIXME: Change tracking (MG) - par.setChange(k, Change::INSERTED); + par.setChange(k, Change(Change::INSERTED)); par.erase(k); } } @@ -218,17 +221,20 @@ void mergeParagraph(BufferParams const & bparams, // one. It will (should) remain "orphaned", having no CT info to it, // and check() in changes.C will assert. Setting the para break // forcibly to "black" prevents this scenario. -- MV 13.3.2006 - par.setChange(par.size(), Change::UNCHANGED); + // FIXME: change tracking (MG) + par.setChange(par.size(), Change(Change::UNCHANGED)); Change::Type cr = next.lookupChange(next.size()).type; // ok, now copy the paragraph for (pos_type i = 0, j = 0; i <= pos_end; ++i) { Change::Type change = next.lookupChange(i).type; - if (moveItem(next, par, bparams, i, pos_insert + j, change)) + // FIXME: change tracking (MG) + if (moveItem(next, par, bparams, i, pos_insert + j, Change(change))) ++j; } // Move the change status of "carriage return" over - par.setChange(par.size(), cr); + // FIXME: change tracking (MG) + par.setChange(par.size(), Change(cr)); pars.erase(boost::next(pars.begin(), par_offset + 1)); } diff --git a/src/rowpainter.C b/src/rowpainter.C index bb35ab8ad0..d5c1d5438b 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -282,7 +282,8 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font, if (pos < font_span.first || pos > font_span.last) break; - if (prev_change != par_.lookupChange(pos)) + // FIXME: change tracking (MG) + if (Change(prev_change) != par_.lookupChange(pos)) break; char_type c = par_.getChar(pos); diff --git a/src/text.C b/src/text.C index 975c658a48..f2354a98f4 100644 --- a/src/text.C +++ b/src/text.C @@ -180,7 +180,7 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, string layoutname = lex.getString(); font = LyXFont(LyXFont::ALL_INHERIT, bp.language); - change = Change(); + change = Change(Change::UNCHANGED); LyXTextClass const & tclass = bp.getLyXTextClass(); @@ -373,7 +373,7 @@ void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex, ErrorList lex.nextToken(); string token = lex.getString(); LyXFont font; - Change change; + Change change(Change::UNCHANGED); while (lex.isOK()) { @@ -1173,7 +1173,7 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout) if (cur.buffer().params().trackChanges) { // FIXME: Change tracking (MG) cur.paragraph().setChange(cur.paragraph().size(), - Change::INSERTED); + Change(Change::INSERTED)); } // This check is necessary. Otherwise the new empty paragraph will @@ -1257,7 +1257,8 @@ void LyXText::insertChar(LCursor & cur, char_type c) BOOST_ASSERT(cur.pos() > 0); if ((par.isLineSeparator(cur.pos() - 1) || par.isNewline(cur.pos() - 1)) - && par.lookupChange(cur.pos() - 1) != Change::DELETED) { + // FIXME: change tracking (MG) + && par.lookupChange(cur.pos() - 1) != Change(Change::DELETED)) { static bool sent_space_message = false; if (!sent_space_message) { cur.message(_("You cannot type two spaces this way. " @@ -1268,7 +1269,8 @@ void LyXText::insertChar(LCursor & cur, char_type c) } } - par.insertChar(cur.pos(), c, current_font); + // FIXME: change tracking (MG) + par.insertChar(cur.pos(), c, current_font, Change(Change::INSERTED)); setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary()); charInserted(); } @@ -1501,8 +1503,9 @@ void LyXText::acceptChange(LCursor & cur) boost::next(plist.begin(), et.pit())); // Paragraph merge if appropriate: + // FIXME: change tracking (MG) if (pars_[it.pit()].lookupChange(pars_[it.pit()].size()) - == Change::DELETED) { + == Change(Change::DELETED)) { setCursorIntern(cur, it.pit() + 1, 0); backspacePos0(cur); } @@ -1537,8 +1540,9 @@ void LyXText::rejectChange(LCursor & cur) pars_.erase(boost::next(plist.begin(), it.pit() + 1), boost::next(plist.begin(), et.pit())); // Paragraph merge if appropriate: + // FIXME: change tracking (MG) if (pars_[it.pit()].lookupChange(pars_[it.pit()].size()) - == Change::INSERTED) { + == Change(Change::INSERTED)) { setCursorIntern(cur, it.pit() + 1, 0); backspacePos0(cur); } @@ -1662,7 +1666,8 @@ bool LyXText::erase(LCursor & cur) recordUndo(cur, Undo::DELETE, cur.pit()); setCursorIntern(cur, cur.pit(), cur.pos() + 1, false, cur.boundary()); needsUpdate = backspace(cur); - if (cur.paragraph().lookupChange(cur.pos()) == Change::DELETED) + // FIXME: change tracking (MG) + if (cur.paragraph().lookupChange(cur.pos()) == Change(Change::DELETED)) cur.posRight(); } else if (cur.pit() != cur.lastpit()) { LCursor scur = cur; @@ -1675,7 +1680,8 @@ bool LyXText::erase(LCursor & cur) // FIXME: Change tracking (MG) // move forward after the paragraph break is DELETED Paragraph & par = cur.paragraph(); - if (par.lookupChange(par.size()) == Change::DELETED) + // FIXME: change tracking (MG) + if (par.lookupChange(par.size()) == Change(Change::DELETED)) setCursorIntern(cur, cur.pit() + 1, 0); } } else { @@ -1782,8 +1788,10 @@ bool LyXText::backspace(LCursor & cur) // deleted: Paragraph & par = pars_[cur.pit() - 1]; // Take care of a just inserted para break: - if (par.lookupChange(par.size()) != Change::INSERTED) { - par.setChange(par.size(), Change::DELETED); + // FIXME: change tracking (MG) + if (par.lookupChange(par.size()) != Change(Change::INSERTED)) { + // FIXME: change tracking (MG) + par.setChange(par.size(), Change(Change::DELETED)); setCursorIntern(cur, cur.pit() - 1, par.size()); return true; } @@ -1871,7 +1879,8 @@ bool LyXText::redoParagraph(pit_type const pit) if (!hasbibitem) { InsetBibitem * inset(new InsetBibitem(InsetCommandParams("bibitem"))); - par.insertInset(0, static_cast(inset)); + // FIXME: change tracking (MG) + par.insertInset(0, static_cast(inset), Change(Change::INSERTED)); bv()->cursor().posRight(); } } @@ -2372,7 +2381,8 @@ string LyXText::currentState(LCursor & cur) Paragraph const & par = cur.paragraph(); std::ostringstream os; - bool const show_change = par.lookupChange(cur.pos()) != Change::UNCHANGED; + // FIXME: change tracking (MG) + bool const show_change = par.lookupChange(cur.pos()) != Change(Change::UNCHANGED); if (buf.params().trackChanges) os << "[C] "; diff --git a/src/text2.C b/src/text2.C index f9f4134399..1deec53ee6 100644 --- a/src/text2.C +++ b/src/text2.C @@ -647,7 +647,8 @@ void LyXText::insertInset(LCursor & cur, InsetBase * inset) { BOOST_ASSERT(this == cur.text()); BOOST_ASSERT(inset); - cur.paragraph().insertInset(cur.pos(), inset); + // FIXME: change tracking (MG) + cur.paragraph().insertInset(cur.pos(), inset, Change(Change::INSERTED)); } @@ -1260,10 +1261,12 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old) && old.pos() < oldpar.size() && oldpar.isLineSeparator(old.pos()) && oldpar.isLineSeparator(old.pos() - 1) - && oldpar.lookupChange(old.pos() - 1) != Change::DELETED) { + // FIXME: change tracking (MG) + && oldpar.lookupChange(old.pos() - 1) != Change(Change::DELETED)) { // We need to set the text to Change::INSERTED to // get it erased properly - oldpar.setChange(old.pos() -1, Change::INSERTED); + // FIXME: change tracking (MG) + oldpar.setChange(old.pos() -1, Change(Change::INSERTED)); oldpar.erase(old.pos() - 1); #ifdef WITH_WARNINGS #warning This will not work anymore when we have multiple views of the same buffer -- 2.39.2