summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2014-06-27 11:28:02 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2014-09-30 09:47:53 +0200
commit8ca8c81a6677bd0228d0d4b07de0a8919cd2659d (patch)
tree42bf972d2865da11a4a8137df10fd93deababdad
parent1e3575f9f8254a16f4ec11c54b19f88ccc36f701 (diff)
MM: fix workaround for single paragraph docs
There is already a workaround for pasting a document with a single paragraph by appending a dummy empty paragraph to the working copy. This patch removes the dummy paragraph from the target document. Change-Id: I288d35264bf6f1a5f92c50d6a309e3bdd4ab5836 Reviewed-on: https://gerrit.libreoffice.org/10964 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit 01e5ff37499d115e652ddab793488a54174fb4a9) Conflicts: sw/source/uibase/dbui/dbmgr.cxx
-rw-r--r--sw/source/ui/dbui/dbmgr.cxx33
1 files changed, 30 insertions, 3 deletions
diff --git a/sw/source/ui/dbui/dbmgr.cxx b/sw/source/ui/dbui/dbmgr.cxx
index 271f17d2ea38..8611149ff396 100644
--- a/sw/source/ui/dbui/dbmgr.cxx
+++ b/sw/source/ui/dbui/dbmgr.cxx
@@ -895,6 +895,8 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
// in case of creating a single resulting file this has to be created here
SwWrtShell* pTargetShell = 0;
+ SwDoc* pTargetDoc = 0;
+ SwNodes* pTargetNodes = 0;
// the shell will be explicitly closed at the end of the method, but it is
// still more safe to use SfxObjectShellLock here
@@ -918,6 +920,8 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
//initiate SelectShell() to create sub shells
pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
pTargetShell = pTargetView->GetWrtShellPtr();
+ pTargetDoc = pTargetShell->GetDoc();
+ pTargetNodes = &pTargetDoc->GetNodes();
//copy the styles from the source to the target document
pTargetView->GetDocShell()->_LoadStyles( *pSourceDocSh, sal_True );
//determine the page style and number used at the start of the source document
@@ -1079,8 +1083,6 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
{
//create a new pagestyle
//copy the pagedesc from the current document to the new document and change the name of the to-be-applied style
-
- SwDoc* pTargetDoc = pTargetShell->GetDoc();
SwPageDesc* pSourcePageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc );
String sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
pTargetDoc->MakePageDesc( sNewPageDescName );
@@ -1098,7 +1100,9 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
else
pTargetShell->SetPageStyle(sModifiedStartingPageDesc);
OSL_ENSURE(!pTargetShell->GetTableFmt(),"target document ends with a table - paragraph should be appended");
+
//#i51359# add a second paragraph in case there's only one
+ bool para_added = false;
{
SwNodeIndex aIdx( pWorkDoc->GetNodes().GetEndOfExtras(), 2 );
SwPosition aTestPos( aIdx );
@@ -1107,10 +1111,19 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
{
//append a paragraph
pWorkDoc->AppendTxtNode( aTestPos );
+ para_added = true;
}
}
pTargetShell->Paste( rWorkShell.GetDoc(), sal_True );
+ if ( para_added ) {
+ // Move cursor to the start or Delete will assert because
+ // of the cursors SwIndex ref on the deleting node.
+ pTargetShell->SttEndDoc( sal_True );
+ SwNodeIndex aTargetIdx( pTargetNodes->GetEndOfContent(), -1 );
+ pTargetNodes->Delete( aTargetIdx, 1 );
+ }
+
//convert fields in page styles (header/footer - has to be done after the first document has been pasted
if(1 == nDocNo)
{
@@ -2791,6 +2804,9 @@ sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
//initiate SelectShell() to create sub shells
pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
SwWrtShell* pTargetShell = pTargetView->GetWrtShellPtr();
+ SwDoc* pTargetDoc = pTargetShell->GetDoc();
+ SwNodes* pTargetNodes = &pTargetDoc->GetNodes();
+
// #i63806#
const SwPageDesc* pSourcePageDesc = rSourceShell.FindPageDescByName( sStartingPageDesc );
const SwFrmFmt& rMaster = pSourcePageDesc->GetMaster();
@@ -2891,7 +2907,6 @@ sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
//create a new pagestyle
//copy the pagedesc from the current document to the new document and change the name of the to-be-applied style
- SwDoc* pTargetDoc = pTargetShell->GetDoc();
String sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
pTargetShell->GetDoc()->MakePageDesc( sNewPageDescName );
SwPageDesc* pTargetPageDesc = pTargetShell->FindPageDescByName( sNewPageDescName );
@@ -2918,6 +2933,8 @@ sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
}
sal_uInt16 nPageCountBefore = pTargetShell->GetPageCnt();
OSL_ENSURE(!pTargetShell->GetTableFmt(),"target document ends with a table - paragraph should be appended");
+ bool para_added = false;
+
//#i51359# add a second paragraph in case there's only one
{
SwNodeIndex aIdx( pWorkDoc->GetNodes().GetEndOfExtras(), 2 );
@@ -2927,6 +2944,7 @@ sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
{
//append a paragraph
pWorkDoc->AppendTxtNode( aTestPos );
+ para_added = true;
}
}
@@ -2935,6 +2953,15 @@ sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo );
#endif
pTargetShell->Paste( rWorkShell.GetDoc(), sal_True );
+
+ if ( para_added ) {
+ // Move cursor to the start or Delete will assert because
+ // of the cursors SwIndex ref on the deleting node.
+ pTargetShell->SttEndDoc( sal_True );
+ SwNodeIndex aTargetIdx( pTargetNodes->GetEndOfContent(), -1 );
+ pTargetNodes->Delete( aTargetIdx, 1 );
+ }
+
//convert fields in page styles (header/footer - has to be done after the first document has been pasted
if(1 == nDocNo)
{