sw/inc/doc.hxx | 2 +- sw/inc/fesh.hxx | 1 + sw/source/core/docnode/ndtbl.cxx | 8 +++++--- sw/source/core/frmedt/fetab.cxx | 26 ++++++++++++++++++++++++-- sw/source/ui/table/tautofmt.cxx | 19 ++++++++++--------- 5 files changed, 41 insertions(+), 15 deletions(-)
New commits: commit 828cc5e63ece8a9c1004c3cc9213e004871871f7 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Wed Jul 17 19:01:27 2024 +0200 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Wed Jul 24 08:37:33 2024 +0200 (related tdf#126008) sw: allow removing table autoformat from a table ... via the Table->AutoFormat Styles... dialog: add a "None" option like already exists in Table->Insert Table... Change-Id: I41d5cb0a7dcd1bfe3e93fe56f0f42765149ff42b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170641 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Tested-by: Jenkins (cherry picked from commit a7c1163684fa5c0376efebe8dc6225a7dfb8e700) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170695 Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 946c96fd29db..b5028561fb66 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1255,7 +1255,7 @@ public: /// AutoFormat for table/table selection. /// @param bResetDirect Reset direct formatting that might be applied to the cells. - bool SetTableAutoFormat(const SwSelBoxes& rBoxes, const SwTableAutoFormat& rNew, bool bResetDirect = false, bool isSetStyleName = false); + bool SetTableAutoFormat(const SwSelBoxes& rBoxes, const SwTableAutoFormat& rNew, bool bResetDirect = false, OUString const* pStyleNameToSet = nullptr); // Query attributes. bool GetTableAutoFormat( const SwSelBoxes& rBoxes, SwTableAutoFormat& rGet ); diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx index 3d2ba0308ce2..974d8120474b 100644 --- a/sw/inc/fesh.hxx +++ b/sw/inc/fesh.hxx @@ -734,6 +734,7 @@ public: /// Set table style of the current table. void SetTableStyle(const OUString& rStyleName); bool SetTableStyle(const SwTableAutoFormat& rNew); + bool ResetTableStyle(); /// Update the direct formatting according to the current table style. /// @param pTableNode Table node to update. When nullptr, current cursor position is used. diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index f3b3a07d63b5..8c9490fbf4e7 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -3767,7 +3767,9 @@ static bool lcl_SetAFormatBox(FndBox_ & rBox, SetAFormatTabPara *pSetPara, bool return true; } -bool SwDoc::SetTableAutoFormat(const SwSelBoxes& rBoxes, const SwTableAutoFormat& rNew, bool bResetDirect, bool const isSetStyleName) +bool SwDoc::SetTableAutoFormat(const SwSelBoxes& rBoxes, + const SwTableAutoFormat& rNew, bool bResetDirect, + OUString const*const pStyleNameToSet) { OSL_ENSURE( !rBoxes.empty(), "No valid Box list" ); SwTableNode* pTableNd = const_cast<SwTableNode*>(rBoxes[0]->GetSttNd()->FindTableNode()); @@ -3806,9 +3808,9 @@ bool SwDoc::SetTableAutoFormat(const SwSelBoxes& rBoxes, const SwTableAutoFormat GetIDocumentUndoRedo().DoUndo(false); } - if (isSetStyleName) + if (pStyleNameToSet) { // tdf#98226 do this here where undo can record it - pTableNd->GetTable().SetTableStyleName(rNew.GetName()); + pTableNd->GetTable().SetTableStyleName(*pStyleNameToSet); } rNew.RestoreTableProperties(table); diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx index 72b093a87a1c..25270568df52 100644 --- a/sw/source/core/frmedt/fetab.cxx +++ b/sw/source/core/frmedt/fetab.cxx @@ -66,6 +66,7 @@ #include <fmtrowsplt.hxx> #include <node.hxx> #include <sortedobjs.hxx> +#include <shellres.hxx> using namespace ::com::sun::star; @@ -1403,6 +1404,16 @@ void SwFEShell::SetTableStyle(const OUString& rStyleName) UpdateTableStyleFormatting(pTableNode, false, &rStyleName); } +bool SwFEShell::ResetTableStyle() +{ + SwTableNode *pTableNode = const_cast<SwTableNode*>(IsCursorInTable()); + if (!pTableNode) + return false; + + OUString takingAddressOfRValue; + return UpdateTableStyleFormatting(pTableNode, false, &takingAddressOfRValue); +} + // AutoFormat for the table/table selection bool SwFEShell::SetTableStyle(const SwTableAutoFormat& rStyle) { @@ -1430,7 +1441,18 @@ bool SwFEShell::UpdateTableStyleFormatting(SwTableNode *pTableNode, OUString const aTableStyleName(pStyleName ? *pStyleName : pTableNode->GetTable().GetTableStyleName()); - SwTableAutoFormat* pTableStyle = GetDoc()->GetTableStyles().FindAutoFormat(aTableStyleName); + + std::unique_ptr<SwTableAutoFormat> pNone; + SwTableAutoFormat* pTableStyle; + if (pStyleName && pStyleName->isEmpty()) + { + pNone.reset(new SwTableAutoFormat(SwViewShell::GetShellRes()->aStrNone)); + pTableStyle = pNone.get(); + } + else + { + pTableStyle = GetDoc()->GetTableStyles().FindAutoFormat(aTableStyleName); + } if (!pTableStyle) return false; @@ -1455,7 +1477,7 @@ bool SwFEShell::UpdateTableStyleFormatting(SwTableNode *pTableNode, CurrShell aCurr( this ); StartAllAction(); bRet = GetDoc()->SetTableAutoFormat( - aBoxes, *pTableStyle, bResetDirect, pStyleName != nullptr); + aBoxes, *pTableStyle, bResetDirect, pStyleName); ClearFEShellTabCols(*GetDoc(), nullptr); EndAllActionAndCall(); } diff --git a/sw/source/ui/table/tautofmt.cxx b/sw/source/ui/table/tautofmt.cxx index 8dbc965e80ba..0e55bb1ade1c 100644 --- a/sw/source/ui/table/tautofmt.cxx +++ b/sw/source/ui/table/tautofmt.cxx @@ -125,14 +125,10 @@ void SwAutoFormatDlg::Init( const SwTableAutoFormat* pSelFormat ) m_xBtnAdd->set_sensitive(m_bSetAutoFormat); - m_nIndex = 0; - if( !m_bSetAutoFormat ) - { - // Then the list to be expanded by the entry "- none -". - m_xLbFormat->append_text(SwViewShell::GetShellRes()->aStrNone); - m_nDfltStylePos = 1; - m_nIndex = 255; - } + // Then the list to be expanded by the entry "- none -". + m_xLbFormat->append_text(SwViewShell::GetShellRes()->aStrNone); + m_nDfltStylePos = 1; + m_nIndex = 255; for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(m_xTableTable->size()); i < nCount; i++) @@ -401,7 +397,12 @@ short SwAutoFormatDlg::run() { short nRet = SfxDialogController::run(); if (nRet == RET_OK && m_bSetAutoFormat) - m_pShell->SetTableStyle((*m_xTableTable)[m_nIndex]); + { + if (m_nIndex == 255) + m_pShell->ResetTableStyle(); + else + m_pShell->SetTableStyle((*m_xTableTable)[m_nIndex]); + } return nRet; }