sw/qa/extras/uiwriter/uiwriter5.cxx |   63 ++++++++++++++++++++++++++++++++++++
 sw/source/core/frmedt/fetab.cxx     |   17 +++++++++
 2 files changed, 80 insertions(+)

New commits:
commit e91faddabdf5d586c0044a3e125bdea6c2e21532
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Thu Jul 27 15:40:52 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Aug 2 12:14:41 2023 +0200

    tdf#156475 sw tracked table column: delete empty cell
    
    Tracking changes, only non-empty cells of the deleted
    columns got coloring, and were hidden in Hide Changes
    mode.
    
    Add dummy text content to empty cells of the deleted
    columns to get visible deletion in Show Changes mode,
    also working context menu in that cell; to allow hiding
    them in Hide Changes mode, also to store the time stamp
    of the deletion, if all the other rows are removed during
    editing.
    
    Follow-up to commit 472abf99a4d90d7a53316394a2e51a26b7e62345
    "tdf#155341 sw tracked table column: add insertion".
    
    Change-Id: Ieb5d237b3c82c81fded25608ef3d2906d7474003
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154994
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit fe43f5971dfd2a121634eea9e39c7ad0cf3f962a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154962

diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index 937567b9b2bc..07579cc6662a 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -2605,6 +2605,69 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf156474)
     CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getColumns()->getCount());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, tdf156475)
+{
+    // load a table, and insert a row without change tracking,
+    // and delete the first column with the empty cell in the second row with 
change tracking
+    createSwDoc("tdf118311.fodt");
+    SwDoc* pDoc = getSwDoc();
+
+    // turn off red-lining and show changes
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete
+                                                      | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be off",
+                           !pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+
+    // insert table row
+    dispatchCommand(mxComponent, ".uno:InsertRowsAfter", {});
+
+    // check table
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 2);
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row[1]/cell", 2);
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row[2]/cell", 2);
+
+    // turn on red-lining
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | 
RedlineFlags::ShowDelete
+                                                      | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+
+    // delete table column with enabled change tracking
+    // (HasTextChangesOnly property of the cell will be false)
+    dispatchCommand(mxComponent, ".uno:DeleteColumns", {});
+
+    // go down to the empty cell
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Down(/*bSelect=*/false);
+
+    // Without the fix in place, this couldn't work
+    dispatchCommand(mxComponent, ".uno:AcceptTrackedChange", {});
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 2);
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row[1]/cell", 1);
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row[2]/cell", 1);
+
+    // test Undo/Redo
+    for (sal_Int32 i = 0; i < 4; ++i)
+    {
+        dispatchCommand(mxComponent, ".uno:Undo", {});
+    }
+
+    for (sal_Int32 i = 0; i < 4; ++i)
+    {
+        dispatchCommand(mxComponent, ".uno:Redo", {});
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf155747)
 {
     // load a table, and delete the first column with enabled change tracking:
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index daca7b86bc9c..c271d975d567 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -37,6 +37,8 @@
 #include <docsh.hxx>
 #include <IDocumentState.hxx>
 #include <IDocumentLayoutAccess.hxx>
+#include <IDocumentRedlineAccess.hxx>
+#include <IDocumentUndoRedo.hxx>
 #include <cntfrm.hxx>
 #include <txtfrm.hxx>
 #include <notxtfrm.hxx>
@@ -302,6 +304,21 @@ bool SwFEShell::DeleteCol()
                 SwCursor aCursor( SwPosition(aIdx), nullptr );
                 SvxPrintItem aHasTextChangesOnly(RES_PRINT, false);
                 GetDoc()->SetBoxAttr( aCursor, aHasTextChangesOnly );
+
+                // add dummy text content to the empty box for change tracking
+                if ( pBox->IsEmpty() )
+                {
+                    IDocumentContentOperations& rIDCO = 
GetDoc()->getIDocumentContentOperations();
+                    IDocumentRedlineAccess& rIDRA = 
GetDoc()->getIDocumentRedlineAccess();
+                    RedlineFlags eOld = rIDRA.GetRedlineFlags();
+                    rIDRA.SetRedlineFlags_intern(RedlineFlags::NONE);
+                    rIDCO.InsertString( aCursor, 
OUStringChar(CH_TXT_TRACKED_DUMMY_CHAR) );
+                    aCursor.SetMark();
+                    aCursor.GetMark()->SetContent(0);
+                    rIDRA.SetRedlineFlags_intern( eOld );
+                    rIDCO.DeleteAndJoin( aCursor );
+                }
+
             }
         }
 

Reply via email to