include/svx/tbcontrl.hxx | 1 svx/source/tbxctrls/tbcontrl.cxx | 82 +++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 46 deletions(-)
New commits: commit 524f68ed5c2fd6795c192f130fcf05b32a678247 Author: Szymon Kłos <[email protected]> AuthorDate: Fri Dec 26 08:31:12 2025 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Wed Feb 25 09:21:30 2026 +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-on: https://gerrit.libreoffice.org/c/core/+/200257 Reviewed-by: Szymon Kłos <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/include/svx/tbcontrl.hxx b/include/svx/tbcontrl.hxx index 63811d9b6f73..e9dd731a83e2 100644 --- a/include/svx/tbcontrl.hxx +++ b/include/svx/tbcontrl.hxx @@ -186,6 +186,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 8bbdd1e3f3b9..538c0b1521fb 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -152,10 +152,14 @@ 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(); } + int find_text(const OUString& rStr) + { + return m_xWidget->find_text(rStr); + } + void append_text(const OUString& rStr) { OUString sId(OUString::number(m_xWidget->get_count())); @@ -3298,73 +3302,45 @@ void SvxStyleToolBoxControl::FillStyleBox() return; const SfxStyleFamily eFamily = GetActFamily(); - SfxStyleSheetBase* pStyle = nullptr; - bool bDoFill = false; - - auto xIter = m_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; - // use a set to avoid O(n^2) performance problem in insert loop - std::unordered_set<OUString> aStylesSet; - - // add used styles - pStyle = xIter->Next(); - while ( pStyle ) - { - aStyles.push_back(pStyle->GetName()); - pStyle = xIter->Next(); - } + // Insert Clear button if (m_pImpl->bSpecModeWriter || m_pImpl->bSpecModeCalc) { pBox->append_text(m_pImpl->aClearForm); pBox->insert_separator(1, u"separator"_ustr); + } + + // Add used, favourite and user defined + + std::vector<OUString> aStyles; - // add default styles if less than 12 items + AppendStyles(aStyles, eFamily, SfxStyleSearchBits::Favourite); + AppendStyles(aStyles, eFamily, SfxStyleSearchBits::UserDefined); + AppendStyles(aStyles, eFamily, SfxStyleSearchBits::Used); + + // Add default styles on top first + if (m_pImpl->bSpecModeWriter || m_pImpl->bSpecModeCalc) + { for( const auto &rStyle : m_pImpl->aDefaultStyles ) - { - if ( aStyles.size() + pBox->get_count() > 12) - break; pBox->append_text(rStyle.second); - aStylesSet.insert(rStyle.second); - } } - std::sort(aStyles.begin(), aStyles.end()); + // Insert styles for (const auto& rStyle : aStyles) { // do not duplicate default styles - if (aStylesSet.insert(rStyle).second) + if (pBox->find_text(rStyle) == -1) pBox->append_text(rStyle); } + // Insert More button if ((m_pImpl->bSpecModeWriter || m_pImpl->bSpecModeCalc) && !comphelper::LibreOfficeKit::isActive()) pBox->append_text(m_pImpl->aMore); @@ -3373,6 +3349,20 @@ void SvxStyleToolBoxControl::FillStyleBox() pBox->SetFamily( eFamily ); } +void SvxStyleToolBoxControl::AppendStyles(std::vector<OUString>& rStyles, SfxStyleFamily eFamily, + SfxStyleSearchBits eBits) +{ + auto xIter = m_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 = m_pImpl->m_pBox;
