Author: schmitt
Date: Tue Jan 23 22:53:16 2007
New Revision: 16830
URL: http://www.lyx.org/trac/changeset/16830
Log:
* src/lyxtext.h:
* src/BufferView.C:
* src/text3.C:
* src/text.C: merge methods acceptChange() and rejectChange() to
acceptOrRejectChange() because they share a lot of tricky code
* src/text.C: yet another revision of acceptOrRejectChange()
* src/paragraph.C:
* src/paragraph.h:
* src/paragraph_pimpl.C:
* src/paragraph_pimpl.h:
* src/insets/insettabular.C:
* src/insets/insettabular.h:
* src/insets/insettext.C:
* src/insets/insettext.h:
* src/insets/insetbase.h: pass BufferParams to acceptChanges() and
rejectChanges() (needed for paragraph merging)
* src/insets/insettext.C: handle end-of-par in acceptChanges() and
rejectChanges()
Modified:
lyx-devel/trunk/src/BufferView.C
lyx-devel/trunk/src/insets/insetbase.h
lyx-devel/trunk/src/insets/insettabular.C
lyx-devel/trunk/src/insets/insettabular.h
lyx-devel/trunk/src/insets/insettext.C
lyx-devel/trunk/src/insets/insettext.h
lyx-devel/trunk/src/lyxtext.h
lyx-devel/trunk/src/paragraph.C
lyx-devel/trunk/src/paragraph.h
lyx-devel/trunk/src/paragraph_pimpl.C
lyx-devel/trunk/src/paragraph_pimpl.h
lyx-devel/trunk/src/text.C
lyx-devel/trunk/src/text3.C
Modified: lyx-devel/trunk/src/BufferView.C
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/BufferView.C?rev=16830
==============================================================================
--- lyx-devel/trunk/src/BufferView.C (original)
+++ lyx-devel/trunk/src/BufferView.C Tue Jan 23 22:53:16 2007
@@ -859,7 +859,7 @@
#warning FIXME changes
#endif
while (findNextChange(this))
- getLyXText()->acceptChange(cursor_);
+ getLyXText()->acceptOrRejectChange(cursor_, true);
update();
break;
}
@@ -870,7 +870,7 @@
#warning FIXME changes
#endif
while (findNextChange(this))
- getLyXText()->rejectChange(cursor_);
+ getLyXText()->acceptOrRejectChange(cursor_, false);
break;
}
Modified: lyx-devel/trunk/src/insets/insetbase.h
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/insetbase.h?rev=16830
==============================================================================
--- lyx-devel/trunk/src/insets/insetbase.h (original)
+++ lyx-devel/trunk/src/insets/insetbase.h Tue Jan 23 22:53:16 2007
@@ -23,6 +23,7 @@
namespace lyx {
class Buffer;
+class BufferParams;
class BufferView;
class CursorSlice;
class FuncRequest;
@@ -421,9 +422,9 @@
/// set the change for the entire inset
virtual void setChange(Change const &) {}
/// accept the changes within the inset
- virtual void acceptChanges() {};
+ virtual void acceptChanges(BufferParams const & bparams) {};
/// reject the changes within the inset
- virtual void rejectChanges() {};
+ virtual void rejectChanges(BufferParams const & bparams) {};
/// pretty arbitrary
virtual int width() const { return 10; }
Modified: lyx-devel/trunk/src/insets/insettabular.C
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/insettabular.C?rev=16830
==============================================================================
--- lyx-devel/trunk/src/insets/insettabular.C (original)
+++ lyx-devel/trunk/src/insets/insettabular.C Tue Jan 23 22:53:16 2007
@@ -1933,17 +1933,17 @@
}
-void InsetTabular::acceptChanges()
+void InsetTabular::acceptChanges(BufferParams const & bparams)
{
for (idx_type idx = 0; idx < nargs(); ++idx)
- cell(idx)->acceptChanges();
-}
-
-
-void InsetTabular::rejectChanges()
+ cell(idx)->acceptChanges(bparams);
+}
+
+
+void InsetTabular::rejectChanges(BufferParams const & bparams)
{
for (idx_type idx = 0; idx < nargs(); ++idx)
- cell(idx)->rejectChanges();
+ cell(idx)->rejectChanges(bparams);
}
Modified: lyx-devel/trunk/src/insets/insettabular.h
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/insettabular.h?rev=16830
==============================================================================
--- lyx-devel/trunk/src/insets/insettabular.h (original)
+++ lyx-devel/trunk/src/insets/insettabular.h Tue Jan 23 22:53:16 2007
@@ -118,9 +118,9 @@
/// set the change for the entire inset
void setChange(Change const & change);
/// accept the changes within the inset
- void acceptChanges();
+ void acceptChanges(BufferParams const & bparams);
/// reject the changes within the inset
- void rejectChanges();
+ void rejectChanges(BufferParams const & bparams);
// this should return true if we have a "normal" cell, otherwise false.
// "normal" means without width set!
Modified: lyx-devel/trunk/src/insets/insettext.C
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/insettext.C?rev=16830
==============================================================================
--- lyx-devel/trunk/src/insets/insettext.C (original)
+++ lyx-devel/trunk/src/insets/insettext.C Tue Jan 23 22:53:16 2007
@@ -277,27 +277,70 @@
}
-void InsetText::acceptChanges()
-{
- ParagraphList::iterator pit = paragraphs().begin();
- ParagraphList::iterator end = paragraphs().end();
- for (; pit != end; ++pit) {
- // FIXME: change tracking (MG)
- // we must handle end-of-par chars!
- pit->acceptChanges(0, pit->size() + 1);
- }
-}
-
-
-void InsetText::rejectChanges()
-{
- ParagraphList::iterator pit = paragraphs().begin();
- ParagraphList::iterator end = paragraphs().end();
- for (; pit != end; ++pit) {
- // FIXME: change tracking (MG)
- // we must handle end-of-par chars!
- pit->rejectChanges(0, pit->size() + 1);
- }
+void InsetText::acceptChanges(BufferParams const & bparams)
+{
+ ParagraphList & pars = paragraphs();
+
+ // first, accept changes within each individual paragraph (do not
consider end-of-par)
+
+ for (pit_type pit = 0; pit < pars.size(); ++pit) {
+ if (pars[pit].size() != 0) // prevent assertion failure
+ pars[pit].acceptChanges(bparams, 0, pars[pit].size());
+ }
+
+ // next, accept imaginary end-of-par characters
+
+ for (pit_type pit = 0; pit < pars.size(); ++pit) {
+ pos_type pos = pars[pit].size();
+
+ if (pars[pit].isInserted(pos)) {
+ pars[pit].setChange(pos, Change(Change::UNCHANGED));
+ } else if (pars[pit].isDeleted(pos)) {
+ if (pit == pars.size() - 1) {
+ // we cannot remove a par break at the end of
the last paragraph;
+ // instead, we mark it unchanged
+ pars[pit].setChange(pos,
Change(Change::UNCHANGED));
+ } else {
+ mergeParagraph(bparams, pars, pit);
+ --pit;
+ }
+ }
+ }
+
+ // FIXME: finally, invoke the DEPM
+}
+
+
+void InsetText::rejectChanges(BufferParams const & bparams)
+{
+ ParagraphList & pars = paragraphs();
+
+ // first, reject changes within each individual paragraph (do not
consider end-of-par)
+
+ for (pit_type pit = 0; pit < pars.size(); ++pit) {
+ if (pars[pit].size() != 0) // prevent assertion failure
+ pars[pit].rejectChanges(bparams, 0, pars[pit].size());
+ }
+
+ // next, reject imaginary end-of-par characters
+
+ for (pit_type pit = 0; pit < pars.size(); ++pit) {
+ pos_type pos = pars[pit].size();
+
+ if (pars[pit].isDeleted(pos)) {
+ pars[pit].setChange(pos, Change(Change::UNCHANGED));
+ } else if (pars[pit].isInserted(pos)) {
+ if (pit == pars.size() - 1) {
+ // we mark the par break at the end of the last
paragraph unchanged
+ pars[pit].setChange(pos,
Change(Change::UNCHANGED));
+ } else {
+ mergeParagraph(bparams, pars, pit);
+ --pit;
+ }
+ }
+ }
+
+ // FIXME: finally, invoke the DEPM
}
Modified: lyx-devel/trunk/src/insets/insettext.h
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/insets/insettext.h?rev=16830
==============================================================================
--- lyx-devel/trunk/src/insets/insettext.h (original)
+++ lyx-devel/trunk/src/insets/insettext.h Tue Jan 23 22:53:16 2007
@@ -103,9 +103,9 @@
/// set the change for the entire inset
void setChange(Change const & change);
/// accept the changes within the inset
- void acceptChanges();
+ void acceptChanges(BufferParams const & bparams);
/// reject the changes within the inset
- void rejectChanges();
+ void rejectChanges(BufferParams const & bparams);
/// append text onto the existing text
void appendParagraphs(Buffer * bp, ParagraphList &);
Modified: lyx-devel/trunk/src/lyxtext.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/lyxtext.h?rev=16830
==============================================================================
--- lyx-devel/trunk/src/lyxtext.h (original)
+++ lyx-devel/trunk/src/lyxtext.h Tue Jan 23 22:53:16 2007
@@ -153,10 +153,8 @@
/// just selects the word the cursor is in
void selectWord(LCursor & cur, word_location loc);
- /// accept selected change
- void acceptChange(LCursor & cur);
- /// reject selected change
- void rejectChange(LCursor & cur);
+ /// accept or reject the selected change
+ void acceptOrRejectChange(LCursor & cur, bool accept);
/// returns true if par was empty and was removed
bool setCursor(LCursor & cur, pit_type par, pos_type pos,
Modified: lyx-devel/trunk/src/paragraph.C
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/paragraph.C?rev=16830
==============================================================================
--- lyx-devel/trunk/src/paragraph.C (original)
+++ lyx-devel/trunk/src/paragraph.C Tue Jan 23 22:53:16 2007
@@ -1462,15 +1462,15 @@
}
-void Paragraph::acceptChanges(pos_type start, pos_type end)
-{
- return pimpl_->acceptChanges(start, end);
-}
-
-
-void Paragraph::rejectChanges(pos_type start, pos_type end)
-{
- return pimpl_->rejectChanges(start, end);
+void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start,
pos_type end)
+{
+ return pimpl_->acceptChanges(bparams, start, end);
+}
+
+
+void Paragraph::rejectChanges(BufferParams const & bparams, pos_type start,
pos_type end)
+{
+ return pimpl_->rejectChanges(bparams, start, end);
}
Modified: lyx-devel/trunk/src/paragraph.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/paragraph.h?rev=16830
==============================================================================
--- lyx-devel/trunk/src/paragraph.h (original)
+++ lyx-devel/trunk/src/paragraph.h Tue Jan 23 22:53:16 2007
@@ -211,10 +211,10 @@
void setChange(pos_type pos, Change const & change);
/// accept changes within the given range
- void acceptChanges(pos_type start, pos_type end);
+ void acceptChanges(BufferParams const & bparams, pos_type start,
pos_type end);
/// reject changes within the given range
- void rejectChanges(pos_type start, pos_type end);
+ void rejectChanges(BufferParams const & bparams, pos_type start,
pos_type end);
/// Paragraphs can contain "manual labels", for example, Description
/// environment. The text for this user-editable label is stored in
Modified: lyx-devel/trunk/src/paragraph_pimpl.C
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/paragraph_pimpl.C?rev=16830
==============================================================================
--- lyx-devel/trunk/src/paragraph_pimpl.C (original)
+++ lyx-devel/trunk/src/paragraph_pimpl.C Tue Jan 23 22:53:16 2007
@@ -163,7 +163,7 @@
}
-void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end)
+void Paragraph::Pimpl::acceptChanges(BufferParams const & bparams, pos_type
start, pos_type end)
{
BOOST_ASSERT(start >= 0 && start <= size());
BOOST_ASSERT(end > start && end <= size() + 1);
@@ -173,7 +173,7 @@
case Change::UNCHANGED:
// accept changes in nested inset
if (pos < size() && owner_->isInset(pos)) {
- owner_->getInset(pos)->acceptChanges();
+
owner_->getInset(pos)->acceptChanges(bparams);
}
break;
@@ -182,7 +182,7 @@
changes_.set(Change(Change::UNCHANGED), pos);
// also accept changes in nested inset
if (pos < size() && owner_->isInset(pos)) {
- owner_->getInset(pos)->acceptChanges();
+
owner_->getInset(pos)->acceptChanges(bparams);
}
break;
@@ -201,7 +201,7 @@
}
-void Paragraph::Pimpl::rejectChanges(pos_type start, pos_type end)
+void Paragraph::Pimpl::rejectChanges(BufferParams const & bparams, pos_type
start, pos_type end)
{
BOOST_ASSERT(start >= 0 && start <= size());
BOOST_ASSERT(end > start && end <= size() + 1);
@@ -211,7 +211,7 @@
case Change::UNCHANGED:
// reject changes in nested inset
if (pos < size() && owner_->isInset(pos)) {
- owner_->getInset(pos)->rejectChanges();
+
owner_->getInset(pos)->rejectChanges(bparams);
}
break;
Modified: lyx-devel/trunk/src/paragraph_pimpl.h
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/paragraph_pimpl.h?rev=16830
==============================================================================
--- lyx-devel/trunk/src/paragraph_pimpl.h (original)
+++ lyx-devel/trunk/src/paragraph_pimpl.h Tue Jan 23 22:53:16 2007
@@ -51,9 +51,9 @@
/// set change at given pos
void setChange(pos_type pos, Change const & change);
/// accept changes within the given range
- void acceptChanges(pos_type start, pos_type end);
+ void acceptChanges(BufferParams const & bparams, pos_type start,
pos_type end);
/// reject changes within the given range
- void rejectChanges(pos_type start, pos_type end);
+ void rejectChanges(BufferParams const & bparams, pos_type start,
pos_type end);
///
value_type getChar(pos_type pos) const;
Modified: lyx-devel/trunk/src/text.C
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/text.C?rev=16830
==============================================================================
--- lyx-devel/trunk/src/text.C (original)
+++ lyx-devel/trunk/src/text.C Tue Jan 23 22:53:16 2007
@@ -845,7 +845,7 @@
}
-void LyXText::acceptChange(LCursor & cur)
+void LyXText::acceptOrRejectChange(LCursor & cur, bool accept)
{
BOOST_ASSERT(this == cur.text());
@@ -854,70 +854,91 @@
recordUndoSelection(cur, Undo::ATOMIC);
- DocIterator beg = cur.selectionBegin();
- DocIterator end = cur.selectionEnd();
-
- // first, accept changes within each individual paragraph (do not
consider end-of-par)
+ pit_type begPit = cur.selectionBegin().pit();
+ pit_type endPit = cur.selectionEnd().pit();
+
+ pos_type begPos = cur.selectionBegin().pos();
+ pos_type endPos = cur.selectionEnd().pos();
+
+ // keep selection info, because endPos becomes invalid after the first
loop
+ bool endsBeforeEndOfPar = (endPos < pars_[endPit].size());
+
+ // first, accept/reject changes within each individual paragraph (do
not consider end-of-par)
- for (pit_type pit = beg.pit(); pit <= end.pit(); ++pit) {
- // ignore empty paragraphs; otherwise, an assertion will fail for acceptChanges(0, 0)
- if (pars_[pit].size() == 0)
+ for (pit_type pit = begPit; pit <= endPit; ++pit) {
+ pos_type parSize = pars_[pit].size();
+
+ // ignore empty paragraphs; otherwise, an assertion will fail
for
+ // acceptChanges(bparams, 0, 0) or rejectChanges(bparams, 0, 0)
+ if (parSize == 0)
continue;
// do not consider first paragraph if the cursor starts at pos size()
- if (pit == beg.pit() && beg.pos() == pars_[pit].size())
+ if (pit == begPit && begPos == parSize)
continue;
// do not consider last paragraph if the cursor ends at pos 0
- if (pit == end.pit() && end.pos() == 0)
+ if (pit == endPit && endPos == 0)
break; // last iteration anyway
- pos_type left = (pit == beg.pit() ? beg.pos() : 0);
- pos_type right = (pit == end.pit() ? end.pos() :
pars_[pit].size());
- pars_[pit].acceptChanges(left, right);
+ pos_type left = (pit == begPit ? begPos : 0);
+ pos_type right = (pit == endPit ? endPos : parSize);
+
+ if (accept) {
+ pars_[pit].acceptChanges(cur.buffer().params(), left,
right);
+ } else {
+ pars_[pit].rejectChanges(cur.buffer().params(), left,
right);
+ }
}
- // next, accept imaginary end-of-par characters
- // iterate from last to first paragraph such that we don't have to care for a changing 'end'
+ // next, accept/reject imaginary end-of-par characters
- pos_type endpit = end.pit();
- for (pit_type pit = endpit; pit >= beg.pit(); --pit) {
+ for (pit_type pit = begPit; pit <= endPit; ++pit) {
pos_type pos = pars_[pit].size();
- // last paragraph of the selection requires special handling
- if (pit == end.pit()) {
- // skip if the selection ends before the end-of-par
- if (end.pos() < pos)
- continue;
-
- // skip if the selection ends with the end-of-par and
this is not the
- // last paragraph of the document
- // note: the user must be able to accept the end-of-par
of the last par!
- if (end.pos() == pos && pit != pars_.size() - 1)
- continue;
- }
-
-
- if (!pars_[pit].isUnchanged(pos)) {
+ // skip if the selection ends before the end-of-par
+ if (pit == endPit && endsBeforeEndOfPar)
+ break; // last iteration anyway
+
+ // skip if this is not the last paragraph of the document
+ // note: the user should be able to accept/reject the par break
of the last par!
+ if (pit == endPit && pit != pars_.size() - 1)
+ break; // last iteration anway
+
+ if (accept) {
if (pars_[pit].isInserted(pos)) {
pars_[pit].setChange(pos,
Change(Change::UNCHANGED));
- } else { // isDeleted
- if (pit == pars_.size()) {
- // we cannot remove a par break at the
end of the last paragraph
+ } else if (pars_[pit].isDeleted(pos)) {
+ if (pit == pars_.size() - 1) {
+ // we cannot remove a par break at the
end of the last paragraph;
// instead, we mark it unchanged
pars_[pit].setChange(pos,
Change(Change::UNCHANGED));
} else {
mergeParagraph(cur.buffer().params(),
pars_, pit);
- endpit--;
+ --endPit;
+ --pit;
}
}
+ } else {
+ if (pars_[pit].isDeleted(pos)) {
+ pars_[pit].setChange(pos,
Change(Change::UNCHANGED));
+ } else if (pars_[pit].isInserted(pos)) {
+ if (pit == pars_.size() - 1) {
+ // we mark the par break at the end of
the last paragraph unchanged
+ pars_[pit].setChange(pos,
Change(Change::UNCHANGED));
+ } else {
+ mergeParagraph(cur.buffer().params(),
pars_, pit);
+ --endPit;
+ --pit;
+ }
+ }
}
}
// finally, invoke the DEPM
// FIXME: the following code will be changed in the near future
- setCursorIntern(cur, endpit, 0);
- for (pit_type pit = endpit - 1; pit >= beg.pit(); --pit) {
+ setCursorIntern(cur, endPit, 0);
+ for (pit_type pit = endPit - 1; pit >= begPit; --pit) {
bool dummy;
LCursor old = cur;
setCursorIntern(cur, pit, 0);
@@ -926,94 +947,7 @@
finishUndo();
cur.clearSelection();
- setCursorIntern(cur, beg.pit(), beg.pos());
- cur.updateFlags(Update::Force);
- updateLabels(cur.buffer());
-}
-
-
-void LyXText::rejectChange(LCursor & cur)
-{
- BOOST_ASSERT(this == cur.text());
-
- if (!cur.selection())
- return;
-
- recordUndoSelection(cur, Undo::ATOMIC);
-
- DocIterator beg = cur.selectionBegin();
- DocIterator end = cur.selectionEnd();
-
- // first, accept changes within each individual paragraph (do not
consider end-of-par)
-
- for (pit_type pit = beg.pit(); pit <= end.pit(); ++pit) {
- // ignore empty paragraphs; otherwise, an assertion will fail for acceptChanges(0, 0)
- if (pars_[pit].size() == 0)
- continue;
-
- // do not consider first paragraph if the cursor starts at pos
size()
- if (pit == beg.pit() && beg.pos() == pars_[pit].size())
- continue;
-
- // do not consider last paragraph if the cursor ends at pos 0
- if (pit == end.pit() && end.pos() == 0)
- break; // last iteration anyway
-
- pos_type left = (pit == beg.pit() ? beg.pos() : 0);
- pos_type right = (pit == end.pit() ? end.pos() :
pars_[pit].size());
- pars_[pit].rejectChanges(left, right);
- }
-
- // next, accept imaginary end-of-par characters
- // iterate from last to first paragraph such that we don't have to care for a changing 'end'
-
- pos_type endpit = end.pit();
- for (pit_type pit = endpit; pit >= beg.pit(); --pit) {
- pos_type pos = pars_[pit].size();
-
- // last paragraph of the selection requires special handling
- if (pit == end.pit()) {
- // skip if the selection ends before the end-of-par
- if (end.pos() < pos)
- continue;
-
- // skip if the selection ends with the end-of-par and
this is not the
- // last paragraph of the document
- // note: the user must be able to accept the end-of-par
of the last par!
- if (end.pos() == pos && pit != pars_.size() - 1)
- continue;
- }
-
-
- if (!pars_[pit].isUnchanged(pos)) {
- if (pars_[pit].isDeleted(pos)) {
- pars_[pit].setChange(pos,
Change(Change::UNCHANGED));
- } else { // isInserted
- if (pit == pars_.size()) {
- // we cannot remove a par break at the
end of the last paragraph
- // instead, we mark it unchanged
- pars_[pit].setChange(pos,
Change(Change::UNCHANGED));
- } else {
- mergeParagraph(cur.buffer().params(),
pars_, pit);
- endpit--;
- }
- }
- }
- }
-
- // finally, invoke the DEPM
- // FIXME: the following code will be changed in the near future
- setCursorIntern(cur, endpit, 0);
- for (pit_type pit = endpit - 1; pit >= beg.pit(); --pit) {
- bool dummy;
- LCursor old = cur;
- setCursorIntern(cur, pit, 0);
- deleteEmptyParagraphMechanism(cur, old, dummy);
- }
-
- finishUndo();
- cur.clearSelection();
- setCursorIntern(cur, beg.pit(), beg.pos());
+ setCursorIntern(cur, begPit, begPos);
cur.updateFlags(Update::Force);
updateLabels(cur.buffer());
}
Modified: lyx-devel/trunk/src/text3.C
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/text3.C?rev=16830
==============================================================================
--- lyx-devel/trunk/src/text3.C (original)
+++ lyx-devel/trunk/src/text3.C Tue Jan 23 22:53:16 2007
@@ -1429,12 +1429,12 @@
}
case LFUN_CHANGE_ACCEPT: {
- acceptChange(cur);
+ acceptOrRejectChange(cur, true);
break;
}
case LFUN_CHANGE_REJECT: {
- rejectChange(cur);
+ acceptOrRejectChange(cur, false);
break;
}
_______________________________________________
Cvslog mailing list
[EMAIL PROTECTED]
http://www.lyx.org/mailman/listinfo/cvslog