Kaydet (Commit) c28aadc7 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

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
üst 1b243b14
......@@ -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*);
};
......
......@@ -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();
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment