[Libreoffice-commits] core.git: Branch 'private/kohei/external-ref-refresh' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Mon May 19 22:03:43 PDT 2014


 sc/inc/externalrefmgr.hxx                |    4 ++
 sc/source/core/data/documen8.cxx         |   56 ++++++++++++++++++++-----------
 sc/source/ui/docshell/externalrefmgr.cxx |   30 ++++++++++++++--
 3 files changed, 67 insertions(+), 23 deletions(-)

New commits:
commit 70658b23f2d426e9a1a42d194f11c954cb2f5890
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 00:59:29 2014 -0400

    cp#1000072: Stop the external doc shell timer while mass-updating.
    
    To prevent collision with the timer wanting to purge the doc cache
    while updating external links.
    
    Also, show progress bar, and make the timer interval and the document
    cache life span longer.
    
    Change-Id: I325984c8fa68425a2621cf8f9c016463291afc89

diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index 1c7fcc1..bbb3094 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -689,6 +689,8 @@ public:
 
     void insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell);
 
+    void enableDocTimer( bool bEnable );
+
 private:
     ScExternalRefManager();
     ScExternalRefManager(const ScExternalRefManager&);
@@ -822,6 +824,8 @@ private:
      */
     bool mbUserInteractionEnabled:1;
 
+    bool mbDocTimerEnabled:1;
+
     AutoTimer maSrcDocTimer;
     DECL_LINK(TimeOutHdl, AutoTimer*);
 };
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 316738a..4563b02 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -780,6 +780,9 @@ bool ScDocument::IsInLinkUpdate() const
 
 void ScDocument::UpdateExternalRefLinks(Window* pWin)
 {
+    if (!pExternalRefMgr.get())
+        return;
+
     sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc);
     if (!pMgr)
         return;
@@ -788,33 +791,48 @@ void ScDocument::UpdateExternalRefLinks(Window* pWin)
     sal_uInt16 nCount = rLinks.size();
 
     bool bAny = false;
+
+    // Collect all the external ref links first.
+    std::vector<ScExternalRefLink*> aRefLinks;
     for (sal_uInt16 i = 0; i < nCount; ++i)
     {
         ::sfx2::SvBaseLink* pBase = *rLinks[i];
         ScExternalRefLink* pRefLink = dynamic_cast<ScExternalRefLink*>(pBase);
         if (pRefLink)
+            aRefLinks.push_back(pRefLink);
+    }
+
+    pExternalRefMgr->enableDocTimer(false);
+    ScProgress aProgress(GetDocumentShell(), "Updating external links", aRefLinks.size());
+    for (size_t i = 0, n = aRefLinks.size(); i < n; ++i)
+    {
+        aProgress.SetState(i);
+
+        ScExternalRefLink* pRefLink = aRefLinks[i];
+        if (pRefLink->Update())
         {
-            if (pRefLink->Update())
-                bAny = true;
-            else
-            {
-                // Update failed.  Notify the user.
-
-                OUString aFile;
-                pMgr->GetDisplayNames(pRefLink, NULL, &aFile, NULL, NULL);
-                // Decode encoded URL for display friendliness.
-                INetURLObject aUrl(aFile,INetURLObject::WAS_ENCODED);
-                aFile = aUrl.GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS);
-
-                OUStringBuffer aBuf;
-                aBuf.append(OUString(ScResId(SCSTR_EXTDOC_NOT_LOADED)));
-                aBuf.appendAscii("\n\n");
-                aBuf.append(aFile);
-                ErrorBox aBox(pWin, WB_OK, aBuf.makeStringAndClear());
-                aBox.Execute();
-            }
+            bAny = true;
+            continue;
         }
+
+        // Update failed.  Notify the user.
+
+        OUString aFile;
+        pMgr->GetDisplayNames(pRefLink, NULL, &aFile, NULL, NULL);
+        // Decode encoded URL for display friendliness.
+        INetURLObject aUrl(aFile,INetURLObject::WAS_ENCODED);
+        aFile = aUrl.GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS);
+
+        OUStringBuffer aBuf;
+        aBuf.append(OUString(ScResId(SCSTR_EXTDOC_NOT_LOADED)));
+        aBuf.appendAscii("\n\n");
+        aBuf.append(aFile);
+        ErrorBox aBox(pWin, WB_OK, aBuf.makeStringAndClear());
+        aBox.Execute();
     }
+
+    pExternalRefMgr->enableDocTimer(true);
+
     if (bAny)
     {
         TrackFormulas();
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 549549a..ded749f 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -71,8 +71,8 @@ using ::std::list;
 using ::std::unary_function;
 using namespace formula;
 
-#define SRCDOC_LIFE_SPAN     6000       // 1 minute (in 100th of a sec)
-#define SRCDOC_SCAN_INTERVAL 1000*5     // every 5 seconds (in msec)
+#define SRCDOC_LIFE_SPAN     30000      // 5 minutes (in 100th of a sec)
+#define SRCDOC_SCAN_INTERVAL 1000*30    // every 30 seconds (in msec)
 
 namespace {
 
@@ -1537,7 +1537,8 @@ static ScTokenArray* lcl_fillEmptyMatrix(const ScRange& rRange)
 ScExternalRefManager::ScExternalRefManager(ScDocument* pDoc) :
     mpDoc(pDoc),
     mbInReferenceMarking(false),
-    mbUserInteractionEnabled(true)
+    mbUserInteractionEnabled(true),
+    mbDocTimerEnabled(true)
 {
     maSrcDocTimer.SetTimeoutHdl( LINK(this, ScExternalRefManager, TimeOutHdl) );
     maSrcDocTimer.SetTimeout(SRCDOC_SCAN_INTERVAL);
@@ -2009,6 +2010,27 @@ void ScExternalRefManager::insertRefCell(sal_uInt16 nFileId, const ScAddress& rC
         itr->second.insert(pCell);
 }
 
+void ScExternalRefManager::enableDocTimer( bool bEnable )
+{
+    if (mbDocTimerEnabled == bEnable)
+        return;
+
+    mbDocTimerEnabled = bEnable;
+    if (mbDocTimerEnabled)
+    {
+        if (!maDocShells.empty())
+        {
+            DocShellMap::iterator it = maDocShells.begin(), itEnd = maDocShells.end();
+            for (; it != itEnd; ++it)
+                it->second.maLastAccess = Time(Time::SYSTEM);
+
+            maSrcDocTimer.Start();
+        }
+    }
+    else
+        maSrcDocTimer.Stop();
+}
+
 void ScExternalRefManager::fillCellFormat(sal_uLong nFmtIndex, ScExternalRefCache::CellFormat* pFmt) const
 {
     if (!pFmt)
@@ -2331,7 +2353,7 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
 
 ScDocument* ScExternalRefManager::cacheNewDocShell( sal_uInt16 nFileId, SrcShell& rSrcShell )
 {
-    if (maDocShells.empty())
+    if (mbDocTimerEnabled && maDocShells.empty())
         // If this is the first source document insertion, start up the timer.
         maSrcDocTimer.Start();
 


More information about the Libreoffice-commits mailing list