>>>>> "Michael" == Michael Gerz <[EMAIL PROTECTED]> writes:
Michael> In other words, you want me to introduce some
Michael> enum AcceptReject { ACCEPT, REJECT }
Michael> and pass it as parameter, right?
I am sorry that I did not answer in time. To try to compensate, here
is a patch showing what I mean. The idea is to use the complete
symmetry between accept and reject:
- accept: remove DELETED chunks, keep INSERTED chunks
- reject: remove INSERTED chunks, keep DELETED chunks
The patch below (proof of concept really, but it works as is) shows
how this reduces code duplication. We should go farther and merge
Paragraph::(accept|reject)Changes. Then the code would be even
simpler.
acceptOrRejectChanges should probably be renamed to something like
acceptChangesOfType.
Do you see better what I mean?
JMarc
Index: src/lyxtext.h
===================================================================
--- src/lyxtext.h (revision 16865)
+++ src/lyxtext.h (working copy)
@@ -158,8 +158,11 @@ public:
ACCEPT,
REJECT
};
- /// accept or reject the selected change
- void acceptOrRejectChanges(LCursor & cur, ChangeOp op);
+ /** accept or reject the selected change: the kind of change
+ * that should be kept is given as parameter, the other type
+ * is discarded.
+ */
+ void acceptOrRejectChanges(LCursor & cur, Change::Type keepwhat);
/// accept the changes within the complete LyXText
void acceptChanges(BufferParams const & bparams);
/// reject the changes within the complete LyXText
Index: src/text3.C
===================================================================
--- src/text3.C (revision 16865)
+++ src/text3.C (working copy)
@@ -1429,12 +1429,12 @@ void LyXText::dispatch(LCursor & cur, Fu
}
case LFUN_CHANGE_ACCEPT: {
- acceptOrRejectChanges(cur, ACCEPT);
+ acceptOrRejectChanges(cur, Change::INSERTED);
break;
}
case LFUN_CHANGE_REJECT: {
- acceptOrRejectChanges(cur, REJECT);
+ acceptOrRejectChanges(cur, Change::DELETED);
break;
}
Index: src/BufferView.C
===================================================================
--- src/BufferView.C (revision 16865)
+++ src/BufferView.C (working copy)
@@ -862,7 +862,7 @@ Update::flags BufferView::dispatch(FuncR
#warning FIXME changes
#endif
while (findNextChange(this))
- getLyXText()->acceptOrRejectChanges(cursor_, LyXText::ACCEPT);
+ getLyXText()->acceptOrRejectChanges(cursor_, Change::INSERTED);
break;
}
@@ -872,7 +872,7 @@ Update::flags BufferView::dispatch(FuncR
#warning FIXME changes
#endif
while (findNextChange(this))
- getLyXText()->acceptOrRejectChanges(cursor_, LyXText::REJECT);
+ getLyXText()->acceptOrRejectChanges(cursor_, Change::DELETED);
break;
}
Index: src/text.C
===================================================================
--- src/text.C (revision 16865)
+++ src/text.C (working copy)
@@ -845,9 +845,10 @@ bool LyXText::selectWordWhenUnderCursor(
}
-void LyXText::acceptOrRejectChanges(LCursor & cur, ChangeOp op)
+void LyXText::acceptOrRejectChanges(LCursor & cur, Change::Type keepwhat)
{
BOOST_ASSERT(this == cur.text());
+ BOOST_ASSERT(keepwhat != Change::UNCHANGED);
if (!cur.selection())
return;
@@ -884,7 +885,7 @@ void LyXText::acceptOrRejectChanges(LCur
pos_type left = (pit == begPit ? begPos : 0);
pos_type right = (pit == endPit ? endPos : parSize);
- if (op == ACCEPT) {
+ if (keepwhat == Change::INSERTED) {
pars_[pit].acceptChanges(cur.buffer().params(), left, right);
} else {
pars_[pit].rejectChanges(cur.buffer().params(), left, right);
@@ -902,14 +903,15 @@ void LyXText::acceptOrRejectChanges(LCur
// 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)
+ if (pit == endPit && pit + 1 != pars_.size())
break; // last iteration anway
- if (op == ACCEPT) {
- if (pars_[pit].isInserted(pos)) {
+ Change::Type chtype = pars_[pit].lookupChange(pos).type;
+ if (chtype != Change::UNCHANGED) {
+ if (chtype == keepwhat) {
pars_[pit].setChange(pos, Change(Change::UNCHANGED));
- } else if (pars_[pit].isDeleted(pos)) {
- if (pit == pars_.size() - 1) {
+ } else {
+ if (pit + 1 == 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));
@@ -919,19 +921,6 @@ void LyXText::acceptOrRejectChanges(LCur
--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;
- }
- }
}
}