sc/source/ui/attrdlg/scdlgfact.cxx |    5 +
 sc/source/ui/attrdlg/scdlgfact.hxx |    5 +
 sc/source/ui/inc/tabvwsh.hxx       |    3 +
 sc/source/ui/view/tabvwshf.cxx     |   97 ++++++++++++++++++++++---------------
 4 files changed, 71 insertions(+), 39 deletions(-)

New commits:
commit e5e95c95b05ab79298b7e9f0de82536a1bd04c9b
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 24 13:06:35 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Jan 29 13:15:02 2024 +0100

    make append/rename table dialog async
    
    Change-Id: I3713271d121c525daa9800dcc1ac39bbd25e9c7e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162512
    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 10c27561a2c2..ef4ee9583585 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -936,6 +936,11 @@ short AbstractScStringInputDlg_Impl::Execute()
     return m_xDlg->run();
 }
 
+bool 
AbstractScStringInputDlg_Impl::StartExecuteAsync(VclAbstractDialog::AsyncContext
 &rCtx)
+{
+    return weld::DialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 OUString AbstractScStringInputDlg_Impl::GetInputString() const
 {
     return m_xDlg->GetInputString();
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx 
b/sc/source/ui/attrdlg/scdlgfact.hxx
index d490e6004df5..d5b59a15d5b9 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -559,13 +559,14 @@ public:
 
 class AbstractScStringInputDlg_Impl :  public AbstractScStringInputDlg
 {
-    std::unique_ptr<ScStringInputDlg> m_xDlg;
+    std::shared_ptr<ScStringInputDlg> m_xDlg;
 public:
-    explicit AbstractScStringInputDlg_Impl(std::unique_ptr<ScStringInputDlg> p)
+    explicit AbstractScStringInputDlg_Impl(std::shared_ptr<ScStringInputDlg> p)
         : m_xDlg(std::move(p))
     {
     }
     virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &rCtx) override;
     virtual OUString GetInputString() const override;
 
     // screenshotting
diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index c7bd83ec1f55..7e7a79142ea0 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -44,6 +44,7 @@ struct SfxChildWinInfo;
 class AbstractScInsertTableDlg;
 class AbstractScMoveTableDlg;
 class AbstractScTabBgColorDlg;
+class AbstractScStringInputDlg;
 class ScArea;
 class ScAuditingShell;
 class ScDrawShell;
@@ -460,6 +461,8 @@ private:
     void ExecuteInsertTable( SfxRequest& rReq );
     void DoInsertTableFromDialog( SfxRequest& rReq, const 
VclPtr<AbstractScInsertTableDlg>& pDlg );
     void ExecuteAppendOrRenameTable( SfxRequest& rReq );
+    void ExecuteAppendOrRenameTableDialog( const 
VclPtr<AbstractScStringInputDlg>& pDlg, const std::shared_ptr<SfxRequest>& 
xReq, sal_uInt16 nSlot );
+    bool DoAppendOrRenameTableDialog( sal_Int32 nResult, const 
VclPtr<AbstractScStringInputDlg>& pDlg, const std::shared_ptr<SfxRequest>& 
xReq, sal_uInt16 nSlot );
     void ExecuteSetTableBackgroundCol( SfxRequest& rReq );
     void ExecuteTableBackgroundDialog( const VclPtr<AbstractScTabBgColorDlg>& 
pDlg, const std::shared_ptr<SfxRequest>& xReq, Color aOldTabBgColor, sal_uInt16 
nSlot );
     bool DoTableBackgroundDialog( sal_Int32 nResult, const 
VclPtr<AbstractScTabBgColorDlg>& pDlg, const std::shared_ptr<SfxRequest>& xReq, 
Color aOldTabBgColor, sal_uInt16 nSlot );
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index fb66f62a5f67..f73925b23c6b 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -1094,7 +1094,6 @@ void 
ScTabViewShell::ExecuteAppendOrRenameTable(SfxRequest& rReq)
     }
     else
     {
-        OUString aErrMsg ( ScResId( STR_INVALIDTABNAME ) );
         OUString aName;
         OUString aDlgTitle;
         OUString sHelpId;
@@ -1116,54 +1115,78 @@ void 
ScTabViewShell::ExecuteAppendOrRenameTable(SfxRequest& rReq)
 
         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
 
-        ScopedVclPtr<AbstractScStringInputDlg> 
pDlg(pFact->CreateScStringInputDlg(
+        VclPtr<AbstractScStringInputDlg> pDlg(pFact->CreateScStringInputDlg(
             GetFrameWeld(), aDlgTitle, ScResId(SCSTR_NAME),
             aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
             sHelpId));
 
-        sal_uInt16 nRet    = RET_OK;
-        bool     bDone   = false;
-        while ( !bDone && nRet == RET_OK )
+        auto xRequest = std::make_shared<SfxRequest>(rReq);
+        rReq.Ignore(); // the 'old' request is not relevant any more
+        ExecuteAppendOrRenameTableDialog(pDlg, xRequest, nSlot);
+    }
+}
+
+void ScTabViewShell::ExecuteAppendOrRenameTableDialog(const 
VclPtr<AbstractScStringInputDlg>& pDlg,
+                        const std::shared_ptr<SfxRequest>& xReq,
+                        sal_uInt16 nSlot)
+{
+    pDlg->StartExecuteAsync(
+        [this, pDlg, xReq, nSlot] (sal_Int32 nResult)->void
         {
-            nRet = pDlg->Execute();
+            if (DoAppendOrRenameTableDialog(nResult, pDlg, xReq, nSlot))
+                ExecuteAppendOrRenameTableDialog(pDlg, xReq, nSlot);
+            else
+                pDlg->disposeOnce();
+        }
+    );
+}
 
-            if ( nRet == RET_OK )
-            {
-                aName = pDlg->GetInputString();
+bool ScTabViewShell::DoAppendOrRenameTableDialog(sal_Int32 nResult, const 
VclPtr<AbstractScStringInputDlg>& pDlg,
+                        const std::shared_ptr<SfxRequest>& xReq,
+                        sal_uInt16 nSlot)
+{
+    if (nResult != RET_OK)
+        return false;
 
-                switch ( nSlot )
-                {
-                    case FID_TAB_APPEND:
-                        bDone = AppendTable( aName );
-                        break;
-                    case FID_TAB_RENAME:
-                        bDone = RenameTable( aName, nTabNr );
-                        break;
-                }
+    ScViewData& rViewData   = GetViewData();
+    SCTAB nTabNr = rViewData.GetTabNo();
+    bool     bDone   = false;
 
-                if ( bDone )
-                {
-                    rReq.AppendItem( SfxStringItem( nSlot, aName ) );
-                    rReq.Done();
-                }
-                else
-                {
-                    if( rReq.IsAPI() )
-                    {
+    OUString aName = pDlg->GetInputString();
+
+    switch ( nSlot )
+    {
+        case FID_TAB_APPEND:
+            bDone = AppendTable( aName );
+            break;
+        case FID_TAB_RENAME:
+            bDone = RenameTable( aName, nTabNr );
+            break;
+    }
+
+    if ( bDone )
+    {
+        xReq->AppendItem( SfxStringItem( nSlot, aName ) );
+        xReq->Done();
+    }
+    else
+    {
+        if( xReq->IsAPI() )
+        {
 #if HAVE_FEATURE_SCRIPTING
-                        StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); // 
XXX error handling???
+            StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); // XXX error 
handling???
 #endif
-                    }
-                    else
-                    {
-                        std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrameWeld(),
-                                                                  
VclMessageType::Warning, VclButtonsType::Ok, aErrMsg));
-                        nRet = xBox->run();
-                    }
-                }
-            }
+        }
+        else
+        {
+            OUString aErrMsg ( ScResId( STR_INVALIDTABNAME ) );
+            std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrameWeld(),
+                                                      VclMessageType::Warning, 
VclButtonsType::Ok, aErrMsg));
+            xBox->run();
         }
     }
+
+    return !bDone;
 }
 
 void ScTabViewShell::ExecuteSetTableBackgroundCol(SfxRequest& rReq)

Reply via email to