diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2014-08-03 12:10:40 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2014-09-30 09:49:03 +0200 |
commit | 2a76e7d6a871685458e4b074e2af10bd40466b64 (patch) | |
tree | 1b0e1e409b6398f3663bfd200773865b923747b7 | |
parent | MM: restore the non-saving wizard behaviour (diff) | |
download | core-2a76e7d6a871685458e4b074e2af10bd40466b64.tar.gz core-2a76e7d6a871685458e4b074e2af10bd40466b64.zip |
fdo#81782 MM: copy most document properties
Mail merge wasn't copying the document properties into the target
document. It also has to copy most document properties into the
working copy, as ConvertFieldsToText is called just there.
Change-Id: I7e07fec712c225f667d960a94f4eb3fd0b83f041
Reviewed-on: https://gerrit.libreoffice.org/10987
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Tested-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
(cherry picked from commit cde554a731596f1ca53a911656b6503c96dadcc7)
Conflicts:
sw/inc/doc.hxx
sw/source/core/doc/docglos.cxx
sw/source/uibase/dbui/dbmgr.cxx
-rw-r--r-- | sw/inc/doc.hxx | 15 | ||||
-rw-r--r-- | sw/source/core/doc/docglos.cxx | 120 | ||||
-rw-r--r-- | sw/source/ui/dbui/dbmgr.cxx | 46 |
3 files changed, 129 insertions, 52 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 50ce1e971348..fc6de624492b 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1305,6 +1305,21 @@ public: /// Replace all compatability options with those from rSource. void ReplaceCompatabilityOptions(const SwDoc& rSource); + /** Replace all user defined document properties with xSourceDocProps. + + Convenince function used by ReplaceDocumentProperties to skip some UNO calls. + */ + void ReplaceUserDefinedDocumentProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > xSourceDocProps ); + + // Replace all user defined document properties with those from rSource. + void ReplaceUserDefinedDocumentProperties( const SwDoc& rSource ); + + /** Replace document properties with those from rSource. + + This includes the user defined document properties! + */ + void ReplaceDocumentProperties(const SwDoc& rSource); + /// Query if style (paragraph- / character- / frame- / page-) is used. bool IsUsed( const SwModify& ) const; bool IsUsed( const SwNumRule& ) const; diff --git a/sw/source/core/doc/docglos.cxx b/sw/source/core/doc/docglos.cxx index 801ed5bbc1f9..5c205e5027b4 100644 --- a/sw/source/core/doc/docglos.cxx +++ b/sw/source/core/doc/docglos.cxx @@ -36,44 +36,26 @@ using namespace ::com::sun::star; +void SwDoc::ReplaceUserDefinedDocumentProperties( + uno::Reference<document::XDocumentProperties> xSourceDocProps) +{ + OSL_ENSURE(xSourceDocProps.is(), "null reference"); -/// copy document properties via public interface -static void lcl_copyDocumentProperties( - uno::Reference<document::XDocumentProperties> i_xSource, - uno::Reference<document::XDocumentProperties> i_xTarget) { - OSL_ENSURE(i_xSource.is(), "null reference"); - OSL_ENSURE(i_xTarget.is(), "null reference"); - - i_xTarget->setAuthor(i_xSource->getAuthor()); - i_xTarget->setGenerator(i_xSource->getGenerator()); - i_xTarget->setCreationDate(i_xSource->getCreationDate()); - i_xTarget->setTitle(i_xSource->getTitle()); - i_xTarget->setSubject(i_xSource->getSubject()); - i_xTarget->setDescription(i_xSource->getDescription()); - i_xTarget->setKeywords(i_xSource->getKeywords()); - i_xTarget->setLanguage(i_xSource->getLanguage()); - i_xTarget->setModifiedBy(i_xSource->getModifiedBy()); - i_xTarget->setModificationDate(i_xSource->getModificationDate()); - i_xTarget->setPrintedBy(i_xSource->getPrintedBy()); - i_xTarget->setPrintDate(i_xSource->getPrintDate()); - i_xTarget->setTemplateName(i_xSource->getTemplateName()); - i_xTarget->setTemplateURL(i_xSource->getTemplateURL()); - i_xTarget->setTemplateDate(i_xSource->getTemplateDate()); - i_xTarget->setAutoloadURL(i_xSource->getAutoloadURL()); - i_xTarget->setAutoloadSecs(i_xSource->getAutoloadSecs()); - i_xTarget->setDefaultTarget(i_xSource->getDefaultTarget()); - i_xTarget->setDocumentStatistics(i_xSource->getDocumentStatistics()); - i_xTarget->setEditingCycles(i_xSource->getEditingCycles()); - i_xTarget->setEditingDuration(i_xSource->getEditingDuration()); + uno::Reference<document::XDocumentPropertiesSupplier> xDPS( + GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> xDocProps( + xDPS->getDocumentProperties() ); + OSL_ENSURE(xDocProps.is(), "null reference"); uno::Reference<beans::XPropertySet> xSourceUDSet( - i_xSource->getUserDefinedProperties(), uno::UNO_QUERY_THROW); + xSourceDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); uno::Reference<beans::XPropertyContainer> xTargetUD( - i_xTarget->getUserDefinedProperties()); + xDocProps->getUserDefinedProperties()); uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD, uno::UNO_QUERY_THROW); uno::Sequence<beans::Property> tgtprops = xTargetUDSet->getPropertySetInfo()->getProperties(); + for (sal_Int32 i = 0; i < tgtprops.getLength(); ++i) { try { xTargetUD->removeProperty(tgtprops [i].Name); @@ -81,20 +63,71 @@ static void lcl_copyDocumentProperties( // ignore } } - try { - uno::Reference<beans::XPropertySetInfo> xSetInfo - = xSourceUDSet->getPropertySetInfo(); - uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties(); - for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) { + + uno::Reference<beans::XPropertySetInfo> xSetInfo + = xSourceUDSet->getPropertySetInfo(); + uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties(); + + for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) { + try { OUString name = srcprops[i].Name; xTargetUD->addProperty(name, srcprops[i].Attributes, xSourceUDSet->getPropertyValue(name)); + } catch (uno::Exception &) { + // ignore } - } catch (uno::Exception &) { - // ignore } } +void SwDoc::ReplaceUserDefinedDocumentProperties(const SwDoc& rSource) +{ + uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS( + rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> xSourceDocProps( + xSourceDPS->getDocumentProperties() ); + + ReplaceUserDefinedDocumentProperties( xSourceDocProps ); +} + +void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource) +{ + uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS( + rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> xSourceDocProps( + xSourceDPS->getDocumentProperties() ); + OSL_ENSURE(xSourceDocProps.is(), "null reference"); + + uno::Reference<document::XDocumentPropertiesSupplier> xDPS( + GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> xDocProps( + xDPS->getDocumentProperties() ); + OSL_ENSURE(xDocProps.is(), "null reference"); + + xDocProps->setAuthor(xSourceDocProps->getAuthor()); + xDocProps->setGenerator(xSourceDocProps->getGenerator()); + xDocProps->setCreationDate(xSourceDocProps->getCreationDate()); + xDocProps->setTitle(xSourceDocProps->getTitle()); + xDocProps->setSubject(xSourceDocProps->getSubject()); + xDocProps->setDescription(xSourceDocProps->getDescription()); + xDocProps->setKeywords(xSourceDocProps->getKeywords()); + xDocProps->setLanguage(xSourceDocProps->getLanguage()); + xDocProps->setModifiedBy(xSourceDocProps->getModifiedBy()); + xDocProps->setModificationDate(xSourceDocProps->getModificationDate()); + xDocProps->setPrintedBy(xSourceDocProps->getPrintedBy()); + xDocProps->setPrintDate(xSourceDocProps->getPrintDate()); + xDocProps->setTemplateName(xSourceDocProps->getTemplateName()); + xDocProps->setTemplateURL(xSourceDocProps->getTemplateURL()); + xDocProps->setTemplateDate(xSourceDocProps->getTemplateDate()); + xDocProps->setAutoloadURL(xSourceDocProps->getAutoloadURL()); + xDocProps->setAutoloadSecs(xSourceDocProps->getAutoloadSecs()); + xDocProps->setDefaultTarget(xSourceDocProps->getDefaultTarget()); + xDocProps->setDocumentStatistics(xSourceDocProps->getDocumentStatistics()); + xDocProps->setEditingCycles(xSourceDocProps->getEditingCycles()); + xDocProps->setEditingDuration(xSourceDocProps->getEditingDuration()); + + ReplaceUserDefinedDocumentProperties( xSourceDocProps ); +} + /// inserts an AutoText block bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const String& rEntry, SwPaM& rPaM, SwCrsrShell* pShell ) @@ -118,17 +151,8 @@ bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const String& rEntry, // target document to the glossary document // OSL_ENSURE(GetDocShell(), "no SwDocShell"); // may be clipboard! OSL_ENSURE(pGDoc->GetDocShell(), "no SwDocShell at glossary"); - if (GetDocShell() && pGDoc->GetDocShell()) { - uno::Reference<document::XDocumentPropertiesSupplier> xDPS( - GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); - uno::Reference<document::XDocumentProperties> xDocProps( - xDPS->getDocumentProperties() ); - uno::Reference<document::XDocumentPropertiesSupplier> xGlosDPS( - pGDoc->GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); - uno::Reference<document::XDocumentProperties> xGlosDocProps( - xGlosDPS->getDocumentProperties() ); - lcl_copyDocumentProperties(xDocProps, xGlosDocProps); - } + if (GetDocShell() && pGDoc->GetDocShell()) + pGDoc->ReplaceDocumentProperties( *this ); pGDoc->SetFixFields(false, NULL); // StartAllAction(); diff --git a/sw/source/ui/dbui/dbmgr.cxx b/sw/source/ui/dbui/dbmgr.cxx index a171ef704558..229b5848f899 100644 --- a/sw/source/ui/dbui/dbmgr.cxx +++ b/sw/source/ui/dbui/dbmgr.cxx @@ -833,6 +833,32 @@ static void lcl_RemoveSectionLinks( SwWrtShell& rWorkShell ) rWorkShell.SetLabelDoc( sal_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 ); +} + #ifdef DBG_UTIL #define MAX_DOC_DUMP 3 @@ -906,6 +932,15 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, // Try saving the source document SfxDispatcher* pSfxDispatcher = pSourceShell->GetView().GetViewFrame()->GetDispatcher(); SwDocShell* pSourceDocSh = pSourceShell->GetView().GetDocShell(); + + uno::Reference<document::XDocumentProperties> xSourceDocProps; + { + uno::Reference<document::XDocumentPropertiesSupplier> + xDPS(pSourceDocSh->GetModel(), uno::UNO_QUERY); + xSourceDocProps.set(xDPS->getDocumentProperties()); + OSL_ENSURE(xSourceDocProps.is(), "DocumentProperties is null"); + } + if( !bMergeOnly && pSourceDocSh->IsModified() ) pSfxDispatcher->Execute( pSourceDocSh->HasName() ? SID_SAVEDOC : SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD); if( bMergeOnly || !pSourceDocSh->IsModified() ) @@ -1006,6 +1041,8 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, lcl_CopyCompatibilityOptions( *pSourceShell, *pTargetShell); // #72821# copy dynamic defaults lcl_CopyDynamicDefaults( *pSourceShell->GetDoc(), *pTargetShell->GetDoc() ); + + lcl_CopyDocumentPorperties( xSourceDocProps, xTargetDocShell, pTargetDoc ); } // Progress, to prohibit KeyInputs @@ -1096,10 +1133,6 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, // 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 ); -#ifdef DBG_UTIL - if ( nDocNo <= MAX_DOC_DUMP ) - lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo ); -#endif //create a view frame for the document SwView* pWorkView = static_cast< SwView* >( SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 )->GetViewShell() ); @@ -1108,6 +1141,11 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, pWorkView->AttrChangedNotify( &rWorkShell );// in order for SelectShell to be called SwDoc* pWorkDoc = rWorkShell.GetDoc(); + lcl_CopyDocumentPorperties( xSourceDocProps, xWorkDocSh, pWorkDoc ); +#ifdef DBG_UTIL + if ( nDocNo <= MAX_DOC_DUMP ) + lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo ); +#endif SwNewDBMgr* pOldDBMgr = pWorkDoc->GetNewDBMgr(); pWorkDoc->SetNewDBMgr( this ); pWorkDoc->EmbedAllLinks(); |