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 a7c1163684fa5c0376efebe8dc6225a7dfb8e700 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Wed Jul 17 19:01:27 2024 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Thu Jul 18 15:45:32 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 diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 5a366a86a6cc..a3fa61143214 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1256,7 +1256,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 b032a0b05b7b..6e4466dc60d7 100644 --- a/sw/inc/fesh.hxx +++ b/sw/inc/fesh.hxx @@ -733,6 +733,7 @@ public: /// Set table style of the current table. void SetTableStyle(const OUString& rStyleName); SW_DLLPUBLIC bool SetTableStyle(const SwTableAutoFormat& rNew); + SW_DLLPUBLIC 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 a27ad9a32707..a3f2de6507f3 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 696915947bf1..eda5200dba0c 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 8206cb508574..ca05712486e2 100644 --- a/sw/source/ui/table/tautofmt.cxx +++ b/sw/source/ui/table/tautofmt.cxx @@ -119,14 +119,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; - } + // Expand list with 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++) { @@ -395,7 +391,12 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, SelFormatHdl, weld::TreeView&, void) void SwAutoFormatDlg::Apply() { if (m_bSetAutoFormat) - m_pShell->SetTableStyle((*m_xTableTable)[m_nIndex]); + { + if (m_nIndex == 255) + m_pShell->ResetTableStyle(); + else + m_pShell->SetTableStyle((*m_xTableTable)[m_nIndex]); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */