svx/source/tbxctrls/tbcontrl.cxx |   47 ++++++++++-----------------------------
 1 file changed, 13 insertions(+), 34 deletions(-)

New commits:
commit 95756934cf56e4a9ff58464bc0ed6881c15fe411
Author:     Heiko Tietze <tietze.he...@gmail.com>
AuthorDate: Tue Jan 10 15:10:41 2023 +0100
Commit:     Heiko Tietze <heiko.tie...@documentfoundation.org>
CommitDate: Wed Jan 11 08:21:47 2023 +0000

    Resolves tdf#152666 - Hide default styles for large lists
    
    Show the default styles only if the number of items
    are low and hide successively otherwise
    
    Change-Id: Iefafa0cfee7629fb034b9583d7aed7501475a54a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145268
    Tested-by: Jenkins
    Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org>

diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 4563010ac053..03b4f4706ce3 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -3180,38 +3180,12 @@ void SvxStyleToolBoxControl::FillStyleBox()
 
     std::vector<OUString> aStyles;
 
+    // add used styles
+    pStyle = xIter->Next();
+    while ( pStyle )
     {
+        aStyles.push_back(pStyle->GetName());
         pStyle = xIter->Next();
-
-        if( pImpl->bSpecModeWriter || pImpl->bSpecModeCalc )
-        {
-            while ( pStyle )
-            {
-                // sort out default styles
-                bool bInsert = true;
-                OUString aName( pStyle->GetName() );
-                for( auto const & _i: pImpl->aDefaultStyles )
-                {
-                    if( _i.first == aName || _i.second == aName )
-                    {
-                        bInsert = false;
-                        break;
-                    }
-                }
-
-                if( bInsert )
-                    aStyles.push_back(aName);
-                pStyle = xIter->Next();
-            }
-        }
-        else
-        {
-            while ( pStyle )
-            {
-                aStyles.push_back(pStyle->GetName());
-                pStyle = xIter->Next();
-            }
-        }
     }
 
     if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
@@ -3219,11 +3193,16 @@ void SvxStyleToolBoxControl::FillStyleBox()
         pBox->append_text(pImpl->aClearForm);
         pBox->insert_separator(1, "separator");
 
-        // insert default styles
-        for (const auto &rStyle : pImpl->aDefaultStyles)
-            pBox->append_text(rStyle.second);
+        // add default styles if less than 12 items
+        for( const auto &rStyle : pImpl->aDefaultStyles )
+        {
+            if ( aStyles.size() + pBox->get_count() > 12)
+                break;
+            // insert default style only if not used (and added to rStyle 
before)
+            if (std::find(aStyles.begin(), aStyles.end(), rStyle.second) >= 
aStyles.end())
+                pBox->append_text(rStyle.second);
+        }
     }
-
     std::sort(aStyles.begin(), aStyles.end());
 
     for (const auto& rStyle : aStyles)

Reply via email to