[Libreoffice-commits] core.git: Branch 'libreoffice-7-2-0' - sc/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 3 10:41:06 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 1663fd0f85a523bfbd46e836436e979344f009d3
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:40:30 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/+/119852
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    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 b5d01215baf8..e5815200e063 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 968ebb0cdbfe..99d33d2416db 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -1138,6 +1138,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 2b66e13e2327..e44e364c461a 100644
--- a/sc/source/ui/docshell/arealink.cxx
+++ b/sc/source/ui/docshell/arealink.cxx
@@ -226,6 +226,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 29435d90a2f4..8e2c3c45218f 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -586,21 +586,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
@@ -1090,11 +1076,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
@@ -1161,8 +1143,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 f3eca38a7da9..85ee0a42ff2d 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 eb6203362110..57f172ef2b5e 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