sw/qa/uitest/data/TC-table-del-add.docx |binary
 sw/qa/uitest/table/tdf146145.py         |  110 ++++++++++++++++++++++++++++++++
 sw/source/uibase/uiview/view2.cxx       |   55 +++++++++++++++-
 sw/source/uibase/uiview/viewstat.cxx    |    9 ++
 4 files changed, 171 insertions(+), 3 deletions(-)

New commits:
commit c50dbeaac64a24c9afd9825fc91ace9482802557
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Mon Dec 13 12:09:10 2021 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Dec 14 16:09:11 2021 +0100

    tdf#146145 sw: 1-click Accept/Reject of table row changes
    
    Now context menu of a changed table row shows Accept Change/
    Reject Change menu items, which accept or reject
    the deletion or insertion of the table row.
    Also Accept Change/Reject Change icons of the Track Changes
    toolbar are enabled, and do the same, if the cursor is not
    before or in a tracked change.
    
    Add the following labels to the Undo actions:
    
    "Accept change: Row Inserted"
    "Accept change: Row Deleted"
    "Reject change: Row Inserted"
    "Reject change: Row Deleted"
    
    Change-Id: I12ae0158d059b044e430cc0ab86f0cf8931eadd0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126770
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 95c003d75e0f8b255344715a35358072b5eba99d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126811
    Tested-by: Jenkins

diff --git a/sw/qa/uitest/data/TC-table-del-add.docx 
b/sw/qa/uitest/data/TC-table-del-add.docx
new file mode 100644
index 000000000000..841e63f0d12b
Binary files /dev/null and b/sw/qa/uitest/data/TC-table-del-add.docx differ
diff --git a/sw/qa/uitest/table/tdf146145.py b/sw/qa/uitest/table/tdf146145.py
new file mode 100644
index 000000000000..a082ea780018
--- /dev/null
+++ b/sw/qa/uitest/table/tdf146145.py
@@ -0,0 +1,110 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
+import time
+
+from com.sun.star.accessibility.AccessibleStateType import ENABLED
+
+class tdf146145(UITestCase):
+
+   # access to the private:resource changes toolbar via accessibility API
+   def is_enabled_Accept_Track_Change(self):
+       xFrame = self.document.getCurrentController().getFrame()
+
+       for i in xFrame.getPropertyValue("LayoutManager").getElements():
+           if i.getPropertyValue('ResourceURL') == 
'private:resource/toolbar/changes':
+               return ENABLED in 
i.getRealInterface().getAccessibleContext().getAccessibleChild(5).getAccessibleStateSet().getStates()
+
+       return False
+
+   def test_tdf146145(self):
+        with 
self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as 
self.document:
+
+            # Check enabling Accept/Reject Track Change icons
+            # and Accept Change/Reject Change context menu items
+            # on table rows with tracked deletion or insertion
+
+            # enable Track Changes toolbar
+            
self.xUITest.executeCommand(".uno:AvailableToolbars?Toolbar:string=changes")
+
+            xToolkit = 
self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
+            xToolkit.processEventsToIdle()
+
+            # cursor at changed text: Accept Track Change is enabled
+            self.assertTrue(self.is_enabled_Accept_Track_Change())
+
+            # cursor in a changed row, but not at changed text: Accept Track 
Change is enabled now
+            self.xUITest.executeCommand(".uno:GoRight")
+            xToolkit.processEventsToIdle()
+            # This was false
+            self.assertTrue(self.is_enabled_Accept_Track_Change())
+
+            # cursor in a not changed row: Accept Track Change is disabled
+            self.xUITest.executeCommand(".uno:GoDown")
+            xToolkit.processEventsToIdle()
+            while self.is_enabled_Accept_Track_Change():
+                time.sleep(0.1)
+            self.assertFalse(self.is_enabled_Accept_Track_Change())
+
+            # check the fix again to avoid of the asynchron state changes
+            self.xUITest.executeCommand(".uno:GoUp")
+            xToolkit.processEventsToIdle()
+            while not self.is_enabled_Accept_Track_Change():
+                time.sleep(0.1)
+            self.assertTrue(self.is_enabled_Accept_Track_Change())
+
+            # check 1-click accept of table row deletion (3 redlines in the 
row)
+
+            # not at changed text, but Accept Track Change removes the whole 
row now
+
+            tables = self.document.getTextTables()
+            self.assertEqual(len(tables[0].getRows()), 4)
+
+            self.xUITest.executeCommand(".uno:AcceptTrackedChange")
+            xToolkit.processEventsToIdle()
+            self.assertEqual(len(tables[0].getRows()), 3)
+
+            self.xUITest.executeCommand(".uno:Undo")
+            xToolkit.processEventsToIdle()
+            self.assertEqual(len(tables[0].getRows()), 4)
+
+            self.xUITest.executeCommand(".uno:Redo")
+            xToolkit.processEventsToIdle()
+            self.assertEqual(len(tables[0].getRows()), 3)
+
+            self.xUITest.executeCommand(".uno:Undo")
+            xToolkit.processEventsToIdle()
+            self.assertEqual(len(tables[0].getRows()), 4)
+
+            # check 1-click reject of table row insertion (3 redlines in the 
row)
+
+            for i in range(3):
+                self.xUITest.executeCommand(".uno:GoDown")
+
+            # not at changed text (the cursor is there at the end of the text 
of the table row),
+            # but Reject Track Change removes the whole row now
+
+            tables = self.document.getTextTables()
+            self.assertEqual(len(tables[0].getRows()), 4)
+
+            self.xUITest.executeCommand(".uno:RejectTrackedChange")
+            xToolkit.processEventsToIdle()
+            self.assertEqual(len(tables[0].getRows()), 3)
+
+            self.xUITest.executeCommand(".uno:Undo")
+            xToolkit.processEventsToIdle()
+            self.assertEqual(len(tables[0].getRows()), 4)
+
+            self.xUITest.executeCommand(".uno:Redo")
+            xToolkit.processEventsToIdle()
+            self.assertEqual(len(tables[0].getRows()), 3)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/uibase/uiview/view2.cxx 
b/sw/source/uibase/uiview/view2.cxx
index 6cb9340b758c..c6e2ff5db8f1 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -827,8 +827,59 @@ void SwView::Execute(SfxRequest &rReq)
                 else
                     pRedline = 
pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline);
 
-                assert(pRedline != nullptr);
-                if (pRedline)
+                // accept or reject table row deletion or insertion
+                bool bTableChange = false;
+                if ( !pRedline && m_pWrtShell->IsCursorInTable() )
+                {
+                    nRedline = 0;
+                    auto pTabLine = 
pCursor->Start()->nNode.GetNode().GetTableBox()->GetUpper();
+
+                    if ( RedlineType::None != pTabLine->GetRedlineType() )
+                    {
+                        nRedline = pTabLine->UpdateTextChangesOnly(nRedline);
+
+                        if ( nRedline != SwRedlineTable::npos )
+                        {
+                            bTableChange = true;
+
+                            SwWrtShell& rSh = GetWrtShell();
+                            SwRewriter aRewriter;
+
+                            aRewriter.AddRule(UndoArg1, SwResId(
+                                rRedlineTable[nRedline]->GetType() == 
RedlineType::Delete
+                                    ? STR_REDLINE_TABLE_ROW_DELETE
+                                    : STR_REDLINE_TABLE_ROW_INSERT ));
+
+                            SwUndoId eUndoId =
+                                (FN_REDLINE_ACCEPT_DIRECT == nSlot || 
FN_REDLINE_ACCEPT_TONEXT == nSlot)
+                                    ? SwUndoId::ACCEPT_REDLINE
+                                    : SwUndoId::REJECT_REDLINE;
+
+                            rSh.StartUndo( eUndoId, &aRewriter);
+                            while ( nRedline != SwRedlineTable::npos && 
nRedline < rRedlineTable.size() )
+                            {
+                                pRedline = rRedlineTable[nRedline];
+
+                                // until next redline is not in the same row
+                                SwTableBox* pTableBox = 
pRedline->Start()->nNode.GetNode().GetTableBox();
+                                if ( !pTableBox || pTableBox->GetUpper() != 
pTabLine )
+                                    break;
+
+                                if (FN_REDLINE_ACCEPT_DIRECT == nSlot || 
FN_REDLINE_ACCEPT_TONEXT == nSlot)
+                                    m_pWrtShell->AcceptRedline(nRedline);
+                                else
+                                    m_pWrtShell->RejectRedline(nRedline);
+                            }
+                            rSh.EndUndo( eUndoId, &aRewriter);
+                        }
+                    }
+                }
+                else
+                {
+                    assert(pRedline != nullptr);
+                }
+
+                if (pRedline && !bTableChange)
                 {
                     if (FN_REDLINE_ACCEPT_DIRECT == nSlot || 
FN_REDLINE_ACCEPT_TONEXT == nSlot)
                         m_pWrtShell->AcceptRedline(nRedline);
diff --git a/sw/source/uibase/uiview/viewstat.cxx 
b/sw/source/uibase/uiview/viewstat.cxx
index c2e94cb85479..e7ab14f6c3f8 100644
--- a/sw/source/uibase/uiview/viewstat.cxx
+++ b/sw/source/uibase/uiview/viewstat.cxx
@@ -408,8 +408,15 @@ void SwView::GetState(SfxItemSet &rSet)
                 {
                     // If the cursor position isn't on a redline, disable
                     // accepting/rejecting changes.
-                    if (nullptr == 
pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), nullptr))
+                    SwTableBox* pTableBox;
+                    if (nullptr == 
pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), nullptr) &&
+                       // except in the case of an inserted or deleted table 
row
+                       ( !m_pWrtShell->IsCursorInTable() ||
+                           (pTableBox = 
pCursor->Start()->nNode.GetNode().GetTableBox() ) == nullptr ||
+                           RedlineType::None == 
pTableBox->GetUpper()->GetRedlineType() ) )
+                    {
                         bDisable = true;
+                    }
                 }
 
                 // LibreOfficeKit wants to handle changes by index, so always 
allow here.

Reply via email to