diff options
author | Anshu <anshukhare50@gmail.com> | 2020-12-02 08:51:15 +0530 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2021-04-14 12:00:59 +0200 |
commit | eac9eff48292df7a172c57e5c4e7bd9224d201a4 (patch) | |
tree | fd72ad417653b177a4a6b7288d3cafec743cfca4 /sc | |
parent | 02269dc9cdb8b24108d4309ac221c62cac53a5c3 (diff) |
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@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 71 | ||||
-rw-r--r-- | sc/source/ui/view/viewfunc.cxx | 1 |
2 files changed, 25 insertions, 47 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index e533d0b634fe..3fbab69b9229 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; @@ -3936,22 +3937,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(); @@ -3980,6 +3988,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 { @@ -3989,26 +4000,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; } @@ -4057,9 +4050,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) @@ -4072,22 +4062,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 d0484beb37c9..051771e1dabe 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -2512,7 +2512,6 @@ void ScViewFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect ) for (const auto& rTab : rMark) { rFunc.ProtectSheet(rTab, rProtect); - SetTabProtectionSymbol(rTab, true); } if (bUndo) |