sw/qa/extras/unowriter/data/tdf164921.odt |binary sw/qa/extras/unowriter/unowriter.cxx | 44 ++++++++++++++++++++++++++++++ sw/source/core/doc/docnum.cxx | 19 +++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-)
New commits: commit fe1a74c68b892d01bf5d8be9aed90c12c5bf6abd Author: Oliver Specht <oliver.spe...@cib.de> AuthorDate: Wed Jan 29 12:38:55 2025 +0100 Commit: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> CommitDate: Tue Feb 11 23:05:52 2025 +0100 tdf#164921 Renaming list styles fixed User defined list styles are now correctly updated in paragraph styles that are using them and only directly applied to paragraphs that had a direct formating before. Change-Id: I9b671655ffa430d643c48fc35f15f38b41de4b9b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180892 Reviewed-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> Tested-by: Jenkins diff --git a/sw/qa/extras/unowriter/data/tdf164921.odt b/sw/qa/extras/unowriter/data/tdf164921.odt new file mode 100644 index 000000000000..b24b4b6f3299 Binary files /dev/null and b/sw/qa/extras/unowriter/data/tdf164921.odt differ diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index fee61f62b819..0e74fb83cdde 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -47,6 +47,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/compbase.hxx> +#include <unotools/mediadescriptor.hxx> #include <wrtsh.hxx> #include <ndtxt.hxx> @@ -1516,6 +1517,49 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testTdf164885) CPPUNIT_ASSERT_EQUAL(u".uno:Open"_ustr, interceptor->pDispatch->sLastCommand); } +CPPUNIT_TEST_FIXTURE(SwUnoWriter, testTdf164921) +{ + // check renaming list style + OUString sChangedListStyle = u"ChangedListStyle"_ustr; + + { + createSwDoc("tdf164921.odt"); + //change list style name + //auto xModel = mxComponent.queryThrow<frame::XModel>(); + uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XNameContainer> xListStyles( + xSFS->getStyleFamilies()->getByName(u"NumberingStyles"_ustr), uno::UNO_QUERY); + uno::Reference<container::XNamed> xListStyle(xListStyles->getByName(u"NewListStyle"_ustr), + uno::UNO_QUERY); + xListStyle->setName(sChangedListStyle); + + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor[u"FilterName"_ustr] <<= u"writer8"_ustr; + uno::Reference<frame::XStorable> const xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + } + { + saveAndReload(u"writer8"_ustr); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XNameContainer> xListStyles( + xSFS->getStyleFamilies()->getByName(u"NumberingStyles"_ustr), uno::UNO_QUERY); + uno::Reference<container::XNamed> xNewListStyle( + xListStyles->getByName(u"ChangedListStyle"_ustr), uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(xNewListStyle->getName(), sChangedListStyle); + + uno::Reference<container::XNameContainer> xParaStyles( + xSFS->getStyleFamilies()->getByName(u"ParagraphStyles"_ustr), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xBodyTextStyle(xParaStyles->getByName("Text body"), + uno::UNO_QUERY); + + rtl::OUString sListStyleName; + xBodyTextStyle->getPropertyValue(u"NumberingStyleName"_ustr) >>= sListStyleName; + CPPUNIT_ASSERT_EQUAL(sListStyleName, sChangedListStyle); + } +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index afbdfe7b63dc..c33c4fd77e49 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -1232,12 +1232,27 @@ bool SwDoc::RenameNumRule(const OUString & rOldName, const OUString & rNewName, pNumRule->GetTextNodeList( aTextNodeList ); pNumRule->SetName( rNewName, getIDocumentListsAccess() ); - SwNumRuleItem aItem(rNewName); + const size_t nArrLen = GetTextFormatColls()->size(); + for( size_t i = 0; i < nArrLen; i++ ) + { + SwTextFormatColl* pColl = (*GetTextFormatColls())[ i ]; + const SwAttrSet& rAttrSet = pColl->GetAttrSet(); + + const SfxPoolItem* pTempItem = nullptr; + if (SfxItemState::SET == rAttrSet.GetItemState(RES_PARATR_NUMRULE, false, &pTempItem)) + { + const SwNumRuleItem* pNumItem = static_cast<const SwNumRuleItem*>(pTempItem); + if (pNumItem->GetValue().equals(rOldName)) + pColl->SetFormatAttr( aItem ); + } + } + for ( SwTextNode* pTextNd : aTextNodeList ) { - pTextNd->SetAttr(aItem); + if (SfxItemState::SET == pTextNd->GetSwAttrSet().GetItemState(RES_PARATR_NUMRULE, false)) + pTextNd->SetAttr(aItem); } bResult = true;