diff options
author | Noel Power <npower@openoffice.org> | 2003-10-15 07:35:32 +0000 |
---|---|---|
committer | Noel Power <npower@openoffice.org> | 2003-10-15 07:35:32 +0000 |
commit | 523410191cee137ccea76c603525add921282538 (patch) | |
tree | cd0405089e57a2253aa4f21d4876baf0dfefb816 | |
parent | 690c84cb8b109199a028d7f3b8992ef68da96a6f (diff) |
#i21213#
#i21214#
changes to basic provider to ensure that scripts get displayed ( implemented XPropertySet on script node implementation basmethnode. Also changed basprov ( basic provider ) to handle application context invoke requests ( also display of share scripts ). Now when basic provider is created ( regardless of context ) it will always be able to execute a script, whatever the location.
-rw-r--r-- | scripting/source/basprov/baslibnode.cxx | 10 | ||||
-rw-r--r-- | scripting/source/basprov/baslibnode.hxx | 8 | ||||
-rw-r--r-- | scripting/source/basprov/basmethnode.cxx | 122 | ||||
-rw-r--r-- | scripting/source/basprov/basmethnode.hxx | 59 | ||||
-rw-r--r-- | scripting/source/basprov/basmodnode.cxx | 10 | ||||
-rw-r--r-- | scripting/source/basprov/basmodnode.hxx | 8 | ||||
-rw-r--r-- | scripting/source/basprov/basprov.cxx | 193 | ||||
-rw-r--r-- | scripting/source/basprov/basprov.hxx | 15 |
8 files changed, 368 insertions, 57 deletions
diff --git a/scripting/source/basprov/baslibnode.cxx b/scripting/source/basprov/baslibnode.cxx index 98374d00c737..83e029ad6a4d 100644 --- a/scripting/source/basprov/baslibnode.cxx +++ b/scripting/source/basprov/baslibnode.cxx @@ -2,9 +2,9 @@ * * $RCSfile: baslibnode.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: tbe $ $Date: 2003-09-23 10:08:44 $ + * last change: $Author: npower $ $Date: 2003-10-15 08:35:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -95,10 +95,10 @@ namespace basprov // ============================================================================= BasicLibraryNodeImpl::BasicLibraryNodeImpl( BasicManager* pBasicManager, - const Reference< script::XLibraryContainer >& xLibContainer, const ::rtl::OUString& sLibName ) + const Reference< script::XLibraryContainer >& xLibContainer, const ::rtl::OUString& sLibName, bool isAppScript ) :m_pBasicManager( pBasicManager ) ,m_xLibContainer( xLibContainer ) - ,m_sLibName( sLibName ) + ,m_sLibName( sLibName ),m_bIsAppScript( isAppScript ) { if ( m_xLibContainer.is() ) { @@ -150,7 +150,7 @@ namespace basprov { SbModule* pModule = pBasic->FindModule( pNames[i] ); if ( pModule ) - pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicModuleNodeImpl( pModule ) ); + pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicModuleNodeImpl( pModule, m_bIsAppScript ) ); } } } diff --git a/scripting/source/basprov/baslibnode.hxx b/scripting/source/basprov/baslibnode.hxx index 3499ecc70057..15c35ff4bf53 100644 --- a/scripting/source/basprov/baslibnode.hxx +++ b/scripting/source/basprov/baslibnode.hxx @@ -2,9 +2,9 @@ * * $RCSfile: baslibnode.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: tbe $ $Date: 2003-09-23 10:08:38 $ + * last change: $Author: npower $ $Date: 2003-10-15 08:35:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -96,11 +96,11 @@ namespace basprov ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer > m_xLibContainer; ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xLibrary; ::rtl::OUString m_sLibName; - + bool m_bIsAppScript; public: BasicLibraryNodeImpl( BasicManager* pBasicManager, const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& xLibContainer, - const ::rtl::OUString& sLibName ); + const ::rtl::OUString& sLibName, bool isAppScript=true ); virtual ~BasicLibraryNodeImpl(); // XBrowseNode diff --git a/scripting/source/basprov/basmethnode.cxx b/scripting/source/basprov/basmethnode.cxx index d540d78ec73e..45c09f7f3203 100644 --- a/scripting/source/basprov/basmethnode.cxx +++ b/scripting/source/basprov/basmethnode.cxx @@ -2,9 +2,9 @@ * * $RCSfile: basmethnode.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: tbe $ $Date: 2003-09-23 10:09:14 $ + * last change: $Author: npower $ $Date: 2003-10-15 08:35:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -73,7 +73,9 @@ #ifndef _SB_SBMETH_HXX #include <basic/sbmeth.hxx> #endif - +#ifndef _SB_SBMOD_HXX +#include <basic/sbmod.hxx> +#endif using namespace ::com::sun::star; using namespace ::com::sun::star::lang; @@ -90,9 +92,40 @@ namespace basprov // BasicMethodNodeImpl // ============================================================================= - BasicMethodNodeImpl::BasicMethodNodeImpl( SbMethod* pMethod ) - :m_pMethod( pMethod ) + BasicMethodNodeImpl::BasicMethodNodeImpl( SbMethod* pMethod, bool isAppScript ) + :m_pMethod( pMethod ), m_bIsAppScript( isAppScript ) { + // TO DO ( needs changing to vnd...script::// syntax ) + String sModName = m_pMethod->GetModule()->GetName(); + String sLibName = m_pMethod->GetModule()->GetParent()->GetName(); + String sMethName = m_pMethod->GetName(); + String sTmp = String::CreateFromAscii("script://"); + sTmp += sLibName; + sTmp += '.'; + sTmp += sModName; + sTmp += '.'; + sTmp += sMethName; + sTmp += String::CreateFromAscii("?language=Basic&location="); + if ( m_bIsAppScript ) + { + sTmp += String::CreateFromAscii("application"); + } + else + { + sTmp += String::CreateFromAscii("document"); + } + rtl::OUString sUrl( sTmp ); + try + { + Any aURIVal; + aURIVal <<= sUrl; + setPropertyValue( ::rtl::OUString::createFromAscii("URI"), aURIVal); + } + catch ( RuntimeException& re ) + { + OSL_TRACE("caught exception trying to set property %s", + ::rtl::OUStringToOString( re.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + } } // ----------------------------------------------------------------------------- @@ -145,6 +178,85 @@ namespace basprov // ----------------------------------------------------------------------------- + +//************************************************************************* +// XPropertySet implementation +//************************************************************************* +Reference< beans::XPropertySetInfo > SAL_CALL BasicMethodNodeImpl::getPropertySetInfo( ) + throw ( RuntimeException ) +{ + return Reference< beans::XPropertySetInfo > (); // Not supported +} + +//************************************************************************* +void SAL_CALL BasicMethodNodeImpl::setPropertyValue( const ::rtl::OUString& aPropertyName, + const Any& aValue ) + throw ( beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + RuntimeException ) +{ + m_hProps[ aPropertyName ] = aValue; +} + +//************************************************************************* +Any SAL_CALL BasicMethodNodeImpl::getPropertyValue( const ::rtl::OUString& PropertyName ) + throw ( beans::UnknownPropertyException, + lang::WrappedTargetException, RuntimeException ) +{ + Any returnValue = m_hProps[ PropertyName ]; + + return returnValue; +} + +//************************************************************************* +void SAL_CALL BasicMethodNodeImpl::addPropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const Reference< beans::XPropertyChangeListener >& xListener ) + throw ( beans::UnknownPropertyException, lang::WrappedTargetException, + RuntimeException ) +{ + throw RuntimeException( + ::rtl::OUString::createFromAscii( "BasicMethodNodeImpl::addPropertyChangeListener: method not supported" ), + Reference< XInterface >() ); +} + +//************************************************************************* +void SAL_CALL BasicMethodNodeImpl::removePropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const Reference< beans::XPropertyChangeListener >& aListener ) + throw ( beans::UnknownPropertyException, lang::WrappedTargetException, + RuntimeException ) +{ + throw RuntimeException( + ::rtl::OUString::createFromAscii( "BasicMethodNodeImpl::removePropertyChangeListener: method not supported" ), + Reference< XInterface >() ); +} + +//************************************************************************* +void SAL_CALL BasicMethodNodeImpl::addVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const Reference< beans::XVetoableChangeListener >& aListener ) + throw ( beans::UnknownPropertyException, lang::WrappedTargetException, + RuntimeException ) +{ + throw RuntimeException( + ::rtl::OUString::createFromAscii( "BasicMethodNodeImpl::addVetoableChangeListener: method not supported" ), + Reference< XInterface >() ); +} + +//************************************************************************* +void SAL_CALL BasicMethodNodeImpl::removeVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const Reference< beans::XVetoableChangeListener >& aListener ) + throw ( beans::UnknownPropertyException, lang::WrappedTargetException, + RuntimeException ) +{ + throw RuntimeException( + ::rtl::OUString::createFromAscii( "BasicMethodNodeImpl::removeVetoableChangeListener: method not supported" ), + Reference< XInterface >() ); +} + + //......................................................................... } // namespace basprov //......................................................................... diff --git a/scripting/source/basprov/basmethnode.hxx b/scripting/source/basprov/basmethnode.hxx index 79896dc1d27d..6519ace99c59 100644 --- a/scripting/source/basprov/basmethnode.hxx +++ b/scripting/source/basprov/basmethnode.hxx @@ -2,9 +2,9 @@ * * $RCSfile: basmethnode.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: tbe $ $Date: 2003-09-23 10:09:05 $ + * last change: $Author: npower $ $Date: 2003-10-15 08:35:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,6 +69,10 @@ #ifndef _CPPUHELPER_IMPLBASE1_HXX_ #include <cppuhelper/implbase1.hxx> #endif +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <hash_map> class SbMethod; @@ -82,17 +86,21 @@ namespace basprov // class BasicMethodNodeImpl // ---------------------------------------------------- - typedef ::cppu::WeakImplHelper1< - ::drafts::com::sun::star::script::framework::browse::XBrowseNode > BasicMethodNodeImpl_BASE; + typedef ::cppu::WeakImplHelper2< + ::drafts::com::sun::star::script::framework::browse::XBrowseNode, + com::sun::star::beans::XPropertySet > BasicMethodNodeImpl_BASE; + typedef ::std::hash_map < ::rtl::OUString, com::sun::star::uno::Any, ::rtl::OUStringHash, + ::std::equal_to< ::rtl::OUString > > Props_hash; class BasicMethodNodeImpl : public BasicMethodNodeImpl_BASE { private: SbMethod* m_pMethod; - + Props_hash m_hProps; + bool m_bIsAppScript; public: - BasicMethodNodeImpl( SbMethod* pMethod ); + BasicMethodNodeImpl( SbMethod* pMethod, bool isAppScript = true ); virtual ~BasicMethodNodeImpl(); // XBrowseNode @@ -104,6 +112,45 @@ namespace basprov throw (::com::sun::star::uno::RuntimeException); virtual sal_Int16 SAL_CALL getType( ) throw (::com::sun::star::uno::RuntimeException); + // XPropertySet implementation + virtual com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo( ) + throw ( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, + const com::sun::star::uno::Any& aValue ) + throw ( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) + throw ( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw ( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL removePropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw ( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL addVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw ( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL removeVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw ( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + }; //......................................................................... diff --git a/scripting/source/basprov/basmodnode.cxx b/scripting/source/basprov/basmodnode.cxx index 6a228635afa4..e439b41526cf 100644 --- a/scripting/source/basprov/basmodnode.cxx +++ b/scripting/source/basprov/basmodnode.cxx @@ -2,9 +2,9 @@ * * $RCSfile: basmodnode.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: tbe $ $Date: 2003-09-23 10:08:59 $ + * last change: $Author: npower $ $Date: 2003-10-15 08:35:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -100,8 +100,8 @@ namespace basprov // BasicModuleNodeImpl // ============================================================================= - BasicModuleNodeImpl::BasicModuleNodeImpl( SbModule* pModule ) - :m_pModule( pModule ) + BasicModuleNodeImpl::BasicModuleNodeImpl( SbModule* pModule, bool isAppScript ) + :m_pModule( pModule ), m_bIsAppScript( isAppScript ) { } @@ -147,7 +147,7 @@ namespace basprov { SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< USHORT >( i ) ) ); if ( pMethod ) - pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicMethodNodeImpl( pMethod ) ); + pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicMethodNodeImpl( pMethod, m_bIsAppScript ) ); } } } diff --git a/scripting/source/basprov/basmodnode.hxx b/scripting/source/basprov/basmodnode.hxx index db256c5e315c..5184b93c1f71 100644 --- a/scripting/source/basprov/basmodnode.hxx +++ b/scripting/source/basprov/basmodnode.hxx @@ -2,9 +2,9 @@ * * $RCSfile: basmodnode.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: tbe $ $Date: 2003-09-23 10:08:51 $ + * last change: $Author: npower $ $Date: 2003-10-15 08:35:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -90,9 +90,9 @@ namespace basprov { private: SbModule* m_pModule; - + bool m_bIsAppScript; public: - BasicModuleNodeImpl( SbModule* pModule ); + BasicModuleNodeImpl( SbModule* pModule, bool isAppScript = true ); virtual ~BasicModuleNodeImpl(); // XBrowseNode diff --git a/scripting/source/basprov/basprov.cxx b/scripting/source/basprov/basprov.cxx index 34d167736ff5..d9a1a6d008cf 100644 --- a/scripting/source/basprov/basprov.cxx +++ b/scripting/source/basprov/basprov.cxx @@ -2,9 +2,9 @@ * * $RCSfile: basprov.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: tbe $ $Date: 2003-09-23 15:06:47 $ + * last change: $Author: npower $ $Date: 2003-10-15 08:35:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -102,6 +102,8 @@ #include <sfx2/objsh.hxx> #endif +#include <com/sun/star/util/XMacroExpander.hpp> +#include <com/sun/star/script/XLibraryContainer2.hpp> using namespace ::com::sun::star; using namespace ::com::sun::star::lang; @@ -158,10 +160,13 @@ namespace basprov // ============================================================================= BasicProviderImpl::BasicProviderImpl( const Reference< XComponentContext >& xContext ) - :m_pBasicManager( 0 ) - ,m_xLibContainer( 0 ) + :m_pAppBasicManager( 0 ) + ,m_pDocBasicManager( 0 ) + ,m_xLibContainerApp( 0 ) + ,m_xLibContainerDoc( 0 ) ,m_xContext( xContext ) ,m_xScriptingContext( 0 ) + ,m_bIsAppScriptCtx( true ) { } @@ -210,8 +215,29 @@ namespace basprov ::osl::MutexGuard aGuard( StarBASIC::GetGlobalMutex() ); - if ( aArguments.getLength() == 1 ) + if ( aArguments.getLength() == 1 && aArguments[0].getValueType() == ::getCppuType( (const ::rtl::OUString* ) NULL )) { + // Provider has been created with application context for user + // or share + ::rtl::OUString sTmp; + aArguments[0] >>= sTmp; + Any aAny = m_xContext->getValueByName( ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ); + Reference< util::XMacroExpander > xME; + aAny >>= xME; + ::rtl::OUString base = ::rtl::OUString::createFromAscii( + SAL_CONFIGFILE( "${$SYSBINDIR/bootstrap" ) ); + ::rtl::OUString user = ::rtl::OUString::createFromAscii( "::UserInstallation}/user" ); + ::rtl::OUString share = ::rtl::OUString::createFromAscii( "::BaseInstallation}/share" ); + ::rtl::OUString userDirString = xME->expandMacros( base.concat( user ) ); + if ( !sTmp.equals( userDirString ) ) + { + m_bIsUserCtx = false; + } + } + + else if ( aArguments.getLength() == 1 && aArguments[0].getValueType() == ::getCppuType( ( const Reference< beans::XPropertySet >* ) NULL )) + { + // Provider has been created with document context aArguments[0] >>= m_xScriptingContext; if ( m_xScriptingContext.is() ) @@ -226,11 +252,12 @@ namespace basprov { if ( xModel == pObjShell->GetModel() ) { - m_pBasicManager = pObjShell->GetBasicManager(); - m_xLibContainer = Reference< script::XLibraryContainer >( pObjShell->GetBasicContainer(), UNO_QUERY ); + m_pDocBasicManager = pObjShell->GetBasicManager(); + m_xLibContainerDoc = Reference< script::XLibraryContainer >( pObjShell->GetBasicContainer(), UNO_QUERY ); break; } } + m_bIsAppScriptCtx = sal_False; } } else @@ -252,14 +279,49 @@ namespace basprov } // TODO - if ( !m_pBasicManager ) - m_pBasicManager = SFX_APP()->GetBasicManager(); + if ( !m_pAppBasicManager ) + m_pAppBasicManager = SFX_APP()->GetBasicManager(); - if ( !m_xLibContainer.is() ) - m_xLibContainer = Reference< script::XLibraryContainer >( SFX_APP()->GetBasicContainer(), UNO_QUERY ); + if ( !m_xLibContainerApp.is() ) + m_xLibContainerApp = Reference< script::XLibraryContainer >( SFX_APP()->GetBasicContainer(), UNO_QUERY ); } // ----------------------------------------------------------------------------- + // TO DO, this code needs removal after integration of URI parsing service + ::rtl::OUString BasicProviderImpl::getLocationFromURI( const ::rtl::OUString& scriptURI ) + { + ::rtl::OUString language; + ::rtl::OUString attr; + sal_Int32 len = scriptURI.indexOf( '?' ); + if( ( len < 0 ) || ( scriptURI.getLength() == 0 ) ) + { + return language; + } + // if we have a match, then start the search after the ? + + len++; + do + { + attr = scriptURI.getToken( 0, '&', len ); + //OSL_TRACE( "chunk is %s, len is %d", + // ::rtl::OUStringToOString( attr, + // RTL_TEXTENCODING_ASCII_US ).pData->buffer, len ); + if( attr.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "location" ) ) + == sal_True ) + { + sal_Int32 len2 = attr.indexOf('='); + language = attr.copy( len2 + 1 ); + //OSL_TRACE( "Language name is %s", + // ::rtl::OUStringToOString( language, + // RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + break; + } + } + while ( len >= 0 ); + return language; + + } + // XScriptProvider // ----------------------------------------------------------------------------- @@ -278,8 +340,11 @@ namespace basprov sal_Int32 nSchemaLen = aSchema.getLength(); sal_Int32 nLen = scriptURI.indexOf( '?' ); ::rtl::OUString aDescription; + ::rtl::OUString aLocation; if ( nLen - nSchemaLen > 0 ) + { aDescription = scriptURI.copy( nSchemaLen, nLen - nSchemaLen ); + } sal_Int32 nIndex = 0; ::rtl::OUString aLibrary = aDescription.getToken( 0, (sal_Unicode)'.', nIndex ); ::rtl::OUString aModule; @@ -289,16 +354,28 @@ namespace basprov if ( nIndex != -1 ) aMethod = aDescription.getToken( 0, (sal_Unicode)'.', nIndex ); - if ( aLibrary.getLength() != 0 && aModule.getLength() != 0 && aMethod.getLength() != 0 ) + aLocation = getLocationFromURI( scriptURI ); + + if ( aLibrary.getLength() != 0 && aModule.getLength() != 0 && aMethod.getLength() != 0 && aLocation.getLength() != 0 ) { - if ( m_pBasicManager ) + BasicManager* pBasicMgr = NULL; + if ( aLocation.equals( ::rtl::OUString::createFromAscii("document") ) ) + { + pBasicMgr = m_pDocBasicManager; + } + else if ( aLocation.equals( ::rtl::OUString::createFromAscii("application") ) ) + { + pBasicMgr = m_pAppBasicManager; + } + + if ( pBasicMgr ) { - StarBASIC* pBasic = m_pBasicManager->GetLib( aLibrary ); + StarBASIC* pBasic = pBasicMgr->GetLib( aLibrary ); if ( !pBasic ) { - USHORT nId = m_pBasicManager->GetLibId( aLibrary ); - m_pBasicManager->LoadLib( nId ); - pBasic = m_pBasicManager->GetLib( aLibrary ); + USHORT nId = pBasicMgr->GetLibId( aLibrary ); + pBasicMgr->LoadLib( nId ); + pBasic = pBasicMgr->GetLib( aLibrary ); } if ( pBasic ) { @@ -346,22 +423,81 @@ namespace basprov { ::osl::MutexGuard aGuard( StarBASIC::GetGlobalMutex() ); + Reference< script::XLibraryContainer > xLibContainer; + Reference< script::XLibraryContainer2 > xLibContainer2; + BasicManager* pBasicManager = NULL; + + if ( m_bIsAppScriptCtx ) + { + xLibContainer = m_xLibContainerApp; + pBasicManager = m_pAppBasicManager; + } + else + { + xLibContainer = m_xLibContainerDoc; + pBasicManager = m_pDocBasicManager; + } + xLibContainer2 = Reference< script::XLibraryContainer2 >( xLibContainer, UNO_QUERY ); + Sequence< Reference< browse::XBrowseNode > > aChildNodes; - if ( m_pBasicManager && m_xLibContainer.is() ) + if ( pBasicManager && xLibContainer.is() && xLibContainer2.is() ) { - Sequence< ::rtl::OUString > aLibNames = m_xLibContainer->getElementNames(); + Sequence< ::rtl::OUString > aLibNames = xLibContainer->getElementNames(); sal_Int32 nLibCount = aLibNames.getLength(); const ::rtl::OUString* pLibNames = aLibNames.getConstArray(); aChildNodes.realloc( nLibCount ); Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray(); - + sal_Int32 childsFound = 0; for ( sal_Int32 i = 0 ; i < nLibCount ; ++i ) { - pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicLibraryNodeImpl( m_pBasicManager, m_xLibContainer, pLibNames[i] ) ); + if ( m_bIsAppScriptCtx ) + { + sal_Bool isLibLink = false; + try + { + isLibLink = xLibContainer2->isLibraryLink( pLibNames[i] ); + + } + catch( container::NoSuchElementException e ) + { + // TO DO can we do anything here??? + continue; + } + // TO DO need to look at this + // np - if this Provider has been created with an application + // context then we need to display scripts for the user or + // share area ( this depends on the directory the Provider was + // initialised with ). In basic however it seems that scripts in + // the user area means more or less that the libraries that + // contain the scripts are not links. The share area is + // nothing more than an arbitrary directory contains libraries + // and is referenced by a link. So effectively there is no + // concept of a "share" directory with basic. For this reason + // the script framework will represent any script not in + // user area under the share node ( needs revisiting ) + + if ( m_bIsUserCtx && ( isLibLink == sal_False ) ) + { + pChildNodes[childsFound++] = static_cast< browse::XBrowseNode* >( new BasicLibraryNodeImpl( pBasicManager, xLibContainer, pLibNames[i],m_bIsAppScriptCtx ) ); + continue; + } + if ( !m_bIsUserCtx && ( isLibLink == sal_True ) ) + { + pChildNodes[childsFound++] = static_cast< browse::XBrowseNode* >( new BasicLibraryNodeImpl( pBasicManager, xLibContainer, pLibNames[i],m_bIsAppScriptCtx ) ); + continue; + } + } + else + { + pChildNodes[childsFound++] = static_cast< browse::XBrowseNode* >( new BasicLibraryNodeImpl( pBasicManager, xLibContainer, pLibNames[i],m_bIsAppScriptCtx ) ); + } + } + if ( i != childsFound ) + { + aChildNodes.realloc( childsFound ); } } - return aChildNodes; } @@ -372,8 +508,17 @@ namespace basprov ::osl::MutexGuard aGuard( StarBASIC::GetGlobalMutex() ); sal_Bool bReturn = sal_False; - if ( m_xLibContainer.is() ) - bReturn = m_xLibContainer->hasElements(); + Reference< script::XLibraryContainer > xLibContainer; + if ( m_bIsAppScriptCtx ) + { + xLibContainer = m_xLibContainerApp; + } + else + { + xLibContainer = m_xLibContainerDoc; + } + if ( xLibContainer.is() ) + bReturn = xLibContainer->hasElements(); return bReturn; } diff --git a/scripting/source/basprov/basprov.hxx b/scripting/source/basprov/basprov.hxx index 06b9c90626af..5b1610b7a4c6 100644 --- a/scripting/source/basprov/basprov.hxx +++ b/scripting/source/basprov/basprov.hxx @@ -2,9 +2,9 @@ * * $RCSfile: basprov.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: tbe $ $Date: 2003-09-23 10:07:04 $ + * last change: $Author: npower $ $Date: 2003-10-15 08:35:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -110,10 +110,17 @@ namespace basprov class BasicProviderImpl : public BasicProviderImpl_BASE { private: - BasicManager* m_pBasicManager; - ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer > m_xLibContainer; + BasicManager* m_pAppBasicManager; + BasicManager* m_pDocBasicManager; + ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer > m_xLibContainerApp; + ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer > m_xLibContainerDoc; ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xScriptingContext; + bool m_bIsAppScriptCtx; + bool m_bIsUserCtx; + ::rtl::OUString m_sCtxLocation; + + ::rtl::OUString getLocationFromURI( const ::rtl::OUString& scriptURI ); public: BasicProviderImpl( |