From 9acb432b0c9afbfb421ea85ce4038e200446e02a Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Thu, 19 Oct 2006 17:46:50 +0000 Subject: [PATCH] change tracking: * src/paragraph.h: remove eraseIntern(); pass trackChanges to erase(...) (2 methods) * src/paragraph_pimpl.h: rename eraseIntern() to erase(); pass trackChanges to other erase(...) (2 methods) * src/insets/insettext.C: * src/*.C: adjust properly git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15380 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.C | 6 ++++-- src/insets/insettext.C | 4 +++- src/paragraph.C | 16 +++++----------- src/paragraph.h | 6 ++---- src/paragraph_funcs.C | 5 +++-- src/paragraph_pimpl.C | 26 +++++++++++++++----------- src/paragraph_pimpl.h | 6 +++--- src/text.C | 14 +++++++++----- src/text2.C | 6 +----- 9 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 61dbaca38d..827f441fbb 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -149,7 +149,8 @@ pasteSelectionHelper(LCursor & cur, ParagraphList const & parlist, for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) { for (pos_type j = 0; j < insertion[i].size(); ++j) { if (insertion[i].isNewline(j)) { - insertion[i].erase(j); + // do not track deletion of newline + insertion[i].erase(j, false); breakParagraphConservative( buffer.params(), insertion, i, j); @@ -208,7 +209,8 @@ pasteSelectionHelper(LCursor & cur, ParagraphList const & parlist, for (pos_type i = 0; i < tmpbuf->size(); ++i) { if (tmpbuf->getChar(i) == Paragraph::META_INSET && !pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode())) - tmpbuf->erase(i--); + // do not track deletion of invalid insets + tmpbuf->erase(i--, false); } // FIXME: Change tracking (MG) diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 5079038526..7ade80ae4c 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -356,7 +356,9 @@ void InsetText::setAutoBreakRows(bool flag) for (; it != end; ++it) for (int i = 0; i < it->size(); ++i) if (it->isNewline(i)) - it->erase(i); + // do not track the change, because the user + // is not allowed to revert/reject it + it->erase(i, false); } diff --git a/src/paragraph.C b/src/paragraph.C index 038ea5d539..6adfb9cecd 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -238,21 +238,15 @@ void Paragraph::validate(LaTeXFeatures & features) const } -void Paragraph::eraseIntern(lyx::pos_type pos) +bool Paragraph::erase(pos_type pos, bool trackChanges) { - pimpl_->eraseIntern(pos); + return pimpl_->erase(pos, trackChanges); } -bool Paragraph::erase(pos_type pos) +int Paragraph::erase(pos_type start, pos_type end, bool trackChanges) { - return pimpl_->erase(pos); -} - - -int Paragraph::erase(pos_type start, pos_type end) -{ - return pimpl_->erase(start, end); + return pimpl_->erase(start, end, trackChanges); } @@ -568,7 +562,7 @@ int Paragraph::stripLeadingSpaces() int i = 0; while (!empty() && (isNewline(0) || isLineSeparator(0)) && (lookupChange(0).type != Change::DELETED)) { - erase(0); + erase(0, false); // no change tracking here ++i; } diff --git a/src/paragraph.h b/src/paragraph.h index 92aa012dd7..a661950e4e 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -239,12 +239,10 @@ public: /// void applyLayout(LyXLayout_ptr const & new_layout); - /// definite erase - void eraseIntern(lyx::pos_type pos); /// erase the char at the given position - bool erase(lyx::pos_type pos); + bool erase(lyx::pos_type pos, bool trackChanges); /// erase the given range. Returns the number of chars actually erased - int erase(lyx::pos_type start, lyx::pos_type end); + int erase(lyx::pos_type start, lyx::pos_type end, bool trackChanges); /** Get uninstantiated font setting. Returns the difference between the characters font and the layoutfont. diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 9b58b9a1be..99e75e360e 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -123,7 +123,7 @@ void breakParagraph(BufferParams const & bparams, } for (pos_type i = pos_end; i >= pos; --i) - par.eraseIntern(i); + par.erase(i, false); // erase without change tracking } if (pos) { @@ -195,7 +195,8 @@ void breakParagraphConservative(BufferParams const & bparams, if (bparams.trackChanges) // FIXME: Change tracking (MG) par.setChange(k, Change(Change::INSERTED)); - par.erase(k); + // FIXME: change tracking (MG) + par.erase(k, false); } } } diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 51bbd4ffa4..4291cd8850 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -161,8 +161,7 @@ void Paragraph::Pimpl::acceptChange(pos_type start, pos_type end) // Suppress access to nonexistent // "end-of-paragraph char": if (i < size()) { - eraseIntern(i); - changes_->erase(i); + erase(i); --end; --i; } @@ -194,8 +193,7 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end) case Change::INSERTED: if (i < size()) { - eraseIntern(i); - changes_->erase(i); + erase(i); --end; --i; } @@ -266,8 +264,13 @@ void Paragraph::Pimpl::insertInset(pos_type pos, } -void Paragraph::Pimpl::eraseIntern(pos_type pos) +void Paragraph::Pimpl::erase(pos_type pos) { + // FIXME: change tracking (MG) + // do something like changes_->erase(i); + // in one of the next patches, the two erase functions + // will be merged but I don't want to break too many things at the same time :-) + // if it is an inset, delete the inset entry if (owner_->text_[pos] == Paragraph::META_INSET) { owner_->insetlist.erase(pos); @@ -300,18 +303,19 @@ void Paragraph::Pimpl::eraseIntern(pos_type pos) } } - // Update all other entries. + // Update all other entries FontList::iterator fend = fontlist.end(); for (; it != fend; ++it) it->pos(it->pos() - 1); - // Update the insetlist. + // Update the insetlist owner_->insetlist.decreasePosAfterPos(pos); } -bool Paragraph::Pimpl::erase(pos_type pos) +bool Paragraph::Pimpl::erase(pos_type pos, bool trackChanges) { + // FIXME: change tracking (MG) BOOST_ASSERT(pos <= size()); if (tracking()) { @@ -328,7 +332,7 @@ bool Paragraph::Pimpl::erase(pos_type pos) // Don't physically access nonexistent end-of-paragraph char if (pos < size()) { - eraseIntern(pos); + erase(pos); return true; } @@ -336,11 +340,11 @@ bool Paragraph::Pimpl::erase(pos_type pos) } -int Paragraph::Pimpl::erase(pos_type start, pos_type end) +int Paragraph::Pimpl::erase(pos_type start, pos_type end, bool trackChanges) { pos_type i = start; for (pos_type count = end - start; count; --count) { - if (!erase(i)) + if (!erase(i, trackChanges)) ++i; } return end - i; diff --git a/src/paragraph_pimpl.h b/src/paragraph_pimpl.h index a1d223e5d8..b86160a8be 100644 --- a/src/paragraph_pimpl.h +++ b/src/paragraph_pimpl.h @@ -62,11 +62,11 @@ public: /// void insertInset(lyx::pos_type pos, InsetBase * inset, Change const & change); /// definite erase - void eraseIntern(lyx::pos_type pos); + void erase(lyx::pos_type pos); /// erase the given position. Returns true if it was actually erased - bool erase(lyx::pos_type pos); + bool erase(lyx::pos_type pos, bool trackChanges); /// erase the given range - int erase(lyx::pos_type start, lyx::pos_type end); + int erase(lyx::pos_type start, lyx::pos_type end, bool trackChanges); /// InsetBase * inset_owner; diff --git a/src/text.C b/src/text.C index fd3b8a04c5..241b5a44eb 100644 --- a/src/text.C +++ b/src/text.C @@ -1104,7 +1104,8 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout) // Always break behind a space // It is better to erase the space (Dekel) if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos())) - cpar.erase(cur.pos()); + // FIXME: change tracking (MG) + cpar.erase(cur.pos(), cur.buffer().params().trackChanges); // How should the layout for the new paragraph be? int preserve_layout = 0; @@ -1139,7 +1140,8 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout) } while (!pars_[next_par].empty() && pars_[next_par].isNewline(0)) - pars_[next_par].erase(0); + // FIXME: change tracking (MG) + pars_[next_par].erase(0, cur.buffer().params().trackChanges); ParIterator current_it(cur); ParIterator last_it(cur); @@ -1787,7 +1789,8 @@ bool LyXText::backspace(LCursor & cur) // without the dreaded mechanism. (JMarc) setCursorIntern(cur, cur.pit(), cur.pos() - 1, false, cur.boundary()); - cur.paragraph().erase(cur.pos()); + // FIXME: change tracking (MG) + cur.paragraph().erase(cur.pos(), cur.buffer().params().trackChanges); } if (cur.pos() == cur.lastpos()) @@ -1818,9 +1821,10 @@ bool LyXText::dissolveInset(LCursor & cur) { if (spit == 0) spos += cur.pos(); spit += cur.pit(); - cur.paragraph().erase(cur.pos()); + Buffer & b = cur.buffer(); + // FIXME: change tracking (MG) + cur.paragraph().erase(cur.pos(), b.params().trackChanges); if (!plist.empty()) { - Buffer & b = cur.buffer(); pasteParagraphList(cur, plist, b.params().textclass, b.errorList("Paste")); // restore position diff --git a/src/text2.C b/src/text2.C index e50753430b..9076e6ec38 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1264,11 +1264,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old) && oldpar.isLineSeparator(old.pos() - 1) // 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 - // FIXME: change tracking (MG) - oldpar.setChange(old.pos() -1, Change(Change::INSERTED)); - oldpar.erase(old.pos() - 1); + oldpar.erase(old.pos() - 1, false); // do not track changes in DEPM #ifdef WITH_WARNINGS #warning This will not work anymore when we have multiple views of the same buffer // In this case, we will have to correct also the cursors held by -- 2.39.2