From aafbcb76ec238c947a304a71e44ac1e856136ca3 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 4 Dec 2009 12:17:03 +0100 Subject: autorecovery: open the Basic IDE via SFX' document loader --- sfx2/inc/sfx2/frame.hxx | 1 + sfx2/source/appl/appserv.cxx | 65 ++++++++++++++++++++++++++++++++++---------- sfx2/source/view/topfrm.cxx | 22 ++++++++++++--- 3 files changed, 70 insertions(+), 18 deletions(-) diff --git a/sfx2/inc/sfx2/frame.hxx b/sfx2/inc/sfx2/frame.hxx index 095feca0e26c..3f096c9388e4 100644 --- a/sfx2/inc/sfx2/frame.hxx +++ b/sfx2/inc/sfx2/frame.hxx @@ -140,6 +140,7 @@ public: TYPEINFO(); static SfxFrame* Create( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame ); + static SfxFrame* CreateBlank(); static SfxFrame* Create( SfxObjectShell& rDoc, const USHORT nViewId, const bool bHidden ); static SfxFrame* Create( SfxObjectShell& rDoc, Window& rWindow, USHORT nViewId, bool bHidden ); diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 268fdcdf386a..a93769bc1f0d 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -98,6 +98,7 @@ #include #include "about.hxx" +#include "frmload.hxx" #include "referers.hxx" #include #include @@ -822,6 +823,24 @@ namespace } return _pFallback; } + + const ::rtl::OUString& lcl_getBasicIDEServiceName() + { + static const ::rtl::OUString s_sBasicName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.BasicIDE" ) ); + return s_sBasicName; + } + + SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell* i_pBasicIDE ) + { + SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE ); + while ( pView ) + { + if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == lcl_getBasicIDEServiceName() ) + break; + pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE ); + } + return pView; + } } void SfxApplication::OfaExec_Impl( SfxRequest& rReq ) @@ -902,22 +921,40 @@ void SfxApplication::OfaExec_Impl( SfxRequest& rReq ) case SID_BASICIDE_APPEAR: { - SfxViewFrame* pView = SfxViewFrame::GetFirst(); - ::rtl::OUString aBasicName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.BasicIDE" ) ); - while ( pView ) - { - if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == aBasicName ) - break; - pView = SfxViewFrame::GetNext( *pView ); - } - + SfxViewFrame* pView = lcl_getBasicIDEViewFrame( NULL ); if ( !pView ) { - SfxObjectShell* pDocShell = SfxObjectShell::CreateObject( aBasicName ); - pDocShell->DoInitNew( 0 ); - pDocShell->SetModified( FALSE ); - pView = SfxViewFrame::CreateViewFrame( *pDocShell, 0 ); - pView->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) ); + SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( lcl_getBasicIDEServiceName() ); + pBasicIDE->DoInitNew( 0 ); + pBasicIDE->SetModified( FALSE ); + try + { + // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL + // (which could be done via SfxViewFrame::LoadDocument) is not feasible here, since the Basic IDE + // does not really play nice with the framework's concept. For instance, it is a "singleton document", + // which conflicts, at the latest, with the framework's concept of loading into _blank frames. + // So, since we know that our frame loader can handle it, we skip the generic framework loader + // mechanism, and the type detection (which doesn't know about the Basic IDE). + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + Reference< XSynchronousFrameLoader > xLoader( aContext.createComponent( + SfxFrameLoader_Impl::impl_getStaticImplementationName() ), UNO_QUERY_THROW ); + ::comphelper::NamedValueCollection aLoadArgs; + aLoadArgs.put( "Model", pBasicIDE->GetModel() ); + aLoadArgs.put( "URL", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/sbasic" ) ) ); + + SfxFrame* pFrame = SfxFrame::CreateBlank(); + ENSURE_OR_THROW( pFrame, "could not create a blank SfxFrame" ); + + xLoader->load( aLoadArgs.getPropertyValues(), pFrame->GetFrameInterface() ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + pView = lcl_getBasicIDEViewFrame( pBasicIDE ); + if ( pView ) + pView->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) ); } if ( pView ) diff --git a/sfx2/source/view/topfrm.cxx b/sfx2/source/view/topfrm.cxx index 2c61428b823c..a9cdf3441508 100644 --- a/sfx2/source/view/topfrm.cxx +++ b/sfx2/source/view/topfrm.cxx @@ -394,6 +394,23 @@ namespace } } +SfxFrame* SfxFrame::CreateBlank() +{ + SfxFrame* pFrame = NULL; + try + { + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW ); + Reference < XFrame > xFrame = xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ); + pFrame = Create( xFrame ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return pFrame; +} + SfxFrame* SfxFrame::Create( SfxObjectShell& rDoc, const USHORT nViewId, const bool bHidden ) { if ( nViewId ) @@ -466,10 +483,7 @@ SfxFrame* SfxFrame::Create( SfxObjectShell& rDoc, const USHORT nViewId, const bo } if ( !pFrame ) - { - Reference < XFrame > xFrame = xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ); - pFrame = Create( xFrame ); - } + pFrame = SfxFrame::CreateBlank(); pFrame->pImp->bHidden = bHidden; Window* pWindow = pFrame->GetTopWindow_Impl(); -- cgit v1.2.3