include/svx/srchdlg.hxx | 2 - svx/source/dialog/srchdlg.cxx | 47 ++++++++++++++++++------------------------ 2 files changed, 22 insertions(+), 27 deletions(-)
New commits: commit 435e36996197e75f330eea4151935f5d84cd968e Author: Michael Weghorn <[email protected]> AuthorDate: Thu May 29 10:29:22 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Fri May 30 07:45:27 2025 +0200 svx: Simplify SvxSearchDialog::Remember_Impl use So far, the method was called with either * the current text of the search combobox and a value of bSearch=true * the current text of the replace combobox and a value of bSearch=false The method already uses the corresponding combox depending on the value of the `bSearch` param. Therefore move the logic to retrieve the current text also in there and drop the first method param. The checks whether the current text was empty before calling the method was also superfluous, because the method returns early in that case anyway. Change-Id: Ieb3f20f36ff0bbc7bc33b4f7676ce8df3d20c83f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185989 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/include/svx/srchdlg.hxx b/include/svx/srchdlg.hxx index b862e2db217d..9f5336c2247f 100644 --- a/include/svx/srchdlg.hxx +++ b/include/svx/srchdlg.hxx @@ -256,7 +256,7 @@ private: SVX_DLLPRIVATE void Init_Impl( bool bHasItemSet ); SVX_DLLPRIVATE void InitAttrList_Impl( const SfxItemSet* pSSet, const SfxItemSet* pRSet ); - SVX_DLLPRIVATE void Remember_Impl( const OUString &rStr, bool bSearch ); + SVX_DLLPRIVATE void Remember_Impl(bool bSearch); SVX_DLLPRIVATE void PaintAttrText_Impl(); SVX_DLLPRIVATE OUString& BuildAttrText_Impl( OUString& rStr, bool bSrchFlag ) const; diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx index ca7973ef39bf..6c85c5f2734f 100644 --- a/svx/source/dialog/srchdlg.cxx +++ b/svx/source/dialog/srchdlg.cxx @@ -1291,13 +1291,13 @@ IMPL_LINK(SvxSearchDialog, CommandHdl_Impl, weld::Button&, rBtn, void) pSearchItem->SetReplaceString( m_xReplaceLB->get_active_text() ); if ( &rBtn == m_xReplaceBtn.get() ) - Remember_Impl( m_xReplaceLB->get_active_text(), false ); + Remember_Impl(false); else { - Remember_Impl( m_xSearchLB->get_active_text(), true ); + Remember_Impl(true); if ( &rBtn == m_xReplaceAllBtn.get() ) - Remember_Impl( m_xReplaceLB->get_active_text(), false ); + Remember_Impl(false); } } @@ -1376,14 +1376,8 @@ IMPL_LINK(SvxSearchDialog, CommandHdl_Impl, weld::Button&, rBtn, void) { if ( !m_xLayoutBtn->get_active() || bInclusive ) { - OUString aStr( m_xSearchLB->get_active_text() ); - - if ( !aStr.isEmpty() ) - Remember_Impl( aStr, true ); - aStr = m_xReplaceLB->get_active_text(); - - if ( !aStr.isEmpty() ) - Remember_Impl( aStr, false ); + Remember_Impl(true); + Remember_Impl(false); } SaveToModule_Impl(); Close(); @@ -1588,17 +1582,18 @@ IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl, weld::Toggleable&, void) pImpl->bSaveToModule = true; } -void SvxSearchDialog::Remember_Impl( const OUString &rStr, bool _bSearch ) +void SvxSearchDialog::Remember_Impl(bool _bSearch) { - if ( rStr.isEmpty() ) - return; - std::vector<OUString>& rArr = _bSearch ? aSearchStrings : aReplaceStrings; weld::ComboBox& rListBox = _bSearch ? *m_xSearchLB : *m_xReplaceLB; + const OUString sText = rListBox.get_active_text(); + if (sText.isEmpty()) + return; + // tdf#154818 - rearrange the search items - const auto nPos = rListBox.find_text(rStr); - if (nPos == 0 && !rArr.empty() && rArr.at(0) == rStr) + const int nPos = rListBox.find_text(sText); + if (nPos == 0 && !rArr.empty() && rArr.at(0) == sText) // nothing to do, is already the first item return; @@ -1614,8 +1609,8 @@ void SvxSearchDialog::Remember_Impl( const OUString &rStr, bool _bSearch ) rArr.erase(rArr.begin() + nRememberSize - 1); } - rArr.insert(rArr.begin(), rStr); - rListBox.insert_text(0, rStr); + rArr.insert(rArr.begin(), sText); + rListBox.insert_text(0, sText); } void SvxSearchDialog::TemplatesChanged_Impl( SfxStyleSheetBasePool& rPool ) @@ -2278,7 +2273,7 @@ void SvxSearchDialog::SaveToModule_Impl() { pSearchItem->SetSearchString ( m_xSearchLB->get_active_text() ); pSearchItem->SetReplaceString( m_xReplaceLB->get_active_text() ); - Remember_Impl( m_xSearchLB->get_active_text(), true ); + Remember_Impl(true); } pSearchItem->SetRegExp( false ); commit 44d6bdde27ba2bce1c61aa73ec53d34a828bb903 Author: Michael Weghorn <[email protected]> AuthorDate: Thu May 29 00:12:17 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Fri May 30 07:45:18 2025 +0200 svx: Use ref instead of pointer Change-Id: Iab60327c70b33592c559f625b71924aa85b25a75 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185988 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx index a4cb6da25c76..ca7973ef39bf 100644 --- a/svx/source/dialog/srchdlg.cxx +++ b/svx/source/dialog/srchdlg.cxx @@ -1593,29 +1593,29 @@ void SvxSearchDialog::Remember_Impl( const OUString &rStr, bool _bSearch ) if ( rStr.isEmpty() ) return; - std::vector<OUString>* pArr = _bSearch ? &aSearchStrings : &aReplaceStrings; - weld::ComboBox* pListBox = _bSearch ? m_xSearchLB.get() : m_xReplaceLB.get(); + std::vector<OUString>& rArr = _bSearch ? aSearchStrings : aReplaceStrings; + weld::ComboBox& rListBox = _bSearch ? *m_xSearchLB : *m_xReplaceLB; // tdf#154818 - rearrange the search items - const auto nPos = pListBox->find_text(rStr); - if (nPos == 0 && !pArr->empty() && pArr->at(0) == rStr) + const auto nPos = rListBox.find_text(rStr); + if (nPos == 0 && !rArr.empty() && rArr.at(0) == rStr) // nothing to do, is already the first item return; if (nPos != -1) { - pListBox->remove(nPos); - pArr->erase(pArr->begin() + nPos); + rListBox.remove(nPos); + rArr.erase(rArr.begin() + nPos); } - else if (pListBox->get_count() >= nRememberSize) + else if (rListBox.get_count() >= nRememberSize) { // delete oldest entry at maximum occupancy (ListBox and Array) - pListBox->remove(nRememberSize - 1); - pArr->erase(pArr->begin() + nRememberSize - 1); + rListBox.remove(nRememberSize - 1); + rArr.erase(rArr.begin() + nRememberSize - 1); } - pArr->insert(pArr->begin(), rStr); - pListBox->insert_text(0, rStr); + rArr.insert(rArr.begin(), rStr); + rListBox.insert_text(0, rStr); } void SvxSearchDialog::TemplatesChanged_Impl( SfxStyleSheetBasePool& rPool )
