sc/source/ui/attrdlg/scdlgfact.cxx |    5 ++
 sc/source/ui/attrdlg/scdlgfact.hxx |    5 +-
 sc/source/ui/docshell/docsh4.cxx   |   86 ++++++++++++++++++++++---------------
 sc/source/ui/inc/docsh.hxx         |    4 +
 4 files changed, 64 insertions(+), 36 deletions(-)

New commits:
commit 289afffaecf18b2cc5b032fed169a9131dc4c1ac
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Jan 29 14:46:11 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Jan 29 17:17:55 2024 +0100

    make chart-source dialog async
    
    Change-Id: If33d2bc57d5c79d3204079b9858a488e7d92e968
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162689
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx 
b/sc/source/ui/attrdlg/scdlgfact.cxx
index ef4ee9583585..bd8a77b523e8 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -92,6 +92,11 @@ short AbstractScColRowLabelDlg_Impl::Execute()
     return m_xDlg->run();
 }
 
+bool AbstractScColRowLabelDlg_Impl::StartExecuteAsync(AsyncContext &rCtx)
+{
+    return weld::GenericDialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 short AbstractScCondFormatManagerDlg_Impl::Execute()
 {
     return m_xDlg->run();
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx 
b/sc/source/ui/attrdlg/scdlgfact.hxx
index d5b59a15d5b9..aab8cf1cc107 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -86,13 +86,14 @@ public:
 
 class AbstractScColRowLabelDlg_Impl : public AbstractScColRowLabelDlg
 {
-    std::unique_ptr<ScColRowLabelDlg> m_xDlg;
+    std::shared_ptr<ScColRowLabelDlg> m_xDlg;
 public:
-    explicit AbstractScColRowLabelDlg_Impl(std::unique_ptr<ScColRowLabelDlg> p)
+    explicit AbstractScColRowLabelDlg_Impl(std::shared_ptr<ScColRowLabelDlg> p)
         : m_xDlg(std::move(p))
     {
     }
     virtual short Execute() override;
+    virtual bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx) 
override;
     virtual bool IsCol() override;
     virtual bool IsRow() override;
 
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index c449a074ac73..34916e553c30 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -1424,7 +1424,6 @@ void ScDocShell::ExecuteChartSource(SfxRequest& rReq)
         m_pDocument->LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 );
 
     // Dialog for column/row headers
-    bool bOk = true;
     if ( !bAddRange && ( !bColInit || !bRowInit ) )
     {
         ScChartPositioner aChartPositioner( *m_pDocument, nTab, nCol1,nRow1, 
nCol2,nRow2 );
@@ -1433,48 +1432,67 @@ void ScDocShell::ExecuteChartSource(SfxRequest& rReq)
         if (!bRowInit)
             bRowHeaders = aChartPositioner.HasRowHeaders();
 
+        auto xRequest = std::make_shared<SfxRequest>(rReq);
+        rReq.Ignore(); // the 'old' request is not relevant any more
         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
-
-        ScopedVclPtr<AbstractScColRowLabelDlg> 
pDlg(pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders));
-        if ( pDlg->Execute() == RET_OK )
-        {
-            bColHeaders = pDlg->IsRow();
-            bRowHeaders = pDlg->IsCol();
-
-            rReq.AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders));
-            rReq.AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders));
-        }
-        else
-            bOk = false;
+        VclPtr<AbstractScColRowLabelDlg> 
pDlg(pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders));
+        pDlg->StartExecuteAsync(
+            [this, pDlg, xRequest, bUndo, bMultiRange, aChartName, 
aRangeListRef, bAddRange,
+             nCol1, nRow1, nCol2, nRow2, nTab] (sal_Int32 nResult)->void
+            {
+                if (nResult == RET_OK)
+                {
+                    bool bColHeaders2 = pDlg->IsRow();
+                    bool bRowHeaders2 = pDlg->IsCol();
+
+                    xRequest->AppendItem(SfxBoolItem(FN_PARAM_1, 
bColHeaders2));
+                    xRequest->AppendItem(SfxBoolItem(FN_PARAM_2, 
bRowHeaders2));
+                    ExecuteChartSourcePost(bUndo, bMultiRange,
+                        aChartName, aRangeListRef, bColHeaders2, bRowHeaders2, 
bAddRange,
+                        nCol1, nRow1, nCol2, nRow2, nTab);
+                }
+                pDlg->disposeOnce();
+                xRequest->Done();
+            }
+        );
     }
+    else
+    {
+        ExecuteChartSourcePost(bUndo, bMultiRange,
+            aChartName, aRangeListRef, bColHeaders, bRowHeaders, bAddRange,
+            nCol1, nRow1,nCol2, nRow2, nTab);
+        rReq.Done();
+    }
+}
 
-    if (bOk)            // execute
+void ScDocShell::ExecuteChartSourcePost(bool bUndo, bool bMultiRange,
+    const OUString& rChartName, const ScRangeListRef& rRangeListRef,
+    bool bColHeaders, bool bRowHeaders, bool bAddRange,
+    SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab )
+{
+    if (bMultiRange)
     {
-        if (bMultiRange)
+        if (bUndo)
         {
-            if (bUndo)
-            {
-                GetUndoManager()->AddUndoAction(
-                    std::make_unique<ScUndoChartData>( this, aChartName, 
aRangeListRef,
-                                            bColHeaders, bRowHeaders, 
bAddRange ) );
-            }
-            m_pDocument->UpdateChartArea( aChartName, aRangeListRef,
-                                        bColHeaders, bRowHeaders, bAddRange );
+            GetUndoManager()->AddUndoAction(
+                std::make_unique<ScUndoChartData>( this, rChartName, 
rRangeListRef,
+                                        bColHeaders, bRowHeaders, bAddRange ) 
);
         }
-        else
+        m_pDocument->UpdateChartArea( rChartName, rRangeListRef,
+                                    bColHeaders, bRowHeaders, bAddRange );
+    }
+    else
+    {
+        ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
+        if (bUndo)
         {
-            ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
-            if (bUndo)
-            {
-                GetUndoManager()->AddUndoAction(
-                    std::make_unique<ScUndoChartData>( this, aChartName, 
aNewRange,
-                                            bColHeaders, bRowHeaders, 
bAddRange ) );
-            }
-            m_pDocument->UpdateChartArea( aChartName, aNewRange,
-                                        bColHeaders, bRowHeaders, bAddRange );
+            GetUndoManager()->AddUndoAction(
+                std::make_unique<ScUndoChartData>( this, rChartName, aNewRange,
+                                        bColHeaders, bRowHeaders, bAddRange ) 
);
         }
+        m_pDocument->UpdateChartArea( rChartName, aNewRange,
+                                    bColHeaders, bRowHeaders, bAddRange );
     }
-    rReq.Done();
 }
 
 bool ScDocShell::ExecuteChangeProtectionDialog( bool bJustQueryIfProtected )
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 744108a80002..306b22cebe03 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -436,6 +436,10 @@ public:
 
 private:
     void ExecuteChartSource(SfxRequest& rReq);
+    void ExecuteChartSourcePost( bool bUndo, bool bMultiRange,
+        const OUString& rChartName, const ScRangeListRef& rRangeListRef,
+        bool bColHeaders, bool bRowHeaders, bool bAddRange,
+        SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab);
 };
 
 void UpdateAcceptChangesDialog();

Reply via email to