[Libreoffice-commits] core.git: Branch 'feature/mailmerge-toolbar' - 4 commits - sw/inc sw/source

Jan Holesovsky kendy at collabora.com
Wed Jan 6 03:48:16 PST 2016


 sw/inc/dbmgr.hxx                |   12 ++----
 sw/source/uibase/app/apphdl.cxx |   32 ++++++++++------
 sw/source/uibase/dbui/dbmgr.cxx |   77 +++++++++++++++++++++-------------------
 3 files changed, 67 insertions(+), 54 deletions(-)

New commits:
commit 9c9b2335be70a803eae0becde7909d8ecb3a67c2
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jan 6 12:07:55 2016 +0100

    mailmerge: Create the target view independantly of the mailmerge execution.
    
    Change-Id: Ib6a53b89b0fe2a30eac104afd1c8fe75d2348edd

diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index f20ba61..de9efc9 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -246,7 +246,7 @@ friend class SwConnectionDisposedListener_Impl;
         return css::uno::Reference<css::beans::XPropertySet>( xRowSet, css::uno::UNO_QUERY );
     }
 
-    SAL_DLLPRIVATE void CreateDumpDocs(sal_Int32 &nMaxDumpDocs);
+    SAL_DLLPRIVATE static sal_Int32 GetMaxDumpDocs();
 
     SAL_DLLPRIVATE void SetSourceProp(SwDocShell* pSourceDocSh);
 
@@ -261,11 +261,6 @@ friend class SwConnectionDisposedListener_Impl;
                                           std::unique_ptr< INetURLObject > &aTempFileURL,
                                           SwDocShell *pSourceDocSh, sal_Int32 nDocNo);
 
-    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 CreateProgessDlg(vcl::Window *&pSourceWindow, VclPtr<CancelableDialog> &pProgressDlg,
@@ -519,6 +514,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 f219cdd..ca57274 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 e135f86..c91bad8 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -927,9 +927,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)
     {
@@ -978,12 +976,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;
@@ -996,12 +993,20 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
 
             CreateProgessDlg(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();
@@ -1270,8 +1275,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)
@@ -1282,6 +1288,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)
@@ -1364,16 +1372,17 @@ void SwDBManager::UpdateProgressDlg(bool bMergeShell, VclPtr<CancelableDialog> p
     }
 }
 
-void SwDBManager::CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell, vcl::Window *pSourceWindow,
-                                       SwWrtShell *pSourceShell, SwDocShell *pSourceDocSh,
-                                       SfxObjectShellRef &xTargetDocShell, SwDoc *&pTargetDoc,
-                                       SwWrtShell *&pTargetShell, SwView  *&pTargetView)
+SwView* SwDBManager::CreateTargetDocShell(bool bMergeShell, vcl::Window *pSourceWindow,
+        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 +1391,12 @@ void SwDBManager::CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell,
         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 +1408,8 @@ void SwDBManager::CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell,
     pTargetShell->GetDoc()->ReplaceDefaults( *pSourceShell->GetDoc());
 
     pTargetShell->GetDoc()->ReplaceDocumentProperties( *pSourceShell->GetDoc());
+
+    return pTargetView;
 }
 
 void SwDBManager::LockUnlockDisp(bool bLock, SwDocShell *pSourceDocSh)
commit dff90d06c0f8be6eee63e7d312f4640f30d90723
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jan 6 10:32:24 2016 +0100

    mailmerge: nStartingPageNo and sStartingPageDesc shouldn't be return values.
    
    Change-Id: I86a049411c2ec461e66009e6dc54d8ea086e7f12

diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index d865517..f20ba61 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -264,8 +264,7 @@ friend class SwConnectionDisposedListener_Impl;
     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_uInt16 &nStartingPageNo, OUString &sStartingPageDesc);
+                                             SwWrtShell *&pTargetShell, SwView  *&pTargetView);
 
     SAL_DLLPRIVATE void LockUnlockDisp(bool bLock, SwDocShell *pSourceDocSh);
 
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 0a2797e..e135f86 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -999,8 +999,13 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
             if (bCreateSingleFile)
             {
                 CreateTargetDocShell(nMaxDumpDocs, bMergeShell, pSourceWindow, pSourceShell,
-                        pSourceDocSh, xTargetDocShell, pTargetDoc, pTargetShell,
-                        pTargetView, nStartingPageNo, sStartingPageDesc);
+                        pSourceDocSh, xTargetDocShell, pTargetDoc,
+                        pTargetShell, pTargetView);
+
+                // determine the page style and number used at the start of the source document
+                pSourceShell->SttEndDoc(true);
+                nStartingPageNo = pSourceShell->GetVirtPageNum();
+                sStartingPageDesc = pSourceShell->GetPageDesc(pSourceShell->GetCurPageDesc()).GetName();
 
                 // #i72517#
                 const SwPageDesc* pSourcePageDesc = pSourceShell->FindPageDescByName(sStartingPageDesc);
@@ -1362,8 +1367,7 @@ void SwDBManager::UpdateProgressDlg(bool bMergeShell, VclPtr<CancelableDialog> p
 void SwDBManager::CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell, vcl::Window *pSourceWindow,
                                        SwWrtShell *pSourceShell, SwDocShell *pSourceDocSh,
                                        SfxObjectShellRef &xTargetDocShell, SwDoc *&pTargetDoc,
-                                       SwWrtShell *&pTargetShell, SwView  *&pTargetView,
-                                       sal_uInt16 &nStartingPageNo, OUString &sStartingPageDesc)
+                                       SwWrtShell *&pTargetShell, SwView  *&pTargetView)
 {
     // create a target docshell to put the merged document into
     xTargetDocShell = new SwDocShell( SfxObjectCreateMode::STANDARD );
@@ -1389,12 +1393,6 @@ void SwDBManager::CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell,
     //copy the styles from the source to the target document
     pTargetView->GetDocShell()->_LoadStyles( *pSourceDocSh, true );
 
-    //determine the page style and number used at the start of the source document
-    pSourceShell->SttEndDoc(true);
-    nStartingPageNo = pSourceShell->GetVirtPageNum();
-    sStartingPageDesc = pSourceShell->GetPageDesc(
-        pSourceShell->GetCurPageDesc()).GetName();
-
     // copy compatibility options
     pTargetShell->GetDoc()->ReplaceCompatibilityOptions( *pSourceShell->GetDoc());
     // #72821# copy dynamic defaults
commit 507ffa23a236e90be244d84a528471c74eae2142
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jan 6 10:12:35 2016 +0100

    mailmerge: bPageStylesWithHeaderFooter should not be a return value.
    
    Change-Id: I8d39b6b031b543e4cc6a31cf57d207b04a19ba38

diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index 580b0f1..d865517 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -261,7 +261,7 @@ friend class SwConnectionDisposedListener_Impl;
                                           std::unique_ptr< INetURLObject > &aTempFileURL,
                                           SwDocShell *pSourceDocSh, sal_Int32 nDocNo);
 
-    SAL_DLLPRIVATE bool CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell, vcl::Window *pSourceWindow,
+    SAL_DLLPRIVATE void CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell, vcl::Window *pSourceWindow,
                                              SwWrtShell *pSourceShell, SwDocShell *pSourceDocSh,
                                              SfxObjectShellRef &xTargetDocShell, SwDoc *&pTargetDoc,
                                              SwWrtShell *&pTargetShell, SwView  *&pTargetView,
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index dc81201..0a2797e 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -996,11 +996,16 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
 
             CreateProgessDlg(pSourceWindow, pProgressDlg, bMergeShell, pSourceShell, pParent);
 
-            if(bCreateSingleFile)
+            if (bCreateSingleFile)
             {
-                bPageStylesWithHeaderFooter = CreateTargetDocShell(nMaxDumpDocs, bMergeShell, pSourceWindow, pSourceShell,
-                                                                   pSourceDocSh, xTargetDocShell, pTargetDoc, pTargetShell,
-                                                                   pTargetView, nStartingPageNo, sStartingPageDesc);
+                CreateTargetDocShell(nMaxDumpDocs, bMergeShell, pSourceWindow, pSourceShell,
+                        pSourceDocSh, xTargetDocShell, pTargetDoc, pTargetShell,
+                        pTargetView, nStartingPageNo, sStartingPageDesc);
+
+                // #i72517#
+                const SwPageDesc* pSourcePageDesc = pSourceShell->FindPageDescByName(sStartingPageDesc);
+                const SwFrameFormat& rMaster = pSourcePageDesc->GetMaster();
+                bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive() || rMaster.GetFooter().IsActive();
 
                 sModifiedStartingPageDesc = sStartingPageDesc;
             }
@@ -1354,7 +1359,7 @@ void SwDBManager::UpdateProgressDlg(bool bMergeShell, VclPtr<CancelableDialog> p
     }
 }
 
-bool SwDBManager::CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell, vcl::Window *pSourceWindow,
+void SwDBManager::CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell, vcl::Window *pSourceWindow,
                                        SwWrtShell *pSourceShell, SwDocShell *pSourceDocSh,
                                        SfxObjectShellRef &xTargetDocShell, SwDoc *&pTargetDoc,
                                        SwWrtShell *&pTargetShell, SwView  *&pTargetView,
@@ -1390,20 +1395,12 @@ bool SwDBManager::CreateTargetDocShell(sal_Int32 nMaxDumpDocs, bool bMergeShell,
     sStartingPageDesc = pSourceShell->GetPageDesc(
         pSourceShell->GetCurPageDesc()).GetName();
 
-    // #i72517#
-    const SwPageDesc* pSourcePageDesc = pSourceShell->FindPageDescByName( sStartingPageDesc );
-    const SwFrameFormat& rMaster = pSourcePageDesc->GetMaster();
-    bool bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive()  ||
-                                       rMaster.GetFooter().IsActive();
-
     // copy compatibility options
     pTargetShell->GetDoc()->ReplaceCompatibilityOptions( *pSourceShell->GetDoc());
     // #72821# copy dynamic defaults
     pTargetShell->GetDoc()->ReplaceDefaults( *pSourceShell->GetDoc());
 
     pTargetShell->GetDoc()->ReplaceDocumentProperties( *pSourceShell->GetDoc());
-
-    return bPageStylesWithHeaderFooter;
 }
 
 void SwDBManager::LockUnlockDisp(bool bLock, SwDocShell *pSourceDocSh)
commit ea4609720f10f044eb5022ac7f1e050ee72ea1e5
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jan 6 10:05:19 2016 +0100

    This assert is useless.
    
    Change-Id: I2a76f449d4fb3452583407dc3cbb73f10a3d1705

diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 6fcd7b5..dc81201 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -1067,7 +1067,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
 
                         UpdateExpFields(rWorkShell, xWorkDocSh);
 
-                        if(bCreateSingleFile)
+                        if (bCreateSingleFile)
                         {
                             MergeSingleFiles(pWorkDoc, rWorkShell, pTargetShell, pTargetDoc, xWorkDocSh, xTargetDocShell,
                                              bPageStylesWithHeaderFooter, bSynchronizedDoc, sModifiedStartingPageDesc,
@@ -1077,7 +1077,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
                         }
                         else if( rMergeDescriptor.nMergeType == DBMGR_MERGE_PRINTER )
                         {
-                            assert(!bCreateSingleFile);
                             if( 1 == nDocNo ) // set up printing only once at the beginning
                             {
                                 // printing should be done synchronously otherwise the document


More information about the Libreoffice-commits mailing list