[Libreoffice-commits] core.git: include/sfx2 sfx2/source
Vert D (via logerrit)
logerrit at kemper.freedesktop.org
Wed Dec 23 10:39:27 UTC 2020
include/sfx2/templatedlglocalview.hxx | 2 +-
include/sfx2/templatelocalview.hxx | 2 ++
sfx2/source/control/templatedlglocalview.cxx | 8 +++++++-
sfx2/source/control/templatelocalview.cxx | 22 ++++++++++++++++++++++
sfx2/source/control/templatesearchview.cxx | 7 ++++++-
sfx2/source/doc/templatedlg.cxx | 4 ++--
sfx2/source/inc/templatesearchview.hxx | 2 +-
7 files changed, 41 insertions(+), 6 deletions(-)
New commits:
commit 86f3fa919a6de6767177193d5b7714f8f6dbd5c4
Author: Vert D <devoptmsoi at gmx.com>
AuthorDate: Sat Dec 12 00:39:51 2020 -0500
Commit: Heiko Tietze <heiko.tietze at documentfoundation.org>
CommitDate: Wed Dec 23 11:38:50 2020 +0100
tdf#138246 Disable edit rename delete contextmenu items for built-in templates
Change-Id: I7bcaa8acc034a3d3e9926db2f1f54bbeceddca2d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107611
Tested-by: Jenkins
Tested-by: Heiko Tietze <heiko.tietze at documentfoundation.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
Reviewed-by: Heiko Tietze <heiko.tietze at documentfoundation.org>
diff --git a/include/sfx2/templatedlglocalview.hxx b/include/sfx2/templatedlglocalview.hxx
index b3a50eeff50c..c6caca46f519 100644
--- a/include/sfx2/templatedlglocalview.hxx
+++ b/include/sfx2/templatedlglocalview.hxx
@@ -26,7 +26,7 @@ public:
void showRegion(std::u16string_view rName);
- void createContextMenu(const bool bIsDefault);
+ void createContextMenu(const bool bIsDefault, const bool bIsBuiltIn);
virtual void Show() override;
diff --git a/include/sfx2/templatelocalview.hxx b/include/sfx2/templatelocalview.hxx
index 9304e858ad9b..a37d72d1cf50 100644
--- a/include/sfx2/templatelocalview.hxx
+++ b/include/sfx2/templatelocalview.hxx
@@ -153,6 +153,8 @@ public:
static bool IsDefaultTemplate(const OUString& rPath);
+ static bool IsInternalTemplate(const OUString& rPath);
+
protected:
virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override;
diff --git a/sfx2/source/control/templatedlglocalview.cxx b/sfx2/source/control/templatedlglocalview.cxx
index 0949e684c414..39b88774cade 100644
--- a/sfx2/source/control/templatedlglocalview.cxx
+++ b/sfx2/source/control/templatedlglocalview.cxx
@@ -63,7 +63,7 @@ void TemplateDlgLocalView::showRegion(std::u16string_view rName)
}
}
-void TemplateDlgLocalView::createContextMenu(const bool bIsDefault)
+void TemplateDlgLocalView::createContextMenu(const bool bIsDefault, const bool bIsBuiltIn)
{
mxContextMenu->clear();
mxContextMenu->append("open", SfxResId(STR_OPEN));
@@ -77,6 +77,12 @@ void TemplateDlgLocalView::createContextMenu(const bool bIsDefault)
mxContextMenu->append_separator("separator");
mxContextMenu->append("rename", SfxResId(STR_SFX_RENAME));
mxContextMenu->append("delete", SfxResId(STR_DELETE));
+ if (bIsBuiltIn)
+ {
+ mxContextMenu->set_sensitive("rename", false);
+ mxContextMenu->set_sensitive("edit", false);
+ mxContextMenu->set_sensitive("delete", false);
+ }
if (mViewMode == TemplateViewMode::eThumbnailView)
{
deselectItems();
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 5faba8b552d1..87e07fd30642 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -26,6 +26,11 @@
#include <sfx2/strings.hrc>
#include <bitmaps.hlst>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/util/thePathSettings.hpp>
+#include <unotools/ucbhelper.hxx>
+#include <sfxurlrelocator.hxx>
+
using namespace ::com::sun::star;
bool ViewFilter_Application::isFilteredExtension(FILTER_APPLICATION filter, std::u16string_view rExt)
@@ -919,5 +924,22 @@ void TemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pItem)
maOpenTemplateHdl.Call(pViewItem);
}
+bool TemplateLocalView::IsInternalTemplate(const OUString& rPath)
+{
+ uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
+ css::uno::Reference< css::util::XPathSettings > xPathSettings = css::util::thePathSettings::get(xContext);
+ uno::Sequence<OUString> aInternalTemplateDirs;
+ uno::Any aAny = xPathSettings->getPropertyValue("Template_internal");
+ aAny >>= aInternalTemplateDirs;
+ SfxURLRelocator_Impl aRelocator(xContext);
+ for (auto& rInternalTemplateDir : aInternalTemplateDirs)
+ {
+ aRelocator.makeRelocatableURL(rInternalTemplateDir);
+ aRelocator.makeAbsoluteURL(rInternalTemplateDir);
+ if(::utl::UCBContentHelper::IsSubPath(rInternalTemplateDir, rPath))
+ return true;
+ }
+ return false;
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/templatesearchview.cxx b/sfx2/source/control/templatesearchview.cxx
index e1d2f8083fac..bde9769cd751 100644
--- a/sfx2/source/control/templatesearchview.cxx
+++ b/sfx2/source/control/templatesearchview.cxx
@@ -131,7 +131,7 @@ bool TemplateSearchView::Command(const CommandEvent& rCEvt)
return true;
}
-void TemplateSearchView::createContextMenu(const bool bIsDefault)
+void TemplateSearchView::createContextMenu(const bool bIsDefault, const bool bIsBuiltIn)
{
mxContextMenu->clear();
mxContextMenu->append(MNI_OPEN,SfxResId(STR_OPEN));
@@ -144,6 +144,11 @@ void TemplateSearchView::createContextMenu(const bool bIsDefault)
mxContextMenu->append_separator("separator");
mxContextMenu->append(MNI_DELETE,SfxResId(STR_DELETE));
+ if(bIsBuiltIn)
+ {
+ mxContextMenu->set_sensitive(MNI_EDIT, false);
+ mxContextMenu->set_sensitive(MNI_DELETE, false);
+ }
if(mViewMode == TemplateViewMode::eThumbnailView)
{
maSelectedItem->setSelection(true);
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index f7d6a1d72210..13444e6b4280 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -671,9 +671,9 @@ IMPL_LINK(SfxTemplateManagerDlg, CreateContextMenuHdl, ThumbnailViewItem*, pItem
if (pViewItem)
{
if (mxSearchView->IsVisible())
- mxSearchView->createContextMenu(pViewItem->IsDefaultTemplate());
+ mxSearchView->createContextMenu(pViewItem->IsDefaultTemplate(), TemplateLocalView::IsInternalTemplate(pViewItem->getPath()));
else
- mxLocalView->createContextMenu(pViewItem->IsDefaultTemplate());
+ mxLocalView->createContextMenu(pViewItem->IsDefaultTemplate(), TemplateLocalView::IsInternalTemplate(pViewItem->getPath()));
}
}
diff --git a/sfx2/source/inc/templatesearchview.hxx b/sfx2/source/inc/templatesearchview.hxx
index 8f02f206b296..324c97a30709 100644
--- a/sfx2/source/inc/templatesearchview.hxx
+++ b/sfx2/source/inc/templatesearchview.hxx
@@ -37,7 +37,7 @@ public:
void setDefaultTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
- void createContextMenu(const bool bIsDefault);
+ void createContextMenu(const bool bIsDefault, const bool bIsBuiltIn);
void AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx,
const OUString &rTitle, const OUString &rSubtitle,
More information about the Libreoffice-commits
mailing list