diff options
author | László Németh <nemeth@numbertext.org> | 2022-04-22 13:23:55 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2022-04-22 19:24:17 +0200 |
commit | 0204c00f241313e1d292b4c3ea117d42af7dec69 (patch) | |
tree | 1e0abec3719f82244c7755103dd0fb40362d55f1 | |
parent | 9c8029866146b43014ecc7b08f7cd9b73045844f (diff) |
tdf#147453 sw: disable Delete Table functions on tracked deletions
In Show Changes mode, disable "Delete Selected Rows" icons
and the same menu options in the following cases:
- no table selection, but the text cursor in a deleted table row;
- with table selection, all selected cells in deleted table rows.
Disable also "Deleted Selected Columns" and "Delete Table"
icons and the same menu options, when the cursor is there
in a deleted table.
Follow-up to commit c4f6fee3bea0d8618b5815e60304ff9359ccd21c
"tdf#147435 sw: enable Accept Change for table selection".
Change-Id: Ic6781ccee794c7458e6979f2e981840339cd3883
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133320
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/source/uibase/shells/tabsh.cxx | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx index a7136e38ba17..9dbb1b689e8e 100644 --- a/sw/source/uibase/shells/tabsh.cxx +++ b/sw/source/uibase/shells/tabsh.cxx @@ -55,6 +55,7 @@ #include <fmtfsize.hxx> #include <swmodule.hxx> #include <wrtsh.hxx> +#include <rootfrm.hxx> #include <wview.hxx> #include <frmatr.hxx> #include <uitool.hxx> @@ -443,6 +444,43 @@ static void lcl_TabGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLi rBorderLine.SetColor(pBorderLine->GetColor()); } +static bool lcl_BoxesInDeletedRows(SwWrtShell &rSh, const SwSelBoxes& rBoxes) +{ + // cursor and selection are there only in deleted rows in Show Changes mode + if ( rSh.GetLayout()->IsHideRedlines() ) + return false; + + // not selected or all selected rows are deleted + bool bRet = true; + SwRedlineTable::size_type nRedlinePos = 0; + if ( rBoxes.empty() ) + bRet = rSh.GetCursor()->GetNode().GetTableBox()->GetUpper()->IsDeleted(nRedlinePos); + else + { + tools::Long nBoxes = rBoxes.size(); + SwTableLine* pPrevLine = nullptr; + for ( tools::Long i = 0; i < nBoxes; i++ ) + { + SwTableLine* pLine = rBoxes[i]->GetUpper(); + if ( pLine != pPrevLine ) + bRet &= pLine->IsDeleted(nRedlinePos); + pPrevLine = pLine; + } + } + + return bRet; +} + +static bool lcl_CursorInDeletedTable(SwWrtShell &rSh) +{ + // cursor and selection are there only in deleted table in Show Changes mode + if ( rSh.GetLayout()->IsHideRedlines() ) + return false; + + SwTableNode* pTableNd = rSh.GetCursor()->GetPoint()->nNode.GetNode().FindTableNode(); + return pTableNd && pTableNd->GetTable().IsDeleted(); +} + void SwTableShell::Execute(SfxRequest &rReq) { const SfxItemSet* pArgs = rReq.GetArgs(); @@ -1380,7 +1418,7 @@ void SwTableShell::GetState(SfxItemSet &rSet) { SwSelBoxes aBoxes; ::GetTableSel( rSh, aBoxes, SwTableSearchType::Row ); - if( ::HasProtectedCells( aBoxes )) + if( ::HasProtectedCells( aBoxes ) || lcl_BoxesInDeletedRows( rSh, aBoxes ) ) rSet.DisableItem( nSlot ); } break; @@ -1388,10 +1426,14 @@ void SwTableShell::GetState(SfxItemSet &rSet) { SwSelBoxes aBoxes; ::GetTableSel( rSh, aBoxes, SwTableSearchType::Col ); - if( ::HasProtectedCells( aBoxes )) + if( ::HasProtectedCells( aBoxes ) || lcl_CursorInDeletedTable( rSh ) ) rSet.DisableItem( nSlot ); } break; + case FN_TABLE_DELETE_TABLE: + if( lcl_CursorInDeletedTable( rSh ) ) + rSet.DisableItem( nSlot ); + break; case FN_TABLE_UNSET_READ_ONLY_CELLS: // disable in readonly sections, but enable in protected cells |