sw/qa/extras/uiwriter/uiwriter4.cxx | 55 ++++++++++++++++++++++++++++++++++++ sw/source/core/edit/edredln.cxx | 46 ++++++++++++++++++++++++++++-- sw/source/uibase/uiview/view2.cxx | 14 ++++++++- 3 files changed, 112 insertions(+), 3 deletions(-)
New commits: commit d4a503a030706bf609e498e25888d400cc5aaefa Author: László Németh <nem...@numbertext.org> AuthorDate: Wed Feb 9 12:15:33 2022 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Thu Feb 10 09:37:10 2022 +0100 tdf#147182 sw: accept/reject all changes of a table selection Selecting multiple cells of a text table which contain tracked text changes, and choosing Accept Track Change/Reject Track Change, only text changes of the first cell were accepted/rejected (a problem inherited from OOo). The fix allows to accept/reject also all tracked row deletions/insertions in the selected table rows by a single click. Note for manual testing: first cell of the selection should still contain a tracked change, otherwise Accept Track Change/ Reject Track Change menu items/icons aren't active. Conflicts: sw/qa/extras/uiwriter/uiwriter4.cxx Change-Id: I11e71075f4144bba86dda690ec712a24ccf815dd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129717 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry-picked from commit 23846867ea32667ccf328c36142394dd6aaee8ba) Change-Id: I0d04de5b4c482e64ffd1a3b166968163139e7791 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129743 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index f7ff97ca1f02..aa807418e348 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -202,6 +202,7 @@ public: void testTableRedlineRedoCrash(); void testTableRemoveHasTextChangesOnly(); void testTableRemoveHasTextChangesOnly2(); + void testTdf147182_AcceptAllChangesInTableSelection(); void testTdf66405(); void testTdf35021_tabOverMarginDemo(); void testTdf106701_tabOverMarginAutotab(); @@ -329,6 +330,7 @@ public: CPPUNIT_TEST(testTableRedlineRedoCrash); CPPUNIT_TEST(testTableRemoveHasTextChangesOnly); CPPUNIT_TEST(testTableRemoveHasTextChangesOnly2); + CPPUNIT_TEST(testTdf147182_AcceptAllChangesInTableSelection); CPPUNIT_TEST(testTdf66405); CPPUNIT_TEST(testTdf35021_tabOverMarginDemo); CPPUNIT_TEST(testTdf106701_tabOverMarginAutotab); @@ -1657,6 +1659,59 @@ void SwUiWriterTest4::testTableRemoveHasTextChangesOnly2() CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(14), pEditShell->GetRedlineCount()); } +void SwUiWriterTest4::testTdf147182_AcceptAllChangesInTableSelection() +{ + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "TC-table-del-add.docx"); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + // check redline count + SwEditShell* const pEditShell(pDoc->GetEditShell()); + CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(14), pEditShell->GetRedlineCount()); + + // 4 rows in Show Changes mode + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + assertXPath(pXmlDoc, "/root/page[1]/body/tab[1]/row", 4); + + // Select the first table to get a table selection + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:AcceptTrackedChange", {}); + Scheduler::ProcessEventsToIdle(); + discardDumpedLayout(); + pXmlDoc = parseLayoutDump(); + // Accepting tracked changes in the selected table results 3 rows + // This was 4 (only text changes of the first selected cell were accepted) + assertXPath(pXmlDoc, "/root/page[1]/body/tab[1]/row", 3); + CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(8), pEditShell->GetRedlineCount()); + + // Undo: 4 rows again + pDoc->GetIDocumentUndoRedo().Undo(); + discardDumpedLayout(); + pXmlDoc = parseLayoutDump(); + assertXPath(pXmlDoc, "/root/page[1]/body/tab[1]/row", 4); + CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(14), pEditShell->GetRedlineCount()); + + // To check Undo of HasTextChangesOnly reject the same row results 3 rows + dispatchCommand(mxComponent, ".uno:Escape", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:RejectTrackedChange", {}); + Scheduler::ProcessEventsToIdle(); + discardDumpedLayout(); + pXmlDoc = parseLayoutDump(); + // This was 4 (only text changes of the first selected cell were rejected) + assertXPath(pXmlDoc, "/root/page[1]/body/tab[1]/row", 3); + + // Undo: 4 rows again + pDoc->GetIDocumentUndoRedo().Undo(); + discardDumpedLayout(); + pXmlDoc = parseLayoutDump(); + assertXPath(pXmlDoc, "/root/page[1]/body/tab[1]/row", 4); + CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(14), pEditShell->GetRedlineCount()); +} + void SwUiWriterTest4::testTdf66405() { // Imported formula should have zero margins diff --git a/sw/source/core/edit/edredln.cxx b/sw/source/core/edit/edredln.cxx index 3fd94b4a64d5..835a1c37389c 100644 --- a/sw/source/core/edit/edredln.cxx +++ b/sw/source/core/edit/edredln.cxx @@ -90,7 +90,28 @@ bool SwEditShell::AcceptRedlinesInSelection() { CurrShell aCurr( this ); StartAllAction(); - bool bRet = GetDoc()->getIDocumentRedlineAccess().AcceptRedline( *GetCursor(), true ); + // in table selection mode, process the selected boxes in reverse order + // to allow accepting their text changes and the tracked row deletions + bool bRet = false; + if ( IsTableMode() ) + { + const SwSelBoxes& rBoxes = GetTableCursor()->GetSelectedBoxes(); + std::vector<std::unique_ptr<SwPaM>> vBoxes; + for(auto pBox : rBoxes) + { + if ( !pBox->IsEmpty() ) + { + const SwStartNode *pSttNd = pBox->GetSttNd(); + SwNode* pEndNode = pSttNd->GetNodes()[pSttNd->EndOfSectionIndex()]; + vBoxes.push_back(std::unique_ptr<SwPaM>(new SwPaM(*pEndNode, 0, *pSttNd, 0))); + } + } + + for (size_t i = 0; i < vBoxes.size(); ++i) + bRet |= GetDoc()->getIDocumentRedlineAccess().AcceptRedline( *vBoxes[vBoxes.size()-i-1], true ); + } + else + bRet = GetDoc()->getIDocumentRedlineAccess().AcceptRedline( *GetCursor(), true ); EndAllAction(); return bRet; } @@ -99,7 +120,28 @@ bool SwEditShell::RejectRedlinesInSelection() { CurrShell aCurr( this ); StartAllAction(); - bool bRet = GetDoc()->getIDocumentRedlineAccess().RejectRedline( *GetCursor(), true ); + bool bRet = false; + // in table selection mode, process the selected boxes in reverse order + // to allow rejecting their text changes and the tracked row insertions + if ( IsTableMode() ) + { + const SwSelBoxes& rBoxes = GetTableCursor()->GetSelectedBoxes(); + std::vector<std::unique_ptr<SwPaM>> vBoxes; + for(auto pBox : rBoxes) + { + if ( !pBox->IsEmpty() ) + { + const SwStartNode *pSttNd = pBox->GetSttNd(); + SwNode* pEndNode = pSttNd->GetNodes()[pSttNd->EndOfSectionIndex()]; + vBoxes.push_back(std::unique_ptr<SwPaM>(new SwPaM(*pEndNode, 0, *pSttNd, 0))); + } + } + + for (size_t i = 0; i < vBoxes.size(); ++i) + bRet |= GetDoc()->getIDocumentRedlineAccess().RejectRedline( *vBoxes[vBoxes.size()-i-1], true ); + } + else + bRet = GetDoc()->getIDocumentRedlineAccess().RejectRedline( *GetCursor(), true ); EndAllAction(); return bRet; } diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index c6e2ff5db8f1..b96a54625ab2 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -804,10 +804,22 @@ void SwView::Execute(SfxRequest &rReq) if( pCursor->HasMark() && nRedline == SwRedlineTable::npos) { - if (FN_REDLINE_ACCEPT_DIRECT == nSlot || FN_REDLINE_ACCEPT_TONEXT == nSlot) + bool bAccept = FN_REDLINE_ACCEPT_DIRECT == nSlot || FN_REDLINE_ACCEPT_TONEXT == nSlot; + SwUndoId eUndoId = bAccept ? SwUndoId::ACCEPT_REDLINE : SwUndoId::REJECT_REDLINE; + SwWrtShell& rSh = GetWrtShell(); + SwRewriter aRewriter; + bool bTableSelection = rSh.IsTableMode(); + if ( bTableSelection ) + { + aRewriter.AddRule(UndoArg1, SwResId( STR_REDLINE_TABLECHG )); + rSh.StartUndo( eUndoId, &aRewriter); + } + if ( bAccept ) m_pWrtShell->AcceptRedlinesInSelection(); else m_pWrtShell->RejectRedlinesInSelection(); + if ( bTableSelection ) + rSh.EndUndo( eUndoId, &aRewriter); } else {