sc/source/ui/attrdlg/scdlgfact.cxx |   14 ++
 sc/source/ui/attrdlg/scdlgfact.hxx |   10 +
 sc/source/ui/view/cellsh1.cxx      |  199 ++++++++++++++++++++-----------------
 3 files changed, 130 insertions(+), 93 deletions(-)

New commits:
commit 41cfe181e3eb4502847fb56955635852e3928d92
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Mon Nov 30 05:55:55 2020 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Jan 7 08:41:17 2021 +0100

    Make Pivot table db & external source dialogs async
    
    Change-Id: Iff1a49a9fa04b55ece1aa30259ab57d105883eda
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106996
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108798
    Tested-by: Jenkins

diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx 
b/sc/source/ui/attrdlg/scdlgfact.cxx
index 38102c6d4995..43a1e46ba2e9 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -107,6 +107,11 @@ short AbstractScDataPilotDatabaseDlg_Impl::Execute()
     return m_xDlg->run();
 }
 
+bool AbstractScDataPilotDatabaseDlg_Impl::StartExecuteAsync(AsyncContext &rCtx)
+{
+    return weld::DialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 short AbstractScDataPilotSourceTypeDlg_Impl::Execute()
 {
     return m_xDlg->run();
@@ -122,6 +127,11 @@ short AbstractScDataPilotServiceDlg_Impl::Execute()
     return m_xDlg->run();
 }
 
+bool 
AbstractScDataPilotServiceDlg_Impl::StartExecuteAsync(VclAbstractDialog::AsyncContext
 &rCtx)
+{
+    return weld::DialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 short AbstractScDeleteCellDlg_Impl::Execute()
 {
     return m_xDlg->run();
@@ -987,7 +997,7 @@ VclPtr<AbstractScCondFormatManagerDlg> 
ScAbstractDialogFactory_Impl::CreateScCon
 
 VclPtr<AbstractScDataPilotDatabaseDlg> 
ScAbstractDialogFactory_Impl::CreateScDataPilotDatabaseDlg(weld::Window* 
pParent)
 {
-    return 
VclPtr<AbstractScDataPilotDatabaseDlg_Impl>::Create(std::make_unique<ScDataPilotDatabaseDlg>(pParent));
+    return 
VclPtr<AbstractScDataPilotDatabaseDlg_Impl>::Create(std::make_shared<ScDataPilotDatabaseDlg>(pParent));
 }
 
 VclPtr<AbstractScDataPilotSourceTypeDlg> 
ScAbstractDialogFactory_Impl::CreateScDataPilotSourceTypeDlg(
@@ -999,7 +1009,7 @@ VclPtr<AbstractScDataPilotSourceTypeDlg> 
ScAbstractDialogFactory_Impl::CreateScD
 VclPtr<AbstractScDataPilotServiceDlg> 
ScAbstractDialogFactory_Impl::CreateScDataPilotServiceDlg(weld::Window* pParent,
                                                                         const 
std::vector<OUString>& rServices)
 {
-    return 
VclPtr<AbstractScDataPilotServiceDlg_Impl>::Create(std::make_unique<ScDataPilotServiceDlg>(pParent,
 rServices));
+    return 
VclPtr<AbstractScDataPilotServiceDlg_Impl>::Create(std::make_shared<ScDataPilotServiceDlg>(pParent,
 rServices));
 }
 
 VclPtr<AbstractScDeleteCellDlg> 
ScAbstractDialogFactory_Impl::CreateScDeleteCellDlg(weld::Window* pParent,
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx 
b/sc/source/ui/attrdlg/scdlgfact.hxx
index ec995f5302ae..0364e904c6eb 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -164,13 +164,14 @@ public:
 
 class AbstractScDataPilotDatabaseDlg_Impl  :public 
AbstractScDataPilotDatabaseDlg
 {
-    std::unique_ptr<ScDataPilotDatabaseDlg> m_xDlg;
+    std::shared_ptr<ScDataPilotDatabaseDlg> m_xDlg;
 public:
-    explicit 
AbstractScDataPilotDatabaseDlg_Impl(std::unique_ptr<ScDataPilotDatabaseDlg> p)
+    explicit 
AbstractScDataPilotDatabaseDlg_Impl(std::shared_ptr<ScDataPilotDatabaseDlg> p)
         : m_xDlg(std::move(p))
     {
     }
     virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &) override;
     virtual void GetValues( ScImportSourceDesc& rDesc ) override;
 
     // screenshotting
@@ -201,13 +202,14 @@ public:
 
 class AbstractScDataPilotServiceDlg_Impl : public AbstractScDataPilotServiceDlg
 {
-    std::unique_ptr<ScDataPilotServiceDlg> m_xDlg;
+    std::shared_ptr<ScDataPilotServiceDlg> m_xDlg;
 public:
-    explicit 
AbstractScDataPilotServiceDlg_Impl(std::unique_ptr<ScDataPilotServiceDlg> p)
+    explicit 
AbstractScDataPilotServiceDlg_Impl(std::shared_ptr<ScDataPilotServiceDlg> p)
         : m_xDlg(std::move(p))
     {
     }
     virtual short     Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &) override;
     virtual OUString  GetServiceName() const override;
     virtual OUString  GetParSource() const override;
     virtual OUString  GetParName() const override;
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 26efd68b55dd..f38184ac3b1b 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2917,124 +2917,149 @@ void ScCellShell::ExecuteDataPilotDialog()
 
         pTypeDlg->StartExecuteAsync([this, pTypeDlg, pTabViewShell,
                                     pScMod, pFact, &rDoc, &rMark, 
aDestPos](int nResult) mutable {
-            const char* pSrcErrorId = nullptr;
-            std::unique_ptr<ScDPObject> pNewDPObject;
 
             if (nResult == RET_OK )
             {
                 if ( pTypeDlg->IsExternal() )
                 {
                     std::vector<OUString> aSources = 
ScDPObject::GetRegisteredSources();
-                    ScopedVclPtr<AbstractScDataPilotServiceDlg> pServDlg(
+                    VclPtr<AbstractScDataPilotServiceDlg> pServDlg(
                         pFact->CreateScDataPilotServiceDlg(
                             pTabViewShell->GetFrameWeld(), aSources));
 
-                    if ( pServDlg->Execute() == RET_OK )
-                    {
-                        ScDPServiceDesc aServDesc(
-                                pServDlg->GetServiceName(),
-                                pServDlg->GetParSource(),
-                                pServDlg->GetParName(),
-                                pServDlg->GetParUser(),
-                                pServDlg->GetParPass() );
-                        pNewDPObject.reset(new ScDPObject(&rDoc));
-                        pNewDPObject->SetServiceData( aServDesc );
-                    }
+                    pServDlg->StartExecuteAsync([pServDlg, pScMod, 
pTabViewShell,
+                                                 aDestPos, &rDoc](int 
nResult2) mutable {
+                        if ( nResult2 == RET_OK )
+                        {
+                            ScDPServiceDesc aServDesc(
+                                    pServDlg->GetServiceName(),
+                                    pServDlg->GetParSource(),
+                                    pServDlg->GetParName(),
+                                    pServDlg->GetParUser(),
+                                    pServDlg->GetParPass() );
+                            std::unique_ptr<ScDPObject> pNewDPObject(new 
ScDPObject(&rDoc));
+                            pNewDPObject->SetServiceData( aServDesc );
+
+                            if ( pNewDPObject )
+                                pNewDPObject->SetOutRange( aDestPos );
+
+                            RunPivotLayoutDialog(pScMod, pTabViewShell, 
pNewDPObject);
+                        }
+
+                        pServDlg->disposeOnce();
+                    });
                 }
                 else if ( pTypeDlg->IsDatabase() )
                 {
                     assert(pFact && "ScAbstractFactory create fail!");
-                    ScopedVclPtr<AbstractScDataPilotDatabaseDlg> pDataDlg(
+                    VclPtr<AbstractScDataPilotDatabaseDlg> pDataDlg(
                         
pFact->CreateScDataPilotDatabaseDlg(pTabViewShell->GetFrameWeld()));
                     assert(pDataDlg  && "Dialog create fail!");
-                    if ( pDataDlg->Execute() == RET_OK )
-                    {
-                        ScImportSourceDesc aImpDesc(&rDoc);
-                        pDataDlg->GetValues( aImpDesc );
-                        pNewDPObject.reset(new ScDPObject(&rDoc));
-                        pNewDPObject->SetImportDesc( aImpDesc );
-                    }
+
+                    pDataDlg->StartExecuteAsync([pDataDlg, pScMod, 
pTabViewShell,
+                                                 aDestPos, &rDoc](int 
nResult2) mutable {
+                        if ( nResult2 == RET_OK )
+                        {
+                            ScImportSourceDesc aImpDesc(&rDoc);
+                            pDataDlg->GetValues( aImpDesc );
+                            std::unique_ptr<ScDPObject> pNewDPObject(new 
ScDPObject(&rDoc));
+                            pNewDPObject->SetImportDesc( aImpDesc );
+
+                            if ( pNewDPObject )
+                                pNewDPObject->SetOutRange( aDestPos );
+
+                            RunPivotLayoutDialog(pScMod, pTabViewShell, 
pNewDPObject);
+                        }
+
+                        pDataDlg->disposeOnce();
+                    });
                 }
-                else if (pTypeDlg->IsNamedRange())
+                else
                 {
-                    OUString aName = pTypeDlg->GetSelectedNamedRange();
-                    ScSheetSourceDesc aShtDesc(&rDoc);
-                    aShtDesc.SetRangeName(aName);
-                    pSrcErrorId = aShtDesc.CheckSourceRange();
-                    if (!pSrcErrorId)
+                    std::unique_ptr<ScDPObject> pNewDPObject;
+                    const char* pSrcErrorId = nullptr;
+
+                    if (pTypeDlg->IsNamedRange())
                     {
-                        pNewDPObject.reset(new ScDPObject(&rDoc));
-                        pNewDPObject->SetSheetDesc(aShtDesc);
+                        OUString aName = pTypeDlg->GetSelectedNamedRange();
+                        ScSheetSourceDesc aShtDesc(&rDoc);
+                        aShtDesc.SetRangeName(aName);
+                        pSrcErrorId = aShtDesc.CheckSourceRange();
+                        if (!pSrcErrorId)
+                        {
+                            pNewDPObject.reset(new ScDPObject(&rDoc));
+                            pNewDPObject->SetSheetDesc(aShtDesc);
+                        }
                     }
-                }
-                else        // selection
-                {
-                    //! use database ranges (select before type dialog?)
-                    ScRange aRange;
-                    ScMarkType eType = GetViewData()->GetSimpleArea(aRange);
-                    if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
+                    else        // selection
                     {
-                        // Shrink the range to the data area.
-                        SCCOL nStartCol = aRange.aStart.Col(), nEndCol = 
aRange.aEnd.Col();
-                        SCROW nStartRow = aRange.aStart.Row(), nEndRow = 
aRange.aEnd.Row();
-                        if (rDoc.ShrinkToDataArea(aRange.aStart.Tab(), 
nStartCol, nStartRow, nEndCol, nEndRow))
+                        //! use database ranges (select before type dialog?)
+                        ScRange aRange;
+                        ScMarkType eType = 
GetViewData()->GetSimpleArea(aRange);
+                        if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
                         {
-                            aRange.aStart.SetCol(nStartCol);
-                            aRange.aStart.SetRow(nStartRow);
-                            aRange.aEnd.SetCol(nEndCol);
-                            aRange.aEnd.SetRow(nEndRow);
-                            rMark.SetMarkArea(aRange);
-                            pTabViewShell->MarkRange(aRange);
-                        }
+                            // Shrink the range to the data area.
+                            SCCOL nStartCol = aRange.aStart.Col(), nEndCol = 
aRange.aEnd.Col();
+                            SCROW nStartRow = aRange.aStart.Row(), nEndRow = 
aRange.aEnd.Row();
+                            if (rDoc.ShrinkToDataArea(aRange.aStart.Tab(), 
nStartCol, nStartRow, nEndCol, nEndRow))
+                            {
+                                aRange.aStart.SetCol(nStartCol);
+                                aRange.aStart.SetRow(nStartRow);
+                                aRange.aEnd.SetCol(nEndCol);
+                                aRange.aEnd.SetRow(nEndRow);
+                                rMark.SetMarkArea(aRange);
+                                pTabViewShell->MarkRange(aRange);
+                            }
 
-                        bool bOK = true;
-                        if ( rDoc.HasSubTotalCells( aRange ) )
-                        {
-                            //  confirm selection if it contains SubTotal cells
-                            std::unique_ptr<weld::MessageDialog> 
xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
-                                                                        
VclMessageType::Question, VclButtonsType::YesNo,
-                                                                        
ScResId(STR_DATAPILOT_SUBTOTAL)));
-                            xQueryBox->set_default_response(RET_YES);
-                            if (xQueryBox->run() == RET_NO)
-                                bOK = false;
-                        }
-                        if (bOK)
-                        {
-                            ScSheetSourceDesc aShtDesc(&rDoc);
-                            aShtDesc.SetSourceRange(aRange);
-                            pSrcErrorId = aShtDesc.CheckSourceRange();
-                            if (!pSrcErrorId)
+                            bool bOK = true;
+                            if ( rDoc.HasSubTotalCells( aRange ) )
                             {
-                                pNewDPObject.reset(new ScDPObject(&rDoc));
-                                pNewDPObject->SetSheetDesc( aShtDesc );
+                                //  confirm selection if it contains SubTotal 
cells
+                                std::unique_ptr<weld::MessageDialog> 
xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
+                                                                            
VclMessageType::Question, VclButtonsType::YesNo,
+                                                                            
ScResId(STR_DATAPILOT_SUBTOTAL)));
+                                xQueryBox->set_default_response(RET_YES);
+                                if (xQueryBox->run() == RET_NO)
+                                    bOK = false;
                             }
+                            if (bOK)
+                            {
+                                ScSheetSourceDesc aShtDesc(&rDoc);
+                                aShtDesc.SetSourceRange(aRange);
+                                pSrcErrorId = aShtDesc.CheckSourceRange();
+                                if (!pSrcErrorId)
+                                {
+                                    pNewDPObject.reset(new ScDPObject(&rDoc));
+                                    pNewDPObject->SetSheetDesc( aShtDesc );
+                                }
 
-                            //  output below source data
-                            if ( aRange.aEnd.Row()+2 <= rDoc.MaxRow() - 4 )
-                                aDestPos = ScAddress( aRange.aStart.Col(),
-                                                        aRange.aEnd.Row()+2,
-                                                        aRange.aStart.Tab() );
+                                //  output below source data
+                                if ( aRange.aEnd.Row()+2 <= rDoc.MaxRow() - 4 )
+                                    aDestPos = ScAddress( aRange.aStart.Col(),
+                                                            
aRange.aEnd.Row()+2,
+                                                            
aRange.aStart.Tab() );
+                            }
                         }
                     }
-                }
-            }
 
-            if (pSrcErrorId)
-            {
-                // Error occurred during data creation.  Launch an error and 
bail out.
-                std::unique_ptr<weld::MessageDialog> 
xInfoBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
-                                                            
VclMessageType::Info, VclButtonsType::Ok,
-                                                            
ScResId(pSrcErrorId)));
-                xInfoBox->run();
-                return;
-            }
+                    if (pSrcErrorId)
+                    {
+                        // Error occurred during data creation.  Launch an 
error and bail out.
+                        std::unique_ptr<weld::MessageDialog> 
xInfoBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
+                                                                    
VclMessageType::Info, VclButtonsType::Ok,
+                                                                    
ScResId(pSrcErrorId)));
+                        xInfoBox->run();
+                        return;
+                    }
 
-            if ( pNewDPObject )
-                pNewDPObject->SetOutRange( aDestPos );
+                    if ( pNewDPObject )
+                        pNewDPObject->SetOutRange( aDestPos );
 
-            pTypeDlg->disposeOnce();
+                    RunPivotLayoutDialog(pScMod, pTabViewShell, pNewDPObject);
+                }
+            }
 
-            RunPivotLayoutDialog(pScMod, pTabViewShell, pNewDPObject);
+            pTypeDlg->disposeOnce();
         });
     }
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to