diff options
author | Eike Rathke <erack@redhat.com> | 2021-08-01 21:40:15 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-08-01 22:35:28 +0200 |
commit | 55abc3eb93fb8314b413453e384261cb00fde087 (patch) | |
tree | 15c660885d22e47dae0863709e51627a696bf62c /sc/source/ui/docshell/docsh4.cxx | |
parent | c0ce120b55ba389729e97babf80f2cb39ce38e9f (diff) |
Consolidate link update handling
Have it at one central place and identical for all document
loading paths.
Change-Id: Ib00153a9f5831e223d0129df0538353a7e20961e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119835
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'sc/source/ui/docshell/docsh4.cxx')
-rw-r--r-- | sc/source/ui/docshell/docsh4.cxx | 90 |
1 files changed, 55 insertions, 35 deletions
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 1f166eedfa19..e188d5e58423 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -110,6 +110,61 @@ using namespace ::com::sun::star; #include <svx/xdef.hxx> +void ScDocShell::SetInitialLinkUpdate( SfxMedium* pMed ) +{ + if (pMed) + { + const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>( pMed->GetItemSet(), + SID_UPDATEDOCMODE, false); + m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE; + } + + // GetLinkUpdateModeState() evaluates m_nCanUpdate so that must have + // been set first. Do not override an already forbidden LinkUpdate (the + // default is allow). + comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer(); + if (rEmbeddedObjectContainer.getUserAllowsLinkUpdate()) + { + // For anything else than LM_ALWAYS we need user confirmation. + rEmbeddedObjectContainer.setUserAllowsLinkUpdate( GetLinkUpdateModeState() == LM_ALWAYS); + } +} + +ScLkUpdMode ScDocShell::GetLinkUpdateModeState() const +{ + ScLkUpdMode nSet; + if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE) + nSet = LM_NEVER; + else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE) + nSet = LM_ALWAYS; + else + { + nSet = GetDocument().GetLinkMode(); + if (nSet == LM_UNKNOWN) + { + ScAppOptions aAppOptions = SC_MOD()->GetAppOptions(); + nSet = aAppOptions.GetLinkMode(); + } + } + + if (nSet == LM_ALWAYS + && !(SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks( + GetMedium() == nullptr ? OUString() : GetMedium()->GetName()) + || (IsDocShared() + && SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks( + GetSharedFileURL())))) + { + nSet = LM_ON_DEMAND; + } + if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE + && nSet == LM_ON_DEMAND) + { + nSet = LM_NEVER; + } + + return nSet; +} + void ScDocShell::AllowLinkUpdate() { m_aDocument.SetLinkFormulaNeedingCheck(false); @@ -150,41 +205,6 @@ IMPL_LINK_NOARG( ScDocShell, ReloadAllLinksHdl, weld::Button&, void ) SAL_WARN_IF(!pViewFrame, "sc", "expected there to be a ViewFrame"); } -ScLkUpdMode ScDocShell::GetLinkUpdateModeState() const -{ - const ScDocument& rDoc = GetDocument(); - - ScLkUpdMode nSet = rDoc.GetLinkMode(); - - if (nSet == LM_UNKNOWN) - { - ScAppOptions aAppOptions = SC_MOD()->GetAppOptions(); - nSet = aAppOptions.GetLinkMode(); - } - - if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE) - nSet = LM_NEVER; - else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE) - nSet = LM_ALWAYS; - - if (nSet == LM_ALWAYS - && !(SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks( - GetMedium() == nullptr ? OUString() : GetMedium()->GetName()) - || (IsDocShared() - && SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks( - GetSharedFileURL())))) - { - nSet = LM_ON_DEMAND; - } - if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE - && nSet == LM_ON_DEMAND) - { - nSet = LM_NEVER; - } - - return nSet; -} - void ScDocShell::Execute( SfxRequest& rReq ) { const SfxItemSet* pReqArgs = rReq.GetArgs(); |