summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2015-02-15 22:53:57 +0100
committerLuboš Luňák <l.lunak@collabora.com>2015-02-26 16:50:29 +0100
commit5a7bb3f0484654fd0499e9bb030c83284e0d6571 (patch)
tree485e74402ae2cf42db7a3bc213cb403860c2e279
parent7f88e26321d112e1a3ed43e2ac4cba8d6b374a09 (diff)
avoid creating temporary document copies in non-singlefile MM mode
The singlefile mode needs a new copy for every record, because it modifies it (such as changing fields to text), but the non-singlefile mode does not need all that relatively expensive work, because it just updates the fields and nothing else. Change-Id: If02cf8aca1d0f050ffb63cd85d5a9455afc5a6ea
-rw-r--r--sw/source/ui/dbui/dbmgr.cxx46
1 files changed, 36 insertions, 10 deletions
diff --git a/sw/source/ui/dbui/dbmgr.cxx b/sw/source/ui/dbui/dbmgr.cxx
index 79ebd0d1e252..ca697eb3d65e 100644
--- a/sw/source/ui/dbui/dbmgr.cxx
+++ b/sw/source/ui/dbui/dbmgr.cxx
@@ -1077,6 +1077,14 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
bool bFreezedLayouts = false;
// collect temporary files
::std::vector< String> aFilesToRemove;
+
+ // The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here
+ SfxObjectShellLock xWorkDocSh;
+ // a view frame for the document
+ SwView* pWorkView = NULL;
+ SwDoc* pWorkDoc = NULL;
+ SwNewDBMgr* pOldDBManager = NULL;
+
do
{
nStartRow = pImpl->pMergeData ? pImpl->pMergeData->xResultSet->getRow() : 0;
@@ -1143,21 +1151,26 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
for( sal_uInt16 i = 0; i < 25; i++ )
Application::Reschedule();
- // The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here
- // copy the source document
- SfxObjectShellLock xWorkDocSh = pSourceDocSh->GetDoc()->CreateCopy( true );
+ // Create a copy of the source document and work with that one instead of the source.
+ // If we're not in the single file mode (which requires modifying the document for the merging),
+ // it is enough to do this just once.
+ if( 1 == nDocNo || rMergeDescriptor.bCreateSingleFile )
+ {
+ assert( !xWorkDocSh.Is());
+ // copy the source document
+ xWorkDocSh = pSourceDocSh->GetDoc()->CreateCopy( true );
//create a view frame for the document
- SwView* pWorkView = static_cast< SwView* >( SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 )->GetViewShell() );
+ pWorkView = static_cast< SwView* >( SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 )->GetViewShell() );
//request the layout calculation
SwWrtShell& rWorkShell = pWorkView->GetWrtShell();
pWorkView->AttrChangedNotify( &rWorkShell );// in order for SelectShell to be called
- SwDoc* pWorkDoc = rWorkShell.GetDoc();
+ pWorkDoc = rWorkShell.GetDoc();
lcl_CopyDocumentPorperties( xSourceDocProps, xWorkDocSh, pWorkDoc );
if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo );
- SwNewDBMgr* pOldDBMgr = pWorkDoc->GetNewDBMgr();
+ pOldDBManager = pWorkDoc->GetNewDBMgr();
pWorkDoc->SetNewDBMgr( this );
pWorkDoc->EmbedAllLinks();
@@ -1165,12 +1178,15 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
rWorkShell.LockExpFlds();
rWorkShell.CalcLayout();
rWorkShell.UnlockExpFlds();
+ }
+ SwWrtShell& rWorkShell = pWorkView->GetWrtShell();
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE), xWorkDocSh));
rWorkShell.ViewShell::UpdateFlds();
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE_FINISHED), xWorkDocSh));
- pWorkDoc->RemoveInvisibleContent();
+ if( rMergeDescriptor.bCreateSingleFile )
+ pWorkDoc->RemoveInvisibleContent();
// launch MailMergeEvent if required
const SwXMailMerge *pEvtSrc = GetMailMergeEvtSrc();
@@ -1344,9 +1360,12 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
}
}
}
- pWorkDoc->SetNewDBMgr( pOldDBMgr );
-
- xWorkDocSh->DoClose();
+ if( rMergeDescriptor.bCreateSingleFile )
+ {
+ pWorkDoc->SetNewDBMgr( pOldDBManager );
+ xWorkDocSh->DoClose();
+ xWorkDocSh = NULL;
+ }
}
}
nDocNo++;
@@ -1363,6 +1382,13 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
}
} while( !bCancel &&
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
+
+ if( !rMergeDescriptor.bCreateSingleFile )
+ {
+ pWorkDoc->SetNewDBMgr( pOldDBManager );
+ xWorkDocSh->DoClose();
+ }
+
if (rMergeDescriptor.bCreateSingleFile)
{
// sw::DocumentLayoutManager::CopyLayoutFmt() did not generate