include/svx/tbcontrl.hxx         |    1 
 svx/source/tbxctrls/tbcontrl.cxx |   75 +++++++++++++++++----------------------
 2 files changed, 34 insertions(+), 42 deletions(-)

New commits:
commit eddb8071b23e5f55ffd2c633e5edb9bd6f029912
Author:     Szymon Kłos <[email protected]>
AuthorDate: Fri Dec 26 08:31:12 2025 +0000
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Mon Dec 29 06:23:11 2025 +0100

    sidebar: unify style list with notebookbar
    
    - similar as in commit cee5c21e0c8c64c78e5d04ff4e300edfaac30404
      Writer: iterate styles to show also favourite in the notebookbar
    - make sidebar list similar
    - use deterministic alogithm without number of default styles
      depending on how much used styles are in the document
    - do not sort entries to show in natural order
      (we can try to introduce priority inside iterator)
    - show all favourite, user defined and used styles
    - helps to use defined template and follow style guidelines
      as we see customstyles which are not yet used too
    - both sidebar and notebookbar users see the same list
    
    Change-Id: Iae81aeaf99a8f60f5ed14eb63960ee38f76bcaa1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196226
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/include/svx/tbcontrl.hxx b/include/svx/tbcontrl.hxx
index 6f6a15b7c33c..969172fc4e76 100644
--- a/include/svx/tbcontrl.hxx
+++ b/include/svx/tbcontrl.hxx
@@ -189,6 +189,7 @@ private:
 
     void Update();
     void FillStyleBox();
+    void AppendStyles(std::vector<OUString>& rStyles, SfxStyleFamily eFamily, 
SfxStyleSearchBits eBits);
     void SelectStyle(const OUString& rStyleName);
 
 friend class SfxStyleControllerItem_Impl;
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index ca2ee543328b..32a0ad942715 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -153,7 +153,6 @@ public:
 
     void            SetDefaultStyle( const OUString& rDefault ) { 
sDefaultStyle = rDefault; }
 
-    int get_count() const { return m_xWidget->get_count(); }
     OUString get_text(int nIndex) const { return m_xWidget->get_text(nIndex); }
     OUString get_active_text() const { return m_xWidget->get_active_text(); }
 
@@ -3287,67 +3286,45 @@ void SvxStyleToolBoxControl::FillStyleBox()
         return;
 
     const SfxStyleFamily    eFamily     = GetActFamily();
-    SfxStyleSheetBase*      pStyle      = nullptr;
-    bool                    bDoFill     = false;
 
-    auto xIter = pStyleSheetPool->CreateIterator(eFamily, 
SfxStyleSearchBits::Used);
-    sal_uInt16 nCount = xIter->Count();
-
-    // Check whether fill is necessary
-    pStyle = xIter->First();
-    //!!! TODO: This condition isn't right any longer, because we always show 
some default entries
-    //!!! so the list doesn't show the count
-    if ( nCount != pBox->get_count() )
-    {
-        bDoFill = true;
-    }
-    else
-    {
-        sal_uInt16 i= 0;
-        while ( pStyle && !bDoFill )
-        {
-            bDoFill = ( pBox->get_text(i) != pStyle->GetName() );
-            pStyle = xIter->Next();
-            i++;
-        }
-    }
-
-    if ( !bDoFill )
-        return;
+    // TODO: Check whether fill is necessary
 
     OUString aStrSel(pBox->get_active_text());
     pBox->freeze();
     pBox->clear();
 
-    std::vector<OUString> aStyles;
-
-    // add used styles
-    pStyle = xIter->Next();
-    while ( pStyle )
-    {
-        aStyles.push_back(pStyle->GetName());
-        pStyle = xIter->Next();
-    }
+    // Insert Clear button
 
     if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
     {
         pBox->append_text(pImpl->aClearForm);
         pBox->insert_separator(1, u"separator"_ustr);
+    }
+
+    // Add used, favourite and user defined
 
-        // add default styles if less than 12 items
+    std::vector<OUString> aStyles;
+
+    AppendStyles(aStyles, eFamily, SfxStyleSearchBits::Favourite);
+    AppendStyles(aStyles, eFamily, SfxStyleSearchBits::UserDefined);
+    AppendStyles(aStyles, eFamily, SfxStyleSearchBits::Used);
+
+    // Add default styles on top first
+    if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
+    {
         for( const auto &rStyle : pImpl->aDefaultStyles )
-        {
-            if ( aStyles.size() + pBox->get_count() > 12)
-                break;
             pBox->append_text(rStyle.second);
-        }
     }
-    std::sort(aStyles.begin(), aStyles.end());
 
+    // Insert styles
     for (const auto& rStyle : aStyles)
+    {
+        // do not duplicate default styles
         if (pBox->find_text(rStyle) == -1)
             pBox->append_text(rStyle);
+    }
 
+    // Insert More button
     if ((pImpl->bSpecModeWriter || pImpl->bSpecModeCalc) && 
!comphelper::LibreOfficeKit::isActive())
         pBox->append_text(pImpl->aMore);
 
@@ -3356,6 +3333,20 @@ void SvxStyleToolBoxControl::FillStyleBox()
     pBox->SetFamily( eFamily );
 }
 
+void SvxStyleToolBoxControl::AppendStyles(std::vector<OUString>& rStyles, 
SfxStyleFamily eFamily,
+                                          SfxStyleSearchBits eBits)
+{
+    auto xIter = pStyleSheetPool->CreateIterator(eFamily, eBits);
+    SfxStyleSheetBase* pStyle = xIter->First();
+
+    pStyle = xIter->Next();
+    while ( pStyle )
+    {
+        rStyles.push_back(pStyle->GetName());
+        pStyle = xIter->Next();
+    }
+}
+
 void SvxStyleToolBoxControl::SelectStyle( const OUString& rStyleName )
 {
     SvxStyleBox_Base* pBox = pImpl->m_pBox;

Reply via email to