sc/source/ui/docshell/docfunc.cxx |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

New commits:
commit cc17915f6937a333bf7b741110dbdee39b1e3eb4
Author: Mike Kaganski <mike.kagan...@collabora.com>
Date:   Mon Nov 21 18:08:35 2016 +0300

    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 <c...@libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 4942c28..d84c47d 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);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to