svx/source/tbxctrls/StylesPreviewWindow.cxx |   50 +++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 12 deletions(-)

New commits:
commit 46914195fb557f573a25b7b9a297d5d4c16f0d7e
Author:     Szymon Kłos <[email protected]>
AuthorDate: Mon Nov 17 08:29:11 2025 +0000
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Mon Nov 17 14:12:46 2025 +0100

    notebookbar: style previews should show user defined styles
    
    - favourites are only supported in docx so far
    - user defined were previously shown too
    - avoid duplicates in the icon view
    
    Change-Id: Ic58c8a2e036d8b218c992999310357335ebdd553
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194094
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx 
b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index 4384281dafaf..e2e785037908 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -527,7 +527,10 @@ void StylesPreviewWindow_Base::Select(const OUString& 
rStyleName)
 
 void StylesPreviewWindow_Base::UpdateSelection()
 {
-    for (std::vector<std::pair<OUString, OUString>>::size_type i = 0; i < 
m_aAllStyles.size(); ++i)
+    if (!m_xStylesView || !m_xStylesView->n_children())
+        return;
+
+    for (StylePreviewList::size_type i = 0; i < m_aAllStyles.size(); ++i)
     {
         if (m_aAllStyles[i].first == m_sSelectedStyle || 
m_aAllStyles[i].second == m_sSelectedStyle)
         {
@@ -615,6 +618,36 @@ OString 
StylesPreviewWindow_Base::GetCachedPreviewJson(const StylePreviewDescrip
     return sResult;
 }
 
+namespace
+{
+inline void lcl_AppendParaStyles(StylePreviewList& rAllStyles, 
SfxStyleSheetBasePool* pPool,
+                                 SfxStyleSearchBits eBits)
+{
+    if (!pPool)
+        return;
+
+    auto xIter = pPool->CreateIterator(SfxStyleFamily::Para, eBits);
+
+    SfxStyleSheetBase* pStyle = xIter->First();
+
+    while (pStyle)
+    {
+        const OUString sName(pStyle->GetName());
+
+        // do not duplicate
+        const auto aFound = std::find_if(
+            rAllStyles.begin(), rAllStyles.end(), [sName](const 
StylePreviewDescriptor& element) {
+                return element.first == sName || element.second == sName;
+            });
+
+        if (aFound == rAllStyles.end())
+            rAllStyles.push_back(StylePreviewDescriptor(sName, sName));
+
+        pStyle = xIter->Next();
+    }
+}
+}
+
 void StylesPreviewWindow_Base::UpdateStylesList()
 {
     m_aAllStyles = m_aDefaultStyles;
@@ -623,20 +656,13 @@ void StylesPreviewWindow_Base::UpdateStylesList()
     SfxStyleSheetBasePool* pStyleSheetPool = nullptr;
 
     if (pDocShell)
-        pStyleSheetPool = pDocShell->GetStyleSheetPool();
-
-    if (pStyleSheetPool)
     {
-        auto xIter
-            = pStyleSheetPool->CreateIterator(SfxStyleFamily::Para, 
SfxStyleSearchBits::Favourite);
-
-        SfxStyleSheetBase* pStyle = xIter->First();
+        pStyleSheetPool = pDocShell->GetStyleSheetPool();
 
-        while (pStyle)
+        if (pStyleSheetPool)
         {
-            OUString sName(pStyle->GetName());
-            m_aAllStyles.push_back(std::pair<OUString, OUString>(sName, 
sName));
-            pStyle = xIter->Next();
+            lcl_AppendParaStyles(m_aAllStyles, pStyleSheetPool,
+                                 SfxStyleSearchBits::Favourite | 
SfxStyleSearchBits::UserDefined);
         }
     }
 

Reply via email to