[LyX/master] Fixup b321bb1a: set changebar when inset contains changes

Jean-Marc Lasgouttes lasgouttes at lyx.org
Sun Jan 12 20:05:12 UTC 2020


commit ce950f1ea50ec1fcc3df3938cb94c20347f5b71e
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Sat Jan 11 21:21:34 2020 +0100

    Fixup b321bb1a: set changebar when inset contains changes
    
    Add Paragraph::isChanged() and InetText::isCgchanged() which indicate
    the presence of a change in the relevant object.
    
    Sets Row::needsChangebar() when adding an inset that contains changes.
    
    Related to bug #8645.
---
 src/Paragraph.cpp               |    6 ++++++
 src/Paragraph.h                 |    2 ++
 src/Row.cpp                     |    1 +
 src/insets/Inset.h              |    2 ++
 src/insets/InsetCollapsible.cpp |   22 ++++++++--------------
 src/insets/InsetText.cpp        |   17 +++++++++++++----
 src/insets/InsetText.h          |    2 ++
 7 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index dab004e..10263d1 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -611,6 +611,12 @@ bool Paragraph::isChanged(pos_type start, pos_type end) const
 }
 
 
+bool Paragraph::isChanged() const
+{
+	return d->changes_.isChanged();
+}
+
+
 bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
 {
 	// keep the logic here in sync with the logic of eraseChars()
diff --git a/src/Paragraph.h b/src/Paragraph.h
index 694222b..08d1bad 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -268,6 +268,8 @@ public:
 	bool isChanged(pos_type start, pos_type end) const;
 	/// is there an unchanged char at the given pos ?
 	bool isChanged(pos_type pos) const;
+	/// is there a change in the paragraph ?
+	bool isChanged() const;
 
 	/// is there an insertion at the given pos ?
 	bool isInserted(pos_type pos) const;
diff --git a/src/Row.cpp b/src/Row.cpp
index 117b2ac..1e9e3ec 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -392,6 +392,7 @@ void Row::add(pos_type const pos, Inset const * ins, Dimension const & dim,
 	e.dim = dim;
 	elements_.push_back(e);
 	dim_.wid += dim.wid;
+	changebar_ |= ins->isChanged();
 }
 
 
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index ae5af7c..cffaf77 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -594,6 +594,8 @@ public:
 	 */
 	virtual bool resetFontEdit() const;
 
+	/// does the inset contain changes ?
+	virtual bool isChanged() const { return false; }
 	/// set the change for the entire inset
 	virtual void setChange(Change const &) {}
 	/// accept the changes within the inset
diff --git a/src/insets/InsetCollapsible.cpp b/src/insets/InsetCollapsible.cpp
index fab5d34..8fc49cb 100644
--- a/src/insets/InsetCollapsible.cpp
+++ b/src/insets/InsetCollapsible.cpp
@@ -445,13 +445,9 @@ docstring const InsetCollapsible::getNewLabel(docstring const & l) const
 	pos_type const n = min(max_length, p_siz);
 	pos_type i = 0;
 	pos_type j = 0;
-	bool changed_content = false;
 	for (; i < n && j < p_siz; ++j) {
-		if (paragraphs().begin()->isChanged(j)) {
-			changed_content = true;
-			if (paragraphs().begin()->isDeleted(j))
-				continue;
-		}
+		if (paragraphs().begin()->isDeleted(j))
+			continue;
 		if (paragraphs().begin()->isInset(j)) {
 			if (!paragraphs().begin()->getInset(j)->isChar())
 				continue;
@@ -463,12 +459,7 @@ docstring const InsetCollapsible::getNewLabel(docstring const & l) const
 	if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
 		label << "...";
 	}
-	docstring lbl;
-	// indicate changed content in label (#8645)
-	if (changed_content)
-		lbl = char_type(0x270E);// ✎ U+270E LOWER RIGHT PENCIL
-	lbl += label.str();
-	return lbl.empty() ? l : lbl;
+	return label.str().empty() ? l : label.str();
 }
 
 
@@ -668,11 +659,14 @@ docstring InsetCollapsible::getLabel() const
 
 docstring const InsetCollapsible::buttonLabel(BufferView const & bv) const
 {
+	// indicate changed content in label (#8645)
+	// ✎ U+270E LOWER RIGHT PENCIL
+	docstring indicator = isChanged() ? docstring(1, 0x270E) : docstring();
 	InsetLayout const & il = getLayout();
 	docstring const label = getLabel();
 	if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
-		return label;
-	return getNewLabel(label);
+		return indicator + label;
+	return indicator + getNewLabel(label);
 }
 
 
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index c37c1c2..eca69df 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -410,6 +410,18 @@ void InsetText::fixParagraphsFont()
 }
 
 
+bool InsetText::isChanged() const
+{
+	ParagraphList::const_iterator pit = paragraphs().begin();
+	ParagraphList::const_iterator end = paragraphs().end();
+	for (; pit != end; ++pit) {
+		if (pit->isChanged())
+			return true;
+	}
+	return false;
+}
+
+
 void InsetText::setChange(Change const & change)
 {
 	ParagraphList::iterator pit = paragraphs().begin();
@@ -1077,7 +1089,6 @@ docstring InsetText::toolTipText(docstring prefix, size_t const len) const
 	ParagraphList::const_iterator end = paragraphs().end();
 	ParagraphList::const_iterator it = beg;
 	bool ref_printed = false;
-	bool changed_content = false;
 
 	for (; it != end; ++it) {
 		if (it != beg)
@@ -1085,13 +1096,11 @@ docstring InsetText::toolTipText(docstring prefix, size_t const len) const
 		if ((*it).isRTL(buffer().params()))
 			oss << "<div dir=\"rtl\">";
 		writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, len);
-		if ((*it).isChanged(0, (*it).size()))
-			changed_content = true;
 		if (oss.tellp() >= 0 && size_t(oss.tellp()) > len)
 			break;
 	}
 	docstring str = oss.str();
-	if (changed_content)
+	if (isChanged())
 		str += from_ascii("\n\n") + _("[contains tracked changes]");
 	support::truncateWithEllipsis(str, len);
 	return str;
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index 2552f10..fc43ccb 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -124,6 +124,8 @@ public:
 	///
 	void fixParagraphsFont();
 
+	/// does the inset contain changes ?
+	bool isChanged() const;
 	/// set the change for the entire inset
 	void setChange(Change const & change);
 	/// accept the changes within the inset


More information about the lyx-cvs mailing list