From 52f70f04bdc586a072141e069d451a979c5f4cb7 Mon Sep 17 00:00:00 2001 From: László Németh Date: Mon, 5 Jun 2023 17:34:28 +0200 Subject: tdf#155344 sw tracked table column: 1-click Accept/Reject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now context menu of a changed table column shows Accept Change/ Reject Change menu items, which accept or reject the deletion or insertion of the table column(s). 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: Column Inserted" "Accept change: Column Deleted" "Reject change: Column Inserted" "Reject change: Column Deleted" Follow-up to commit ffd8d20d368a885d6d786749278fa438573227a7 "tdf#150673 sw xmloff: import/export tracked table column". Change-Id: Idff570dfcf8c3ce35b6223f801608779bf1cd28e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152626 Tested-by: László Németh Reviewed-by: László Németh --- sw/source/uibase/uiview/view2.cxx | 73 +++++++++++++++++++++++++++++++++++- sw/source/uibase/uiview/viewstat.cxx | 3 +- 2 files changed, 74 insertions(+), 2 deletions(-) (limited to 'sw/source') diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index 45dcfddb0be4..02823bb43b56 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -927,7 +927,9 @@ void SwView::Execute(SfxRequest &rReq) if ( !pRedline && m_pWrtShell->IsCursorInTable() ) { nRedline = 0; - auto pTabLine = pCursor->Start()->GetNode().GetTableBox()->GetUpper(); + auto pTabBox = pCursor->Start()->GetNode().GetTableBox(); + auto pTabLine = pTabBox->GetUpper(); + const SwTableNode* pTableNd = pCursor->Start()->GetNode().FindTableNode(); if ( RedlineType::None != pTabLine->GetRedlineType() ) { @@ -968,6 +970,75 @@ void SwView::Execute(SfxRequest &rReq) rSh.EndUndo( eUndoId, &aRewriter); } } + else if ( RedlineType::None != pTabBox->GetRedlineType() ) + { + nRedline = pTabBox->GetRedline(); + + if ( nRedline != SwRedlineTable::npos ) + { + bTableChange = true; + + SwWrtShell& rSh = GetWrtShell(); + SwRewriter aRewriter; + + aRewriter.AddRule(UndoArg1, SwResId( + rRedlineTable[nRedline]->GetType() == RedlineType::Delete + ? STR_REDLINE_TABLE_COLUMN_DELETE + : STR_REDLINE_TABLE_COLUMN_INSERT )); + + SwUndoId eUndoId = + (FN_REDLINE_ACCEPT_DIRECT == nSlot || FN_REDLINE_ACCEPT_TONEXT == nSlot) + ? SwUndoId::ACCEPT_REDLINE + : SwUndoId::REJECT_REDLINE; + + // change only the cells with the same data + SwRedlineData aData(rRedlineTable[nRedline]->GetRedlineData(0)); + + // start from the first redline of the table to handle all the + // cells of the changed column(s) + while ( nRedline ) + { + pRedline = rRedlineTable[nRedline-1]; + SwTableBox* pTableBox = pRedline->Start()->GetNode().GetTableBox(); + SwTableNode* pTableNode = pRedline->Start()->GetNode().FindTableNode(); + + // previous redline is not in the same table + if ( !pTableBox || pTableNode != pTableNd ) + break; + + --nRedline; + } + + rSh.StartUndo( eUndoId, &aRewriter); + while ( nRedline != SwRedlineTable::npos && nRedline < rRedlineTable.size() ) + { + pRedline = rRedlineTable[nRedline]; + + // until next redline is not in the same table + SwTableBox* pTableBox = pRedline->Start()->GetNode().GetTableBox(); + SwTableNode* pTableNode = pRedline->Start()->GetNode().FindTableNode(); + if ( !pTableBox || pTableNode != pTableNd ) + break; + + // skip cells which are not from the same author, same type change + // or timestamp, i.e. keep only the cells of the same tracked + // column insertion or deletion + if ( !pRedline->GetRedlineData(0).CanCombine(aData) || + // not a tracked cell change + RedlineType::None == pTableBox->GetRedlineType() ) + { + ++nRedline; + continue; + } + + 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 { diff --git a/sw/source/uibase/uiview/viewstat.cxx b/sw/source/uibase/uiview/viewstat.cxx index 2bd753569ab0..9f44aa214996 100644 --- a/sw/source/uibase/uiview/viewstat.cxx +++ b/sw/source/uibase/uiview/viewstat.cxx @@ -429,7 +429,8 @@ void SwView::GetState(SfxItemSet &rSet) // except in the case of an inserted or deleted table row ( !m_pWrtShell->IsCursorInTable() || (pTableBox = pCursor->Start()->GetNode().GetTableBox() ) == nullptr || - RedlineType::None == pTableBox->GetUpper()->GetRedlineType() ) ) + (RedlineType::None == pTableBox->GetRedlineType() && + RedlineType::None == pTableBox->GetUpper()->GetRedlineType()) ) ) { bDisable = true; } -- cgit