From 119b1324a648edc839833fdee9b9b2d330a9e388 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Tue, 22 Dec 2015 06:32:45 +0100 Subject: mailmerge: Decrease indentation level by an early return. Change-Id: I90dad46d9bced5e0faee4ab3adabc46d7e1bbc9f --- sw/source/uibase/app/apphdl.cxx | 157 ++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx index 68a46a76e65f..a811a4ea5a6d 100644 --- a/sw/source/uibase/app/apphdl.cxx +++ b/sw/source/uibase/app/apphdl.cxx @@ -349,96 +349,95 @@ void SwMailMergeWizardExecutor::ExecuteMailMergeWizard( const SfxItemSet * pArgs return; } - m_pView = ::GetActiveView(); // not owner! - OSL_ENSURE(m_pView, "no current view?"); - if(m_pView) + m_pView = ::GetActiveView(); + if (!m_pView) + return; + + // keep self alive until done. + acquire(); + + // if called from the child window - get the config item and close the ChildWindow, then restore + // the wizard + SwMailMergeChildWindow* pChildWin = + static_cast(m_pView->GetViewFrame()->GetChildWindow(FN_MAILMERGE_CHILDWINDOW)); + bool bRestoreWizard = false; + sal_uInt16 nRestartPage = 0; + if (pChildWin && pChildWin->IsVisible()) { - // keep self alive until done. - acquire(); - - // if called from the child window - get the config item and close the ChildWindow, then restore - // the wizard - SwMailMergeChildWindow* pChildWin = - static_cast(m_pView->GetViewFrame()->GetChildWindow(FN_MAILMERGE_CHILDWINDOW)); - bool bRestoreWizard = false; - sal_uInt16 nRestartPage = 0; - if(pChildWin && pChildWin->IsVisible()) - { - m_pMMConfig = m_pView->GetMailMergeConfigItem(); - nRestartPage = m_pView->GetMailMergeRestartPage(); - if(m_pView->IsMailMergeSourceView()) - m_pMMConfig->SetSourceView( m_pView ); - m_pView->SetMailMergeConfigItem(nullptr, 0, true); - SfxViewFrame* pViewFrame = m_pView->GetViewFrame(); - pViewFrame->ShowChildWindow(FN_MAILMERGE_CHILDWINDOW, false); - OSL_ENSURE(m_pMMConfig, "no MailMergeConfigItem available"); - bRestoreWizard = true; - } - // to make it bullet proof ;-) - if(!m_pMMConfig) - { - m_pMMConfig = new SwMailMergeConfigItem; + m_pMMConfig = m_pView->GetMailMergeConfigItem(); + nRestartPage = m_pView->GetMailMergeRestartPage(); + if (m_pView->IsMailMergeSourceView()) m_pMMConfig->SetSourceView(m_pView); + m_pView->SetMailMergeConfigItem(nullptr, 0, true); + SfxViewFrame* pViewFrame = m_pView->GetViewFrame(); + pViewFrame->ShowChildWindow(FN_MAILMERGE_CHILDWINDOW, false); + OSL_ENSURE(m_pMMConfig, "no MailMergeConfigItem available"); + bRestoreWizard = true; + } + // to make it bullet proof ;-) + if (!m_pMMConfig) + { + m_pMMConfig = new SwMailMergeConfigItem; + m_pMMConfig->SetSourceView(m_pView); - //set the first used database as default source on the config item - const SfxPoolItem* pItem = nullptr; - if(pArgs && SfxItemState::SET == pArgs->GetItemState( - FN_PARAM_DATABASE_PROPERTIES, false, &pItem)) + //set the first used database as default source on the config item + const SfxPoolItem* pItem = nullptr; + if (pArgs && SfxItemState::SET == pArgs->GetItemState( + FN_PARAM_DATABASE_PROPERTIES, false, &pItem)) + { + //mailmerge has been called from the database beamer + uno::Sequence< beans::PropertyValue> aDBValues; + if (static_cast(pItem)->GetValue() >>= aDBValues) { - //mailmerge has been called from the database beamer - uno::Sequence< beans::PropertyValue> aDBValues; - if(static_cast(pItem)->GetValue() >>= aDBValues) - { - SwDBData aDBData; - svx::ODataAccessDescriptor aDescriptor(aDBValues); - aDescriptor[svx::daDataSource] >>= aDBData.sDataSource; - aDescriptor[svx::daCommand] >>= aDBData.sCommand; - aDescriptor[svx::daCommandType] >>= aDBData.nCommandType; - - uno::Sequence< uno::Any > aSelection; - uno::Reference< sdbc::XConnection> xConnection; - uno::Reference< sdbc::XDataSource> xSource; - uno::Reference< sdbcx::XColumnsSupplier> xColumnsSupplier; - if ( aDescriptor.has(svx::daSelection) ) - aDescriptor[svx::daSelection] >>= aSelection; - if ( aDescriptor.has(svx::daConnection) ) - aDescriptor[svx::daConnection] >>= xConnection; - uno::Reference xChild(xConnection, uno::UNO_QUERY); - if(xChild.is()) - xSource.set(xChild->getParent(), uno::UNO_QUERY); - m_pMMConfig->SetCurrentConnection( - xSource, SharedConnection( xConnection, SharedConnection::NoTakeOwnership ), - xColumnsSupplier, aDBData); - } + SwDBData aDBData; + svx::ODataAccessDescriptor aDescriptor(aDBValues); + aDescriptor[svx::daDataSource] >>= aDBData.sDataSource; + aDescriptor[svx::daCommand] >>= aDBData.sCommand; + aDescriptor[svx::daCommandType] >>= aDBData.nCommandType; + + uno::Sequence< uno::Any > aSelection; + uno::Reference< sdbc::XConnection> xConnection; + uno::Reference< sdbc::XDataSource> xSource; + uno::Reference< sdbcx::XColumnsSupplier> xColumnsSupplier; + if (aDescriptor.has(svx::daSelection)) + aDescriptor[svx::daSelection] >>= aSelection; + if (aDescriptor.has(svx::daConnection)) + aDescriptor[svx::daConnection] >>= xConnection; + uno::Reference xChild(xConnection, uno::UNO_QUERY); + if (xChild.is()) + xSource.set(xChild->getParent(), uno::UNO_QUERY); + m_pMMConfig->SetCurrentConnection( + xSource, SharedConnection(xConnection, SharedConnection::NoTakeOwnership), + xColumnsSupplier, aDBData); } - else + } + else + { + std::vector aDBNameList; + std::vector aAllDBNames; + m_pView->GetWrtShell().GetAllUsedDB(aDBNameList, &aAllDBNames); + if (!aDBNameList.empty()) { - std::vector aDBNameList; - std::vector aAllDBNames; - m_pView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames ); - if(!aDBNameList.empty()) - { - OUString sDBName(aDBNameList[0]); - SwDBData aDBData; - aDBData.sDataSource = sDBName.getToken(0, DB_DELIM); - aDBData.sCommand = sDBName.getToken(1, DB_DELIM); - aDBData.nCommandType = sDBName.getToken(2, DB_DELIM ).toInt32(); - //set the currently used database for the wizard - m_pMMConfig->SetCurrentDBData( aDBData ); - } + OUString sDBName(aDBNameList[0]); + SwDBData aDBData; + aDBData.sDataSource = sDBName.getToken(0, DB_DELIM); + aDBData.sCommand = sDBName.getToken(1, DB_DELIM); + aDBData.nCommandType = sDBName.getToken(2, DB_DELIM).toInt32(); + //set the currently used database for the wizard + m_pMMConfig->SetCurrentDBData(aDBData); } } + } - SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - m_pWizard = pFact->CreateMailMergeWizard(*m_pView, *m_pMMConfig); - - if(bRestoreWizard) - { - m_pWizard->ShowPage( nRestartPage ); - } + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + m_pWizard = pFact->CreateMailMergeWizard(*m_pView, *m_pMMConfig); - ExecuteWizard(); + if (bRestoreWizard) + { + m_pWizard->ShowPage(nRestartPage); } + + ExecuteWizard(); } void SwMailMergeWizardExecutor::ExecutionFinished( bool bDeleteConfigItem ) -- cgit