[Libreoffice-commits] core.git: sc/source

Anshu (via logerrit) logerrit at kemper.freedesktop.org
Sat Jan 2 06:28:41 UTC 2021


 sc/source/ui/docshell/docfunc.cxx |   71 +++++++++++++-------------------------
 sc/source/ui/view/viewfunc.cxx    |    1 
 2 files changed, 25 insertions(+), 47 deletions(-)

New commits:
commit 05284641e381ec2bb3b72a39b5c7334127f6c7ba
Author:     Anshu <anshukhare50 at gmail.com>
AuthorDate: Wed Dec 2 08:51:15 2020 +0530
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Jan 2 07:28:05 2021 +0100

    tdf#133257 : Protection icon in front of sheet name
    
    Change-Id: Ifdbe0fad1f8a1d7dd6ac1dfd35c529f9e0c9fd80
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107041
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index e05513039d9e..18171bd5c44b 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -99,6 +99,7 @@
 #include <basic/basmgr.hxx>
 #include <set>
 #include <vector>
+#include <sfx2/viewfrm.hxx>
 
 using namespace com::sun::star;
 using ::std::vector;
@@ -3935,22 +3936,29 @@ void ScDocFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect )
 {
     ScDocument& rDoc = rDocShell.GetDocument();
 
+    std::unique_ptr<ScTableProtection> p;
+    if (!rProtect.isProtected() && rDoc.IsUndoEnabled())
+    {
+        // In case of unprotecting, use a copy of passed ScTableProtection object for undo
+        p = std::make_unique<ScTableProtection>(rProtect);
+    }
     rDoc.SetTabProtection(nTab, &rProtect);
     if (rDoc.IsUndoEnabled())
     {
-        ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
-        OSL_ENSURE(pProtect, "ScDocFunc::Unprotect: ScTableProtection pointer is NULL!");
-        if (pProtect)
+        if (!p)
         {
-            ::std::unique_ptr<ScTableProtection> p(new ScTableProtection(*pProtect));
-            p->setProtected(true); // just in case ...
-            rDocShell.GetUndoManager()->AddUndoAction(
-                std::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(p)) );
-
-            // ownership of unique_ptr now transferred to ScUndoTabProtect.
+            // For protection case, use a copy of resulting ScTableProtection for undo
+            ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+            p = std::make_unique<ScTableProtection>(*pProtect);
         }
+        rDocShell.GetUndoManager()->AddUndoAction(
+            std::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(p)));
+        // ownership of unique_ptr now transferred to ScUndoTabProtect.
     }
-
+    for (SfxViewFrame* fr = SfxViewFrame::GetFirst(&rDocShell); fr;
+         fr = SfxViewFrame::GetNext(*fr, &rDocShell))
+        if (ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(fr->GetViewShell()))
+            pTabViewShell->SetTabProtectionSymbol(nTab, rProtect.isProtected());
     rDocShell.PostPaintGridAll();
     ScDocShellModificator aModificator(rDocShell);
     aModificator.SetDocumentModified();
@@ -3979,6 +3987,9 @@ bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword )
                 // ownership of unique_ptr is transferred to ScUndoDocProtect.
             }
         }
+        rDocShell.PostPaintGridAll();
+        ScDocShellModificator aModificator(rDocShell);
+        aModificator.SetDocumentModified();
     }
     else
     {
@@ -3988,26 +3999,8 @@ bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword )
         ::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);
-            OSL_ENSURE(pProtect, "ScDocFunc::Unprotect: ScTableProtection pointer is NULL!");
-            if (pProtect)
-            {
-                ::std::unique_ptr<ScTableProtection> p(new ScTableProtection(*pProtect));
-                p->setProtected(true); // just in case ...
-                rDocShell.GetUndoManager()->AddUndoAction(
-                    std::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(p)) );
-                // ownership of unique_ptr now transferred to ScUndoTabProtect.
-            }
-        }
+        ProtectSheet(nTab, *pNewProtection);
     }
-
-    rDocShell.PostPaintGridAll();
-    ScDocShellModificator aModificator( rDocShell );
-    aModificator.SetDocumentModified();
-
     return true;
 }
 
@@ -4056,9 +4049,6 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi )
         if (!pTabProtect || !pTabProtect->isProtected())
             // already unprotected (should not happen)!
             return true;
-
-        // save the protection state before unprotect (for undo).
-        ::std::unique_ptr<ScTableProtection> pProtectCopy(new ScTableProtection(*pTabProtect));
         if (!pTabProtect->verifyPassword(rPassword))
         {
             if (!bApi)
@@ -4071,22 +4061,11 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi )
             return false;
         }
 
-        ::std::unique_ptr<ScTableProtection> pNewProtection(new ScTableProtection(*pTabProtect));
-        pNewProtection->setProtected(false);
-        rDoc.SetTabProtection(nTab, pNewProtection.get());
-        if (rDoc.IsUndoEnabled())
-        {
-            pProtectCopy->setProtected(false);
-            rDocShell.GetUndoManager()->AddUndoAction(
-                std::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(pProtectCopy)) );
-            // ownership of unique_ptr now transferred to ScUndoTabProtect.
-        }
+        ScTableProtection aNewProtection(*pTabProtect);
+        aNewProtection.setProtected(false);
+        ProtectSheet(nTab, aNewProtection);
     }
 
-    rDocShell.PostPaintGridAll();
-    ScDocShellModificator aModificator( rDocShell );
-    aModificator.SetDocumentModified();
-
     return true;
 }
 
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 1c8d699b690a..164327616a6a 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -2511,7 +2511,6 @@ void ScViewFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect )
     for (const auto& rTab : rMark)
     {
         rFunc.ProtectSheet(rTab, rProtect);
-        SetTabProtectionSymbol(rTab, true);
     }
 
     if (bUndo)


More information about the Libreoffice-commits mailing list