summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2016-11-21 18:08:35 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2016-11-22 13:47:05 +0000
commitcc17915f6937a333bf7b741110dbdee39b1e3eb4 (patch)
tree4135f4bb8918fab22c03212a7a7b513af184ca9d
parent87e040fd0f04307534920d0765af6d5878794a98 (diff)
Retain sheet protect options throughout unprotect/protect session
Currently, unprotecting a sheet clears the protection options it had (i.e. if to allow users to select protected/unprotected cells). So, protecting next time requires setting these options again. Unprotecting a sheet usually happens when author edits e.g. a form and intents to re-protect it when the edit is done, so it would be handy to restore previous flags as they were before. This patch allows saving the protection settings by using current ScTableProtection copy with its protection set to appropriate value, instead of new clean ScTableProtection or nullptr. This does not allow to save the flags between edit sessions if the protection is unset. Change-Id: Ieaba4eee746efcf05308dbc88e402c200a59b0d2 Reviewed-on: https://gerrit.libreoffice.org/31044 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--sc/source/ui/docshell/docfunc.cxx13
1 files changed, 8 insertions, 5 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 4942c28995e6..d84c47da3c90 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -3777,10 +3777,11 @@ bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword, bool /*bApi*/ )
{
// sheet protection
- ScTableProtection aProtection;
- aProtection.setProtected(true);
- aProtection.setPassword(rPassword);
- rDoc.SetTabProtection(nTab, &aProtection);
+ const ScTableProtection* pOldProtection = rDoc.GetTabProtection(nTab);
+ ::std::unique_ptr<ScTableProtection> pNewProtection(pOldProtection ? new ScTableProtection(*pOldProtection) : new ScTableProtection());
+ pNewProtection->setProtected(true);
+ pNewProtection->setPassword(rPassword);
+ rDoc.SetTabProtection(nTab, pNewProtection.get());
if (rDoc.IsUndoEnabled())
{
ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
@@ -3859,7 +3860,9 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi )
return false;
}
- rDoc.SetTabProtection(nTab, nullptr);
+ ::std::unique_ptr<ScTableProtection> pNewProtection(new ScTableProtection(*pTabProtect));
+ pNewProtection->setProtected(false);
+ rDoc.SetTabProtection(nTab, pNewProtection.get());
if (rDoc.IsUndoEnabled())
{
pProtectCopy->setProtected(false);