Folks,

this is the next part of the CT cleanup.

I must confess that this patch will break CT in some cases (but not compilation, of course!). However, as I redesign the internal data structures (change tracking is no longer an "add-on" but an integral part of any paragraph and inset) it was impossible for me to find another self-contained set of changes that can be applied without breaking anything. I think we have to live with a broken CT for a week or two now (depending on how fast you accept my incremental changes).

Please have a look at the patch and tell me whether it is OK. Its overall objective is to make things simpler and clearer.

Regards,

Michael
Index: paragraph.h
===================================================================
--- paragraph.h	(Revision 13812)
+++ paragraph.h	(Arbeitskopie)
@@ -232,6 +232,9 @@
 	/// set change type at given pos
 	void setChangeType(lyx::pos_type pos, Change::Type type);
 
+	/// set change type for the entire par
+	void setChangeType(Change::Type type);
+	
 	/// set change at given pos
 	void setChange(lyx::pos_type pos, Change change);
 
@@ -241,9 +244,6 @@
 	/// reject change
 	void rejectChange(lyx::pos_type start, lyx::pos_type end);
 
-	/// mark whole par as erased or not
-	void markErased(bool erased);
-
 	/// Paragraphs can contain "manual labels", for example, Description
 	/// environment. The text for this user-editable label is stored in
 	/// the paragraph alongside the text of the rest of the paragraph
Index: insets/insetbase.h
===================================================================
--- insets/insetbase.h	(Revision 13811)
+++ insets/insetbase.h	(Arbeitskopie)
@@ -16,6 +16,8 @@
 #include <string>
 #include <vector>
 
+#include "changes.h"
+
 class Buffer;
 class BufferView;
 class CursorSlice;
@@ -396,8 +398,8 @@
 	 */
 	virtual bool noFontChange() const { return false; }
 
-	/// mark the inset as erased or not
-	virtual void markErased(bool erased);
+	/// set the change type for the entire inset
+	virtual void setChangeType(Change::Type type);
 
 	/// pretty arbitrary
 	virtual int width() const { return 10; }
Index: insets/insettext.h
===================================================================
--- insets/insettext.h	(Revision 13811)
+++ insets/insettext.h	(Arbeitskopie)
@@ -102,18 +102,9 @@
 	///
 	bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
 
-	/// mark as erased for change tracking
-	void markErased(bool erased);
+	/// set the change type for the entire inset
+	void setChangeType(Change::Type type);
 
-	/**
-	 * Mark as new. Used when pasting in tabular, and adding rows
-	 * or columns. Note that pasting will ensure that tracking already
-	 * happens, and this just resets the changes for the copied text,
-	 * whereas for row/col add, we need to start tracking changes
-	 * for the (empty) paragraph contained.
-	 */
-	void markNew(bool track_changes = false);
-
 	/// append text onto the existing text
 	void appendParagraphs(Buffer * bp, ParagraphList &);
 
Index: insets/insettabular.C
===================================================================
--- insets/insettabular.C	(Revision 13811)
+++ insets/insettabular.C	(Arbeitskopie)
@@ -1714,7 +1714,10 @@
 			shared_ptr<InsetText> inset(
 				new InsetText(*paste_tabular->getCellInset(r1, c1)));
 			tabular.setCellInset(r2, c2, inset);
-			inset->markNew();
+#ifdef WITH_WARNINGS
+#warning MG: Check logic of the following statement at the end of the CT cleanup
+#endif
+			inset->setChangeType(Change::INSERTED);
 			cur.pos() = 0;
 		}
 	}
@@ -1735,7 +1738,7 @@
 			shared_ptr<InsetText> t
 				= cell(tabular.getCellNumber(i, j));
 			if (cur.buffer().params().tracking_changes)
-				t->markErased(true);
+				t->setChangeType(Change::DELETED);
 			else
 				t->clear();
 		}
@@ -1784,10 +1787,10 @@
 }
 
 
-void InsetTabular::markErased(bool erased)
+void InsetTabular::setChangeType(Change::Type type)
 {
 	for (idx_type idx = 0; idx < nargs(); ++idx)
-		cell(idx)->markErased(erased);
+		cell(idx)->setChangeType(type);
 }
 
 
Index: insets/insettabular.h
===================================================================
--- insets/insettabular.h	(Revision 13811)
+++ insets/insettabular.h	(Arbeitskopie)
@@ -113,7 +113,7 @@
 	LyXText * getText(int) const;
 
 	///
-	void markErased(bool);
+	void setChangeType(Change::Type type);
 
 	// this should return true if we have a "normal" cell, otherwise false.
 	// "normal" means without width set!
Index: insets/insetbase.C
===================================================================
--- insets/insetbase.C	(Revision 13811)
+++ insets/insetbase.C	(Arbeitskopie)
@@ -273,7 +273,7 @@
 }
 
 
-void InsetBase::markErased(bool)
+void InsetBase::setChangeType(Change::Type type)
 {}
 
 
Index: insets/insettext.C
===================================================================
--- insets/insettext.C	(Revision 13811)
+++ insets/insettext.C	(Arbeitskopie)
@@ -114,14 +114,6 @@
 }
 
 
-void InsetText::markErased(bool erased)
-{
-	ParagraphList & pars = paragraphs();
-	for_each(pars.begin(), pars.end(),
-		 bind(&Paragraph::markErased, _1, erased));
-}
-
-
 void InsetText::clear()
 {
 	ParagraphList & pars = paragraphs();
@@ -292,6 +284,17 @@
 }
 
 
+void InsetText::setChangeType(Change::Type type)
+{
+	ParagraphList::iterator pit = paragraphs().begin();
+	ParagraphList::iterator end = paragraphs().end();
+
+	for (; pit != end; ++pit) {
+		pit->setChangeType(type);
+	}
+}
+
+
 int InsetText::latex(Buffer const & buf, ostream & os,
 		     OutputParams const & runparams) const
 {
@@ -353,19 +356,6 @@
 }
 
 
-void InsetText::markNew(bool track_changes)
-{
-	ParagraphList::iterator pit = paragraphs().begin();
-	ParagraphList::iterator end = paragraphs().end();
-	for (; pit != end; ++pit) {
-		if (track_changes)
-			pit->trackChanges();
-		else // no-op when not tracking
-			pit->cleanChanges();
-	}
-}
-
-
 void InsetText::setText(string const & data, LyXFont const & font)
 {
 	clear();
Index: paragraph_pimpl.C
===================================================================
--- paragraph_pimpl.C	(Revision 13812)
+++ paragraph_pimpl.C	(Arbeitskopie)
@@ -156,6 +156,26 @@
 }
 
 
+void Paragraph::Pimpl::setChangeType(Change::Type type)
+{
+#ifdef WITH_WARNINGS
+#warning MG: Check logic at the end of the CT cleanup
+#endif
+	switch (type) {
+		case Change::UNCHANGED:
+		case Change::INSERTED:
+			for (pos_type i = 0; i < size(); ++i) {
+				changes_->set(type, i);
+				if (owner_->isInset(i))
+					owner_->getInset(i)->setChangeType(type);
+			}
+			break;
+		case Change::DELETED:
+			erase(0, size());
+	}
+}
+
+
 void Paragraph::Pimpl::setChange(pos_type pos, Change change)
 {
 	if (!tracking())
@@ -174,22 +194,6 @@
 }
 
 
-void Paragraph::Pimpl::markErased(bool erased)
-{
-	BOOST_ASSERT(tracking());
-
-	if (erased) {
-		erase(0, size());
-	} else {
-		for (pos_type i = 0; i < size(); ++i) {
-			changes_->set(Change::UNCHANGED, i);
-			if (owner_->isInset(i))
-				owner_->getInset(i)->markErased(false);
-		}
-	}
-}
-
-
 void Paragraph::Pimpl::acceptChange(pos_type start, pos_type end)
 {
 	if (!tracking())
@@ -260,7 +264,7 @@
 				changes_->set(Change::UNCHANGED, i);
 				// No real char at position size():
 				if (i < size() && owner_->isInset(i))
-					owner_->getInset(i)->markErased(false);
+					owner_->getInset(i)->setChangeType(Change::UNCHANGED);
 				break;
 		}
 	}
@@ -376,7 +380,7 @@
 		// only allow the actual removal if it was /new/ text
 		if (changetype != Change::INSERTED) {
 			if (pos < size() && owner_->isInset(pos))
-				owner_->getInset(pos)->markErased(true);
+				owner_->getInset(pos)->setChangeType(Change::DELETED);
 			return false;
 		}
 	}
Index: paragraph_pimpl.h
===================================================================
--- paragraph_pimpl.h	(Revision 13812)
+++ paragraph_pimpl.h	(Arbeitskopie)
@@ -52,10 +52,10 @@
 	bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
 	/// set change type at given pos
 	void setChangeType(lyx::pos_type pos, Change::Type type);
+	/// set change type for the entire par
+	void setChangeType(Change::Type type);
 	/// set change at given pos
 	void setChange(lyx::pos_type pos, Change change);
-	/// mark as erased
-	void markErased(bool);
 	/// accept change
 	void acceptChange(lyx::pos_type start, lyx::pos_type end);
 	/// reject change
Index: tabular.C
===================================================================
--- tabular.C	(Revision 13811)
+++ tabular.C	(Arbeitskopie)
@@ -476,7 +476,7 @@
 
 	if (bp.tracking_changes)
 		for (col_type j = 0; j < columns_; ++j)
-			cell_info[row + 1][j].inset->markNew(true);
+			cell_info[row + 1][j].inset->setChangeType(Change::INSERTED);
 
 	set_row_column_number_info();
 }
@@ -520,7 +520,7 @@
 	for (row_type i = 0; i < rows_; ++i) {
 		cell_info[i][column + 1].inset->clear();
 		if (bp.tracking_changes)
-			cell_info[i][column + 1].inset->markNew(true);
+			cell_info[i][column + 1].inset->setChangeType(Change::INSERTED);
 	}
 	fixCellNums();
 }
Index: paragraph.C
===================================================================
--- paragraph.C	(Revision 13812)
+++ paragraph.C	(Arbeitskopie)
@@ -1651,15 +1651,15 @@
 }
 
 
-void Paragraph::setChange(lyx::pos_type pos, Change change)
+void Paragraph::setChangeType(Change::Type type)
 {
-	pimpl_->setChange(pos, change);
+	pimpl_->setChangeType(type);
 }
 
 
-void Paragraph::markErased(bool erased)
+void Paragraph::setChange(lyx::pos_type pos, Change change)
 {
-	pimpl_->markErased(erased);
+	pimpl_->setChange(pos, change);
 }
 
 

Reply via email to