include/sfx2/templatedlg.hxx | 2 +- include/sfx2/templatelocalview.hxx | 3 ++- sfx2/source/control/templatelocalview.cxx | 9 ++++----- sfx2/source/doc/templatedlg.cxx | 28 +++++++++------------------- 4 files changed, 16 insertions(+), 26 deletions(-)
New commits: commit 4a1378c04832ea366099cab603bb09560fd0edbc Author: Michael Weghorn <[email protected]> AuthorDate: Wed Dec 31 12:09:32 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Jan 3 08:10:18 2026 +0100 Use more specific type instead of casting in SfxTemplateManagerDlg Use the concrete TemplateViewItem subclass for the elements in SfxTemplateManagerDlg::maSelTemplates instead of the ThumbnailViewItem subclass and casting in various places. Change-Id: Id32262f3d2e827a8f3c7ae0202713d8dbfc8ff75 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196378 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx index 2ebc1287ad93..78943113e719 100644 --- a/include/sfx2/templatedlg.hxx +++ b/include/sfx2/templatedlg.hxx @@ -116,7 +116,7 @@ protected: SAL_DLLPRIVATE FILTER_APPLICATION getCurrentApplicationFilter() const; protected: - std::set<const ThumbnailViewItem*, selection_cmp_fn> maSelTemplates; + std::set<const TemplateViewItem*, selection_cmp_fn> maSelTemplates; css::uno::Reference<css::frame::XModel> m_xModel; css::uno::Reference<css::frame::XDesktop2> mxDesktop; diff --git a/include/sfx2/templatelocalview.hxx b/include/sfx2/templatelocalview.hxx index 63c3c9d77a52..e239aa1a7dff 100644 --- a/include/sfx2/templatelocalview.hxx +++ b/include/sfx2/templatelocalview.hxx @@ -110,7 +110,8 @@ public: bool removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId); - void moveTemplates (const std::set<const ThumbnailViewItem*,selection_cmp_fn> &rItems, const sal_uInt16 nTargetItem); + void moveTemplates(const std::set<const TemplateViewItem*, selection_cmp_fn>& rItems, + const sal_uInt16 nTargetItem); bool copyFrom(TemplateContainerItem *pItem, const OUString &rPath); diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index 4828c4b234de..cdc10297dc77 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -423,8 +423,8 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt return true; } -void TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, selection_cmp_fn> &rItems, - const sal_uInt16 nTargetItem) +void TemplateLocalView::moveTemplates( + const std::set<const TemplateViewItem*, selection_cmp_fn>& rItems, const sal_uInt16 nTargetItem) { TemplateContainerItem *pTarget = nullptr; TemplateContainerItem *pSrc = nullptr; @@ -444,10 +444,9 @@ void TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx std::vector<sal_uInt16> aItemIds; // List of moved items ids (also prevents the invalidation of rItems iterators when we remove them as we go) - std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator aSelIter; - for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx ) + for (auto aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx) { - const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter); + const TemplateViewItem* pViewItem = *aSelIter; sal_uInt16 nSrcRegionId = pViewItem->mnRegionId; for (auto const & pRegion : maRegions) diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index ded5744e29b2..ca9c3a242905 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -658,10 +658,8 @@ IMPL_LINK(SfxTemplateManagerDlg, CreateContextMenuHdl, ThumbnailViewItem*, pItem bool bIsDefault = false; bool bIsInternal = false; - for (const ThumbnailViewItem* pSelItem : maSelTemplates) + for (const TemplateViewItem* pSelTemplate : maSelTemplates) { - const TemplateViewItem* pSelTemplate = dynamic_cast<const TemplateViewItem*>(pSelItem); - assert(pSelTemplate); if (pSelTemplate->IsDefaultTemplate()) bIsDefault = true; if (TemplateLocalView::IsInternalTemplate(pSelTemplate->getPath())) @@ -737,15 +735,14 @@ IMPL_LINK(SfxTemplateManagerDlg, EditTemplateHdl, ThumbnailViewItem*, pItem, voi IMPL_LINK_NOARG(SfxTemplateManagerDlg, DeleteTemplateHdl, void*, void) { - std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates; + std::set<const TemplateViewItem*, selection_cmp_fn> aSelTemplates = maSelTemplates; OUString aDeletedTemplate; for (auto const& pItem : aSelTemplates) { - const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem); - sal_uInt16 nRegionItemId = mxLocalView->getRegionId(pViewItem->mnRegionId); + sal_uInt16 nRegionItemId = mxLocalView->getRegionId(pItem->mnRegionId); - if (!mxLocalView->removeTemplate(pViewItem->mnDocId + 1, nRegionItemId))//mnId w.r.t. region is mnDocId + 1; + if (!mxLocalView->removeTemplate(pItem->mnDocId + 1, nRegionItemId))//mnId w.r.t. region is mnDocId + 1; { aDeletedTemplate += pItem->maTitle+" "; } @@ -1002,10 +999,8 @@ void SfxTemplateManagerDlg::OnTemplateExport() sal_uInt16 i = 1; auto aSelTemplates = maSelTemplates; - for (auto const& selTemplate : aSelTemplates) + for (const TemplateViewItem* pItem : aSelTemplates) { - const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(selTemplate); - INetURLObject aItemPath(pItem->getPath()); if ( 1 == i ) @@ -1048,8 +1043,7 @@ void SfxTemplateManagerDlg::OnTemplateExport() void SfxTemplateManagerDlg::OnTemplateOpen () { - const ThumbnailViewItem* pItem = *maSelTemplates.begin(); - + const TemplateViewItem* pItem = *maSelTemplates.begin(); OpenTemplateHdl(pItem); } @@ -1375,7 +1369,7 @@ IMPL_LINK(SfxTemplateSelectionDlg, OpenTemplateHdl, const ThumbnailViewItem*, pI IMPL_LINK_NOARG(SfxTemplateSelectionDlg, OkClickHdl, weld::Button&, void) { - const TemplateViewItem* pViewItem = static_cast<const TemplateViewItem*>(*maSelTemplates.begin()); + const TemplateViewItem* pViewItem = *maSelTemplates.begin(); msTemplatePath = pViewItem->getPath(); m_xDialog->response(RET_OK); commit fd9e9b38ad35959290965eca94bb28d4660561e3 Author: Michael Weghorn <[email protected]> AuthorDate: Wed Dec 31 11:58:33 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Jan 3 08:10:10 2026 +0100 sfx2: Stop copying set elems to vector Use the elements directly while iterating over SfxTemplateManagerDlg::maSelTemplates instead of first copying them to a vector and iterating over that one. And use a "p" prefix for a pointer variable. Change-Id: I2ce435939ca9c34f24c221107d5c9a07fdcd0f62 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196377 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index d5052d1cb429..ded5744e29b2 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -657,18 +657,14 @@ IMPL_LINK(SfxTemplateManagerDlg, CreateContextMenuHdl, ThumbnailViewItem*, pItem const TemplateViewItem *pViewItem = dynamic_cast<TemplateViewItem*>(pItem); bool bIsDefault = false; bool bIsInternal = false; - std::vector<const TemplateViewItem*> aSelTemplates; - for(const auto& aSelTmpl : maSelTemplates) - { - const TemplateViewItem *aItem = dynamic_cast<const TemplateViewItem*>(aSelTmpl); - aSelTemplates.push_back(aItem); - } - for(const auto& aSelTmpl : aSelTemplates) + for (const ThumbnailViewItem* pSelItem : maSelTemplates) { - if(aSelTmpl->IsDefaultTemplate()) + const TemplateViewItem* pSelTemplate = dynamic_cast<const TemplateViewItem*>(pSelItem); + assert(pSelTemplate); + if (pSelTemplate->IsDefaultTemplate()) bIsDefault = true; - if(TemplateLocalView::IsInternalTemplate(aSelTmpl->getPath())) + if (TemplateLocalView::IsInternalTemplate(pSelTemplate->getPath())) { bIsInternal = true; if(bIsDefault)
