diff options
author | Noel Grandin <noel@peralex.com> | 2013-02-26 16:24:53 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2013-03-07 08:23:38 +0200 |
commit | cd8ea20aa4b85128956a79c80f7953d30e99e802 (patch) | |
tree | 2ec962196db84427e97bbc9bb73f9566d70b6fd1 /sfx2 | |
parent | 1b4b53a2ecd7f2283a2c86b2c474786918cbfbf2 (diff) |
fdo#46808, Convert ui::UIConfigurationManager to new-style
Change-Id: I62c37eb6d0e0b2a681a84e1fa0067d0a9f967cf2
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/sfx2/sfxbasemodel.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 148 |
2 files changed, 73 insertions, 77 deletions
diff --git a/sfx2/inc/sfx2/sfxbasemodel.hxx b/sfx2/inc/sfx2/sfxbasemodel.hxx index 66b9c9c20445..e0ac759e38b4 100644 --- a/sfx2/inc/sfx2/sfxbasemodel.hxx +++ b/sfx2/inc/sfx2/sfxbasemodel.hxx @@ -68,6 +68,7 @@ #include <com/sun/star/lang/EventObject.hpp> #include <com/sun/star/datatransfer/XTransferable.hpp> #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp> +#include <com/sun/star/ui/XUIConfigurationManager2.hpp> #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> #include <com/sun/star/embed/XVisualObject.hpp> #include <com/sun/star/uno/Sequence.hxx> @@ -1503,6 +1504,7 @@ private: @onerror - */ + css::uno::Reference< css::ui::XUIConfigurationManager2 > getUIConfigurationManager2() throw ( RUNTIMEEXCEPTION ); bool impl_getPrintHelper(); SAL_DLLPRIVATE void ListenForStorage_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); SAL_DLLPRIVATE ::rtl::OUString GetMediumFilterName_Impl(); diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 06f496294f65..e62cb4a71953 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -41,8 +41,7 @@ #include <com/sun/star/container/XIndexContainer.hpp> #include <com/sun/star/script/provider/XScriptProviderFactory.hpp> #include <com/sun/star/script/provider/XScriptProvider.hpp> -#include <com/sun/star/ui/XUIConfigurationStorage.hpp> -#include <com/sun/star/ui/XUIConfigurationPersistence.hpp> +#include <com/sun/star/ui/UIConfigurationManager.hpp> #include <com/sun/star/embed/ElementModes.hpp> #include <com/sun/star/embed/Aspects.hpp> #include <com/sun/star/document/DocumentProperties.hpp> @@ -204,7 +203,7 @@ struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument sal_Bool m_bModifiedSinceLastSave; uno::Reference< com::sun::star::view::XPrintable> m_xPrintable ; uno::Reference< script::provider::XScriptProvider > m_xScriptProvider; - uno::Reference< ui::XUIConfigurationManager > m_xUIConfigurationManager; + uno::Reference< ui::XUIConfigurationManager2 > m_xUIConfigurationManager; ::rtl::Reference< ::sfx2::DocumentStorageModifyListener > m_pStorageModifyListen; ::rtl::OUString m_sModuleIdentifier; css::uno::Reference< css::frame::XTitle > m_xTitleHelper; @@ -2767,8 +2766,7 @@ void SfxBaseModel::Notify( SfxBroadcaster& rBC , if ( xConfigStorage.is() || !m_pData->m_pObjectShell->GetStorage()->hasByName( aUIConfigFolderName ) ) { // the storage is different, since otherwise it could not be opened, so it must be exchanged - Reference< ui::XUIConfigurationStorage > xUIConfigStorage( m_pData->m_xUIConfigurationManager, uno::UNO_QUERY ); - xUIConfigStorage->setStorage( xConfigStorage ); + m_pData->m_xUIConfigurationManager->setStorage( xConfigStorage ); } else { @@ -3498,95 +3496,94 @@ static void ConvertSlotsToCommands( SfxObjectShell* pDoc, uno::Reference< contai uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfigurationManager() throw ( uno::RuntimeException ) { + return uno::Reference< ui::XUIConfigurationManager >( getUIConfigurationManager2(), UNO_QUERY_THROW ); +} + +uno::Reference< ui::XUIConfigurationManager2 > SfxBaseModel::getUIConfigurationManager2() + throw ( uno::RuntimeException ) +{ SfxModelGuard aGuard( *this ); if ( !m_pData->m_xUIConfigurationManager.is() ) { - uno::Reference< ui::XUIConfigurationManager > xNewUIConfMan( - ::comphelper::getProcessServiceFactory()->createInstance( - ::rtl::OUString("com.sun.star.ui.UIConfigurationManager")), - uno::UNO_QUERY ); + uno::Reference< ui::XUIConfigurationManager2 > xNewUIConfMan = + ui::UIConfigurationManager::create( comphelper::getProcessComponentContext() ); - Reference< ui::XUIConfigurationStorage > xUIConfigStorage( xNewUIConfMan, uno::UNO_QUERY ); - if ( xUIConfigStorage.is() ) - { - uno::Reference< XSTORAGE > xConfigStorage; + uno::Reference< XSTORAGE > xConfigStorage; - rtl::OUString aUIConfigFolderName( "Configurations2" ); - // First try to open with READWRITE and then READ - xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE ); - if ( xConfigStorage.is() ) + rtl::OUString aUIConfigFolderName( "Configurations2" ); + // First try to open with READWRITE and then READ + xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE ); + if ( xConfigStorage.is() ) + { + rtl::OUString aMediaTypeProp( "MediaType" ); + rtl::OUString aUIConfigMediaType( + "application/vnd.sun.xml.ui.configuration" ); + rtl::OUString aMediaType; + uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY ); + Any a = xPropSet->getPropertyValue( aMediaTypeProp ); + if ( !( a >>= aMediaType ) || aMediaType.isEmpty()) { - rtl::OUString aMediaTypeProp( "MediaType" ); - rtl::OUString aUIConfigMediaType( - "application/vnd.sun.xml.ui.configuration" ); - rtl::OUString aMediaType; - uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY ); - Any a = xPropSet->getPropertyValue( aMediaTypeProp ); - if ( !( a >>= aMediaType ) || aMediaType.isEmpty()) - { - a <<= aUIConfigMediaType; - xPropSet->setPropertyValue( aMediaTypeProp, a ); - } + a <<= aUIConfigMediaType; + xPropSet->setPropertyValue( aMediaTypeProp, a ); } - else - xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ ); + } + else + xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ ); - // initialize ui configuration manager with document substorage - xUIConfigStorage->setStorage( xConfigStorage ); + // initialize ui configuration manager with document substorage + xNewUIConfMan->setStorage( xConfigStorage ); - // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to - // migrate - if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) + // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to + // migrate + if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) + { + // Import old UI configuration from OOo 1.x + uno::Reference< XSTORAGE > xOOo1ConfigStorage; + rtl::OUString aOOo1UIConfigFolderName( "Configurations" ); + + // Try to open with READ + xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ ); + if ( xOOo1ConfigStorage.is() ) { - // Import old UI configuration from OOo 1.x - uno::Reference< XSTORAGE > xOOo1ConfigStorage; - rtl::OUString aOOo1UIConfigFolderName( "Configurations" ); + uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); + uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars; - // Try to open with READ - xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ ); - if ( xOOo1ConfigStorage.is() ) + sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars( + xNewUIConfMan, rToolbars, xContext, xOOo1ConfigStorage ); + if ( bImported ) { - uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); - uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars; + SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell(); - sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars( - xNewUIConfMan, rToolbars, xContext, xOOo1ConfigStorage ); - if ( bImported ) + rtl::OUString aNum( "private:resource/toolbar/custom_OOo1x_" ); + rtl::OUString aTitle( "Toolbar " ); + for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ ) { - SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell(); + rtl::OUString aCustomTbxName = aNum + rtl::OUString::valueOf( i + 1 ); + rtl::OUString aCustomTbxTitle = aTitle + rtl::OUString::valueOf( i + 1 ); - rtl::OUString aNum( "private:resource/toolbar/custom_OOo1x_" ); - rtl::OUString aTitle( "Toolbar " ); - for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ ) + uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i]; + ConvertSlotsToCommands( pObjShell, xToolbar ); + if ( !xNewUIConfMan->hasSettings( aCustomTbxName )) { - rtl::OUString aCustomTbxName = aNum + rtl::OUString::valueOf( i + 1 ); - rtl::OUString aCustomTbxTitle = aTitle + rtl::OUString::valueOf( i + 1 ); - - uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i]; - ConvertSlotsToCommands( pObjShell, xToolbar ); - if ( !xNewUIConfMan->hasSettings( aCustomTbxName )) + // Set UIName for the toolbar with container property + uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY ); + if ( xPropSet.is() ) { - // Set UIName for the toolbar with container property - uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY ); - if ( xPropSet.is() ) + try + { + rtl::OUString aPropName( "UIName" ); + Any aAny( aCustomTbxTitle ); + xPropSet->setPropertyValue( aPropName, aAny ); + } + catch ( beans::UnknownPropertyException& ) { - try - { - rtl::OUString aPropName( "UIName" ); - Any aAny( aCustomTbxTitle ); - xPropSet->setPropertyValue( aPropName, aAny ); - } - catch ( beans::UnknownPropertyException& ) - { - } } - - uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY ); - xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData ); - uno::Reference< ui::XUIConfigurationPersistence > xPersist( xNewUIConfMan, uno::UNO_QUERY ); - xPersist->store(); } + + uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY ); + xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData ); + xNewUIConfMan->store(); } } } @@ -3814,9 +3811,7 @@ void SAL_CALL SfxBaseModel::switchToStorage( const uno::Reference< XSTORAGE >& x else { // UICfgMgr has a reference to the old storage, update it - uno::Reference< ui::XUIConfigurationStorage > xUICfgMgrStorage( getUIConfigurationManager(), uno::UNO_QUERY ); - if ( xUICfgMgrStorage.is() ) - xUICfgMgrStorage->setStorage( xStorage ); + getUIConfigurationManager2()->setStorage( xStorage ); } } m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False; @@ -3900,7 +3895,6 @@ css::uno::Reference< css::frame::XTitle > SfxBaseModel::impl_getTitleHelper () if ( ! m_pData->m_xTitleHelper.is ()) { - css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); css::uno::Reference< css::frame::XUntitledNumbers > xDesktop( css::frame::Desktop::create(xContext), css::uno::UNO_QUERY_THROW); css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW); |