sw/source/ui/dialog/swdlgfact.cxx   |   16 ++++-
 sw/source/ui/dialog/swdlgfact.hxx   |   10 ++-
 sw/source/uibase/app/docsh2.cxx     |  103 ++++++++++++++++++------------------
 sw/source/uibase/dbui/dbmgr.cxx     |   36 +++++++-----
 sw/source/uibase/shells/textsh2.cxx |   75 +++++++++++++-------------
 5 files changed, 136 insertions(+), 104 deletions(-)

New commits:
commit d2101ec9402d067ec6fce1017c9ff6adbaf2808c
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 31 13:12:28 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Feb 1 07:00:17 2024 +0100

    make insert-new-doc dialog async
    
    Change-Id: I4977fc6ef2c6da356051ac5573ed088707d3b311
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162834
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index d4d35f0d0dc0..7333b4ebefcd 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -104,7 +104,13 @@ short AbstractSwWordCountFloatDlg_Impl::Execute()
 
 short AbstractSwInsertAbstractDlg_Impl::Execute()
 {
-    return m_xDlg->run();
+    assert(false);
+    return -1;
+}
+
+bool AbstractSwInsertAbstractDlg_Impl::StartExecuteAsync(AsyncContext &rCtx)
+{
+    return weld::GenericDialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
 }
 
 short SwAbstractSfxController_Impl::Execute()
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index b0283b603172..100833f79f67 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -104,13 +104,14 @@ public:
 
 class AbstractSwInsertAbstractDlg_Impl : public AbstractSwInsertAbstractDlg
 {
-    std::unique_ptr<SwInsertAbstractDlg> m_xDlg;
+    std::shared_ptr<SwInsertAbstractDlg> m_xDlg;
 public:
-    explicit 
AbstractSwInsertAbstractDlg_Impl(std::unique_ptr<SwInsertAbstractDlg> p)
+    explicit 
AbstractSwInsertAbstractDlg_Impl(std::shared_ptr<SwInsertAbstractDlg> p)
         : m_xDlg(std::move(p))
     {
     }
     virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &rCtx) override;
     virtual sal_uInt8   GetLevel() const override ;
     virtual sal_uInt8   GetPara() const override ;
 };
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index 7079c40a3b99..87344ccedd43 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -750,62 +750,67 @@ void SwDocShell::Execute(SfxRequest& rReq)
         case FN_ABSTRACT_NEWDOC:
         {
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
-            ScopedVclPtr<AbstractSwInsertAbstractDlg> 
pDlg(pFact->CreateSwInsertAbstractDlg(GetView()->GetFrameWeld()));
-            if(RET_OK == pDlg->Execute())
-            {
-                sal_uInt8 nLevel = pDlg->GetLevel();
-                sal_uInt8 nPara = pDlg->GetPara();
-                SwDoc* pSmryDoc = new SwDoc();
-                SfxObjectShellLock xDocSh(new SwDocShell(*pSmryDoc, 
SfxObjectCreateMode::STANDARD));
-                xDocSh->DoInitNew();
-
-                bool bImpress = FN_ABSTRACT_STARIMPRESS == nWhich;
-                m_xDoc->Summary(*pSmryDoc, nLevel, nPara, bImpress);
-                if( bImpress )
+            VclPtr<AbstractSwInsertAbstractDlg> 
pDlg(pFact->CreateSwInsertAbstractDlg(GetView()->GetFrameWeld()));
+            pDlg->StartExecuteAsync(
+                [this, pDlg, nWhich] (sal_Int32 nResult)->void
                 {
-                    WriterRef xWrt;
-                    // mba: looks as if relative URLs don't make sense here
-                    ::GetRTFWriter(std::u16string_view(), OUString(), xWrt);
-                    SvMemoryStream *pStrm = new SvMemoryStream();
-                    pStrm->SetBufferSize( 16348 );
-                    SwWriter aWrt( *pStrm, *pSmryDoc );
-                    ErrCodeMsg eErr = aWrt.Write( xWrt );
-                    if( !eErr.IgnoreWarning() )
+                    if (nResult == RET_OK)
                     {
-                        uno::Reference< uno::XComponentContext > xContext = 
::comphelper::getProcessComponentContext();
-                        uno::Reference< frame::XDispatchProvider > xProv = 
drawing::ModuleDispatcher::create( xContext );
+                        sal_uInt8 nLevel = pDlg->GetLevel();
+                        sal_uInt8 nPara = pDlg->GetPara();
+                        SwDoc* pSmryDoc = new SwDoc();
+                        SfxObjectShellLock xDocSh(new SwDocShell(*pSmryDoc, 
SfxObjectCreateMode::STANDARD));
+                        xDocSh->DoInitNew();
+
+                        bool bImpress = FN_ABSTRACT_STARIMPRESS == nWhich;
+                        m_xDoc->Summary(*pSmryDoc, nLevel, nPara, bImpress);
+                        if( bImpress )
+                        {
+                            WriterRef xWrt;
+                            // mba: looks as if relative URLs don't make sense 
here
+                            ::GetRTFWriter(std::u16string_view(), OUString(), 
xWrt);
+                            SvMemoryStream *pStrm = new SvMemoryStream();
+                            pStrm->SetBufferSize( 16348 );
+                            SwWriter aWrt( *pStrm, *pSmryDoc );
+                            ErrCodeMsg eErr = aWrt.Write( xWrt );
+                            if( !eErr.IgnoreWarning() )
+                            {
+                                uno::Reference< uno::XComponentContext > 
xContext = ::comphelper::getProcessComponentContext();
+                                uno::Reference< frame::XDispatchProvider > 
xProv = drawing::ModuleDispatcher::create( xContext );
 
-                        uno::Reference< frame::XDispatchHelper > xHelper( 
frame::DispatchHelper::create(xContext) );
-                        pStrm->Seek( STREAM_SEEK_TO_END );
-                        pStrm->WriteChar( '
-                        pStrm->Seek( STREAM_SEEK_TO_BEGIN );
+                                uno::Reference< frame::XDispatchHelper > 
xHelper( frame::DispatchHelper::create(xContext) );
+                                pStrm->Seek( STREAM_SEEK_TO_END );
+                                pStrm->WriteChar( '
+                                pStrm->Seek( STREAM_SEEK_TO_BEGIN );
 
-                        uno::Sequence< sal_Int8 > aSeq( pStrm->TellEnd() );
-                        pStrm->ReadBytes( aSeq.getArray(), aSeq.getLength() );
+                                uno::Sequence< sal_Int8 > aSeq( 
pStrm->TellEnd() );
+                                pStrm->ReadBytes( aSeq.getArray(), 
aSeq.getLength() );
 
-                        uno::Sequence< beans::PropertyValue > aArgs{
-                            comphelper::makePropertyValue("RtfOutline", aSeq)
-                        };
-                        xHelper->executeDispatch( xProv, 
"SendOutlineToImpress", OUString(), 0, aArgs );
+                                uno::Sequence< beans::PropertyValue > aArgs{
+                                    
comphelper::makePropertyValue("RtfOutline", aSeq)
+                                };
+                                xHelper->executeDispatch( xProv, 
"SendOutlineToImpress", OUString(), 0, aArgs );
+                            }
+                            else
+                                ErrorHandler::HandleError( eErr );
+                        }
+                        else
+                        {
+                            // Create new document
+                            SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( 
*xDocSh, SFX_INTERFACE_NONE );
+                            SwView      *pCurrView = static_cast<SwView*>( 
pFrame->GetViewShell());
+
+                            // Set document's title
+                            OUString aTmp = SwResId(STR_ABSTRACT_TITLE) + 
GetTitle();
+                            xDocSh->SetTitle( aTmp );
+                            pCurrView->GetWrtShell().SetNewDoc();
+                            pFrame->Show();
+                            pSmryDoc->getIDocumentState().SetModified();
+                        }
                     }
-                    else
-                        ErrorHandler::HandleError( eErr );
-                }
-                else
-                {
-                    // Create new document
-                    SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( 
*xDocSh, SFX_INTERFACE_NONE );
-                    SwView      *pCurrView = static_cast<SwView*>( 
pFrame->GetViewShell());
-
-                    // Set document's title
-                    OUString aTmp = SwResId(STR_ABSTRACT_TITLE) + GetTitle();
-                    xDocSh->SetTitle( aTmp );
-                    pCurrView->GetWrtShell().SetNewDoc();
-                    pFrame->Show();
-                    pSmryDoc->getIDocumentState().SetModified();
+                    pDlg->disposeOnce();
                 }
-
-            }
+            );
         }
         break;
         case FN_OUTLINE_TO_CLIPBOARD:
commit 137df7cd67e5bb34cb75f716700d3c765a3efad2
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 31 13:10:52 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Feb 1 07:00:04 2024 +0100

    make insert-db-col-auto-pilot dialog async
    
    Change-Id: I954c9a4c55c9c641955484626aa744dd9fa74995
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162808
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 50498ab480db..d4d35f0d0dc0 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -222,7 +222,13 @@ short AbstractSwConvertTableDlg_Impl::Execute()
 
 short AbstractSwInsertDBColAutoPilot_Impl::Execute()
 {
-    return m_xDlg->run();
+    assert(false);
+    return -1;
+}
+
+bool AbstractSwInsertDBColAutoPilot_Impl::StartExecuteAsync(AsyncContext &rCtx)
+{
+    return weld::GenericDialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
 }
 
 short AbstractDropDownFieldDialog_Impl::Execute()
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index d1f8f4c2b5bd..b0283b603172 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -356,13 +356,14 @@ public:
 
 class AbstractSwInsertDBColAutoPilot_Impl :  public 
AbstractSwInsertDBColAutoPilot
 {
-    std::unique_ptr<SwInsertDBColAutoPilot> m_xDlg;
+    std::shared_ptr<SwInsertDBColAutoPilot> m_xDlg;
 public:
-    explicit 
AbstractSwInsertDBColAutoPilot_Impl(std::unique_ptr<SwInsertDBColAutoPilot> p)
+    explicit 
AbstractSwInsertDBColAutoPilot_Impl(std::shared_ptr<SwInsertDBColAutoPilot> p)
         : m_xDlg(std::move(p))
     {
     }
     virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &rCtx) override;
     virtual void DataToDoc( const css::uno::Sequence< css::uno::Any >& 
rSelection,
         css::uno::Reference< css::sdbc::XDataSource> rxSource,
         css::uno::Reference< css::sdbc::XConnection> xConnection,
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index bb4cdc12cdbe..7c97db631403 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -3070,24 +3070,32 @@ void SwDBManager::InsertText(SwWrtShell& rSh,
     aDBData.nCommandType = nCmdType;
 
     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
-    ScopedVclPtr<AbstractSwInsertDBColAutoPilot> 
pDlg(pFact->CreateSwInsertDBColAutoPilot( rSh.GetView(),
+    VclPtr<AbstractSwInsertDBColAutoPilot> 
pDlg(pFact->CreateSwInsertDBColAutoPilot( rSh.GetView(),
                                                                                
 xSource,
                                                                                
 xColSupp,
                                                                                
 aDBData ));
-    if( RET_OK != pDlg->Execute() )
-        return;
+    pDlg->StartExecuteAsync(
+        [xConnection, xSource, pDlg, xResSet, aSelection] (sal_Int32 
nResult)->void
+        {
+            if (nResult == RET_OK)
+            {
+                OUString sDummy;
+                auto xTmpConnection = xConnection;
+                if(!xTmpConnection.is())
+                    xTmpConnection = xSource->getConnection(sDummy, sDummy);
+                try
+                {
+                    pDlg->DataToDoc( aSelection , xSource, xTmpConnection, 
xResSet);
+                }
+                catch (const uno::Exception&)
+                {
+                    TOOLS_WARN_EXCEPTION("sw.mailmerge", "");
+                }
+                pDlg->disposeOnce();
+            }
+        }
+    );
 
-    OUString sDummy;
-    if(!xConnection.is())
-        xConnection = xSource->getConnection(sDummy, sDummy);
-    try
-    {
-        pDlg->DataToDoc( aSelection , xSource, xConnection, xResSet);
-    }
-    catch (const uno::Exception&)
-    {
-        TOOLS_WARN_EXCEPTION("sw.mailmerge", "");
-    }
 }
 
 uno::Reference<sdbc::XDataSource> SwDBManager::getDataSourceAsParent(const 
uno::Reference< sdbc::XConnection>& _xConnection,const OUString& 
_sDataSourceName)
diff --git a/sw/source/uibase/shells/textsh2.cxx 
b/sw/source/uibase/shells/textsh2.cxx
index 8a62f401fe46..566c8d357a4a 100644
--- a/sw/source/uibase/shells/textsh2.cxx
+++ b/sw/source/uibase/shells/textsh2.cxx
@@ -205,48 +205,53 @@ void SwTextShell::ExecDB(SfxRequest const &rReq)
 
 IMPL_LINK( SwBaseShell, InsertDBTextHdl, void*, p, void )
 {
-    DBTextStruct_Impl* pDBStruct = static_cast<DBTextStruct_Impl*>(p);
-    if( pDBStruct )
-    {
-        bool bDispose = false;
-        Reference< sdbc::XConnection> xConnection = pDBStruct->xConnection;
-        Reference<XDataSource> xSource = 
SwDBManager::getDataSourceAsParent(xConnection,pDBStruct->aDBData.sDataSource);
-        // #111987# the connection is disposed and so no parent has been found
-        if(xConnection.is() && !xSource.is())
-            return;
+    std::shared_ptr<DBTextStruct_Impl> 
pDBStruct(static_cast<DBTextStruct_Impl*>(p));
+    if( !pDBStruct )
+        return;
 
-        if ( !xConnection.is()  )
-        {
-            SwView &rSwView = GetView();
-            xConnection = 
SwDBManager::GetConnection(pDBStruct->aDBData.sDataSource, xSource, &rSwView);
-            bDispose = true;
-        }
+    bool bDispose = false;
+    Reference< sdbc::XConnection> xConnection = pDBStruct->xConnection;
+    Reference<XDataSource> xSource = 
SwDBManager::getDataSourceAsParent(xConnection,pDBStruct->aDBData.sDataSource);
+    // #111987# the connection is disposed and so no parent has been found
+    if(xConnection.is() && !xSource.is())
+        return;
 
-        Reference< XColumnsSupplier> xColSupp;
-        if(xConnection.is())
-            xColSupp = SwDBManager::GetColumnSupplier(xConnection,
-                                    pDBStruct->aDBData.sCommand,
-                                    pDBStruct->aDBData.nCommandType == 
CommandType::QUERY ?
-                                        SwDBSelect::QUERY : SwDBSelect::TABLE);
+    if ( !xConnection.is()  )
+    {
+        SwView &rSwView = GetView();
+        xConnection = 
SwDBManager::GetConnection(pDBStruct->aDBData.sDataSource, xSource, &rSwView);
+        bDispose = true;
+    }
 
-        if( xColSupp.is() )
-        {
-            SwDBData aDBData = pDBStruct->aDBData;
-            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
-            ScopedVclPtr<AbstractSwInsertDBColAutoPilot>pDlg 
(pFact->CreateSwInsertDBColAutoPilot(GetView(),
-                                                                               
                 xSource,
-                                                                               
                 xColSupp,
-                                                                               
                 aDBData));
-            if( RET_OK == pDlg->Execute() )
-            {
-                pDlg->DataToDoc(pDBStruct->aSelection, xSource, xConnection, 
pDBStruct->xCursor);
-            }
-        }
+    Reference< XColumnsSupplier> xColSupp;
+    if(xConnection.is())
+        xColSupp = SwDBManager::GetColumnSupplier(xConnection,
+                                pDBStruct->aDBData.sCommand,
+                                pDBStruct->aDBData.nCommandType == 
CommandType::QUERY ?
+                                    SwDBSelect::QUERY : SwDBSelect::TABLE);
+
+    if( !xColSupp )
+    {
         if ( bDispose )
             ::comphelper::disposeComponent(xConnection);
+        return;
     }
 
-    delete pDBStruct;
+    SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
+    VclPtr<AbstractSwInsertDBColAutoPilot>pDlg 
(pFact->CreateSwInsertDBColAutoPilot(GetView(),
+                                                                               
         xSource,
+                                                                               
         xColSupp,
+                                                                               
         pDBStruct->aDBData));
+    pDlg->StartExecuteAsync(
+        [pDlg, pDBStruct2=std::move(pDBStruct), xSource, xConnection, 
bDispose] (sal_Int32 nResult) mutable
+        {
+            if (nResult == RET_OK)
+                pDlg->DataToDoc(pDBStruct2->aSelection, xSource, xConnection, 
pDBStruct2->xCursor);
+            pDlg->disposeOnce();
+            if ( bDispose )
+                ::comphelper::disposeComponent(xConnection);
+        }
+    );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to