diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-02 10:45:58 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-02 20:05:25 +0200 |
commit | d9946e6d0ba81071f3e50622e5cae9e2ffc9bfb0 (patch) | |
tree | 795444cdd46cc3f0b93f5363e7699f01b1b974e2 /scripting | |
parent | a3695d24087b7958850d73eee7e665c1d78a041b (diff) |
loplugin:flatten in scripting
Change-Id: I8df38b4b581fb674a050ef32624b22498a8e340f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91549
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/source/dlgprov/DialogModelProvider.cxx | 46 | ||||
-rw-r--r-- | scripting/source/dlgprov/dlgevtatt.cxx | 168 | ||||
-rw-r--r-- | scripting/source/dlgprov/dlgprov.cxx | 50 | ||||
-rw-r--r-- | scripting/source/protocolhandler/scripthandler.cxx | 50 | ||||
-rw-r--r-- | scripting/source/provider/ActiveMSPList.cxx | 28 | ||||
-rw-r--r-- | scripting/source/provider/BrowseNodeFactoryImpl.cxx | 24 | ||||
-rw-r--r-- | scripting/source/stringresource/stringresource.cxx | 184 | ||||
-rw-r--r-- | scripting/source/vbaevents/eventhelper.cxx | 130 |
8 files changed, 340 insertions, 340 deletions
diff --git a/scripting/source/dlgprov/DialogModelProvider.cxx b/scripting/source/dlgprov/DialogModelProvider.cxx index bd9525a5bc5b..5f9e4e15a032 100644 --- a/scripting/source/dlgprov/DialogModelProvider.cxx +++ b/scripting/source/dlgprov/DialogModelProvider.cxx @@ -42,33 +42,33 @@ DialogModelProvider::DialogModelProvider(Reference< XComponentContext > const & // lang::XInitialization: void SAL_CALL DialogModelProvider::initialize(const css::uno::Sequence< uno::Any > & aArguments) { - if ( aArguments.getLength() == 1 ) - { - OUString sURL; - if ( !( aArguments[ 0 ] >>= sURL )) - throw css::lang::IllegalArgumentException(); - // Try any other URL with SimpleFileAccess - Reference< ucb::XSimpleFileAccess3 > xSFI = ucb::SimpleFileAccess::create(m_xContext); + if ( aArguments.getLength() != 1 ) + return; + + OUString sURL; + if ( !( aArguments[ 0 ] >>= sURL )) + throw css::lang::IllegalArgumentException(); + // Try any other URL with SimpleFileAccess + Reference< ucb::XSimpleFileAccess3 > xSFI = ucb::SimpleFileAccess::create(m_xContext); - try + try + { + Reference< io::XInputStream > xInput = xSFI->openFileRead( sURL ); + Reference< resource::XStringResourceManager > xStringResourceManager; + if ( xInput.is() ) { - Reference< io::XInputStream > xInput = xSFI->openFileRead( sURL ); - Reference< resource::XStringResourceManager > xStringResourceManager; - if ( xInput.is() ) - { - xStringResourceManager = dlgprov::lcl_getStringResourceManager(m_xContext,sURL); - Any aDialogSourceURLAny; - aDialogSourceURLAny <<= sURL; - - Reference< frame::XModel > xModel; - m_xDialogModel.set( dlgprov::lcl_createDialogModel( m_xContext, xInput , xModel, xStringResourceManager, aDialogSourceURLAny ), UNO_SET_THROW); - m_xDialogModelProp.set(m_xDialogModel, UNO_QUERY_THROW); - } + xStringResourceManager = dlgprov::lcl_getStringResourceManager(m_xContext,sURL); + Any aDialogSourceURLAny; + aDialogSourceURLAny <<= sURL; + + Reference< frame::XModel > xModel; + m_xDialogModel.set( dlgprov::lcl_createDialogModel( m_xContext, xInput , xModel, xStringResourceManager, aDialogSourceURLAny ), UNO_SET_THROW); + m_xDialogModelProp.set(m_xDialogModel, UNO_QUERY_THROW); } - catch( Exception& ) - {} - //m_sURL = sURL; } + catch( Exception& ) + {} + //m_sURL = sURL; } // container::XElementAccess: diff --git a/scripting/source/dlgprov/dlgevtatt.cxx b/scripting/source/dlgprov/dlgevtatt.cxx index 1269395b01f5..b1a3fceee7ec 100644 --- a/scripting/source/dlgprov/dlgevtatt.cxx +++ b/scripting/source/dlgprov/dlgevtatt.cxx @@ -118,37 +118,37 @@ namespace dlgprov args[0] <<= xModel; mxListener.set( xSMgr->createInstanceWithArgumentsAndContext( "ooo.vba.EventListener", args, m_xContext ), UNO_QUERY ); } - if ( rxControl.is() ) + if ( !rxControl.is() ) + return; + + try { - try - { - Reference< XPropertySet > xProps( rxControl->getModel(), UNO_QUERY_THROW ); - xProps->getPropertyValue("Name") >>= msDialogCodeName; - xProps.set( mxListener, UNO_QUERY_THROW ); - xProps->setPropertyValue("Model", args[ 0 ] ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("scripting"); - } + Reference< XPropertySet > xProps( rxControl->getModel(), UNO_QUERY_THROW ); + xProps->getPropertyValue("Name") >>= msDialogCodeName; + xProps.set( mxListener, UNO_QUERY_THROW ); + xProps->setPropertyValue("Model", args[ 0 ] ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("scripting"); } } void DialogVBAScriptListenerImpl::firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* ) { - if ( aScriptEvent.ScriptType == "VBAInterop" && mxListener.is() ) + if ( !(aScriptEvent.ScriptType == "VBAInterop" && mxListener.is()) ) + return; + + ScriptEvent aScriptEventCopy( aScriptEvent ); + aScriptEventCopy.ScriptCode = msDialogLibName.concat( "." ).concat( msDialogCodeName ); + try { - ScriptEvent aScriptEventCopy( aScriptEvent ); - aScriptEventCopy.ScriptCode = msDialogLibName.concat( "." ).concat( msDialogCodeName ); - try - { - mxListener->firing( aScriptEventCopy ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("scripting"); - } + mxListener->firing( aScriptEventCopy ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("scripting"); } } @@ -215,62 +215,62 @@ namespace dlgprov void DialogEventsAttacherImpl::attachEventsToControl( const Reference< XControl>& xControl, const Reference< XScriptEventsSupplier >& xEventsSupplier, const Any& Helper ) { - if ( xEventsSupplier.is() ) - { - Reference< container::XNameContainer > xEventCont = xEventsSupplier->getEvents(); + if ( !xEventsSupplier.is() ) + return; - Reference< XControlModel > xControlModel = xControl->getModel(); - if ( xEventCont.is() ) - { - const Sequence< OUString > aNames = xEventCont->getElementNames(); + Reference< container::XNameContainer > xEventCont = xEventsSupplier->getEvents(); - for ( const OUString& rName : aNames ) - { - ScriptEventDescriptor aDesc; + Reference< XControlModel > xControlModel = xControl->getModel(); + if ( !xEventCont.is() ) + return; - Any aElement = xEventCont->getByName( rName ); - aElement >>= aDesc; - OUString sKey = aDesc.ScriptType; - if ( aDesc.ScriptType == "Script" || aDesc.ScriptType == "UNO" ) - { - sal_Int32 nIndex = aDesc.ScriptCode.indexOf( ':' ); - sKey = aDesc.ScriptCode.copy( 0, nIndex ); - } - Reference< XAllListener > xAllListener = - new DialogAllListenerImpl( getScriptListenerForKey( sKey ), aDesc.ScriptType, aDesc.ScriptCode ); + const Sequence< OUString > aNames = xEventCont->getElementNames(); - // try first to attach event to the ControlModel - bool bSuccess = false; - try - { - Reference< XEventListener > xListener_ = m_xEventAttacher->attachSingleEventListener( - xControlModel, xAllListener, Helper, aDesc.ListenerType, - aDesc.AddListenerParam, aDesc.EventMethod ); + for ( const OUString& rName : aNames ) + { + ScriptEventDescriptor aDesc; - if ( xListener_.is() ) - bSuccess = true; - } - catch ( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("scripting"); - } + Any aElement = xEventCont->getByName( rName ); + aElement >>= aDesc; + OUString sKey = aDesc.ScriptType; + if ( aDesc.ScriptType == "Script" || aDesc.ScriptType == "UNO" ) + { + sal_Int32 nIndex = aDesc.ScriptCode.indexOf( ':' ); + sKey = aDesc.ScriptCode.copy( 0, nIndex ); + } + Reference< XAllListener > xAllListener = + new DialogAllListenerImpl( getScriptListenerForKey( sKey ), aDesc.ScriptType, aDesc.ScriptCode ); - try - { - // if we had no success, try to attach to the control - if ( !bSuccess ) - { - m_xEventAttacher->attachSingleEventListener( - xControl, xAllListener, Helper, aDesc.ListenerType, - aDesc.AddListenerParam, aDesc.EventMethod ); - } - } - catch ( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("scripting"); - } + // try first to attach event to the ControlModel + bool bSuccess = false; + try + { + Reference< XEventListener > xListener_ = m_xEventAttacher->attachSingleEventListener( + xControlModel, xAllListener, Helper, aDesc.ListenerType, + aDesc.AddListenerParam, aDesc.EventMethod ); + + if ( xListener_.is() ) + bSuccess = true; + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("scripting"); + } + + try + { + // if we had no success, try to attach to the control + if ( !bSuccess ) + { + m_xEventAttacher->attachSingleEventListener( + xControl, xAllListener, Helper, aDesc.ListenerType, + aDesc.AddListenerParam, aDesc.EventMethod ); } } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("scripting"); + } } } @@ -507,21 +507,21 @@ namespace dlgprov OUString sScriptURL; OUString sScriptCode( aScriptEvent.ScriptCode ); - if ( aScriptEvent.ScriptType == "StarBasic" ) + if ( aScriptEvent.ScriptType != "StarBasic" ) + return; + + // StarBasic script: convert ScriptCode to scriptURL + sal_Int32 nIndex = sScriptCode.indexOf( ':' ); + if ( nIndex >= 0 && nIndex < sScriptCode.getLength() ) { - // StarBasic script: convert ScriptCode to scriptURL - sal_Int32 nIndex = sScriptCode.indexOf( ':' ); - if ( nIndex >= 0 && nIndex < sScriptCode.getLength() ) - { - sScriptURL = "vnd.sun.star.script:" + - sScriptCode.copy( nIndex + 1 ) + - "?language=Basic&location=" + - sScriptCode.copy( 0, nIndex ); - } - ScriptEvent aSFScriptEvent( aScriptEvent ); - aSFScriptEvent.ScriptCode = sScriptURL; - DialogSFScriptListenerImpl::firing_impl( aSFScriptEvent, pRet ); + sScriptURL = "vnd.sun.star.script:" + + sScriptCode.copy( nIndex + 1 ) + + "?language=Basic&location=" + + sScriptCode.copy( 0, nIndex ); } + ScriptEvent aSFScriptEvent( aScriptEvent ); + aSFScriptEvent.ScriptCode = sScriptURL; + DialogSFScriptListenerImpl::firing_impl( aSFScriptEvent, pRet ); } void DialogUnoScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet ) diff --git a/scripting/source/dlgprov/dlgprov.cxx b/scripting/source/dlgprov/dlgprov.cxx index 8b9a289b95e6..1ed0b899d609 100644 --- a/scripting/source/dlgprov/dlgprov.cxx +++ b/scripting/source/dlgprov/dlgprov.cxx @@ -473,36 +473,36 @@ namespace dlgprov const Reference< XIntrospectionAccess >& rxIntrospectionAccess, bool bDialogProviderMode ) { - if ( rxControl.is() ) - { - Reference< XControlContainer > xControlContainer( rxControl, UNO_QUERY ); - - if ( xControlContainer.is() ) - { - Sequence< Reference< XControl > > aControls = xControlContainer->getControls(); - const Reference< XControl >* pControls = aControls.getConstArray(); - sal_Int32 nControlCount = aControls.getLength(); + if ( !rxControl.is() ) + return; - Sequence< Reference< XInterface > > aObjects( nControlCount + 1 ); - Reference< XInterface >* pObjects = aObjects.getArray(); - for ( sal_Int32 i = 0; i < nControlCount; ++i ) - { - pObjects[i].set( pControls[i], UNO_QUERY ); - } + Reference< XControlContainer > xControlContainer( rxControl, UNO_QUERY ); - // also add the dialog control itself to the sequence - pObjects[nControlCount].set( rxControl, UNO_QUERY ); + if ( !xControlContainer.is() ) + return; - Reference<XScriptEventsAttacher> xScriptEventsAttacher - = new DialogEventsAttacherImpl( - m_xContext, m_xModel, rxControl, rxHandler, rxIntrospectionAccess, - bDialogProviderMode, - (m_BasicInfo ? m_BasicInfo->mxBasicRTLListener : nullptr), msDialogLibName); + Sequence< Reference< XControl > > aControls = xControlContainer->getControls(); + const Reference< XControl >* pControls = aControls.getConstArray(); + sal_Int32 nControlCount = aControls.getLength(); - Any aHelper; - xScriptEventsAttacher->attachEvents( aObjects, Reference< XScriptListener >(), aHelper ); - } + Sequence< Reference< XInterface > > aObjects( nControlCount + 1 ); + Reference< XInterface >* pObjects = aObjects.getArray(); + for ( sal_Int32 i = 0; i < nControlCount; ++i ) + { + pObjects[i].set( pControls[i], UNO_QUERY ); } + + // also add the dialog control itself to the sequence + pObjects[nControlCount].set( rxControl, UNO_QUERY ); + + Reference<XScriptEventsAttacher> xScriptEventsAttacher + = new DialogEventsAttacherImpl( + m_xContext, m_xModel, rxControl, rxHandler, rxIntrospectionAccess, + bDialogProviderMode, + (m_BasicInfo ? m_BasicInfo->mxBasicRTLListener : nullptr), msDialogLibName); + + Any aHelper; + xScriptEventsAttacher->attachEvents( aObjects, Reference< XScriptListener >(), aHelper ); } Reference< XIntrospectionAccess > DialogProviderImpl::inspectHandler( const Reference< XInterface >& rxHandler ) diff --git a/scripting/source/protocolhandler/scripthandler.cxx b/scripting/source/protocolhandler/scripthandler.cxx index 3b3fe4e307ef..ea29661a489a 100644 --- a/scripting/source/protocolhandler/scripthandler.cxx +++ b/scripting/source/protocolhandler/scripthandler.cxx @@ -267,33 +267,33 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( pDlg->Execute(); } - if ( xListener.is() ) - { - // always call dispatchFinished(), because we didn't load a document but - // executed a macro instead! - css::frame::DispatchResultEvent aEvent; + if ( !xListener.is() ) + return; - aEvent.Source = static_cast< ::cppu::OWeakObject* >( this ); - aEvent.Result = invokeResult; - if ( bSuccess ) - { - aEvent.State = css::frame::DispatchResultState::SUCCESS; - } - else - { - aEvent.State = css::frame::DispatchResultState::FAILURE; - } + // always call dispatchFinished(), because we didn't load a document but + // executed a macro instead! + css::frame::DispatchResultEvent aEvent; - try - { - xListener->dispatchFinished( aEvent ) ; - } - catch(const RuntimeException &) - { - TOOLS_WARN_EXCEPTION("scripting", - "ScriptProtocolHandler::dispatchWithNotification: caught RuntimeException" - "while dispatchFinished" ); - } + aEvent.Source = static_cast< ::cppu::OWeakObject* >( this ); + aEvent.Result = invokeResult; + if ( bSuccess ) + { + aEvent.State = css::frame::DispatchResultState::SUCCESS; + } + else + { + aEvent.State = css::frame::DispatchResultState::FAILURE; + } + + try + { + xListener->dispatchFinished( aEvent ) ; + } + catch(const RuntimeException &) + { + TOOLS_WARN_EXCEPTION("scripting", + "ScriptProtocolHandler::dispatchWithNotification: caught RuntimeException" + "while dispatchFinished" ); } } diff --git a/scripting/source/provider/ActiveMSPList.cxx b/scripting/source/provider/ActiveMSPList.cxx index 3cf34551d52c..8233a69be6b8 100644 --- a/scripting/source/provider/ActiveMSPList.cxx +++ b/scripting/source/provider/ActiveMSPList.cxx @@ -234,21 +234,21 @@ ActiveMSPList::addActiveMSP( const Reference< uno::XInterface >& xComponent, ::osl::MutexGuard guard( m_mutex ); Reference< XInterface > xNormalized( xComponent, UNO_QUERY ); ScriptComponent_map::const_iterator pos = m_mScriptComponents.find( xNormalized ); - if ( pos == m_mScriptComponents.end() ) - { - m_mScriptComponents[ xNormalized ] = msp; + if ( pos != m_mScriptComponents.end() ) + return; - // add self as listener for component disposal - // should probably throw from this method!!, reexamine - try - { - Reference< lang::XComponent > xBroadcaster( xComponent, UNO_QUERY_THROW ); - xBroadcaster->addEventListener( this ); - } - catch ( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("scripting"); - } + m_mScriptComponents[ xNormalized ] = msp; + + // add self as listener for component disposal + // should probably throw from this method!!, reexamine + try + { + Reference< lang::XComponent > xBroadcaster( xComponent, UNO_QUERY_THROW ); + xBroadcaster->addEventListener( this ); + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("scripting"); } } diff --git a/scripting/source/provider/BrowseNodeFactoryImpl.cxx b/scripting/source/provider/BrowseNodeFactoryImpl.cxx index a4d91f776d40..8f41a34e11d5 100644 --- a/scripting/source/provider/BrowseNodeFactoryImpl.cxx +++ b/scripting/source/provider/BrowseNodeFactoryImpl.cxx @@ -368,21 +368,21 @@ public: OSL_ENSURE( m_xAggProxy.is(), "DefaultBrowseNode::DefaultBrowseNode: Wrapped BrowseNode cannot be aggregated!" ); - if ( m_xAggProxy.is() ) - { - osl_atomic_increment( &m_refCount ); + if ( !m_xAggProxy.is() ) + return; - /* i35609 - Fix crash on Solaris. The setDelegator call needs - to be in its own block to ensure that all temporary Reference - instances that are acquired during the call are released - before m_refCount is decremented again */ - { - m_xAggProxy->setDelegator( - static_cast< cppu::OWeakObject * >( this ) ); - } + osl_atomic_increment( &m_refCount ); - osl_atomic_decrement( &m_refCount ); + /* i35609 - Fix crash on Solaris. The setDelegator call needs + to be in its own block to ensure that all temporary Reference + instances that are acquired during the call are released + before m_refCount is decremented again */ + { + m_xAggProxy->setDelegator( + static_cast< cppu::OWeakObject * >( this ) ); } + + osl_atomic_decrement( &m_refCount ); } virtual ~DefaultBrowseNode() override diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx index d059a087b274..4e721517c8b0 100644 --- a/scripting/source/stringresource/stringresource.cxx +++ b/scripting/source/stringresource/stringresource.cxx @@ -349,22 +349,22 @@ void StringResourceImpl::setDefaultLocale( const Locale& locale ) void StringResourceImpl::implSetString( const OUString& ResourceID, const OUString& Str, LocaleItem* pLocaleItem ) { - if( pLocaleItem != nullptr && loadLocale( pLocaleItem ) ) - { - IdToStringMap& rHashMap = pLocaleItem->m_aIdToStringMap; + if( !(pLocaleItem != nullptr && loadLocale( pLocaleItem )) ) + return; - IdToStringMap::iterator it = rHashMap.find( ResourceID ); - bool bNew = ( it == rHashMap.end() ); - if( bNew ) - { - IdToIndexMap& rIndexMap = pLocaleItem->m_aIdToIndexMap; - rIndexMap[ ResourceID ] = pLocaleItem->m_nNextIndex++; - implScanIdForNumber( ResourceID ); - } - rHashMap[ ResourceID ] = Str; - pLocaleItem->m_bModified = true; - implModified(); + IdToStringMap& rHashMap = pLocaleItem->m_aIdToStringMap; + + IdToStringMap::iterator it = rHashMap.find( ResourceID ); + bool bNew = ( it == rHashMap.end() ); + if( bNew ) + { + IdToIndexMap& rIndexMap = pLocaleItem->m_aIdToIndexMap; + rIndexMap[ ResourceID ] = pLocaleItem->m_nNextIndex++; + implScanIdForNumber( ResourceID ); } + rHashMap[ ResourceID ] = Str; + pLocaleItem->m_bModified = true; + implModified(); } void StringResourceImpl::setString( const OUString& ResourceID, const OUString& Str ) @@ -479,59 +479,59 @@ void StringResourceImpl::removeLocale( const Locale& locale ) implCheckReadOnly( "StringResourceImpl::removeLocale(): Read only" ); LocaleItem* pRemoveItem = getItemForLocale( locale, true ); - if( pRemoveItem ) + if( !pRemoveItem ) + return; + + // Last locale? + sal_Int32 nLocaleCount = m_aLocaleItemVector.size(); + if( nLocaleCount > 1 ) { - // Last locale? - sal_Int32 nLocaleCount = m_aLocaleItemVector.size(); - if( nLocaleCount > 1 ) + if( m_pCurrentLocaleItem == pRemoveItem || + m_pDefaultLocaleItem == pRemoveItem ) { - if( m_pCurrentLocaleItem == pRemoveItem || - m_pDefaultLocaleItem == pRemoveItem ) + LocaleItem* pFallbackItem = nullptr; + for( const auto& pLocaleItem : m_aLocaleItemVector ) { - LocaleItem* pFallbackItem = nullptr; - for( const auto& pLocaleItem : m_aLocaleItemVector ) - { - if( pLocaleItem.get() != pRemoveItem ) - { - pFallbackItem = pLocaleItem.get(); - break; - } - } - if( m_pCurrentLocaleItem == pRemoveItem ) - { - setCurrentLocale( pFallbackItem->m_locale, false/*FindClosestMatch*/ ); - } - if( m_pDefaultLocaleItem == pRemoveItem ) + if( pLocaleItem.get() != pRemoveItem ) { - setDefaultLocale( pFallbackItem->m_locale ); + pFallbackItem = pLocaleItem.get(); + break; } } - } - auto it = std::find_if(m_aLocaleItemVector.begin(), m_aLocaleItemVector.end(), - [&pRemoveItem](const std::unique_ptr<LocaleItem>& rxItem) { return rxItem.get() == pRemoveItem; }); - if (it != m_aLocaleItemVector.end()) - { - // Remember locale item to delete file while storing - m_aDeletedLocaleItemVector.push_back( std::move(*it) ); - - // Last locale? - if( nLocaleCount == 1 ) + if( m_pCurrentLocaleItem == pRemoveItem ) { - m_nNextUniqueNumericId = 0; - if( m_pDefaultLocaleItem ) - { - m_aChangedDefaultLocaleVector.push_back( - std::make_unique<LocaleItem>( m_pDefaultLocaleItem->m_locale ) ); - } - m_pCurrentLocaleItem = nullptr; - m_pDefaultLocaleItem = nullptr; + setCurrentLocale( pFallbackItem->m_locale, false/*FindClosestMatch*/ ); } + if( m_pDefaultLocaleItem == pRemoveItem ) + { + setDefaultLocale( pFallbackItem->m_locale ); + } + } + } + auto it = std::find_if(m_aLocaleItemVector.begin(), m_aLocaleItemVector.end(), + [&pRemoveItem](const std::unique_ptr<LocaleItem>& rxItem) { return rxItem.get() == pRemoveItem; }); + if (it == m_aLocaleItemVector.end()) + return; - m_aLocaleItemVector.erase( it ); + // Remember locale item to delete file while storing + m_aDeletedLocaleItemVector.push_back( std::move(*it) ); - implModified(); + // Last locale? + if( nLocaleCount == 1 ) + { + m_nNextUniqueNumericId = 0; + if( m_pDefaultLocaleItem ) + { + m_aChangedDefaultLocaleVector.push_back( + std::make_unique<LocaleItem>( m_pDefaultLocaleItem->m_locale ) ); } + m_pCurrentLocaleItem = nullptr; + m_pDefaultLocaleItem = nullptr; } + + m_aLocaleItemVector.erase( it ); + + implModified(); } void StringResourceImpl::implScanIdForNumber( const OUString& ResourceID ) @@ -945,20 +945,20 @@ void StringResourcePersistenceImpl::implStoreAtStorage } // Default locale - if( m_pDefaultLocaleItem != nullptr && (bStoreAll || m_bDefaultModified) ) - { - OUString aStreamName = implGetFileNameForLocaleItem( m_pDefaultLocaleItem, aNameBase ) + ".default"; + if( !(m_pDefaultLocaleItem != nullptr && (bStoreAll || m_bDefaultModified)) ) + return; - Reference< io::XStream > xElementStream = - Storage->openStreamElement( aStreamName, ElementModes::READWRITE ); + OUString aStreamName = implGetFileNameForLocaleItem( m_pDefaultLocaleItem, aNameBase ) + ".default"; - // Only create stream without content - Reference< io::XOutputStream > xOutputStream = xElementStream->getOutputStream(); - xOutputStream->closeOutput(); + Reference< io::XStream > xElementStream = + Storage->openStreamElement( aStreamName, ElementModes::READWRITE ); - if( bUsedForStore ) - m_bDefaultModified = false; - } + // Only create stream without content + Reference< io::XOutputStream > xOutputStream = xElementStream->getOutputStream(); + xOutputStream->closeOutput(); + + if( bUsedForStore ) + m_bDefaultModified = false; } void StringResourcePersistenceImpl::storeToURL( const OUString& URL, @@ -1061,23 +1061,23 @@ void StringResourcePersistenceImpl::implStoreAtLocation implKillChangedDefaultFiles( Location, aNameBase, xFileAccess ); // Default locale - if( m_pDefaultLocaleItem != nullptr && (bStoreAll || bKillAll || m_bDefaultModified) ) - { - OUString aCompleteFileName = - implGetPathForLocaleItem( m_pDefaultLocaleItem, aNameBase, Location, true ); - if( xFileAccess->exists( aCompleteFileName ) ) - xFileAccess->kill( aCompleteFileName ); + if( !(m_pDefaultLocaleItem != nullptr && (bStoreAll || bKillAll || m_bDefaultModified)) ) + return; - if( !bKillAll ) - { - // Create Output stream - Reference< io::XOutputStream > xOutputStream = xFileAccess->openFileWrite( aCompleteFileName ); - if( xOutputStream.is() ) - xOutputStream->closeOutput(); + OUString aCompleteFileName = + implGetPathForLocaleItem( m_pDefaultLocaleItem, aNameBase, Location, true ); + if( xFileAccess->exists( aCompleteFileName ) ) + xFileAccess->kill( aCompleteFileName ); - if( bUsedForStore ) - m_bDefaultModified = false; - } + if( !bKillAll ) + { + // Create Output stream + Reference< io::XOutputStream > xOutputStream = xFileAccess->openFileWrite( aCompleteFileName ); + if( xOutputStream.is() ) + xOutputStream->closeOutput(); + + if( bUsedForStore ) + m_bDefaultModified = false; } } @@ -1765,19 +1765,19 @@ static void CheckContinueInNextLine( const Reference< io::XTextInputStream2 >& x OUString& aLine, bool& bEscapePending, const sal_Unicode*& pBuf, sal_Int32& nLen, sal_Int32& i ) { - if( i == nLen && bEscapePending ) - { - bEscapePending = false; + if( !(i == nLen && bEscapePending) ) + return; - if( !xTextInputStream->isEOF() ) - { - aLine = xTextInputStream->readLine(); - nLen = aLine.getLength(); - pBuf = aLine.getStr(); - i = 0; + bEscapePending = false; - skipWhites( pBuf, nLen, i ); - } + if( !xTextInputStream->isEOF() ) + { + aLine = xTextInputStream->readLine(); + nLen = aLine.getLength(); + pBuf = aLine.getStr(); + i = 0; + + skipWhites( pBuf, nLen, i ); } } diff --git a/scripting/source/vbaevents/eventhelper.cxx b/scripting/source/vbaevents/eventhelper.cxx index e3dc8ab7b670..6e72d1c43315 100644 --- a/scripting/source/vbaevents/eventhelper.cxx +++ b/scripting/source/vbaevents/eventhelper.cxx @@ -849,90 +849,90 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) { xScriptProvider = xSPS->getScriptProvider(); } - if ( xScriptProvider.is() && mpShell ) + if ( !(xScriptProvider.is() && mpShell) ) + return; + + BasicManager* pBasicManager = mpShell->GetBasicManager(); + OUString sProject; + OUString sScriptCode( evt.ScriptCode ); + // dialogs pass their own library, presence of Dot determines that + if ( sScriptCode.indexOf( '.' ) == -1 ) { - BasicManager* pBasicManager = mpShell->GetBasicManager(); - OUString sProject; - OUString sScriptCode( evt.ScriptCode ); - // dialogs pass their own library, presence of Dot determines that - if ( sScriptCode.indexOf( '.' ) == -1 ) - { - //'Project' is a better default but I want to force failures - //OUString sMacroLoc("Project"); - sProject = "Standard"; + //'Project' is a better default but I want to force failures + //OUString sMacroLoc("Project"); + sProject = "Standard"; - if (!pBasicManager->GetName().isEmpty()) - { - sProject = pBasicManager->GetName(); - } + if (!pBasicManager->GetName().isEmpty()) + { + sProject = pBasicManager->GetName(); } - else + } + else + { + sal_Int32 nIndex = sScriptCode.indexOf( '.' ); + sProject = sScriptCode.copy( 0, nIndex ); + sScriptCode = sScriptCode.copy( nIndex + 1 ); + } + OUString sMacroLoc = sProject + "." + sScriptCode + "."; + + for (const auto& rTxInfo : eventInfo_it->second) + { + // If the document is closed, we should not execute macro. + if (m_bDocClosed) { - sal_Int32 nIndex = sScriptCode.indexOf( '.' ); - sProject = sScriptCode.copy( 0, nIndex ); - sScriptCode = sScriptCode.copy( nIndex + 1 ); + break; } - OUString sMacroLoc = sProject + "." + sScriptCode + "."; - for (const auto& rTxInfo : eventInfo_it->second) + OUString sTemp = sName.concat( rTxInfo.sVBAName ); + // see if we have a match for the handlerextension + // where ScriptCode is methodname_handlerextension + OUString sToResolve = sMacroLoc.concat( sTemp ); + + ooo::vba::MacroResolvedInfo aMacroResolvedInfo = ooo::vba::resolveVBAMacro( mpShell, sToResolve ); + if ( aMacroResolvedInfo.mbFound ) { - // If the document is closed, we should not execute macro. - if (m_bDocClosed) + + if (! rTxInfo.ApproveRule(evt, rTxInfo.pPara) ) { - break; + continue; } - OUString sTemp = sName.concat( rTxInfo.sVBAName ); - // see if we have a match for the handlerextension - // where ScriptCode is methodname_handlerextension - OUString sToResolve = sMacroLoc.concat( sTemp ); - - ooo::vba::MacroResolvedInfo aMacroResolvedInfo = ooo::vba::resolveVBAMacro( mpShell, sToResolve ); - if ( aMacroResolvedInfo.mbFound ) + // !! translate arguments & emulate events where necessary + Sequence< Any > aArguments; + if ( rTxInfo.toVBA ) { + aArguments = rTxInfo.toVBA( evt.Arguments ); + } + else + { + aArguments = evt.Arguments; + } + if ( aArguments.hasElements() ) + { + // call basic event handlers for event - if (! rTxInfo.ApproveRule(evt, rTxInfo.pPara) ) - { - continue; - } - - // !! translate arguments & emulate events where necessary - Sequence< Any > aArguments; - if ( rTxInfo.toVBA ) - { - aArguments = rTxInfo.toVBA( evt.Arguments ); - } - else - { - aArguments = evt.Arguments; - } - if ( aArguments.hasElements() ) + // create script url + OUString url = aMacroResolvedInfo.msResolvedMacro; + try { - // call basic event handlers for event - - // create script url - OUString url = aMacroResolvedInfo.msResolvedMacro; - try + uno::Any aDummyCaller = uno::makeAny( OUString("Error") ); + if ( pRet ) { - uno::Any aDummyCaller = uno::makeAny( OUString("Error") ); - if ( pRet ) - { - ooo::vba::executeMacro( mpShell, url, aArguments, *pRet, aDummyCaller ); - } - else - { - uno::Any aRet; - ooo::vba::executeMacro( mpShell, url, aArguments, aRet, aDummyCaller ); - } + ooo::vba::executeMacro( mpShell, url, aArguments, *pRet, aDummyCaller ); } - catch ( const uno::Exception& ) + else { - TOOLS_WARN_EXCEPTION("scripting", "event script raised" ); + uno::Any aRet; + ooo::vba::executeMacro( mpShell, url, aArguments, aRet, aDummyCaller ); } - } + } + catch ( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("scripting", "event script raised" ); + } } } - } + } } namespace { |