cui/source/dialogs/splitcelldlg.cxx  |   35 ++++++++++++++---
 cui/source/factory/dlgfact.cxx       |    2 
 cui/source/inc/splitcelldlg.hxx      |   20 ++++++++-
 svx/source/table/tablecontroller.cxx |   71 +++++++++++++++++------------------
 sw/source/uibase/shells/tabsh.cxx    |   33 +++++++++-------
 5 files changed, 104 insertions(+), 57 deletions(-)

New commits:
commit 817a06d857bff5be35f8eb7bf830b75871556bc5
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Sep 30 10:49:12 2020 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Fri Nov 13 09:38:36 2020 +0100

    Make Split Table Cell dialog async
    
    Change-Id: I4efbb24f721aa50cc4dbbe78ae1e7e6087f8c876
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103670
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105594
    Tested-by: Jenkins

diff --git a/cui/source/dialogs/splitcelldlg.cxx 
b/cui/source/dialogs/splitcelldlg.cxx
index 58d6b7e4f8a0..f58b8cc0ece5 100644
--- a/cui/source/dialogs/splitcelldlg.cxx
+++ b/cui/source/dialogs/splitcelldlg.cxx
@@ -74,15 +74,40 @@ tools::Long SvxSplitTableDlg::GetCount() const
     return m_xCountEdit->get_value();
 }
 
-short SvxSplitTableDlg::Execute()
-{
-    return run();
-}
-
 void SvxSplitTableDlg::SetSplitVerticalByDefault()
 {
     if( mnMaxVertical >= 2 )
         m_xVertBox->set_active(true); // tdf#60242
 }
 
+bool SvxAbstractSplitTableDialog_Impl::IsHorizontal() const
+{
+    return m_xDlg->IsHorizontal();
+}
+
+bool SvxAbstractSplitTableDialog_Impl::IsProportional() const
+{
+    return m_xDlg->IsProportional();
+}
+
+tools::Long SvxAbstractSplitTableDialog_Impl::GetCount() const
+{
+    return m_xDlg->GetCount();
+}
+
+void SvxAbstractSplitTableDialog_Impl::SetSplitVerticalByDefault()
+{
+    m_xDlg->SetSplitVerticalByDefault();
+}
+
+short SvxAbstractSplitTableDialog_Impl::Execute()
+{
+    return m_xDlg->run();
+}
+
+bool SvxAbstractSplitTableDialog_Impl::StartExecuteAsync(AsyncContext& 
rContext)
+{
+    return weld::DialogController::runAsync(m_xDlg, rContext.maEndDialogFn);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index ea2675694f07..e43b027602c4 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -1602,7 +1602,7 @@ VclPtr<SfxAbstractTabDialog> 
AbstractDialogFactory_Impl::CreateSvxFormatCellsDia
 
 VclPtr<SvxAbstractSplitTableDialog> 
AbstractDialogFactory_Impl::CreateSvxSplitTableDialog(weld::Window* pParent, 
bool bIsTableVertical, tools::Long nMaxVertical)
 {
-    return VclPtr<SvxSplitTableDlg>::Create( pParent, bIsTableVertical, 
nMaxVertical, 99 );
+    return VclPtr<SvxAbstractSplitTableDialog_Impl>::Create( 
std::make_shared<SvxSplitTableDlg>(pParent, bIsTableVertical, nMaxVertical, 99 
));
 }
 
 std::shared_ptr<SvxAbstractNewTableDialog> 
AbstractDialogFactory_Impl::CreateSvxNewTableDialog(weld::Window* pParent)
diff --git a/cui/source/inc/splitcelldlg.hxx b/cui/source/inc/splitcelldlg.hxx
index 88b1de85c9a7..5085c1938917 100644
--- a/cui/source/inc/splitcelldlg.hxx
+++ b/cui/source/inc/splitcelldlg.hxx
@@ -21,7 +21,7 @@
 #include <svx/svxdlg.hxx>
 #include <vcl/weld.hxx>
 
-class SvxSplitTableDlg : public SvxAbstractSplitTableDialog, public 
weld::GenericDialogController
+class SvxSplitTableDlg : public weld::GenericDialogController
 {
 private:
     std::unique_ptr<weld::SpinButton> m_xCountEdit;
@@ -37,12 +37,28 @@ public:
 
     DECL_LINK(ClickHdl, weld::Button&, void);
 
+    virtual bool IsHorizontal() const;
+    virtual bool IsProportional() const;
+    virtual tools::Long GetCount() const;
+
+    virtual void SetSplitVerticalByDefault();
+};
+
+class SvxAbstractSplitTableDialog_Impl : public SvxAbstractSplitTableDialog
+{
+    std::shared_ptr<SvxSplitTableDlg> m_xDlg;
+
+public:
+    SvxAbstractSplitTableDialog_Impl(std::shared_ptr<SvxSplitTableDlg> pDlg) : 
m_xDlg(std::move(pDlg)) {}
+
     virtual bool IsHorizontal() const override;
     virtual bool IsProportional() const override;
     virtual tools::Long GetCount() const override;
 
-    virtual short Execute() override;
     virtual void SetSplitVerticalByDefault() override;
+
+    virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext& rContext) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/table/tablecontroller.cxx 
b/svx/source/table/tablecontroller.cxx
index c30f71201277..ee40835ec5d8 100644
--- a/svx/source/table/tablecontroller.cxx
+++ b/svx/source/table/tablecontroller.cxx
@@ -1284,52 +1284,53 @@ void SvxTableController::SplitMarkedCells(const 
SfxRequest& rReq)
         return;
 
     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-    ScopedVclPtr<SvxAbstractSplitTableDialog> 
xDlg(pFact->CreateSvxSplitTableDialog(rReq.GetFrameWeld(), false, 99));
+    VclPtr<SvxAbstractSplitTableDialog> 
xDlg(pFact->CreateSvxSplitTableDialog(rReq.GetFrameWeld(), false, 99));
 
-    if( !xDlg->Execute() )
-        return;
+    xDlg->StartExecuteAsync([xDlg, this](int) {
+        const sal_Int32 nCount = xDlg->GetCount() - 1;
 
-    const sal_Int32 nCount = xDlg->GetCount() - 1;
+        if( nCount < 1 )
+            return;
 
-    if( nCount < 1 )
-        return;
+        CellPos aStart, aEnd;
+        getSelectedCells( aStart, aEnd );
+        Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( 
mxTable->getCellRangeByPosition( aStart.mnCol, aStart.mnRow, aEnd.mnCol, 
aEnd.mnRow ) ), UNO_QUERY_THROW );
+        const sal_Int32 nRowCount = mxTable->getRowCount();
+        const sal_Int32 nColCount = mxTable->getColumnCount();
+        SdrTableObj& rTableObj(*mxTableObj);
 
-    CellPos aStart, aEnd;
-    getSelectedCells( aStart, aEnd );
-    Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( 
mxTable->getCellRangeByPosition( aStart.mnCol, aStart.mnRow, aEnd.mnCol, 
aEnd.mnRow ) ), UNO_QUERY_THROW );
-    const sal_Int32 nRowCount = mxTable->getRowCount();
-    const sal_Int32 nColCount = mxTable->getColumnCount();
-    SdrTableObj& rTableObj(*mxTableObj);
+        if( rTableObj.IsTextEditActive() )
+            mrView.SdrEndTextEdit(true);
 
-    if( rTableObj.IsTextEditActive() )
-        mrView.SdrEndTextEdit(true);
+        TableModelNotifyGuard aGuard( mxTable.get() );
+        SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
+        const bool bUndo(rModel.IsUndoEnabled());
 
-    TableModelNotifyGuard aGuard( mxTable.get() );
-    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
-    const bool bUndo(rModel.IsUndoEnabled());
+        if( bUndo )
+        {
+            rModel.BegUndo( SvxResId(STR_TABLE_SPLIT) );
+            
rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj));
+        }
 
-    if( bUndo )
-    {
-        rModel.BegUndo( SvxResId(STR_TABLE_SPLIT) );
-        
rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj));
-    }
+        if( xDlg->IsHorizontal() )
+        {
+            xRange->split( 0, nCount );
+        }
+        else
+        {
+            xRange->split( nCount, 0 );
+        }
 
-    if( xDlg->IsHorizontal() )
-    {
-        xRange->split( 0, nCount );
-    }
-    else
-    {
-        xRange->split( nCount, 0 );
-    }
+        if( bUndo )
+            rModel.EndUndo();
 
-    if( bUndo )
-        rModel.EndUndo();
+        aEnd.mnRow += mxTable->getRowCount() - nRowCount;
+        aEnd.mnCol += mxTable->getColumnCount() - nColCount;
 
-    aEnd.mnRow += mxTable->getRowCount() - nRowCount;
-    aEnd.mnCol += mxTable->getColumnCount() - nColCount;
+        setSelectedCells( aStart, aEnd );
 
-    setSelectedCells( aStart, aEnd );
+        xDlg->disposeOnce();
+    });
 }
 
 void SvxTableController::DistributeColumns(const bool bOptimize, const bool 
bMinimize)
diff --git a/sw/source/uibase/shells/tabsh.cxx 
b/sw/source/uibase/shells/tabsh.cxx
index ce54bdd02e31..247d5b4955d6 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -982,23 +982,28 @@ void SwTableShell::Execute(SfxRequest &rReq)
             else
             {
                 SvxAbstractDialogFactory* pFact = 
SvxAbstractDialogFactory::Create();
+                SwWrtShell* pSh = &rSh;
                 const tools::Long nMaxVert = rSh.GetAnyCurRect( 
CurRectType::Frame ).Width() / MINLAY;
-                ScopedVclPtr<SvxAbstractSplitTableDialog> 
pDlg(pFact->CreateSvxSplitTableDialog(GetView().GetFrameWeld(), 
rSh.IsTableVertical(), nMaxVert));
+                VclPtr<SvxAbstractSplitTableDialog> 
pDlg(pFact->CreateSvxSplitTableDialog(GetView().GetFrameWeld(), 
rSh.IsTableVertical(), nMaxVert));
                 if(rSh.IsSplitVerticalByDefault())
                     pDlg->SetSplitVerticalByDefault();
-                if( pDlg->Execute() == RET_OK )
-                {
-                    nCount = pDlg->GetCount();
-                    bHorizontal = pDlg->IsHorizontal();
-                    bProportional = pDlg->IsProportional();
-                    rReq.AppendItem( SfxInt32Item( FN_TABLE_SPLIT_CELLS, 
nCount ) );
-                    rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bHorizontal ) );
-                    rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bProportional ) 
);
-
-                    // tdf#60242: remember choice for next time
-                    bool bVerticalWasChecked = !pDlg->IsHorizontal();
-                    rSh.SetSplitVerticalByDefault(bVerticalWasChecked);
-                }
+                pDlg->StartExecuteAsync([pDlg, pSh](int nResult) {
+                    if (nResult == RET_OK)
+                    {
+                        tools::Long nCount2 = pDlg->GetCount();
+                        bool bHorizontal2 = pDlg->IsHorizontal();
+                        bool bProportional2 = pDlg->IsProportional();
+
+                        // tdf#60242: remember choice for next time
+                        bool bVerticalWasChecked = !pDlg->IsHorizontal();
+                        pSh->SetSplitVerticalByDefault(bVerticalWasChecked);
+
+                        if ( nCount2 > 1 )
+                            pSh->SplitTab(!bHorizontal2, static_cast< 
sal_uInt16 >( nCount2-1 ), bProportional2 );
+                    }
+
+                    pDlg->disposeOnce();
+                });
             }
 
             if ( nCount>1 )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to