sc/source/ui/attrdlg/scdlgfact.cxx |   10 +++
 sc/source/ui/attrdlg/scdlgfact.hxx |   10 +--
 sc/source/ui/view/cellsh1.cxx      |  122 +++++++++++++++++++++----------------
 vcl/jsdialog/enabled.cxx           |    2 
 4 files changed, 89 insertions(+), 55 deletions(-)

New commits:
commit d4b5689c18f9bc10e6b552ba7f20b0af2b36d170
Author:     Michael Meeks <michael.me...@collabora.com>
AuthorDate: Tue Nov 1 21:43:08 2022 +0000
Commit:     Michael Meeks <michael.me...@collabora.com>
CommitDate: Wed Nov 2 15:19:00 2022 +0100

    sc: make InsertCell and DeleteCell async.
    
    Also enable them for use with jsdialogs.
    
    Change-Id: I378f228e86959edb98ad691089af919330dcdcec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142144
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx 
b/sc/source/ui/attrdlg/scdlgfact.cxx
index 8b59e672ca12..722c3b8c29e4 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -137,6 +137,11 @@ short AbstractScDeleteCellDlg_Impl::Execute()
     return m_xDlg->run();
 }
 
+bool AbstractScDeleteCellDlg_Impl::StartExecuteAsync(AsyncContext& rCtx)
+{
+    return ScDeleteCellDlg::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 //for dataform
 short AbstractScDataFormDlg_Impl::Execute()
 {
@@ -174,6 +179,11 @@ short AbstractScInsertCellDlg_Impl::Execute()
     return m_xDlg->run();
 }
 
+bool AbstractScInsertCellDlg_Impl::StartExecuteAsync(AsyncContext& rCtx)
+{
+    return ScInsertCellDlg::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 short AbstractScInsertContentsDlg_Impl::Execute()
 {
     return m_xDlg->run();
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx 
b/sc/source/ui/attrdlg/scdlgfact.hxx
index b1703930c584..35782000b979 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -174,13 +174,14 @@ public:
 
 class AbstractScDeleteCellDlg_Impl : public AbstractScDeleteCellDlg
 {
-    std::unique_ptr<ScDeleteCellDlg> m_xDlg;
+    std::shared_ptr<ScDeleteCellDlg> m_xDlg;
 public:
     explicit AbstractScDeleteCellDlg_Impl(std::unique_ptr<ScDeleteCellDlg> p)
         : m_xDlg(std::move(p))
     {
     }
-    virtual short           Execute() override;
+    virtual short Execute() override;
+    virtual bool  StartExecuteAsync(AsyncContext& rCtx) override;
     virtual DelCellCmd GetDelCellCmd() const override;
 
     // screenshotting
@@ -255,13 +256,14 @@ public:
 
 class AbstractScInsertCellDlg_Impl : public AbstractScInsertCellDlg
 {
-    std::unique_ptr<ScInsertCellDlg> m_xDlg;
+    std::shared_ptr<ScInsertCellDlg> m_xDlg;
 public:
     explicit AbstractScInsertCellDlg_Impl(std::unique_ptr<ScInsertCellDlg> p)
         : m_xDlg(std::move(p))
     {
     }
-    virtual short           Execute() override;
+    virtual short Execute() override;
+    virtual bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx) 
override;
     virtual InsCellCmd GetInsCellCmd() const override ;
 };
 
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index b3e03a488a6a..88c1470bc8db 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -169,6 +169,60 @@ void SetTabNoAndCursor( const ScViewData& rViewData, 
std::u16string_view rCellId
         pTabViewShell->SetCursor(aFoundPos.Col(), aFoundPos.Row());
     }
 }
+
+void InsertCells(ScTabViewShell* pTabViewShell, SfxRequest &rReq, InsCellCmd 
eCmd)
+{
+    if (eCmd!=INS_NONE)
+    {
+        pTabViewShell->InsertCells( eCmd );
+
+        if( ! rReq.IsAPI() )
+        {
+            OUString aParam;
+
+            switch( eCmd )
+            {
+            case INS_CELLSDOWN: aParam = "V"; break;
+            case INS_CELLSRIGHT: aParam = ">"; break;
+            case INS_INSROWS_BEFORE: aParam = "R"; break;
+            case INS_INSCOLS_BEFORE: aParam = "C"; break;
+            default:
+            {
+                // added to avoid warnings
+            }
+            }
+            rReq.AppendItem( SfxStringItem( FID_INS_CELL, aParam ) );
+            rReq.Done();
+        }
+    }
+}
+
+void DeleteCells(ScTabViewShell* pTabViewShell, SfxRequest &rReq, DelCellCmd 
eCmd)
+{
+    if (eCmd != DelCellCmd::NONE )
+    {
+        pTabViewShell->DeleteCells( eCmd );
+
+        if( ! rReq.IsAPI() )
+        {
+            OUString aParam;
+
+            switch( eCmd )
+            {
+            case DelCellCmd::CellsUp: aParam = "U"; break;
+            case DelCellCmd::CellsLeft: aParam = "L"; break;
+            case DelCellCmd::Rows: aParam = "R"; break;
+            case DelCellCmd::Cols: aParam = "C"; break;
+            default:
+            {
+                // added to avoid warnings
+            }
+            }
+            rReq.AppendItem( SfxStringItem( FID_DELETE_CELL, aParam ) );
+            rReq.Done();
+        }
+    }
+}
 }
 
 void ScCellShell::ExecuteEdit( SfxRequest& rReq )
@@ -287,35 +341,19 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
 
                         ScAbstractDialogFactory* pFact = 
ScAbstractDialogFactory::Create();
 
-                        ScopedVclPtr<AbstractScInsertCellDlg> 
pDlg(pFact->CreateScInsertCellDlg(pTabViewShell->GetFrameWeld(), bTheFlag));
-                        if (pDlg->Execute() == RET_OK)
-                            eCmd = pDlg->GetInsCellCmd();
-                    }
-                }
-
-                if (eCmd!=INS_NONE)
-                {
-                    pTabViewShell->InsertCells( eCmd );
-
-                    if( ! rReq.IsAPI() )
-                    {
-                        OUString aParam;
-
-                        switch( eCmd )
-                        {
-                            case INS_CELLSDOWN: aParam = "V"; break;
-                            case INS_CELLSRIGHT: aParam = ">"; break;
-                            case INS_INSROWS_BEFORE: aParam = "R"; break;
-                            case INS_INSCOLS_BEFORE: aParam = "C"; break;
-                            default:
+                        VclPtr<AbstractScInsertCellDlg> 
pDlg(pFact->CreateScInsertCellDlg(pTabViewShell->GetFrameWeld(), bTheFlag));
+                        pDlg->StartExecuteAsync([pDlg, 
pTabViewShell](sal_Int32 nResult){
+                            if (nResult == RET_OK)
                             {
-                                // added to avoid warnings
+                                SfxRequest 
aRequest(pTabViewShell->GetViewFrame(), FID_INS_CELL);
+                                InsertCells(pTabViewShell, aRequest, 
pDlg->GetInsCellCmd());
                             }
-                        }
-                        rReq.AppendItem( SfxStringItem( FID_INS_CELL, aParam ) 
);
-                        rReq.Done();
+                            pDlg->disposeOnce();
+                        });
                     }
                 }
+
+                InsertCells(pTabViewShell, rReq, eCmd);
             }
             break;
 
@@ -356,37 +394,19 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                             (rDoc.GetChangeTrack() != nullptr);
 
                         ScAbstractDialogFactory* pFact = 
ScAbstractDialogFactory::Create();
+                        VclPtr<AbstractScDeleteCellDlg> 
pDlg(pFact->CreateScDeleteCellDlg( pTabViewShell->GetFrameWeld(), bTheFlag ));
 
-                        ScopedVclPtr<AbstractScDeleteCellDlg> 
pDlg(pFact->CreateScDeleteCellDlg( pTabViewShell->GetFrameWeld(), bTheFlag ));
-
-                        if (pDlg->Execute() == RET_OK)
-                            eCmd = pDlg->GetDelCellCmd();
-                    }
-                }
-
-                if (eCmd != DelCellCmd::NONE )
-                {
-                    pTabViewShell->DeleteCells( eCmd );
-
-                    if( ! rReq.IsAPI() )
-                    {
-                        OUString aParam;
-
-                        switch( eCmd )
-                        {
-                            case DelCellCmd::CellsUp: aParam = "U"; break;
-                            case DelCellCmd::CellsLeft: aParam = "L"; break;
-                            case DelCellCmd::Rows: aParam = "R"; break;
-                            case DelCellCmd::Cols: aParam = "C"; break;
-                            default:
+                        pDlg->StartExecuteAsync([pDlg, 
pTabViewShell](sal_Int32 nResult){
+                            if (nResult == RET_OK)
                             {
-                                // added to avoid warnings
+                                SfxRequest 
aRequest(pTabViewShell->GetViewFrame(), FID_INS_CELL);
+                                DeleteCells(pTabViewShell, aRequest, 
pDlg->GetDelCellCmd());
                             }
-                        }
-                        rReq.AppendItem( SfxStringItem( FID_DELETE_CELL, 
aParam ) );
-                        rReq.Done();
+                            pDlg->disposeOnce();
+                        });
                     }
                 }
+                DeleteCells(pTabViewShell, rReq, eCmd);
             }
             break;
 
diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx
index f260691a64d7..b1d222d4b7f3 100644
--- a/vcl/jsdialog/enabled.cxx
+++ b/vcl/jsdialog/enabled.cxx
@@ -50,6 +50,8 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool 
bMobile)
         || rUIFile == u"modules/scalc/ui/datafielddialog.ui"
         || rUIFile == u"modules/scalc/ui/pivotfielddialog.ui"
         || rUIFile == u"modules/scalc/ui/datafieldoptionsdialog.ui"
+        || rUIFile == u"modules/scalc/ui/insertcells.ui"
+        || rUIFile == u"modules/scalc/ui/deletecells.ui"
         || rUIFile == u"svx/ui/fontworkgallerydialog.ui"
         || rUIFile == u"svx/ui/findreplacedialog.ui" || rUIFile == 
u"svx/ui/findreplacedialog.ui"
         || rUIFile == u"cui/ui/macroselectordialog.ui" || rUIFile == 
u"uui/ui/macrowarnmedium.ui"

Reply via email to