[Libreoffice-commits] core.git: Branch 'libreoffice-7-1' - sc/source
Eike Rathke (via logerrit)
logerrit at kemper.freedesktop.org
Tue Aug 3 10:40:32 UTC 2021
sc/source/filter/oox/excelfilter.cxx | 8 ++-
sc/source/filter/xml/xmlimprt.cxx | 3 +
sc/source/ui/docshell/arealink.cxx | 3 +
sc/source/ui/docshell/docsh.cxx | 25 +--------
sc/source/ui/docshell/docsh4.cxx | 90 +++++++++++++++++++++--------------
sc/source/ui/inc/docsh.hxx | 1
6 files changed, 71 insertions(+), 59 deletions(-)
New commits:
commit 75a88761b70a098e77c73a0ba716d0e78a6d4659
Author: Eike Rathke <erack at redhat.com>
AuthorDate: Sun Aug 1 21:40:15 2021 +0200
Commit: Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Aug 3 12:39:55 2021 +0200
Consolidate link update handling
Have it at one central place and identical for all document
loading paths.
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119835
Reviewed-by: Eike Rathke <erack at redhat.com>
Tested-by: Jenkins
(cherry picked from commit 55abc3eb93fb8314b413453e384261cb00fde087)
Conflicts:
sc/source/ui/docshell/docsh4.cxx
Change-Id: Ib00153a9f5831e223d0129df0538353a7e20961e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119837
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/sc/source/filter/oox/excelfilter.cxx b/sc/source/filter/oox/excelfilter.cxx
index 4c59a0e9393b..b015f82500c2 100644
--- a/sc/source/filter/oox/excelfilter.cxx
+++ b/sc/source/filter/oox/excelfilter.cxx
@@ -109,14 +109,18 @@ bool ExcelFilter::importDocument()
if (xBookGlob)
{
rtl::Reference<FragmentHandler> xWorkbookFragment( new WorkbookFragment(*xBookGlob, aWorkbookPath));
+
+ const WorkbookFragment* pWF = static_cast<const WorkbookFragment*>(xWorkbookFragment.get());
+ const ScDocument& rDoc = pWF->getScDocument();
+ if (ScDocShell* pDocSh = static_cast<ScDocShell*>(rDoc.GetDocumentShell()))
+ pDocSh->SetInitialLinkUpdate( pDocSh->GetMedium());
+
bool bRet = importFragment( xWorkbookFragment);
if (bRet)
{
- const WorkbookFragment* pWF = static_cast<const WorkbookFragment*>(xWorkbookFragment.get());
const AddressConverter& rAC = pWF->getAddressConverter();
if (rAC.isTabOverflow() || rAC.isColOverflow() || rAC.isRowOverflow())
{
- const ScDocument& rDoc = pWF->getScDocument();
if (rDoc.IsUserInteractionEnabled())
{
// Show data loss warning.
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index e29112fab2b1..1fff4f1c3a32 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -1308,6 +1308,9 @@ void SAL_CALL ScXMLImport::setTargetDocument( const css::uno::Reference< css::la
if (!pDoc)
throw lang::IllegalArgumentException();
+ if (ScDocShell* pDocSh = static_cast<ScDocShell*>(pDoc->GetDocumentShell()))
+ pDocSh->SetInitialLinkUpdate( pDocSh->GetMedium());
+
mpDocImport.reset(new ScDocumentImport(*pDoc));
mpComp.reset(new ScCompiler(*pDoc, ScAddress(), formula::FormulaGrammar::GRAM_ODFF));
diff --git a/sc/source/ui/docshell/arealink.cxx b/sc/source/ui/docshell/arealink.cxx
index 2920ca6ad08d..0d3c51116b0b 100644
--- a/sc/source/ui/docshell/arealink.cxx
+++ b/sc/source/ui/docshell/arealink.cxx
@@ -227,6 +227,9 @@ bool ScAreaLink::Refresh( const OUString& rNewFile, const OUString& rNewFilter,
if (rNewFile.isEmpty() || rNewFilter.isEmpty())
return false;
+ if (!m_pDocSh->GetEmbeddedObjectContainer().getUserAllowsLinkUpdate())
+ return false;
+
OUString aNewUrl( ScGlobal::GetAbsDocName( rNewFile, m_pDocSh ) );
bool bNewUrlName = (aNewUrl != aFileName);
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 91020db0b2e0..e588494e3055 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -583,21 +583,7 @@ bool ScDocShell::Load( SfxMedium& rMedium )
bool bRet = SfxObjectShell::Load(rMedium);
if (bRet)
{
- if (GetMedium())
- {
- const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.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);
- }
+ SetInitialLinkUpdate(&rMedium);
{
// prepare a valid document for XML filter
@@ -1087,11 +1073,7 @@ bool ScDocShell::LoadFrom( SfxMedium& rMedium )
bool bRet = false;
- if (GetMedium())
- {
- const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
- m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
- }
+ SetInitialLinkUpdate(&rMedium);
// until loading/saving only the styles in XML is implemented,
// load the whole file
@@ -1158,8 +1140,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
// So make sure that we transfer the whole file with CreateFileStream
rMedium.GetPhysicalName(); //! Call CreateFileStream directly, if available
- const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
- m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
+ SetInitialLinkUpdate(&rMedium);
std::shared_ptr<const SfxFilter> pFilter = rMedium.GetFilter();
if (pFilter)
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 32e14f99eff4..7fb2a4a848b0 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();
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 41c0b30a42a8..f4ea4ae65296 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -294,6 +294,7 @@ public:
virtual void ReconnectDdeLink(SfxObjectShell& rServer) override;
void UpdateLinks() override;
+ void SetInitialLinkUpdate( SfxMedium* pMedium );
void AllowLinkUpdate();
void ReloadAllLinks();
void ReloadTabLinks();
More information about the Libreoffice-commits
mailing list