sw/qa/extras/uiwriter/uiwriter4.cxx | 53 ++++++++++++++++++++++++++++++++++++ sw/source/core/edit/edredln.cxx | 46 +++++++++++++++++++++++++++++-- sw/source/uibase/uiview/view2.cxx | 14 ++++++++- 3 files changed, 110 insertions(+), 3 deletions(-)
New commits: commit 23846867ea32667ccf328c36142394dd6aaee8ba 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: Wed Feb 9 21:39:30 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. 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> diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index e52318062a7d..6b0724eae54e 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -1533,6 +1533,59 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTableRemoveHasTextChangesOnly2) CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(14), pEditShell->GetRedlineCount()); } +CPPUNIT_TEST_FIXTURE(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()); +} + CPPUNIT_TEST_FIXTURE(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 088de02af581..17acec2e3da7 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -805,10 +805,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 {