[Libreoffice-commits] .: 2 commits - sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Wed Mar 2 11:44:26 PST 2011


 sc/source/ui/docshell/externalrefmgr.cxx |   61 +++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 19 deletions(-)

New commits:
commit 1fd187ab7cece40aead9f49f189c39865ad8ab4a
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 2 14:43:56 2011 -0500

    Remove comment that's no longer true.

diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 18a2469..4b8a7e7 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1711,8 +1711,6 @@ ScExternalRefCache::TokenRef ScExternalRefManager::getSingleRefToken(
     if (pSrcDoc)
     {
         // source document already loaded in memory.  Re-use this instance.
-        // We don't even cache data when the document is loaded.
-
         SCTAB nTab;
         if (!pSrcDoc->GetTable(rTabName, nTab))
         {
commit 0acb3e2bb151dd8cfae5e2c9349d6e0b0297a269
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 2 14:41:52 2011 -0500

    We need to populate the cache with all sheet names even for in-memory doc.
    
    This fixes fdo#34356 and fdo#34853.

diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 4d1a9db..18a2469 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1655,6 +1655,41 @@ void putRangeDataIntoCache(
     }
 }
 
+/**
+ * When accessing an external document for the first time, we need to
+ * populate the cache with all its sheet names (whether they are referenced
+ * or not) in the correct order.  Many client codes that use external
+ * references make this assumption.
+ *
+ * @param rRefCache cache table set.
+ * @param pSrcDoc source document instance.
+ * @param nFileId external file ID associated with the source document.
+ */
+void initDocInCache(ScExternalRefCache& rRefCache, const ScDocument* pSrcDoc, sal_uInt16 nFileId)
+{
+    if (!pSrcDoc)
+        return;
+
+    if (rRefCache.isDocInitialized(nFileId))
+        // Already initialized.  No need to do this twice.
+        return;
+
+    SCTAB nTabCount = pSrcDoc->GetTableCount();
+    if (nTabCount)
+    {
+        // Populate the cache with all table names in the source document.
+        vector<String> aTabNames;
+        aTabNames.reserve(nTabCount);
+        for (SCTAB i = 0; i < nTabCount; ++i)
+        {
+            String aName;
+            pSrcDoc->GetName(i, aName);
+            aTabNames.push_back(aName);
+        }
+        rRefCache.initializeDoc(nFileId, aTabNames);
+    }
+}
+
 }
 
 ScExternalRefCache::TokenRef ScExternalRefManager::getSingleRefToken(
@@ -2027,6 +2062,7 @@ const ScDocument* ScExternalRefManager::getInMemorySrcDocument(sal_uInt16 nFileI
     if (!pFileName)
         return NULL;
 
+    ScDocument* pSrcDoc = NULL;
     TypeId aType(TYPE(ScDocShell));
     ScDocShell* pShell = static_cast<ScDocShell*>(SfxObjectShell::GetFirst(&aType, false));
     while (pShell)
@@ -2039,12 +2075,15 @@ const ScDocument* ScExternalRefManager::getInMemorySrcDocument(sal_uInt16 nFileI
             if (pFileName->EqualsIgnoreCaseAscii(aName))
             {
                 // Found !
-                return pShell->GetDocument();
+                pSrcDoc = pShell->GetDocument();
+                break;
             }
         }
         pShell = static_cast<ScDocShell*>(SfxObjectShell::GetNext(*pShell, &aType, false));
     }
-    return NULL;
+
+    initDocInCache(maRefCache, pSrcDoc, nFileId);
+    return pSrcDoc;
 }
 
 const ScDocument* ScExternalRefManager::getSrcDocument(sal_uInt16 nFileId)
@@ -2087,21 +2126,7 @@ const ScDocument* ScExternalRefManager::getSrcDocument(sal_uInt16 nFileId)
     maDocShells.insert(DocShellMap::value_type(nFileId, aSrcDoc));
     SfxObjectShell* p = aSrcDoc.maShell;
     ScDocument* pSrcDoc = static_cast<ScDocShell*>(p)->GetDocument();
-
-    SCTAB nTabCount = pSrcDoc->GetTableCount();
-    if (!maRefCache.isDocInitialized(nFileId) && nTabCount)
-    {
-        // Populate the cache with all table names in the source document.
-        vector<String> aTabNames;
-        aTabNames.reserve(nTabCount);
-        for (SCTAB i = 0; i < nTabCount; ++i)
-        {
-            String aName;
-            pSrcDoc->GetName(i, aName);
-            aTabNames.push_back(aName);
-        }
-        maRefCache.initializeDoc(nFileId, aTabNames);
-    }
+    initDocInCache(maRefCache, pSrcDoc, nFileId);
     return pSrcDoc;
 }
 


More information about the Libreoffice-commits mailing list