cui/source/customize/cfgutil.cxx | 83 +++++++++++++++++++++------------------ cui/source/inc/cfgutil.hxx | 1 sfx2/source/appl/appserv.cxx | 7 ++- 3 files changed, 52 insertions(+), 39 deletions(-)
New commits: commit 9b227506a5fd3e84d4aa877fc6459996546348ba Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Thu Oct 13 16:53:41 2022 +0200 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Fri Oct 14 07:44:45 2022 +0200 Start to fix the "BASIC Macros" dialog's "Assign..." button c79212479f42cadd39173e77acc5e6446480ff05 "Fix a misuse of two-argument std string_view rfind" found that e.g. in Writer "Tools - Macros - Organize Macros - Basic...", in "Macro From" select "My Macros - Standard - Module1" and in "Existing Macros in: Module 1" select "Main", then "Assign..." had apparently rotten over time and brought up the "Customize" dialog's default "Menus" tab. With this fix, it now brings up the "Customize" dialog's "Keyboard" tab, in the "Category" tree list selects the appropriate "Module1" line, and in the "Function" list shows all the corresponding functions (just "Main" in this case). It doesn't yet select the appropriate line ("Main") in the "Function" list, though. That apparently needs further fixing. Change-Id: Ia5b9ef88d29e01f4f5e22ce3aec20f5fc22b5d45 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141303 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/cui/source/customize/cfgutil.cxx b/cui/source/customize/cfgutil.cxx index ee9d4a3fdc61..0314f1810c47 100644 --- a/cui/source/customize/cfgutil.cxx +++ b/cui/source/customize/cfgutil.cxx @@ -1023,23 +1023,16 @@ IMPL_LINK(CuiConfigGroupListBox, ExpandingHdl, const weld::TreeIter&, rIter, boo #if HAVE_FEATURE_SCRIPTING void CuiConfigGroupListBox::SelectMacro( const SfxMacroInfoItem *pItem ) { - SelectMacro( pItem->GetBasicManager()->GetName(), - pItem->GetQualifiedName() ); -} - -void CuiConfigGroupListBox::SelectMacro( std::u16string_view rBasic, - std::u16string_view rMacro ) -{ - const OUString aBasicName(OUString::Concat(rBasic) + " " + xImp->m_sMacros); - size_t nIdx {rMacro.rfind('.')}; - const std::u16string_view aMethod( rMacro.substr(nIdx == std::u16string_view::npos ? 0 : nIdx + 1) ); + auto const rMacro = pItem->GetQualifiedName(); + sal_Int32 nIdx {rMacro.lastIndexOf('.')}; + const std::u16string_view aMethod( rMacro.subView(nIdx + 1) ); std::u16string_view aLib; std::u16string_view aModule; - if ( nIdx>0 && nIdx != std::u16string_view::npos ) + if ( nIdx>0 ) { // string contains at least 2 tokens - nIdx = rMacro.rfind('.', nIdx - 1); - if (nIdx != std::u16string_view::npos) + nIdx = rMacro.lastIndexOf('.', nIdx); + if (nIdx != -1) { // string contains at least 3 tokens aLib = o3tl::getToken(rMacro, 0, '.' ); @@ -1055,45 +1048,61 @@ void CuiConfigGroupListBox::SelectMacro( std::u16string_view rBasic, do { OUString aEntryBas = m_xTreeView->get_text(*xIter); - if (aEntryBas == aBasicName) + if (aEntryBas == xImp->m_sDlgMacros) { m_xTreeView->expand_row(*xIter); - std::unique_ptr<weld::TreeIter> xLibIter = m_xTreeView->make_iterator(xIter.get()); - if (m_xTreeView->get_iter_first(*xLibIter)) + std::unique_ptr<weld::TreeIter> xLocationIter = m_xTreeView->make_iterator(xIter.get()); + if (m_xTreeView->iter_children(*xLocationIter)) { do { - OUString aEntryLib = m_xTreeView->get_text(*xLibIter); - if (aEntryLib == aLib) + m_xTreeView->expand_row(*xLocationIter); + std::unique_ptr<weld::TreeIter> xLibIter = m_xTreeView->make_iterator(xLocationIter.get()); + if (m_xTreeView->iter_children(*xLibIter)) { - m_xTreeView->expand_row(*xLibIter); - std::unique_ptr<weld::TreeIter> xModIter = m_xTreeView->make_iterator(xLibIter.get()); - if (m_xTreeView->get_iter_first(*xModIter)) + do { - do + OUString aEntryLib = m_xTreeView->get_text(*xLibIter); + if (aEntryLib == aLib) { - OUString aEntryMod = m_xTreeView->get_text(*xModIter); - if ( aEntryMod == aModule ) + m_xTreeView->expand_row(*xLibIter); + std::unique_ptr<weld::TreeIter> xModIter = m_xTreeView->make_iterator(xLibIter.get()); + if (m_xTreeView->iter_children(*xModIter)) { - m_xTreeView->expand_row(*xModIter); - m_xTreeView->scroll_to_row(*xModIter); - m_xTreeView->select(*xModIter); - for (int i = 0, nCount = m_pFunctionListBox->n_children(); i < nCount; ++i) + do { - OUString aEntryMethod = m_pFunctionListBox->get_text(i); - if (aEntryMethod == aMethod) + OUString aEntryMod = m_xTreeView->get_text(*xModIter); + if ( aEntryMod == aModule ) { - m_pFunctionListBox->select(i); - m_pFunctionListBox->scroll_to_row(i); - return; + m_xTreeView->expand_row(*xModIter); + m_xTreeView->scroll_to_row(*xModIter); + m_xTreeView->select(*xModIter); + GroupSelected(); + for (int i = 0, nCount = m_pFunctionListBox->n_children(); i < nCount; ++i) + { + OUString aEntryMethod = m_pFunctionListBox->get_text(i); + if (aEntryMethod == aMethod) + { + m_pFunctionListBox->select(i); + m_pFunctionListBox->scroll_to_row(i); + return; + } + } + m_xTreeView->collapse_row(*xModIter); } - } + } while (m_xTreeView->iter_next_sibling(*xModIter)); } - } while (m_xTreeView->iter_next_sibling(*xModIter)); - } + m_xTreeView->collapse_row(*xLibIter); + } + } while (m_xTreeView->iter_next_sibling(*xLibIter)); } - } while (m_xTreeView->iter_next_sibling(*xLibIter)); + m_xTreeView->collapse_row(*xLocationIter); + } while (m_xTreeView->iter_next_sibling(*xLocationIter)); } + // If the macro can't be located, preselect the "Application Macros" category: + m_xTreeView->scroll_to_row(*xIter); + m_xTreeView->select(*xIter); + return; } } while (m_xTreeView->iter_next_sibling(*xIter)); } diff --git a/cui/source/inc/cfgutil.hxx b/cui/source/inc/cfgutil.hxx index d4da1e76f5f9..ea55df5fa3cc 100644 --- a/cui/source/inc/cfgutil.hxx +++ b/cui/source/inc/cfgutil.hxx @@ -230,7 +230,6 @@ public: void GroupSelected(); #if HAVE_FEATURE_SCRIPTING void SelectMacro(const SfxMacroInfoItem*); - void SelectMacro(std::u16string_view, std::u16string_view); #endif void SetStylesInfo(SfxStylesInfo_Impl* pStyles); }; diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index d6c8fdefb028..e3aefbe4b18a 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -77,6 +77,7 @@ #include <sfx2/request.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/bindings.hxx> +#include <sfx2/minfitem.hxx> #include <sfx2/msg.hxx> #include <sfx2/objface.hxx> #include <sfx2/objsh.hxx> @@ -400,13 +401,17 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) const SfxStringItem* pStringItem = rReq.GetArg<SfxStringItem>(SID_CONFIG); - SfxItemSetFixed<SID_CONFIG, SID_CONFIG> aSet( GetPool() ); + SfxItemSetFixed<SID_CONFIG, SID_CONFIG, SID_MACROINFO, SID_MACROINFO> aSet( GetPool() ); if ( pStringItem ) { aSet.Put( SfxStringItem( SID_CONFIG, pStringItem->GetValue() ) ); } + // Preselect a macro: + if (auto const item = rReq.GetArg<SfxMacroInfoItem>(SID_MACROINFO)) { + aSet.Put(*item); + } Reference <XFrame> xFrame(GetRequestFrame(rReq)); ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateCustomizeTabDialog(rReq.GetFrameWeld(),