[Libreoffice-commits] core.git: sw/inc sw/source

Luboš Luňák l.lunak at collabora.com
Thu Oct 9 08:21:05 PDT 2014


 sw/inc/doc.hxx                     |    2 +-
 sw/source/core/doc/docglos.cxx     |   10 +++++++++-
 sw/source/ui/dbui/mmoutputpage.cxx |    5 +++++
 sw/source/uibase/dbui/dbmgr.cxx    |   30 ++----------------------------
 4 files changed, 17 insertions(+), 30 deletions(-)

New commits:
commit d3a04fdebf65c7381f1087fbd27104a56ba08e78
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Thu Oct 9 17:13:01 2014 +0200

    copy document defaults/properties for separate mailmerge result files
    
    Also remove code duplication (that I'm not even sure why it's there).
    
    Change-Id: I9a20fe0de9b34adbd03155712869bb19f5969f9b

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index cbc9f0d..c072fd1 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -914,7 +914,7 @@ public:
 
         This includes the user defined document properties!
      */
-    void ReplaceDocumentProperties(const SwDoc& rSource);
+    void ReplaceDocumentProperties(const SwDoc& rSource, bool mailMerge = false);
 
     // Query if style (paragraph- / character- / frame- / page-) is used.
     bool IsUsed( const SwModify& ) const;
diff --git a/sw/source/core/doc/docglos.cxx b/sw/source/core/doc/docglos.cxx
index 390177e..1507832 100644
--- a/sw/source/core/doc/docglos.cxx
+++ b/sw/source/core/doc/docglos.cxx
@@ -88,7 +88,7 @@ void SwDoc::ReplaceUserDefinedDocumentProperties(const SwDoc& rSource)
     ReplaceUserDefinedDocumentProperties( xSourceDocProps );
 }
 
-void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource)
+void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource, bool mailMerge)
 {
     uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS(
         rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
@@ -110,6 +110,7 @@ void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource)
     xDocProps->setDescription(xSourceDocProps->getDescription());
     xDocProps->setKeywords(xSourceDocProps->getKeywords());
     xDocProps->setLanguage(xSourceDocProps->getLanguage());
+    // Note: These below originally weren't copied for mailmerge, but I don't see why not.
     xDocProps->setModifiedBy(xSourceDocProps->getModifiedBy());
     xDocProps->setModificationDate(xSourceDocProps->getModificationDate());
     xDocProps->setPrintedBy(xSourceDocProps->getPrintedBy());
@@ -124,6 +125,13 @@ void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource)
     xDocProps->setEditingCycles(xSourceDocProps->getEditingCycles());
     xDocProps->setEditingDuration(xSourceDocProps->getEditingDuration());
 
+    if( mailMerge ) // Note: Not sure this is needed.
+    {
+        // Manually set the creation date, otherwise author field isn't filled
+        // during MM, as it's set when saving the document the first time.
+        xDocProps->setCreationDate( xSourceDocProps->getModificationDate() );
+    }
+
     ReplaceUserDefinedDocumentProperties( xSourceDocProps );
 }
 
diff --git a/sw/source/ui/dbui/mmoutputpage.cxx b/sw/source/ui/dbui/mmoutputpage.cxx
index f1ced02..ba2aa1e 100644
--- a/sw/source/ui/dbui/mmoutputpage.cxx
+++ b/sw/source/ui/dbui/mmoutputpage.cxx
@@ -56,6 +56,7 @@
 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
 #include <com/sun/star/sdb/XColumn.hpp>
 #include <com/sun/star/task/ErrorCodeIOException.hpp>
+#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <dbmgr.hxx>
 #include <swunohelper.hxx>
 #include <osl/mutex.hxx>
@@ -66,6 +67,7 @@
 #include <dbui.hxx>
 #include <dbui.hrc>
 #include <helpid.h>
+#include <doc.hxx>
 #include <sfx2/app.hxx>
 #include <statstr.hrc>
 #include <unomid.h>
@@ -679,6 +681,9 @@ IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton)
             aOpt.SetMerge( false );
             pTempView->GetDocShell()->LoadStylesFromFile(
                     sTargetTempURL, aOpt, true );
+            pTempView->GetDocShell()->GetDoc()->ReplaceCompatabilityOptions( *pTargetView->GetDocShell()->GetDoc());
+            pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
+            pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
 
             pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
                     (sal_uInt16)rInfo.nStartPageInTarget, (sal_uInt16)rInfo.nEndPageInTarget );
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 225b3cc..4d50418 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -776,32 +776,6 @@ static void lcl_RemoveSectionLinks( SwWrtShell& rWorkShell )
     rWorkShell.SetLabelDoc( false );
 }
 
-// based on SwDoc::ReplaceDocumentProperties
-static void lcl_CopyDocumentPorperties(
-    const uno::Reference<document::XDocumentProperties> &xSourceDocProps,
-    const SfxObjectShell *xTargetDocShell, SwDoc *pTargetDoc)
-{
-    uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-        xTargetDocShell->GetModel(), uno::UNO_QUERY_THROW);
-    uno::Reference<document::XDocumentProperties> xTargetDocProps(
-        xDPS->getDocumentProperties());
-    OSL_ENSURE(xTargetDocProps.is(), "DocumentProperties is null");
-
-    xTargetDocProps->setTitle( xSourceDocProps->getTitle() );
-    xTargetDocProps->setSubject( xSourceDocProps->getSubject() );
-    xTargetDocProps->setDescription( xSourceDocProps->getDescription() );
-    xTargetDocProps->setKeywords( xSourceDocProps->getKeywords() );
-    xTargetDocProps->setAuthor( xSourceDocProps->getAuthor() );
-    xTargetDocProps->setGenerator( xSourceDocProps->getGenerator() );
-    xTargetDocProps->setLanguage( xSourceDocProps->getLanguage() );
-
-    // Manually set the creation date, otherwise author field isn't filled
-    // during MM, as it's set when saving the document the first time.
-    xTargetDocProps->setCreationDate( xSourceDocProps->getModificationDate() );
-
-    pTargetDoc->ReplaceUserDefinedDocumentProperties( xSourceDocProps );
-}
-
 static void lcl_SaveDoc( SfxObjectShell *xTargetDocShell,
                          const char *name, int no = 0 )
 {
@@ -989,7 +963,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
                 // #72821# copy dynamic defaults
                 pTargetShell->GetDoc()->ReplaceDefaults( *pSourceShell->GetDoc());
 
-                lcl_CopyDocumentPorperties( xSourceDocProps, xTargetDocShell, pTargetDoc );
+                pTargetShell->GetDoc()->ReplaceDocumentProperties( *pSourceShell->GetDoc());
             }
 
             // Progress, to prohibit KeyInputs
@@ -1088,7 +1062,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
                         pWorkView->AttrChangedNotify( &rWorkShell );// in order for SelectShell to be called
 
                         SwDoc* pWorkDoc = rWorkShell.GetDoc();
-                        lcl_CopyDocumentPorperties( xSourceDocProps, xWorkDocSh, pWorkDoc );
+                        pWorkDoc->ReplaceDocumentProperties( *pSourceDocSh->GetDoc());
                         if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
                             lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo );
                         SwDBManager* pOldDBManager = pWorkDoc->GetDBManager();


More information about the Libreoffice-commits mailing list