]> git.lyx.org Git - features.git/commitdiff
Fixup b321bb1a: set changebar when inset contains changes
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 11 Jan 2020 20:21:34 +0000 (21:21 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:50 +0000 (15:48 +0200)
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
src/Paragraph.h
src/Row.cpp
src/insets/Inset.h
src/insets/InsetCollapsible.cpp
src/insets/InsetText.cpp
src/insets/InsetText.h

index dab004ee3904e3d42ef4e14d36aa4d8201348cd7..10263d1fbf2bab52264091629e811a833e6adafc 100644 (file)
@@ -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()
index 694222b771ae1d9cea0ea0f005fa815962ddd3e3..08d1bad71e0a45c7a80ce31e05f6d4a662c8f6c2 100644 (file)
@@ -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;
index 117b2ac9faea9945452fb4bf44187026d48e99a3..1e9e3eca2bc7fc74a0af3fcf5bc740d00441352b 100644 (file)
@@ -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();
 }
 
 
index ae5af7cc784aedc26ff4ab0b6ea41171ddb74b19..cffaf77c6ea7ac5bd4a3b83d5ba70897afe44744 100644 (file)
@@ -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
index fab5d34864b8bb6817103b5a74a64ce82a40c56b..8fc49cbc1ef90c0987cc8be88211e912faeee23e 100644 (file)
@@ -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);
 }
 
 
index c37c1c26d5db3ea4d12b5e2d64ddd08e5380aea2..eca69df41696f3a9d955761f0af07367a0a532cf 100644 (file)
@@ -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;
index 2552f1096719fb76266a5f1c47b7e563bf094a4f..fc43ccbb38805a8bdc9f544c61b7a3fa5999251d 100644 (file)
@@ -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