sw/qa/uitest/writer_tests/trackedChanges.py |   53 +++++++++++++++++++++++++
 sw/source/uibase/misc/redlndlg.cxx          |   58 ++++++++++++----------------
 2 files changed, 78 insertions(+), 33 deletions(-)

New commits:
commit 42a5ff8011bf0d46eafbb39536b1c9a08a7e314a
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Jun 16 10:53:23 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Fri Jun 16 13:51:41 2023 +0200

    tdf#155847 sw tracked table column: manage multiple changes
    
    In Manage Changes dialog window, group also redlines of
    multiple different column changes.
    
    Follow-up to commit cc52d895314dd7b67de916bd90ccbfa098e77419
    "tdf#155342 sw tracked table column: manage changes".
    
    Change-Id: I3c9e69bf554bc5b4ce9473f95fff5954228758bb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153172
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 4a40a42afc3ba551e6e58947fc2e44689979b629)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153142

diff --git a/sw/qa/uitest/writer_tests/trackedChanges.py 
b/sw/qa/uitest/writer_tests/trackedChanges.py
index 7e780ef61730..111571881b82 100644
--- a/sw/qa/uitest/writer_tests/trackedChanges.py
+++ b/sw/qa/uitest/writer_tests/trackedChanges.py
@@ -544,4 +544,57 @@ class trackedchanges(UITestCase):
 
                 self.assertEqual(0, len(changesList.getChildren()))
 
+    def test_tdf155847_multiple_tracked_columns(self):
+        with 
self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as 
document:
+
+            # accept all changes and insert new columns with change tracking
+            self.xUITest.executeCommand(".uno:AcceptAllTrackedChanges")
+            tables = document.getTextTables()
+            self.assertEqual(2, len(tables))
+            self.assertEqual(len(tables[0].getColumns()), 3)
+            self.xUITest.executeCommand(".uno:InsertColumnsAfter")
+            self.xUITest.executeCommand(".uno:DeleteColumns")
+            self.assertEqual(len(tables[0].getColumns()), 4)
+
+            xToolkit = 
self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
+            xToolkit.processEventsToIdle()
+
+            # check and reject changes
+            with 
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
+                changesList = xTrackDlg.getChild("writerchanges")
+
+                # six changes, but only one visible in the Manage Changes 
dialog window
+                state = get_state_as_dict(changesList)
+                self.assertEqual(state['Children'], '6')
+
+                # This was 4 (missing handling of multiple different columns)
+                self.assertEqual(state['VisibleCount'], '2')
+                # Now: 2 changes (deleted and inserted columns)
+                self.assertEqual(2, len(changesList.getChildren()))
+
+                # accept column deletion
+
+                xAccBtn = xTrackDlg.getChild("accept")
+                xAccBtn.executeAction("CLICK", tuple())
+
+                # deleted column is removed
+
+                self.assertEqual(len(tables[0].getColumns()), 3)
+
+                # single parent left in the dialog window
+                self.assertEqual(1, len(changesList.getChildren()))
+
+                # reject column insertion
+
+                xAccBtn = xTrackDlg.getChild("reject")
+                xAccBtn.executeAction("CLICK", tuple())
+
+                # inserted column is removed
+
+                self.assertEqual(len(tables[0].getColumns()), 2)
+
+                # no changes in the dialog window
+
+                self.assertEqual(0, len(changesList.getChildren()))
+
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/uibase/misc/redlndlg.cxx 
b/sw/source/uibase/misc/redlndlg.cxx
index 3a0a67fa005d..35a15fa940e3 100644
--- a/sw/source/uibase/misc/redlndlg.cxx
+++ b/sw/source/uibase/misc/redlndlg.cxx
@@ -807,12 +807,12 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
     // redlines of the change - 1 (first redline is associated to the parent 
tree list item)
     SwRedlineTable::size_type nSkipRedline = 0;
 
-    // last SwRangeRedline in the table row/column
-    SwRedlineTable::size_type nLastChangeInRow = SwRedlineTable::npos;
     // descriptor redline of the tracked table row/column
     SwRedlineTable::size_type nRowChange = 0;
-    // descriptor redline of the previous table change to join with the next 
one
-    SwRedlineTable::size_type nPrevRowChange = SwRedlineTable::npos;
+
+    // first redlines of the tracked table rows/columns, base of the parent 
tree lists
+    // of the other SwRangeRedlines of the tracked table rows or columns
+    std::vector<SwRedlineTable::size_type> aTableParents;
 
     // show all redlines as tree list items,
     // redlines of a tracked table (row) insertion/deletion showed as children 
of a single parent
@@ -820,6 +820,8 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
     {
         const SwRangeRedline& rRedln = pSh->GetRedline(i);
         const SwRedlineData *pRedlineData = &rRedln.GetRedlineData();
+        // redline is a child associated to this table row/column change
+        SwRedlineTable::size_type nTableParent = SwRedlineTable::npos;
 
         pRedlineParent = new SwRedlineDataParent;
         pRedlineParent->pData    = pRedlineData;
@@ -830,9 +832,6 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
         const SwTableLine* pTableLine;
         bool bChange = false;
         bool bRowChange = false;
-        // first SwRangeRedline of the tracked table rows/columns, base of the 
parent tree list
-        // of the other SwRangeRedlines of the tracked table rows or columns
-        SwRedlineTable::size_type nNewTableParent = SwRedlineTable::npos;
         if ( // not recognized yet as tracked table row change
              nullptr != ( pTableBox = 
pSh->GetRedline(i).Start()->GetNode().GetTableBox() ) &&
              nullptr != ( pTableLine = pTableBox->GetUpper() ) &&
@@ -848,35 +847,30 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
             nRowChange = bRowChange
                             ? pTableLine->UpdateTextChangesOnly(nStartPos)
                             : pTableBox->GetRedline();
+            // redline is there in a tracked table change
             if ( SwRedlineTable::npos != nRowChange )
             {
-                // redline is there in a tracked table change
-
                 // join the consecutive deleted/inserted rows/columns under a 
single treebox item,
                 // if they have the same redline data (equal type, author and 
time stamp)
-                if ( nPrevRowChange != SwRedlineTable::npos )
+                for (size_t j = 0; j < aTableParents.size(); j++)
                 {
                     // note: CanCombine() allows a time frame to join the 
changes within a short
                     // time period: this avoid of falling apart of the tracked 
columns inserted
                     // by several clicks
                     if ( pSh->GetRedline(nRowChange).GetRedlineData()
-                             
.CanCombine(pSh->GetRedline(nPrevRowChange).GetRedlineData()) &&
-                         // in the same table?
-                         
pSh->GetRedline(nRowChange).Start()->GetNode().FindTableNode() ==
-                             
pSh->GetRedline(nPrevRowChange).Start()->GetNode().FindTableNode() )
+                             
.CanCombine(pSh->GetRedline(aTableParents[j]).GetRedlineData()) )
                     {
                         nSkipRedline++;
+                        nTableParent = aTableParents[j];
+                        break;
                     }
-                    else
-                    {
-                        nNewTableParent = i;
-                        nLastChangeInRow = i;
-                    }
+
                 }
-                else
+
+                if ( SwRedlineTable::npos == nTableParent )
                 {
-                    nLastChangeInRow = i;
-                    nNewTableParent = i;
+                    // table redline didn't fit in the stored ones, create new 
parent
+                    aTableParents.push_back(i);
                 }
             }
             else
@@ -886,6 +880,12 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
             }
         }
 
+        // empty parent cache for the last table
+        if ( !pTableBox )
+        {
+            aTableParents.clear();
+        }
+
         bool bShowDeletedTextAsComment = bIsShowChangesInMargin &&
                 RedlineType::Delete == rRedln.GetType() && 
rRedln.GetComment().isEmpty();
         const OUString& sComment = bShowDeletedTextAsComment
@@ -903,7 +903,7 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
         // the correct redline type, author and time stamp of the tracked row 
change
         const SwRangeRedline& rChangeRedln = pSh->GetRedline(bChange ? 
nRowChange : i);
 
-        OUString sImage = GetActionImage(rChangeRedln, 0, bChange && 
nNewTableParent != SwRedlineTable::npos, bRowChange );
+        OUString sImage = GetActionImage(rChangeRedln, 0, bChange && 
aTableParents.back() == i, bRowChange );
         OUString sAuthor = rChangeRedln.GetAuthorString(0);
         pData->aDateTime = rChangeRedln.GetTimeStamp(0);
         pData->eType = rChangeRedln.GetType(0);
@@ -912,7 +912,7 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
         OUString sId = weld::toId(pData.get());
         std::unique_ptr<weld::TreeIter> xParent(rTreeView.make_iterator());
 
-        if ( !bChange || nNewTableParent != SwRedlineTable::npos )
+        if ( !bChange || aTableParents.back() == i )
         {
             rTreeView.insert(nullptr, i - nSkipRedlines, nullptr, &sId, 
nullptr, nullptr, false, xParent.get());
             // before this was a tracked table change with more than a single 
redline
@@ -925,7 +925,7 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
         else
         {
             // put 2nd or more redlines of deleted/inserted rows as children 
of their first redline
-            SwRedlineDataParent *const pParent = 
m_RedlineParents[nLastChangeInRow].get();
+            SwRedlineDataParent *const pParent = 
m_RedlineParents[nTableParent].get();
             rTreeView.insert(pParent->xTLBParent.get(), -1, nullptr, &sId, 
nullptr, nullptr, false, xParent.get());
         }
 
@@ -948,9 +948,6 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
         pRedlineParent->xTLBParent = std::move(xParent);
 
         InsertChildren(pRedlineParent, rRedln, bHasRedlineAutoFormat);
-
-        nPrevRowChange = nRowChange;
-        nNewTableParent = SwRedlineTable::npos;
     }
     rTreeView.thaw();
     if (m_pTable->IsSorted())
commit 8147efa82bfb62305ded9cf5b496ba7328775ccc
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Jun 13 17:22:18 2023 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Fri Jun 16 13:51:33 2023 +0200

    cid#1532367 Unused value
    
    Within the loop nPrevRowChange is not read after it is set
    and nPrevRowChange is always set to nRowChange at the end of
    the loop. There is no continue within the loop, so it looks
    like there is no point changing nPrevRowChange as it will be
    overwritten with nRowChange in any case.
    
    probably this is the case since:
    
    commit cc52d895314dd7b67de916bd90ccbfa098e77419
    Date:   Wed Jun 7 16:53:42 2023 +0200
    
        tdf#155342 sw tracked table column: manage changes
    
    Change-Id: Ib7cf2da23a7553bdeea13862cf4f67248bc829a7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152994
    Tested-by: Jenkins
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit 76d5bf35a618dc8f7f268ec5cd40e546a4d48e17)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153141
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/source/uibase/misc/redlndlg.cxx 
b/sw/source/uibase/misc/redlndlg.cxx
index e583dc3af1a9..3a0a67fa005d 100644
--- a/sw/source/uibase/misc/redlndlg.cxx
+++ b/sw/source/uibase/misc/redlndlg.cxx
@@ -871,7 +871,6 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
                     {
                         nNewTableParent = i;
                         nLastChangeInRow = i;
-                        nPrevRowChange = nRowChange;
                     }
                 }
                 else
@@ -884,12 +883,8 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
             {
                 // redline is not in a tracked table change
                 bChange = bRowChange = false;
-                nPrevRowChange = SwRedlineTable::npos;
             }
         }
-        else
-            // redline is not in a tracked table change
-            nPrevRowChange = SwRedlineTable::npos;
 
         bool bShowDeletedTextAsComment = bIsShowChangesInMargin &&
                 RedlineType::Delete == rRedln.GetType() && 
rRedln.GetComment().isEmpty();

Reply via email to