sw/qa/filter/xml/xml.cxx        |   20 ++++++++++++++++++++
 sw/source/filter/xml/xmlexp.cxx |   12 +++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

New commits:
commit a66ad821ca698d1b729db2df279dbeeacb91175b
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Apr 8 09:20:14 2025 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Apr 8 10:53:45 2025 +0200

    Related: cool#11226 fix 'record track changes' export to FODT
    
    Create a Writer document, enable tracked changes, save to FODT, reopen,
    changes are no longer tracked.
    
    This seems to be an export problem, <text:tracked-changes
    text:track-changes="true"> is simply not in the export result.
    
    What happens is that the export wants to show insertions and hide
    deletions during the export, and this happens in
    SwXMLExport::exportDoc() for FODT while it happens in
    SwXMLWriter::Write_() for ODT. This went wrong in commit
    6af264883910fe31433b4164b1956f4f9ed75ecb (#94187# switch redline mode
    outside of XML export components (or inside for each of them),
    2001-11-08), where the mask to clear out the "show" bits was wrong for
    the flat case and good for the package case.
    
    Now that we actually set redline flags to hide deletions during FODT
    export (or anything based on that, like the XHTML export), an additional
    problem is that SetRedlineFlags() asserts in UnHide() for
    CppunitTest_sw_xhtmlexport's testTdf66305, because there is no
    StartAllAction() / EndAllAction() around it, while that is happening in
    SwWriter::Write() for the ODT case. Fix this, too.
    
    Change-Id: I227a883ecc5d68611d8aee5c80d65485b5f3c4c8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183834
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/qa/filter/xml/xml.cxx b/sw/qa/filter/xml/xml.cxx
index 39a651183947..9a0d9c1ff59b 100644
--- a/sw/qa/filter/xml/xml.cxx
+++ b/sw/qa/filter/xml/xml.cxx
@@ -54,6 +54,26 @@ CPPUNIT_TEST_FIXTURE(Test, testCoveredCellBackground)
     // i.e. part of the merged cell had a bad white background.
     CPPUNIT_ASSERT_EQUAL(Color(0xe8f2a1), rBackground.GetColor());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testRedlineRecordFlatExport)
+{
+    // Given a document with track changes enabled:
+    createSwDoc();
+    dispatchCommand(mxComponent, ".uno:TrackChanges", {});
+
+    // When saving that to FODT:
+    save(u"OpenDocument Text Flat XML"_ustr);
+
+    // Then make sure this is written in the export result:
+    xmlDocUniquePtr pDoc = parseXml(maTempFile);
+    CPPUNIT_ASSERT(pDoc);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - XPath '/office:document/office:body/office:text/text:tracked-changes' 
number of nodes is incorrect
+    // i.e. the entire XML element was missing.
+    OUString aValue = getXPath(
+        pDoc, "/office:document/office:body/office:text/text:tracked-changes", 
"track-changes");
+    CPPUNIT_ASSERT_EQUAL(u"true"_ustr, aValue);
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index 6ccdf667ce20..db43a13594ca 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -66,6 +66,7 @@
 
 
 #include <pausethreadstarting.hxx>
+#include <editsh.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::lang;
@@ -293,6 +294,11 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
     RedlineFlags nRedlineFlags = RedlineFlags::NONE;
     SwRootFrame const*const 
pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     m_bSavedShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();
+    SwEditShell* pESh = m_pDoc->GetEditShell();
+    if (pESh)
+    {
+        pESh->StartAllAction();
+    }
     if( bSaveRedline )
     {
         // tdf#133487 call this once in flat-ODF case
@@ -303,7 +309,7 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
         // now save and switch redline mode
         nRedlineFlags = pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
         pDoc->getIDocumentRedlineAccess().SetRedlineFlags(
-                 ( nRedlineFlags & RedlineFlags::ShowMask ) | 
RedlineFlags::ShowInsert );
+                 ( nRedlineFlags & ~RedlineFlags::ShowMask ) | 
RedlineFlags::ShowInsert );
     }
 
     ErrCode nRet = SvXMLExport::exportDoc( eClass );
@@ -313,6 +319,10 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
     {
       pDoc->getIDocumentRedlineAccess().SetRedlineFlags( nRedlineFlags );
     }
+    if (pESh)
+    {
+        pESh->EndAllAction();
+    }
 
     if (xGraphicStorageHandler)
         xGraphicStorageHandler->dispose();

Reply via email to