Resolves: tdf#161430 reindex the correct style if there are duplicate names
Change-Id: I6d4e96faef3ec6caa038edf7595f91f20d964807
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168436
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
diff --git a/include/svl/IndexedStyleSheets.hxx b/include/svl/IndexedStyleSheets.hxx
index c58a4b7..4904d53 100644
--- a/include/svl/IndexedStyleSheets.hxx
+++ b/include/svl/IndexedStyleSheets.hxx
@@ -144,7 +144,8 @@ public:
void Clear(StyleSheetDisposer& cleanup);
void Reindex();
void ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName);
void ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName,
const OUString& rNewName);
/** Warning: counting for n starts at 0, i.e., the 0th style sheet is the first that is found. */
SfxStyleSheetBase* GetNthStyleSheetThatMatchesPredicate(sal_Int32 n,
diff --git a/include/svl/style.hxx b/include/svl/style.hxx
index 87c5563..eeab434 100644
--- a/include/svl/style.hxx
+++ b/include/svl/style.hxx
@@ -275,7 +275,7 @@ public:
virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
void Reindex();
void ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName);
void ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName);
/** Add a style sheet.
* Not an actual public function. Do not call it from non-subclasses.
*/
diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx
index 3761f0e..90df6be 100644
--- a/svl/source/items/IndexedStyleSheets.cxx
+++ b/svl/source/items/IndexedStyleSheets.cxx
@@ -83,14 +83,18 @@ sal_Int32 IndexedStyleSheets::GetNumberOfStyleSheets() const
}
void
IndexedStyleSheets::ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName)
IndexedStyleSheets::ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName)
{
auto it = mPositionsByName.find(rOldName);
if (it != mPositionsByName.end())
std::pair<MapType::const_iterator, MapType::const_iterator> range = mPositionsByName.equal_range(rOldName);
for (MapType::const_iterator it = range.first; it != range.second; ++it)
{
unsigned nPos = it->second;
mPositionsByName.erase(it);
mPositionsByName.insert(std::make_pair(rNewName, nPos));
if (mStyleSheets[it->second].get() == &style)
{
unsigned nPos = it->second;
mPositionsByName.erase(it);
mPositionsByName.insert(std::make_pair(rNewName, nPos));
break;
}
}
}
diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx
index bfdbac6..916b162 100644
--- a/svl/source/items/style.cxx
+++ b/svl/source/items/style.cxx
@@ -178,7 +178,7 @@ bool SfxStyleSheetBase::SetName(const OUString& rName, bool bReIndexNow)
aFollow = rName;
aName = rName;
if (bReIndexNow)
m_pPool->ReindexOnNameChange(aOldName, rName);
m_pPool->ReindexOnNameChange(*this, aOldName, rName);
m_pPool->Broadcast( SfxStyleSheetModifiedHint( aOldName, *this ) );
return true;
@@ -891,9 +891,9 @@ SfxStyleSheetBasePool::Reindex()
}
void
SfxStyleSheetBasePool::ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName)
SfxStyleSheetBasePool::ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName)
{
pImpl->mxIndexedStyleSheets->ReindexOnNameChange(rOldName, rNewName);
pImpl->mxIndexedStyleSheets->ReindexOnNameChange(style, rOldName, rNewName);
}
const svl::IndexedStyleSheets&