sc/source/ui/inc/tabvwsh.hxx   |    2 +
 sc/source/ui/view/tabvwshf.cxx |   80 +++++++++++++++++++++++++----------------
 2 files changed, 52 insertions(+), 30 deletions(-)

New commits:
commit fee9b337eb25f81191ec4b270860de1a0d7eaf61
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 24 11:47:20 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jan 24 21:33:01 2024 +0100

    make move table dialog async
    
    Change-Id: I85ddcd2589b6cb27f2022746607e9eda3818abd6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162499
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index b85400e02692..1f8fe640fcd3 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -42,6 +42,7 @@ class SfxChildWindow;
 class SvxNumberInfoItem;
 struct SfxChildWinInfo;
 class AbstractScInsertTableDlg;
+class AbstractScMoveTableDlg;
 class ScArea;
 class ScAuditingShell;
 class ScDrawShell;
@@ -454,6 +455,7 @@ public:
 
 private:
     void ExecuteMoveTable( SfxRequest& rReq );
+    void DoMoveTableFromDialog( SfxRequest& rReq, const 
VclPtr<AbstractScMoveTableDlg>& pDlg );
     void ExecuteInsertTable( SfxRequest& rReq );
     void DoInsertTableFromDialog( SfxRequest& rReq, const 
VclPtr<AbstractScInsertTableDlg>& pDlg );
 };
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index c7a53f87427d..a94640450a26 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -1016,7 +1016,7 @@ void ScTabViewShell::ExecuteMoveTable( SfxRequest& rReq )
 
         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
 
-        ScopedVclPtr<AbstractScMoveTableDlg> 
pDlg(pFact->CreateScMoveTableDlg(GetFrameWeld(),
+        VclPtr<AbstractScMoveTableDlg> 
pDlg(pFact->CreateScMoveTableDlg(GetFrameWeld(),
             aDefaultName));
 
         SCTAB nTableCount = rDoc.GetTableCount();
@@ -1032,39 +1032,18 @@ void ScTabViewShell::ExecuteMoveTable( SfxRequest& rReq 
)
         // is selected.
         pDlg->EnableRenameTable(nTabSelCount == 1);
 
-        if ( pDlg->Execute() == RET_OK )
-        {
-            nDoc = pDlg->GetSelectedDocument();
-            nTab = pDlg->GetSelectedTable();
-            bCpy = pDlg->GetCopyTable();
-            bool bRna = pDlg->GetRenameTable();
-            // Leave aTabName string empty, when Rename is FALSE.
-            if( bRna )
-            {
-               pDlg->GetTabNameString( aTabName );
-            }
-            bDoIt = true;
-
-            OUString aFoundDocName;
-            if ( nDoc != SC_DOC_NEW )
+        auto xRequest = std::make_shared<SfxRequest>(rReq);
+        rReq.Ignore(); // the 'old' request is not relevant any more
+        pDlg->StartExecuteAsync(
+            [this, pDlg, xRequest] (sal_Int32 nResult)->void
             {
-                ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
-                if (pSh)
+                if (nResult == RET_OK)
                 {
-                    aFoundDocName = pSh->GetTitle();
-                    if ( !pSh->GetDocument().IsDocEditable() )
-                    {
-                        ErrorMessage(STR_READONLYERR);
-                        bDoIt = false;
-                    }
+                    DoMoveTableFromDialog(*xRequest, pDlg);
                 }
+                pDlg->disposeOnce();
             }
-            rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
-            // 1-based table, if not APPEND
-            SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
-            rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, 
static_cast<sal_uInt16>(nBasicTab) ) );
-            rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
-        }
+        );
     }
 
     if( bDoIt )
@@ -1238,4 +1217,45 @@ void ScTabViewShell::DoInsertTableFromDialog(SfxRequest& 
rReq, const VclPtr<Abst
         }
     }
 }
+
+void ScTabViewShell::DoMoveTableFromDialog( SfxRequest& rReq, const 
VclPtr<AbstractScMoveTableDlg>& pDlg )
+{
+    sal_uInt16 nDoc = pDlg->GetSelectedDocument();
+    SCTAB nTab = pDlg->GetSelectedTable();
+    bool bCpy = pDlg->GetCopyTable();
+    bool bRna = pDlg->GetRenameTable();
+    OUString aTabName;
+    // Leave aTabName string empty, when Rename is FALSE.
+    if( bRna )
+    {
+       pDlg->GetTabNameString( aTabName );
+    }
+    bool bDoIt = true;
+
+    OUString aFoundDocName;
+    if ( nDoc != SC_DOC_NEW )
+    {
+        ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
+        if (pSh)
+        {
+            aFoundDocName = pSh->GetTitle();
+            if ( !pSh->GetDocument().IsDocEditable() )
+            {
+                ErrorMessage(STR_READONLYERR);
+                bDoIt = false;
+            }
+        }
+    }
+    rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
+    // 1-based table, if not APPEND
+    SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
+    rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, 
static_cast<sal_uInt16>(nBasicTab) ) );
+    rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
+    if( bDoIt )
+    {
+        rReq.Done();        // record, while doc is active
+        MoveTable( nDoc, nTab, bCpy, &aTabName );
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to