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
This commit is contained in:
Michael Schmitt 2006-10-19 17:46:50 +00:00
parent 850962d0ba
commit 9acb432b0c
9 changed files with 45 additions and 44 deletions

View File

@ -149,7 +149,8 @@ pasteSelectionHelper(LCursor & cur, ParagraphList const & parlist,
for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) { for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) {
for (pos_type j = 0; j < insertion[i].size(); ++j) { for (pos_type j = 0; j < insertion[i].size(); ++j) {
if (insertion[i].isNewline(j)) { if (insertion[i].isNewline(j)) {
insertion[i].erase(j); // do not track deletion of newline
insertion[i].erase(j, false);
breakParagraphConservative( breakParagraphConservative(
buffer.params(), buffer.params(),
insertion, i, j); insertion, i, j);
@ -208,7 +209,8 @@ pasteSelectionHelper(LCursor & cur, ParagraphList const & parlist,
for (pos_type i = 0; i < tmpbuf->size(); ++i) { for (pos_type i = 0; i < tmpbuf->size(); ++i) {
if (tmpbuf->getChar(i) == Paragraph::META_INSET && if (tmpbuf->getChar(i) == Paragraph::META_INSET &&
!pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode())) !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) // FIXME: Change tracking (MG)

View File

@ -356,7 +356,9 @@ void InsetText::setAutoBreakRows(bool flag)
for (; it != end; ++it) for (; it != end; ++it)
for (int i = 0; i < it->size(); ++i) for (int i = 0; i < it->size(); ++i)
if (it->isNewline(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);
} }

View File

@ -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); return pimpl_->erase(start, end, trackChanges);
}
int Paragraph::erase(pos_type start, pos_type end)
{
return pimpl_->erase(start, end);
} }
@ -568,7 +562,7 @@ int Paragraph::stripLeadingSpaces()
int i = 0; int i = 0;
while (!empty() && (isNewline(0) || isLineSeparator(0)) while (!empty() && (isNewline(0) || isLineSeparator(0))
&& (lookupChange(0).type != Change::DELETED)) { && (lookupChange(0).type != Change::DELETED)) {
erase(0); erase(0, false); // no change tracking here
++i; ++i;
} }

View File

@ -239,12 +239,10 @@ public:
/// ///
void applyLayout(LyXLayout_ptr const & new_layout); void applyLayout(LyXLayout_ptr const & new_layout);
/// definite erase
void eraseIntern(lyx::pos_type pos);
/// erase the char at the given position /// 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 /// 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 /** Get uninstantiated font setting. Returns the difference
between the characters font and the layoutfont. between the characters font and the layoutfont.

View File

@ -123,7 +123,7 @@ void breakParagraph(BufferParams const & bparams,
} }
for (pos_type i = pos_end; i >= pos; --i) for (pos_type i = pos_end; i >= pos; --i)
par.eraseIntern(i); par.erase(i, false); // erase without change tracking
} }
if (pos) { if (pos) {
@ -195,7 +195,8 @@ void breakParagraphConservative(BufferParams const & bparams,
if (bparams.trackChanges) if (bparams.trackChanges)
// FIXME: Change tracking (MG) // FIXME: Change tracking (MG)
par.setChange(k, Change(Change::INSERTED)); par.setChange(k, Change(Change::INSERTED));
par.erase(k); // FIXME: change tracking (MG)
par.erase(k, false);
} }
} }
} }

View File

@ -161,8 +161,7 @@ void Paragraph::Pimpl::acceptChange(pos_type start, pos_type end)
// Suppress access to nonexistent // Suppress access to nonexistent
// "end-of-paragraph char": // "end-of-paragraph char":
if (i < size()) { if (i < size()) {
eraseIntern(i); erase(i);
changes_->erase(i);
--end; --end;
--i; --i;
} }
@ -194,8 +193,7 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
case Change::INSERTED: case Change::INSERTED:
if (i < size()) { if (i < size()) {
eraseIntern(i); erase(i);
changes_->erase(i);
--end; --end;
--i; --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 it is an inset, delete the inset entry
if (owner_->text_[pos] == Paragraph::META_INSET) { if (owner_->text_[pos] == Paragraph::META_INSET) {
owner_->insetlist.erase(pos); 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(); FontList::iterator fend = fontlist.end();
for (; it != fend; ++it) for (; it != fend; ++it)
it->pos(it->pos() - 1); it->pos(it->pos() - 1);
// Update the insetlist. // Update the insetlist
owner_->insetlist.decreasePosAfterPos(pos); 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()); BOOST_ASSERT(pos <= size());
if (tracking()) { if (tracking()) {
@ -328,7 +332,7 @@ bool Paragraph::Pimpl::erase(pos_type pos)
// Don't physically access nonexistent end-of-paragraph char // Don't physically access nonexistent end-of-paragraph char
if (pos < size()) { if (pos < size()) {
eraseIntern(pos); erase(pos);
return true; 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; pos_type i = start;
for (pos_type count = end - start; count; --count) { for (pos_type count = end - start; count; --count) {
if (!erase(i)) if (!erase(i, trackChanges))
++i; ++i;
} }
return end - i; return end - i;

View File

@ -62,11 +62,11 @@ public:
/// ///
void insertInset(lyx::pos_type pos, InsetBase * inset, Change const & change); void insertInset(lyx::pos_type pos, InsetBase * inset, Change const & change);
/// definite erase /// 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 /// 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 /// 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; InsetBase * inset_owner;

View File

@ -1104,7 +1104,8 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
// Always break behind a space // Always break behind a space
// It is better to erase the space (Dekel) // It is better to erase the space (Dekel)
if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos())) 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? // How should the layout for the new paragraph be?
int preserve_layout = 0; 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)) 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 current_it(cur);
ParIterator last_it(cur); ParIterator last_it(cur);
@ -1787,7 +1789,8 @@ bool LyXText::backspace(LCursor & cur)
// without the dreaded mechanism. (JMarc) // without the dreaded mechanism. (JMarc)
setCursorIntern(cur, cur.pit(), cur.pos() - 1, setCursorIntern(cur, cur.pit(), cur.pos() - 1,
false, cur.boundary()); 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()) if (cur.pos() == cur.lastpos())
@ -1818,9 +1821,10 @@ bool LyXText::dissolveInset(LCursor & cur) {
if (spit == 0) if (spit == 0)
spos += cur.pos(); spos += cur.pos();
spit += cur.pit(); spit += cur.pit();
cur.paragraph().erase(cur.pos());
if (!plist.empty()) {
Buffer & b = cur.buffer(); Buffer & b = cur.buffer();
// FIXME: change tracking (MG)
cur.paragraph().erase(cur.pos(), b.params().trackChanges);
if (!plist.empty()) {
pasteParagraphList(cur, plist, b.params().textclass, pasteParagraphList(cur, plist, b.params().textclass,
b.errorList("Paste")); b.errorList("Paste"));
// restore position // restore position

View File

@ -1264,11 +1264,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
&& oldpar.isLineSeparator(old.pos() - 1) && oldpar.isLineSeparator(old.pos() - 1)
// FIXME: change tracking (MG) // FIXME: change tracking (MG)
&& oldpar.lookupChange(old.pos() - 1) != Change(Change::DELETED)) { && oldpar.lookupChange(old.pos() - 1) != Change(Change::DELETED)) {
// We need to set the text to Change::INSERTED to oldpar.erase(old.pos() - 1, false); // do not track changes in DEPM
// get it erased properly
// FIXME: change tracking (MG)
oldpar.setChange(old.pos() -1, Change(Change::INSERTED));
oldpar.erase(old.pos() - 1);
#ifdef WITH_WARNINGS #ifdef WITH_WARNINGS
#warning This will not work anymore when we have multiple views of the same buffer #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 // In this case, we will have to correct also the cursors held by