include/svx/tbcontrl.hxx | 1 svx/source/tbxctrls/tbcontrl.cxx | 75 +++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 42 deletions(-)
New commits: commit f4c7443b561eaa58be3eea5bd2598a7090ef386b Author: Szymon Kłos <[email protected]> AuthorDate: Fri Dec 26 08:31:12 2025 +0000 Commit: Szymon Kłos <[email protected]> CommitDate: Mon Dec 29 09:41:49 2025 +0100 tdf#108239 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/+/196276 Tested-by: Jenkins Reviewed-by: Szymon Kłos <[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 5d2eba20a149..7f43648a3e25 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(); } @@ -3239,67 +3238,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; - - // 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 - // 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 (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); - } } - 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 ((m_pImpl->bSpecModeWriter || m_pImpl->bSpecModeCalc) && !comphelper::LibreOfficeKit::isActive()) pBox->append_text(m_pImpl->aMore); @@ -3308,6 +3285,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;
