sw: Optionally disable bookmark manipulation GUIs
If the ProtectBookmarks bit is set, don't allow bookmark
changes, neither via the bookmark dialog nor the navigator.
Change-Id: I035faaf3871c7107dd1aac38c4e6867291827346
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87361
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index 755bcc5..a1297ed 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -684,6 +684,7 @@
#define STR_POSTIT_HIDE NC_("STR_POSTIT_HIDE", "Hide All")
#define STR_POSTIT_DELETE NC_("STR_POSTIT_DELETE", "Delete All")
#define STR_RESOLVED NC_("STR_RESOLVED", "RESOLVED")
#define STR_PROTECTED NC_("STR_PROTECTED", "Protected")
#define STR_MARGIN_TOOLTIP_LEFT NC_("STR_MARGIN_TOOLTIP_LEFT", "Left: ")
#define STR_MARGIN_TOOLTIP_RIGHT NC_("STR_MARGIN_TOOLTIP_RIGHT", ". Right: ")
diff --git a/sw/source/ui/misc/bookmark.cxx b/sw/source/ui/misc/bookmark.cxx
index 9243f6c..d480068 100644
--- a/sw/source/ui/misc/bookmark.cxx
+++ b/sw/source/ui/misc/bookmark.cxx
@@ -32,6 +32,7 @@
#include <ndtxt.hxx>
#include <strings.hrc>
#include <svtools/miscopt.hxx>
#include <IDocumentSettingAccess.hxx>
using namespace ::com::sun::star;
@@ -78,12 +79,12 @@ IMPL_LINK_NOARG(SwInsertBookmarkDlg, ModifyHdl, weld::Entry&, void)
}
// allow to add new bookmark only if one name provided and it's not taken
m_xInsertBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 0 && !bHasForbiddenChars);
m_xInsertBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 0 && !bHasForbiddenChars && !m_bAreProtected);
// allow to delete only if all bookmarks are recognized
m_xDeleteBtn->set_sensitive(nEntries > 0 && nSelectedEntries == nEntries);
m_xDeleteBtn->set_sensitive(nEntries > 0 && nSelectedEntries == nEntries && !m_bAreProtected);
m_xGotoBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1);
m_xRenameBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1);
m_xRenameBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1 && !m_bAreProtected);
}
// callback to delete a text mark
@@ -160,13 +161,12 @@ IMPL_LINK_NOARG(SwInsertBookmarkDlg, SelectionChangedHdl, weld::TreeView&, void)
{
m_xInsertBtn->set_sensitive(false);
m_xGotoBtn->set_sensitive(nSelectedRows == 1);
m_xRenameBtn->set_sensitive(nSelectedRows == 1);
m_xDeleteBtn->set_sensitive(true);
m_xRenameBtn->set_sensitive(nSelectedRows == 1 && !m_bAreProtected);
m_xEditBox->set_text(sEditBoxText.makeStringAndClear());
}
else
{
m_xInsertBtn->set_sensitive(true);
m_xInsertBtn->set_sensitive(!m_bAreProtected);
m_xGotoBtn->set_sensitive(false);
m_xRenameBtn->set_sensitive(false);
m_xDeleteBtn->set_sensitive(false);
@@ -340,6 +340,7 @@ SwInsertBookmarkDlg::SwInsertBookmarkDlg(weld::Window* pParent, SwWrtShell& rS,
m_xConditionED->set_visible( false );
}
m_bAreProtected = rSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS);
}
IMPL_LINK(SwInsertBookmarkDlg, HeaderBarClick, int, nColumn, void)
diff --git a/sw/source/uibase/inc/bookmark.hxx b/sw/source/uibase/inc/bookmark.hxx
index 7522dbe..3a8ee15 100644
--- a/sw/source/uibase/inc/bookmark.hxx
+++ b/sw/source/uibase/inc/bookmark.hxx
@@ -69,6 +69,7 @@ class SwInsertBookmarkDlg : public SfxDialogController
std::vector<std::pair<sw::mark::IMark*, OUString>> aTableBookmarks;
sal_Int32 m_nLastBookmarksCount;
bool m_bSorted;
bool m_bAreProtected;
std::unique_ptr<weld::Entry> m_xEditBox;
std::unique_ptr<weld::Button> m_xInsertBtn;
diff --git a/sw/source/uibase/inc/conttree.hxx b/sw/source/uibase/inc/conttree.hxx
index 89333bf..e9c2278 100644
--- a/sw/source/uibase/inc/conttree.hxx
+++ b/sw/source/uibase/inc/conttree.hxx
@@ -88,6 +88,7 @@ class SwContentTree final
OUString const m_sPostItShow;
OUString const m_sPostItHide;
OUString const m_sPostItDelete;
OUString const m_sProtected;
SwWrtShell* m_pHiddenShell; // dropped Doc
SwWrtShell* m_pActiveShell; // the active or a const. open view
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 17b15bd..f8bd62c 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -677,7 +677,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
case FN_DELETE_BOOKMARK:
{
if ( pItem )
if (pItem && !rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
{
IDocumentMarkAccess* const pMarkAccess = rWrtSh.getIDocumentMarkAccess();
pMarkAccess->deleteMark( pMarkAccess->findMark(static_cast<const SfxStringItem*>(pItem)->GetValue()) );
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 1b9d2ee..2a7826b 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -51,6 +51,7 @@
#include <navicfg.hxx>
#include <edtwin.hxx>
#include <doc.hxx>
#include <IDocumentSettingAccess.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentOutlineNodes.hxx>
#include <unotxvw.hxx>
@@ -335,7 +336,9 @@ void SwContentType::Init(bool* pbInvalidateWindow)
pMarkAccess->getBookmarksEnd(),
&lcl_IsUiVisibleBookmark);
m_sTypeToken.clear();
m_bEdit = true;
const bool bProtectedBM = m_pWrtShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS);
m_bEdit = !bProtectedBM;
m_bDelete = !bProtectedBM;
}
break;
case ContentTypeId::REGION :
@@ -862,6 +865,7 @@ SwContentTree::SwContentTree(vcl::Window* pParent, SwNavigationPI* pDialog)
, m_sPostItShow(SwResId(STR_POSTIT_SHOW))
, m_sPostItHide(SwResId(STR_POSTIT_HIDE))
, m_sPostItDelete(SwResId(STR_POSTIT_DELETE))
, m_sProtected(SwResId(STR_PROTECTED))
, m_pHiddenShell(nullptr)
, m_pActiveShell(nullptr)
, m_pConfig(SW_MOD()->GetNavigationConfig())
@@ -1277,19 +1281,21 @@ VclPtr<PopupMenu> SwContentTree::CreateContextMenu()
assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
const SwContentType* pContType = static_cast<SwContent*>(pEntry->GetUserData())->GetParent();
const ContentTypeId nContentType = pContType->GetType();
bool bReadonly = m_pActiveShell->GetView().GetDocShell()->IsReadOnly();
bool bVisible = !static_cast<SwContent*>(pEntry->GetUserData())->IsInvisible();
bool bProtected = static_cast<SwContent*>(pEntry->GetUserData())->IsProtect();
bool bEditable = pContType->IsEditable() &&
((bVisible && !bProtected) ||ContentTypeId::REGION == nContentType);
bool bDeletable = pContType->IsDeletable() &&
((bVisible && !bProtected) ||ContentTypeId::REGION == nContentType);
bool bRenamable = bEditable && !bReadonly &&
const bool bReadonly = m_pActiveShell->GetView().GetDocShell()->IsReadOnly();
const bool bVisible = !static_cast<SwContent*>(pEntry->GetUserData())->IsInvisible();
const bool bProtected = static_cast<SwContent*>(pEntry->GetUserData())->IsProtect();
const bool bProtectBM = (ContentTypeId::BOOKMARK == nContentType)
&& m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS);
const bool bEditable = pContType->IsEditable() &&
((bVisible && !bProtected && !bProtectBM) || ContentTypeId::REGION == nContentType);
const bool bDeletable = pContType->IsDeletable() &&
((bVisible && !bProtected && !bProtectBM) || ContentTypeId::REGION == nContentType);
const bool bRenamable = bEditable && !bReadonly &&
(ContentTypeId::TABLE == nContentType ||
ContentTypeId::FRAME == nContentType ||
ContentTypeId::GRAPHIC == nContentType ||
ContentTypeId::OLE == nContentType ||
ContentTypeId::BOOKMARK == nContentType ||
(ContentTypeId::BOOKMARK == nContentType && !bProtectBM) ||
ContentTypeId::REGION == nContentType ||
ContentTypeId::INDEX == nContentType ||
ContentTypeId::DRAWOBJECT == nContentType);
@@ -1365,6 +1371,11 @@ VclPtr<PopupMenu> SwContentTree::CreateContextMenu()
if(bRenamable)
pPop->InsertItem(502, m_sRename);
}
else if (bProtectBM)
{
pPop->InsertItem(503, m_sProtected);
pPop->EnableItem(503, false);
}
pPop->SetAccelKey(501, vcl::KeyCode(KEY_DELETE, false, false, false, false));
}
else if( pEntry )
@@ -3615,6 +3626,7 @@ void SwContentTree::EditEntry(SvTreeListEntry const * pEntry, EditEntryMode nMod
nSlot = FN_FORMAT_FRAME_DLG;
break;
case ContentTypeId::BOOKMARK :
assert(!m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS));
if(nMode == EditEntryMode::DELETE)
{
IDocumentMarkAccess* const pMarkAccess = m_pActiveShell->getIDocumentMarkAccess();