diff options
author | Jan Holesovsky <kendy@collabora.com> | 2016-01-06 12:07:55 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2016-03-16 14:56:02 +0100 |
commit | 5af73bfa73625fc8529de4a7b6dd5e1cb564798a (patch) | |
tree | 2b4b56b41daf045466d88907f28fe93c7698e2bb | |
parent | f518c859b4f805600ce4b3991cf7e8d2b401eb9d (diff) |
mailmerge: Create the target view independantly of the mailmerge execution.
Change-Id: Ib6a53b89b0fe2a30eac104afd1c8fe75d2348edd
-rw-r--r-- | sw/inc/dbmgr.hxx | 11 | ||||
-rw-r--r-- | sw/source/uibase/app/apphdl.cxx | 32 | ||||
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 45 |
3 files changed, 55 insertions, 33 deletions
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx index 335bd0c84941..b50f73473ce2 100644 --- a/sw/inc/dbmgr.hxx +++ b/sw/inc/dbmgr.hxx @@ -236,7 +236,7 @@ friend class SwConnectionDisposedListener_Impl; GetRowSet(css::uno::Reference< css::sdbc::XConnection>, const OUString& rTableOrQuery, SwDBSelect eTableOrQuery); - SAL_DLLPRIVATE void CreateDumpDocs(sal_Int32 &nMaxDumpDocs); + SAL_DLLPRIVATE static sal_Int32 GetMaxDumpDocs(); SAL_DLLPRIVATE void SetSourceProp(SwDocShell* pSourceDocSh); @@ -248,11 +248,6 @@ friend class SwConnectionDisposedListener_Impl; const SwMergeDescriptor& rMergeDescriptor, std::shared_ptr<const SfxFilter> pStoreToFilter); - SAL_DLLPRIVATE void CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell, vcl::Window *pSourceWindow, - SwWrtShell *pSourceShell, SwDocShell *pSourceDocSh, - SfxObjectShellRef &xTargetDocShell, SwDoc *&pTargetDoc, - SwWrtShell *&pTargetShell, SwView *&pTargetView); - SAL_DLLPRIVATE void LockUnlockDisp(bool bLock, SwDocShell *pSourceDocSh); SAL_DLLPRIVATE void CreateWorkDoc(SfxObjectShellLock &xWorkDocSh, SwView *&pWorkView, SwDoc *&pWorkDoc, SwDBManager *&pOldDBManager, @@ -495,6 +490,10 @@ public: SwDoc* getDoc() const; /// Stop reacting to removed database registrations. void releaseRevokeListener(); + + /// Creates & sets up the target docshell. + static SwView* CreateTargetDocShell(bool bMergeShell, vcl::Window *pSourceWindow, + SwWrtShell *pSourceShell, SwDocShell *pSourceDocSh); }; #endif diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx index a3a837ca44d9..53e4238d20e7 100644 --- a/sw/source/uibase/app/apphdl.cxx +++ b/sw/source/uibase/app/apphdl.cxx @@ -55,6 +55,7 @@ #include <sfx2/objface.hxx> #include <sfx2/app.hxx> +#include <edtwin.hxx> #include <view.hxx> #include <pview.hxx> #include <srcview.hxx> @@ -779,6 +780,8 @@ void SwModule::ExecOther(SfxRequest& rReq) aDescriptor[ svx::daSelection ] <<= pConfigItem->GetSelection(); SwWrtShell& rSh = pView->GetWrtShell(); + pConfigItem->SetTargetView(nullptr); + SwMergeDescriptor aMergeDesc(DBMGR_MERGE_SHELL, rSh, aDescriptor); aMergeDesc.pMailMergeConfigItem = pConfigItem; aMergeDesc.bCreateSingleFile = true; @@ -789,21 +792,28 @@ void SwModule::ExecOther(SfxRequest& rReq) pConfigItem->GetTargetView()->GetViewFrame()->GetFrame().Appear(); } case FN_MAILMERGE_SAVE_DOCUMENTS: - { - SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - pFact->ExecuteMMResultSaveDialog(); - } - break; case FN_MAILMERGE_PRINT_DOCUMENTS: - { - SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - pFact->ExecuteMMResultPrintDialog(); - } - break; case FN_MAILMERGE_EMAIL_DOCUMENTS: { + SwView* pView = ::GetActiveView(); + SwMailMergeConfigItem* pConfigItem = pView->GetMailMergeConfigItem(); + if (!pConfigItem) + return; + + if (!pConfigItem->GetTargetView()) + { + SwView* pSourceView = pConfigItem->GetSourceView(); + assert(pSourceView); + pConfigItem->SetTargetView(SwDBManager::CreateTargetDocShell(true, &pSourceView->GetEditWin(), pSourceView->GetWrtShellPtr(), pSourceView->GetDocShell())); + } + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - pFact->ExecuteMMResultEmailDialog(); + switch (nWhich) + { + case FN_MAILMERGE_SAVE_DOCUMENTS: pFact->ExecuteMMResultSaveDialog(); break; + case FN_MAILMERGE_PRINT_DOCUMENTS: pFact->ExecuteMMResultPrintDialog(); break; + case FN_MAILMERGE_EMAIL_DOCUMENTS: pFact->ExecuteMMResultEmailDialog(); break; + } } break; #endif diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 4303cbdacd15..a63ab1f836c8 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -947,9 +947,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, OUString sBodyMimeType; rtl_TextEncoding eEncoding = ::osl_getThreadTextEncoding(); - static sal_Int32 nMaxDumpDocs = 0; - - CreateDumpDocs(nMaxDumpDocs); + const sal_Int32 nMaxDumpDocs = GetMaxDumpDocs(); if(bEMail) { @@ -999,12 +997,11 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, bCancel = false; // in case of creating a single resulting file this has to be created here + SwView* pTargetView = rMergeDescriptor.pMailMergeConfigItem->GetTargetView(); SwWrtShell* pTargetShell = nullptr; SwDoc* pTargetDoc = nullptr; + SfxObjectShellRef xTargetDocShell = nullptr; - SfxObjectShellRef xTargetDocShell; - - SwView* pTargetView = nullptr; std::unique_ptr< utl::TempFile > aTempFile; bool createTempFile = ( bEMail || rMergeDescriptor.nMergeType == DBMGR_MERGE_FILE ); OUString sModifiedStartingPageDesc; @@ -1021,12 +1018,20 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, pSourceWindow, pProgressDlg, bMergeShell, pSourceShell, pParent); } - if (bCreateSingleFile) + if (bCreateSingleFile && !pTargetView) { - CreateTargetDocShell(nMaxDumpDocs, bMergeShell, pSourceWindow, pSourceShell, - pSourceDocSh, xTargetDocShell, pTargetDoc, - pTargetShell, pTargetView); + pTargetView = CreateTargetDocShell(bMergeShell, pSourceWindow, pSourceShell, pSourceDocSh); + } + + if (pTargetView) + { + pTargetShell = pTargetView->GetWrtShellPtr(); + pTargetDoc = pTargetShell->GetDoc(); + xTargetDocShell = pTargetView->GetDocShell(); + } + if (bCreateSingleFile) + { // determine the page style and number used at the start of the source document pSourceShell->SttEndDoc(true); nStartingPageNo = pSourceShell->GetVirtPageNum(); @@ -1298,8 +1303,9 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, return bNoError; } -void SwDBManager::CreateDumpDocs(sal_Int32 &nMaxDumpDocs) +sal_Int32 SwDBManager::GetMaxDumpDocs() { + static sal_Int32 nMaxDumpDocs = 0; static const char *sMaxDumpDocs = nullptr; if (!sMaxDumpDocs) @@ -1310,6 +1316,8 @@ void SwDBManager::CreateDumpDocs(sal_Int32 &nMaxDumpDocs) else nMaxDumpDocs = rtl_ustr_toInt32(reinterpret_cast<const sal_Unicode*>( sMaxDumpDocs ), 10); } + + return nMaxDumpDocs; } void SwDBManager::SetSourceProp(SwDocShell* pSourceDocSh) @@ -1370,10 +1378,13 @@ SwView* SwDBManager::CreateTargetDocShell(bool bMergeShell, vcl::Window *pSource SwWrtShell *pSourceShell, SwDocShell *pSourceDocSh) { // create a target docshell to put the merged document into - xTargetDocShell = new SwDocShell( SfxObjectCreateMode::STANDARD ); + SfxObjectShellRef xTargetDocShell = new SwDocShell( SfxObjectCreateMode::STANDARD ); xTargetDocShell->DoInitNew( ); + + const sal_Int32 nMaxDumpDocs = GetMaxDumpDocs(); if (nMaxDumpDocs) - lcl_SaveDoc( xTargetDocShell, "MergeDoc" ); + lcl_SaveDoc(xTargetDocShell, "MergeDoc"); + SfxViewFrame* pTargetFrame = SfxViewFrame::LoadHiddenDocument( *xTargetDocShell, 0 ); if (bMergeShell && pSourceWindow) { @@ -1382,12 +1393,12 @@ SwView* SwDBManager::CreateTargetDocShell(bool bMergeShell, vcl::Window *pSource rTargetWindow.SetPosPixel(pSourceWindow->GetPosPixel()); } - pTargetView = static_cast<SwView*>( pTargetFrame->GetViewShell() ); + SwView *pTargetView = static_cast<SwView*>(pTargetFrame->GetViewShell()); //initiate SelectShell() to create sub shells pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() ); - pTargetShell = pTargetView->GetWrtShellPtr(); - pTargetDoc = pTargetShell->GetDoc(); + SwWrtShell *pTargetShell = pTargetView->GetWrtShellPtr(); + SwDoc *pTargetDoc = pTargetShell->GetDoc(); pTargetDoc->SetInMailMerge(true); //copy the styles from the source to the target document @@ -1399,6 +1410,8 @@ SwView* SwDBManager::CreateTargetDocShell(bool bMergeShell, vcl::Window *pSource pTargetShell->GetDoc()->ReplaceDefaults( *pSourceShell->GetDoc()); pTargetShell->GetDoc()->ReplaceDocumentProperties( *pSourceShell->GetDoc()); + + return pTargetView; } void SwDBManager::LockUnlockDisp(bool bLock, SwDocShell *pSourceDocSh) |