diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-01-31 13:10:52 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-02-01 07:00:04 +0100 |
commit | 137df7cd67e5bb34cb75f716700d3c765a3efad2 (patch) | |
tree | 503ed29dbe1f1caef4af145c99693c416c5f60ba /sw/source | |
parent | 1276daee3d0d4f30ee8844b6df55d72e0b54093f (diff) |
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.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.cxx | 8 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.hxx | 5 | ||||
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 36 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh2.cxx | 75 |
4 files changed, 72 insertions, 52 deletions
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: */ |