include/sfx2/templatedlg.hxx | 6 +++--- include/sfx2/templatelocalview.hxx | 8 ++++---- sfx2/source/control/templatedefaultview.cxx | 2 +- sfx2/source/control/templatedlglocalview.cxx | 6 +++--- sfx2/source/control/templatelocalview.cxx | 10 +++++----- sfx2/source/dialog/backingwindow.cxx | 12 ++++-------- sfx2/source/dialog/backingwindow.hxx | 4 ++-- sfx2/source/doc/templatedlg.cxx | 21 ++++++++------------- 8 files changed, 30 insertions(+), 39 deletions(-)
New commits: commit f8483e93132338cac4c2518f813dc9e929129edc Author: Michael Weghorn <[email protected]> AuthorDate: Wed Dec 31 12:35:09 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Jan 3 08:10:35 2026 +0100 Pass path instead of ThumbnailViewItem in template edit hdl Switch the param for TemplateLocalView::maEditTemplateHdl from ThumbnailViewItem* to const OUString& and pass the template's URL directly instead of retrieving it from the ThumbnailViewItem in all implementations. This also gets rid of the need for some static_casts. Change-Id: Iad7dae92c9e3fdc28b6ffa5c15c4330728ce60a2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196380 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx index 2314c427d5d0..b04fff15a214 100644 --- a/include/sfx2/templatedlg.hxx +++ b/include/sfx2/templatedlg.hxx @@ -73,7 +73,7 @@ protected: DECL_DLLPRIVATE_LINK(OpenRegionHdl, void*, void); DECL_DLLPRIVATE_LINK(CreateContextMenuHdl, ThumbnailViewItem*, void); DECL_DLLPRIVATE_LINK(OpenTemplateHdl, const OUString&, void); - DECL_DLLPRIVATE_LINK(EditTemplateHdl, ThumbnailViewItem*, void); + DECL_DLLPRIVATE_LINK(EditTemplateHdl, const OUString&, void); DECL_DLLPRIVATE_LINK(DeleteTemplateHdl, void*, void); DECL_DLLPRIVATE_LINK(DefaultTemplateHdl, ThumbnailViewItem*, void); DECL_DLLPRIVATE_LINK(MoveTemplateHdl, void*, void); diff --git a/include/sfx2/templatelocalview.hxx b/include/sfx2/templatelocalview.hxx index c43b6b75a78a..b2f4dad68b38 100644 --- a/include/sfx2/templatelocalview.hxx +++ b/include/sfx2/templatelocalview.hxx @@ -135,7 +135,7 @@ public: void setOpenTemplateHdl(const Link<const OUString&, void>& rLink); - void setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink); + void setEditTemplateHdl(const Link<const OUString&, void>& rLink); void setDeleteTemplateHdl(const Link<void*,void> &rLink); @@ -176,7 +176,7 @@ protected: Link<void*,void> maOpenRegionHdl; Link<ThumbnailViewItem*,void> maCreateContextMenuHdl; Link<const OUString&, void> maOpenTemplateHdl; - Link<ThumbnailViewItem*,void> maEditTemplateHdl; + Link<const OUString&, void> maEditTemplateHdl; Link<void*,void> maDeleteTemplateHdl; Link<ThumbnailViewItem*,void> maDefaultTemplateHdl; Link<void*,void> maMoveTemplateHdl; diff --git a/sfx2/source/control/templatedlglocalview.cxx b/sfx2/source/control/templatedlglocalview.cxx index bb4be6dddc29..8103c9dc15e5 100644 --- a/sfx2/source/control/templatedlglocalview.cxx +++ b/sfx2/source/control/templatedlglocalview.cxx @@ -151,7 +151,7 @@ void TemplateDlgLocalView::ContextMenuSelectHdl(std::u16string_view rIdent) if (rIdent == u"open") maOpenTemplateHdl.Call(maSelectedItem->getPath()); else if (rIdent == u"edit") - maEditTemplateHdl.Call(maSelectedItem); + maEditTemplateHdl.Call(maSelectedItem->getPath()); else if (rIdent == u"rename") { InputDialog aTitleEditDlg(GetDrawingArea(), SfxResId(STR_RENAME_TEMPLATE)); diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index 6325fe16e080..50c0a12b9867 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -195,7 +195,7 @@ void TemplateLocalView::ContextMenuSelectHdl(std::u16string_view rIdent) if (rIdent == u"open") maOpenTemplateHdl.Call(maSelectedItem->getPath()); else if (rIdent == u"edit") - maEditTemplateHdl.Call(maSelectedItem); + maEditTemplateHdl.Call(maSelectedItem->getPath()); else if (rIdent == u"rename") { InputDialog aTitleEditDlg(GetDrawingArea(), SfxResId(STR_RENAME_TEMPLATE)); @@ -793,7 +793,7 @@ void TemplateLocalView::setOpenTemplateHdl(const Link<const OUString&, void>& rL maOpenTemplateHdl = rLink; } -void TemplateLocalView::setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink) +void TemplateLocalView::setEditTemplateHdl(const Link<const OUString&, void>& rLink) { maEditTemplateHdl = rLink; } diff --git a/sfx2/source/dialog/backingwindow.cxx b/sfx2/source/dialog/backingwindow.cxx index 69c80c0b3c2d..ec9275f07ee7 100644 --- a/sfx2/source/dialog/backingwindow.cxx +++ b/sfx2/source/dialog/backingwindow.cxx @@ -703,7 +703,7 @@ IMPL_LINK(BackingWindow, OpenTemplateHdl, const OUString&, rTemplatePath, void) } } -IMPL_LINK(BackingWindow, EditTemplateHdl, ThumbnailViewItem*, pItem, void) +IMPL_LINK(BackingWindow, EditTemplateHdl, const OUString&, rTemplatePath, void) { uno::Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"AsTemplate"_ustr, false), @@ -711,13 +711,11 @@ IMPL_LINK(BackingWindow, EditTemplateHdl, ThumbnailViewItem*, pItem, void) comphelper::makePropertyValue(u"UpdateDocMode"_ustr, UpdateDocMode::ACCORDING_TO_CONFIG), }; - TemplateViewItem *pViewItem = static_cast<TemplateViewItem*>(pItem); - Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY ); try { - dispatchURL( pViewItem->getPath(), u"_default"_ustr, xFrame, aArgs ); + dispatchURL(rTemplatePath, u"_default"_ustr, xFrame, aArgs); } catch( const uno::Exception& ) { diff --git a/sfx2/source/dialog/backingwindow.hxx b/sfx2/source/dialog/backingwindow.hxx index 0e8c79658bfa..7989d49753da 100644 --- a/sfx2/source/dialog/backingwindow.hxx +++ b/sfx2/source/dialog/backingwindow.hxx @@ -99,7 +99,7 @@ class BackingWindow : public InterimItemWindow DECL_STATIC_LINK(BackingWindow, ExtLinkClickHdl, weld::Button&, void); DECL_LINK(CreateContextMenuHdl, ThumbnailViewItem*, void); DECL_LINK(OpenTemplateHdl, const OUString&, void); - DECL_LINK(EditTemplateHdl, ThumbnailViewItem*, void); + DECL_LINK(EditTemplateHdl, const OUString&, void); void initControls(); diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index d5e65c442c05..d6023e5e8593 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -708,7 +708,7 @@ IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, const OUString&, rTemplatePath m_xDialog->response(RET_OK); } -IMPL_LINK(SfxTemplateManagerDlg, EditTemplateHdl, ThumbnailViewItem*, pItem, void) +IMPL_LINK(SfxTemplateManagerDlg, EditTemplateHdl, const OUString&, rTemplatePath, void) { uno::Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"AsTemplate"_ustr, false), @@ -717,11 +717,9 @@ IMPL_LINK(SfxTemplateManagerDlg, EditTemplateHdl, ThumbnailViewItem*, pItem, voi }; uno::Reference< XStorable > xStorable; - TemplateViewItem *pViewItem = static_cast<TemplateViewItem*>(pItem); - try { - xStorable.set( mxDesktop->loadComponentFromURL(pViewItem->getPath(),u"_default"_ustr, 0, aArgs ), + xStorable.set( mxDesktop->loadComponentFromURL(rTemplatePath, u"_default"_ustr, 0, aArgs), uno::UNO_QUERY ); } catch( const uno::Exception& ) commit ec193ec89d8a3e98ff4e8066ae4d5d30ad77bf3a Author: Michael Weghorn <[email protected]> AuthorDate: Wed Dec 31 12:24:55 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Jan 3 08:10:26 2026 +0100 Pass path instead of ThumbnailViewItem in template open hdl Switch the param for TemplateLocalView::maOpenTemplateHdl from ThumbnailViewItem* to const OUString& and pass the template's URL directly instead of retrieving it from the ThumbnailViewItem in all implementations. This also gets rid of the need for some static_casts. Change-Id: Ie3987f86ceb0126846c7f1e24f84ecd5ba4f22f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196379 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx index 78943113e719..2314c427d5d0 100644 --- a/include/sfx2/templatedlg.hxx +++ b/include/sfx2/templatedlg.hxx @@ -72,7 +72,7 @@ protected: DECL_DLLPRIVATE_LINK(OpenRegionHdl, void*, void); DECL_DLLPRIVATE_LINK(CreateContextMenuHdl, ThumbnailViewItem*, void); - DECL_DLLPRIVATE_LINK(OpenTemplateHdl, const ThumbnailViewItem*, void); + DECL_DLLPRIVATE_LINK(OpenTemplateHdl, const OUString&, void); DECL_DLLPRIVATE_LINK(EditTemplateHdl, ThumbnailViewItem*, void); DECL_DLLPRIVATE_LINK(DeleteTemplateHdl, void*, void); DECL_DLLPRIVATE_LINK(DefaultTemplateHdl, ThumbnailViewItem*, void); @@ -179,7 +179,7 @@ public: bool IsStartWithTemplate() const { return mxCBXHideDlg->get_active(); }; private: - DECL_DLLPRIVATE_LINK(OpenTemplateHdl, const ThumbnailViewItem*, void); + DECL_DLLPRIVATE_LINK(OpenTemplateHdl, const OUString&, void); DECL_DLLPRIVATE_LINK(OkClickHdl, weld::Button&, void); DECL_DLLPRIVATE_LINK(TimeOut, Timer*, void); diff --git a/include/sfx2/templatelocalview.hxx b/include/sfx2/templatelocalview.hxx index e239aa1a7dff..c43b6b75a78a 100644 --- a/include/sfx2/templatelocalview.hxx +++ b/include/sfx2/templatelocalview.hxx @@ -133,7 +133,7 @@ public: void setCreateContextMenuHdl(const Link<ThumbnailViewItem*,void> &rLink); - void setOpenTemplateHdl(const Link<const ThumbnailViewItem*, void>& rLink); + void setOpenTemplateHdl(const Link<const OUString&, void>& rLink); void setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink); @@ -175,7 +175,7 @@ protected: Link<void*,void> maOpenRegionHdl; Link<ThumbnailViewItem*,void> maCreateContextMenuHdl; - Link<const ThumbnailViewItem*, void> maOpenTemplateHdl; + Link<const OUString&, void> maOpenTemplateHdl; Link<ThumbnailViewItem*,void> maEditTemplateHdl; Link<void*,void> maDeleteTemplateHdl; Link<ThumbnailViewItem*,void> maDefaultTemplateHdl; diff --git a/sfx2/source/control/templatedefaultview.cxx b/sfx2/source/control/templatedefaultview.cxx index 656625d23e19..fa253daf7544 100644 --- a/sfx2/source/control/templatedefaultview.cxx +++ b/sfx2/source/control/templatedefaultview.cxx @@ -68,7 +68,7 @@ bool TemplateDefaultView::MouseButtonDown( const MouseEvent& rMEvt ) ThumbnailViewItem* pItem = ImplGetItem(nPos); TemplateViewItem* pViewItem = dynamic_cast<TemplateViewItem*>(pItem); if(pViewItem) - maOpenTemplateHdl.Call(pViewItem); + maOpenTemplateHdl.Call(pViewItem->getPath()); return true; } diff --git a/sfx2/source/control/templatedlglocalview.cxx b/sfx2/source/control/templatedlglocalview.cxx index 0e8ae712185a..bb4be6dddc29 100644 --- a/sfx2/source/control/templatedlglocalview.cxx +++ b/sfx2/source/control/templatedlglocalview.cxx @@ -149,7 +149,7 @@ void TemplateDlgLocalView::createContextMenu(const bool bIsDefault, const bool b void TemplateDlgLocalView::ContextMenuSelectHdl(std::u16string_view rIdent) { if (rIdent == u"open") - maOpenTemplateHdl.Call(maSelectedItem); + maOpenTemplateHdl.Call(maSelectedItem->getPath()); else if (rIdent == u"edit") maEditTemplateHdl.Call(maSelectedItem); else if (rIdent == u"rename") @@ -334,7 +334,7 @@ void TemplateDlgLocalView::updateSelection() IMPL_LINK_NOARG(TemplateDlgLocalView, RowActivatedHdl, weld::TreeView&, bool) { - maOpenTemplateHdl.Call(maSelectedItem); + maOpenTemplateHdl.Call(maSelectedItem->getPath()); return true; } diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index cdc10297dc77..6325fe16e080 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -193,7 +193,7 @@ TemplateContainerItem* TemplateLocalView::getRegion(std::u16string_view rName) void TemplateLocalView::ContextMenuSelectHdl(std::u16string_view rIdent) { if (rIdent == u"open") - maOpenTemplateHdl.Call(maSelectedItem); + maOpenTemplateHdl.Call(maSelectedItem->getPath()); else if (rIdent == u"edit") maEditTemplateHdl.Call(maSelectedItem); else if (rIdent == u"rename") @@ -788,7 +788,7 @@ void TemplateLocalView::setCreateContextMenuHdl(const Link<ThumbnailViewItem*,vo maCreateContextMenuHdl = rLink; } -void TemplateLocalView::setOpenTemplateHdl(const Link<const ThumbnailViewItem*, void>& rLink) +void TemplateLocalView::setOpenTemplateHdl(const Link<const OUString&, void>& rLink) { maOpenTemplateHdl = rLink; } @@ -892,7 +892,7 @@ void TemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pItem) TemplateViewItem* pViewItem = dynamic_cast<TemplateViewItem*>(pItem); if( pViewItem ) - maOpenTemplateHdl.Call(pViewItem); + maOpenTemplateHdl.Call(pViewItem->getPath()); } bool TemplateLocalView::IsInternalTemplate(const OUString& rPath) diff --git a/sfx2/source/dialog/backingwindow.cxx b/sfx2/source/dialog/backingwindow.cxx index 71559e5edb30..69c80c0b3c2d 100644 --- a/sfx2/source/dialog/backingwindow.cxx +++ b/sfx2/source/dialog/backingwindow.cxx @@ -683,7 +683,7 @@ IMPL_LINK(BackingWindow, CreateContextMenuHdl, ThumbnailViewItem*, pItem, void) mxLocalView->createContextMenu(); } -IMPL_LINK(BackingWindow, OpenTemplateHdl, const ThumbnailViewItem*, pItem, void) +IMPL_LINK(BackingWindow, OpenTemplateHdl, const OUString&, rTemplatePath, void) { uno::Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"AsTemplate"_ustr, true), @@ -692,13 +692,11 @@ IMPL_LINK(BackingWindow, OpenTemplateHdl, const ThumbnailViewItem*, pItem, void) comphelper::makePropertyValue(u"InteractionHandler"_ustr, task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), nullptr )) }; - const TemplateViewItem* pTemplateItem = static_cast<const TemplateViewItem*>(pItem); - Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY ); try { - dispatchURL( pTemplateItem->getPath(), u"_default"_ustr, xFrame, aArgs ); + dispatchURL(rTemplatePath, u"_default"_ustr, xFrame, aArgs); } catch( const uno::Exception& ) { diff --git a/sfx2/source/dialog/backingwindow.hxx b/sfx2/source/dialog/backingwindow.hxx index b41650db3f56..0e8c79658bfa 100644 --- a/sfx2/source/dialog/backingwindow.hxx +++ b/sfx2/source/dialog/backingwindow.hxx @@ -98,7 +98,7 @@ class BackingWindow : public InterimItemWindow DECL_LINK(MenuSelectHdl, const OUString&, void); DECL_STATIC_LINK(BackingWindow, ExtLinkClickHdl, weld::Button&, void); DECL_LINK(CreateContextMenuHdl, ThumbnailViewItem*, void); - DECL_LINK(OpenTemplateHdl, const ThumbnailViewItem*, void); + DECL_LINK(OpenTemplateHdl, const OUString&, void); DECL_LINK(EditTemplateHdl, ThumbnailViewItem*, void); void initControls(); diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index ca9c3a242905..d5e65c442c05 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -250,7 +250,7 @@ SfxTemplateManagerDlg::~SfxTemplateManagerDlg() // Ignore view events since we are cleaning the object mxLocalView->setItemStateHdl(Link<const ThumbnailViewItem*,void>()); mxLocalView->setOpenRegionHdl(Link<void*,void>()); - mxLocalView->setOpenTemplateHdl(Link<const ThumbnailViewItem*, void>()); + mxLocalView->setOpenTemplateHdl(Link<const OUString&, void>()); } short SfxTemplateManagerDlg::run() @@ -687,7 +687,7 @@ IMPL_LINK(SfxTemplateManagerDlg, CreateContextMenuHdl, ThumbnailViewItem*, pItem mxLocalView->createContextMenu(bIsDefault, bIsInternal, bIsSingleSel, aDefaultImg); } -IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, const ThumbnailViewItem*, pItem, void) +IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, const OUString&, rTemplatePath, void) { uno::Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"AsTemplate"_ustr, true), @@ -697,11 +697,9 @@ IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, const ThumbnailViewItem*, pIte comphelper::makePropertyValue(u"ReadOnly"_ustr, true) }; - const TemplateViewItem* pTemplateItem = static_cast<const TemplateViewItem*>(pItem); - try { - mxDesktop->loadComponentFromURL(pTemplateItem->getPath(),u"_default"_ustr, 0, aArgs ); + mxDesktop->loadComponentFromURL(rTemplatePath, u"_default"_ustr, 0, aArgs ); } catch( const uno::Exception& ) { @@ -1044,7 +1042,7 @@ void SfxTemplateManagerDlg::OnTemplateExport() void SfxTemplateManagerDlg::OnTemplateOpen () { const TemplateViewItem* pItem = *maSelTemplates.begin(); - OpenTemplateHdl(pItem); + OpenTemplateHdl(pItem->getPath()); } void SfxTemplateManagerDlg::OnCategoryNew() @@ -1359,10 +1357,9 @@ IMPL_LINK_NOARG(SfxTemplateSelectionDlg, TimeOut, Timer*, void) m_xDialog->set_centered_on_parent(false); } -IMPL_LINK(SfxTemplateSelectionDlg, OpenTemplateHdl, const ThumbnailViewItem*, pItem, void) +IMPL_LINK(SfxTemplateSelectionDlg, OpenTemplateHdl, const OUString&, rTemplatePath, void) { - const TemplateViewItem* pViewItem = static_cast<const TemplateViewItem*>(pItem); - msTemplatePath = pViewItem->getPath(); + msTemplatePath = rTemplatePath; m_xDialog->response(RET_OK); }
