diff options
author | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-19 16:18:10 +0200 |
---|---|---|
committer | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-19 16:18:10 +0200 |
commit | 59bbf4b37f8572c3fa65bedbc4013fc0ef844c42 (patch) | |
tree | bbe9611b568fbb6fff08e1415aa4ac514da38200 /basic/source/classes/codecompletecache.cxx | |
parent | 9dfcb24d5ec5d38d2362297d62dec46ae02d2359 (diff) |
GSOC work, enable interface name usage instead of it's full namefeature/gsoc-basic-ide-completion-and-other-bits
From now, interfaces/structs/enums can be used as types in BASIC IDE.
This example illustrates the feature the best:
dim aPicker as star.ui.dialogs.XFilePicker
dim aPicker2 as sun.star.ui.dialogs.XFilePicker
dim aPicker3 as com.sun.star.ui.dialogs.XFilePicker
dim aPicker4 as css.ui.dialogs.XFilePicker
dim aPicker5 as ui.dialogs.XFilePicker
dim aPicker6 as XFilePicker
Any of the definitions above are accepted (css is shorthand for com.sun.star).
Change-Id: I1ac2196f21ba0950d2932ef5bc11a1d5d2346b4c
Diffstat (limited to 'basic/source/classes/codecompletecache.cxx')
-rw-r--r-- | basic/source/classes/codecompletecache.cxx | 83 |
1 files changed, 74 insertions, 9 deletions
diff --git a/basic/source/classes/codecompletecache.cxx b/basic/source/classes/codecompletecache.cxx index 71de600c0af0..ee5bd08d703e 100644 --- a/basic/source/classes/codecompletecache.cxx +++ b/basic/source/classes/codecompletecache.cxx @@ -21,6 +21,22 @@ #include <iostream> #include <rtl/instance.hxx> #include <officecfg/Office/BasicIDE.hxx> +#include "com/sun/star/reflection/XIdlReflection.hpp" +#include <comphelper/namedvaluecollection.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/configurationhelper.hxx> +#include "com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp" +#include "com/sun/star/reflection/XIdlMethod.hpp" +#include "com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp" +#include "com/sun/star/reflection/XTypeDescription.hpp" +#include "com/sun/star/reflection/TypeDescriptionSearchDepth.hpp" +#include "com/sun/star/uno/Exception.hpp" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/uno/TypeClass.hpp" +#include "com/sun/star/container/XHierarchicalNameAccess.hpp" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; namespace { @@ -97,21 +113,70 @@ void CodeCompleteOptions::SetAutoCorrectOn( const bool& b ) theCodeCompleteOptions::get().bIsAutoCorrectOn = b; } -OUString CodeCompleteOptions::AddUnoPrefix( const OUString& sTypeName ) +OUString CodeCompleteOptions::GetUnoType( const OUString& sTypeName ) { + //returns the fully qualified UNO type name if exsists, else empty string OUString sNewTypeName = sTypeName; if( sNewTypeName.toAsciiLowerCase().startsWith("css.") ) - {//enables shorthand "css" instead of "com.sun.star" - sNewTypeName = sNewTypeName.replaceFirst("css","com.sun.star"); - } - else + //enables shorthand "css" instead of "com.sun.star" + sNewTypeName = sNewTypeName.replaceFirst("css.",""); + //if "com.sun.star" or any of it left out, add it + else if( sNewTypeName.toAsciiLowerCase().startsWith("com.sun.star.") ) + sNewTypeName = sNewTypeName.replaceFirst("com.sun.star.",""); + + else if( sNewTypeName.toAsciiLowerCase().startsWith("sun.star.") ) + sNewTypeName = sNewTypeName.replaceFirst("sun.star.",""); + + else if( sNewTypeName.toAsciiLowerCase().startsWith("star.") ) + sNewTypeName = sNewTypeName.replaceFirst("star.",""); + + try { - if( !sNewTypeName.toAsciiLowerCase().startsWith("com.sun.star.") ) - {//if "com.sun.star" left out, add it - sNewTypeName = OUString("com.sun.star.") + sTypeName; + Reference< container::XHierarchicalNameAccess > xAccess; + Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() ); + if( xContext.is() ) + { + xContext->getValueByName( + OUString( "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ) + >>= xAccess; + OSL_ENSURE( xAccess.is(), "### TypeDescriptionManager singleton not accessible!?" ); } + if( xAccess.is() ) + { + uno::Sequence< uno::TypeClass > aParams(3); + aParams[0] = uno::TypeClass_INTERFACE; + aParams[1] = uno::TypeClass_STRUCT; + aParams[2] = uno::TypeClass_ENUM; + Reference< reflection::XTypeDescriptionEnumeration > sxEnum; + Reference< reflection::XTypeDescriptionEnumerationAccess> xTypeEnumAccess( xAccess, UNO_QUERY ); + if ( xTypeEnumAccess.is() ) + { + try + { + sxEnum = xTypeEnumAccess->createTypeDescriptionEnumeration( + "com.sun.star", aParams, reflection::TypeDescriptionSearchDepth_INFINITE ); + + Reference< reflection::XTypeDescription > xDesc = sxEnum->nextTypeDescription(); + //check the modules + while( sxEnum->hasMoreElements() ) + { + if( xDesc->getName().endsWithIgnoreAsciiCase(sNewTypeName) ) + { + return xDesc->getName(); + } + + xDesc = sxEnum->nextTypeDescription(); + } + } + catch( const Exception& ex ) { return OUString(""); } + } + } + } + catch( const Exception& ex ) + { + OSL_FAIL("Could not create com.sun.star.reflection.TypeDescriptionManager"); } - return sNewTypeName; + return OUString(""); } std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache) |