From 137df7cd67e5bb34cb75f716700d3c765a3efad2 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 31 Jan 2024 13:10:52 +0200 Subject: 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 --- sw/source/uibase/shells/textsh2.cxx | 75 ++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'sw/source/uibase/shells/textsh2.cxx') 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(p); - if( pDBStruct ) - { - bool bDispose = false; - Reference< sdbc::XConnection> xConnection = pDBStruct->xConnection; - Reference 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 pDBStruct(static_cast(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 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(); - ScopedVclPtrpDlg (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(); + VclPtrpDlg (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: */ -- cgit