[Libreoffice-commits] core.git: Branch 'feature/gsoc-basic-ide-completion-and-other-bits' - basctl/source basic/source

Gergo Mocsi gmocsi91 at gmail.com
Tue Aug 6 04:23:39 PDT 2013


 basctl/source/basicide/baside2.hxx  |    3 +
 basctl/source/basicide/baside2b.cxx |  106 ++++++++++++++++++++++++------------
 basic/source/comp/dim.cxx           |    5 -
 3 files changed, 77 insertions(+), 37 deletions(-)

New commits:
commit c2ada5c77411b23d86eeaf4d88d153f54e0ef69d
Author: Gergo Mocsi <gmocsi91 at gmail.com>
Date:   Tue Aug 6 11:30:21 2013 +0200

    GSOC work, Extended types correction
    
    Stucts can be autocompleted when extended types disabled.
    Created two functions to make the code brighter. They extract the methods/fields from an XIdlClass and return them in a std::vector<OUString>.
    I had to modify file basic/source/comp/dim.cxx, to check on UNO types when code completition is on.
    
    Change-Id: Id93a6fe896424efb7868f6102985f59fb419b17e

diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index 68f16a1..78932cf 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -53,6 +53,7 @@ class SvxSearchItem;
 
 #include <vcl/textdata.hxx>
 #include <basic/codecompletecache.hxx>
+#include "com/sun/star/reflection/XIdlClass.hpp"
 
 namespace com { namespace sun { namespace star { namespace beans {
     class XMultiPropertySet;
@@ -119,6 +120,8 @@ private:
     CodeCompleteDataCache aCodeCompleteCache;
     boost::scoped_ptr< CodeCompleteWindow > pCodeCompleteWnd;
     OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number
+    std::vector< OUString > GetXIdlClassMethods( ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > xClass ) const;
+    std::vector< OUString > GetXIdlClassFields( ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > xClass ) const;
 
 protected:
     virtual void    Paint( const Rectangle& );
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index eb6666a..e49c97b 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -504,10 +504,11 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
 
     if( pCodeCompleteWnd->IsVisible() && CodeCompleteOptions::IsCodeCompleteOn() )
     {
-        std::cerr << "EditorWindow::KeyInput" << std::endl;
+        //std::cerr << "EditorWindow::KeyInput" << std::endl;
         pCodeCompleteWnd->GetListBox()->KeyInput(rKEvt);
         if( rKEvt.GetKeyCode().GetCode() == KEY_UP
-            || rKEvt.GetKeyCode().GetCode() == KEY_DOWN )
+            || rKEvt.GetKeyCode().GetCode() == KEY_DOWN
+            || rKEvt.GetKeyCode().GetCode() == KEY_TAB )
             return;
     }
 
@@ -666,7 +667,8 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
         }
     }
 
-    if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && CodeCompleteOptions::IsCodeCompleteOn() )
+    if( rKEvt.GetKeyCode().GetCode() == KEY_POINT &&
+        (CodeCompleteOptions::IsCodeCompleteOn() || CodeCompleteOptions::IsExtendedTypeDeclaration()) )
     {
         rModulWindow.UpdateModule();
         rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse(aCodeCompleteCache);
@@ -682,7 +684,10 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
             for ( size_t i = 0; i < aPortions.size(); i++ )
             {
                 HighlightPortion& r = aPortions[i];
-                if( r.tokenType == 1 ) // extract the identifers(methods, base variable)
+                if( r.tokenType == 1 || r.tokenType == 9) // extract the identifers(methods, base variable)
+                /* an example: Dim aLocVar2 as com.sun.star.beans.PropertyValue
+                 * here, aLocVar2.Name, and PropertyValue's Name field is treated as a keyword(?!)
+                 * */
                     aVect.push_back( aLine.copy(r.nBegin, r.nEnd - r.nBegin) );
             }
 
@@ -710,39 +715,51 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
                     while( j != aVect.size() )
                     {
                         sMethName = aVect[j];
-                        Reference< reflection::XIdlMethod> xMethod = xClass->getMethod( sMethName );
-                        if( xMethod != NULL ) //method OK
+                        Reference< reflection::XIdlField> xField = xClass->getField( sMethName );
+                        if( xField != NULL )
                         {
-                            xClass = xMethod->getReturnType();
+                            xClass = xField->getType();
                             if( xClass == NULL )
+                            {
                                 break;
+                            }
                         }
                         else
                         {
-                            bReflect = false;
-                            break;
+                            if( CodeCompleteOptions::IsExtendedTypeDeclaration() )
+                            {
+                                Reference< reflection::XIdlMethod> xMethod = xClass->getMethod( sMethName );
+                                if( xMethod != NULL ) //method OK
+                                {
+                                    xClass = xMethod->getReturnType();
+                                    if( xClass == NULL )
+                                    {
+                                        break;
+                                    }
+                                }
+                                else
+                                {//nothing to reflect
+                                    bReflect = false;
+                                    break;
+                                }
+                            }
+                            else
+                            {// no extended types allowed
+                                bReflect = false;
+                                break;
+                            }
                         }
                         j++;
                     }
                     if( bReflect )
                     {
-                        Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
-                        Sequence< Reference< reflection::XIdlField > > aFields = xClass->getFields();
-                        std::vector< OUString > aEntryVect;
-
-                        if( aMethods.getLength() != 0 )
-                        {
-                            for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
-                            {
-                                aEntryVect.push_back(OUString(aMethods[l]->getName()));
-                            }
-                        }
-                        if( aFields.getLength() != 0 )
-                        {
-                            for(sal_Int32 l = 0; l < aFields.getLength(); ++l)
-                            {
-                                aEntryVect.push_back(OUString(aFields[l]->getName()));
-                            }
+                        std::vector< OUString > aEntryVect;//entries to be inserted into the list
+                        std::vector< OUString > aMethVect = GetXIdlClassMethods(xClass);//methods
+                        std::vector< OUString > aFieldVect = GetXIdlClassFields(xClass);//fields
+                        aEntryVect.insert(aEntryVect.end(), aFieldVect.begin(), aFieldVect.end() );
+                        if( CodeCompleteOptions::IsExtendedTypeDeclaration() )
+                        {// if extended types on, reflect classes, else just the structs (XIdlClass without methods)
+                            aEntryVect.insert(aEntryVect.end(), aMethVect.begin(), aMethVect.end() );
                         }
                         if( aEntryVect.size() > 0 )
                         {
@@ -766,7 +783,6 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
                             pCodeCompleteWnd->ResizeListBox();
                             pCodeCompleteWnd->SelectFirstEntry();
                             pEditView->GetWindow()->GrabFocus();
-                            //pEditView->EnableCursor( true );
                         }
                     }
                 }
@@ -816,6 +832,34 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
     }
 }
 
+std::vector< OUString > EditorWindow::GetXIdlClassMethods( Reference< reflection::XIdlClass > xClass ) const
+{
+    Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
+    std::vector< OUString > aRetVect;
+    if( aMethods.getLength() != 0 )
+    {
+        for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
+        {
+            aRetVect.push_back(OUString(aMethods[l]->getName()));
+        }
+    }
+    return aRetVect;
+}
+
+std::vector< OUString > EditorWindow::GetXIdlClassFields( Reference< reflection::XIdlClass > xClass ) const
+{
+    Sequence< Reference< reflection::XIdlField > > aFields = xClass->getFields();
+    std::vector< OUString > aRetVect;
+    if( aFields.getLength() != 0 )
+    {
+        for(sal_Int32 l = 0; l < aFields.getLength(); ++l)
+        {
+            aRetVect.push_back(OUString(aFields[l]->getName()));
+        }
+    }
+    return aRetVect;
+}
+
 void EditorWindow::Paint( const Rectangle& rRect )
 {
     if ( !pEditEngine )     // We need it now at latest
@@ -2614,7 +2658,7 @@ void CodeCompleteListBox::SetVisibleEntries()
 
 void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
 {
-    std::cerr << "CodeCompleteListBox::KeyInput" << std::endl;
+    //std::cerr << "CodeCompleteListBox::KeyInput" << std::endl;
     sal_Unicode aChar = rKeyEvt.GetKeyCode().GetCode();
     if( ( aChar >= KEY_A ) && ( aChar <= KEY_Z ) )
     {
@@ -2648,13 +2692,9 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
                 InsertSelectedEntry();
                 break;
             case KEY_UP: case KEY_DOWN:
-                std::cerr << "up/down ke in CodeCompleteListBox::KeyInput" << std::endl;
-                //GrabFocus();
+                //std::cerr << "up/down ke in CodeCompleteListBox::KeyInput" << std::endl;
                 NotifyEvent nEvt( EVENT_KEYINPUT, NULL, &rKeyEvt );
                 PreNotify(nEvt);
-                //pCodeCompleteWindow->pParent->GrabFocus();
-                //SetVisibleEntries();
-                //pCodeCompleteWindow->pParent->GrabFocus();
                 break;
         }
     }
diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx
index 9a030cc..2b94c39 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -405,12 +405,9 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
             if( !bCompatible && !pDef->IsNew() )
             {
                 OUString aTypeName( aGblStrings.Find( pDef->GetTypeId() ) );
-                /*std::cerr <<"CodeCompleteOptions::IsExtendedTypeDeclaration():" << CodeCompleteOptions::IsExtendedTypeDeclaration() << std::endl;
-                std::cerr << "IsUnoInterface("<<aTypeName<<"):"<< IsUnoInterface(aTypeName) << std::endl;
-                std::cerr << "finally: " << (CodeCompleteOptions::IsExtendedTypeDeclaration() && !IsUnoInterface(aTypeName)) << std::endl;*/
                 if( rTypeArray->Find( aTypeName, SbxCLASS_OBJECT ) == NULL )
                 {
-                    if(!CodeCompleteOptions::IsExtendedTypeDeclaration())
+                    if(!CodeCompleteOptions::IsCodeCompleteOn())
                         Error( SbERR_UNDEF_TYPE, aTypeName );
                     else
                     {


More information about the Libreoffice-commits mailing list