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

Gergo Mocsi gmocsi91 at gmail.com
Mon Aug 19 05:01:25 PDT 2013


 basctl/source/basicide/baside2b.cxx        |   29 +++++++++++++++++++++++------
 basic/source/classes/codecompletecache.cxx |    6 +++---
 basic/source/classes/sbxmod.cxx            |   29 ++++++-----------------------
 include/basic/codecompletecache.hxx        |    2 +-
 4 files changed, 33 insertions(+), 33 deletions(-)

New commits:
commit 7ab327e24930a7e6fc3f72fcad94093dee7e2ce3
Author: Gergo Mocsi <gmocsi91 at gmail.com>
Date:   Mon Aug 19 13:53:38 2013 +0200

    GSOC work, autocorrect procedures+variables
    
    Fixed some small issue with the right arrow key in the ListBox.
    Autocorrection now correct all variable types and procedure names.
    
    Change-Id: Iff1abaf10c621aef04772837faa272bb6f987e37

diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index c8bdb63..4584692 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -584,11 +584,12 @@ void EditorWindow::HandleAutoCorrect()
     if( CodeCompleteOptions::IsExtendedTypeDeclaration() )
     {
         rModulWindow.UpdateModule();
-        rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse(aCodeCompleteCache);
+        rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse( aCodeCompleteCache );
     }
     TextSelection aSel = GetEditView()->GetSelection();
     sal_uLong nLine =  aSel.GetStart().GetPara();
     OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified
+    const OUString& sActSubName = GetActualSubName( nLine ); // the actual procedure
 
     HighlightPortions aPortions;
     aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
@@ -619,14 +620,30 @@ void EditorWindow::HandleAutoCorrect()
     }
     if( r.tokenType == TT_IDENTIFIER )
     {// correct uno types
-        OUString sStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin);
-        if( sStr != aCodeCompleteCache.GetCorrectCaseVarName(sStr) )
+        const OUString& sVarName = aLine.copy(r.nBegin, r.nEnd - r.nBegin);
+        if( !aCodeCompleteCache.GetCorrectCaseVarName( sVarName, sActSubName ).isEmpty() )
         {
-            sStr = aCodeCompleteCache.GetCorrectCaseVarName(sStr);
+            const OUString& sStr = aCodeCompleteCache.GetCorrectCaseVarName( sVarName, sActSubName );
             TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sStr.getLength() );
             TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex()));
             pEditEngine->ReplaceText( sTextSelection, sStr );
             pEditView->SetSelection( aSel );
+            return;
+        }
+
+        //autocorrect procedures
+        SbxArray* pArr = rModulWindow.GetSbModule()->GetMethods();
+        for( sal_uInt32 i=0; i< pArr->Count32(); ++i )
+        {
+            if( pArr->Get32(i)->GetName().equalsIgnoreAsciiCase( sVarName ) )
+            {
+                const OUString& sStr = pArr->Get32(i)->GetName();
+                TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sStr.getLength() );
+                TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex()));
+                pEditEngine->ReplaceText( sTextSelection, sStr );
+                pEditView->SetSelection( aSel );
+                return;
+            }
         }
     }
 }
@@ -780,7 +797,7 @@ void EditorWindow::HandleCodeCompletition()
             TextPaM aStart(nLine, aLine.indexOf(sBaseName) );
             TextPaM aEnd(nLine, aLine.indexOf(sBaseName) + sBaseName.getLength() );
             TextSelection sTextSelection(aStart, aEnd);
-            pEditEngine->ReplaceText( sTextSelection, aCodeCompleteCache.GetCorrectCaseVarName(sBaseName) );
+            pEditEngine->ReplaceText( sTextSelection, aCodeCompleteCache.GetCorrectCaseVarName(sBaseName, GetActualSubName(nLine)) );
             pEditView->SetSelection( aSel );
         }
 
@@ -2632,7 +2649,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
             case KEY_RIGHT:
             {
                 TextSelection aTextSelection( GetParentEditView()->GetSelection() );
-                if( aTextSelection.GetEnd().GetPara() != pCodeCompleteWindow->GetTextSelection().GetEnd().GetPara() )
+                if( aTextSelection.GetEnd().GetPara() != pCodeCompleteWindow->GetTextSelection().GetEnd().GetPara()-1 )
                 {
                     HideAndRestoreFocus();
                 }
diff --git a/basic/source/classes/codecompletecache.cxx b/basic/source/classes/codecompletecache.cxx
index 9d78455..a5b9ce6 100644
--- a/basic/source/classes/codecompletecache.cxx
+++ b/basic/source/classes/codecompletecache.cxx
@@ -182,20 +182,20 @@ OUString CodeCompleteDataCache::GetVarType( const OUString& sVarName ) const
     return OUString(""); //not found
 }
 
-OUString CodeCompleteDataCache::GetCorrectCaseVarName( const OUString& sVarName ) const
+OUString CodeCompleteDataCache::GetCorrectCaseVarName( const OUString& sVarName, const OUString& sActProcName ) const
 {
     for( CodeCompleteVarScopes::const_iterator aIt = aVarScopes.begin(); aIt != aVarScopes.end(); ++aIt )
     {
         CodeCompleteVarTypes aTypes = aIt->second;
         for( CodeCompleteVarTypes::const_iterator aOtherIt = aTypes.begin(); aOtherIt != aTypes.end(); ++aOtherIt )
         {
-            if( aOtherIt->first.equalsIgnoreAsciiCase( sVarName ) )
+            if( aOtherIt->first.equalsIgnoreAsciiCase( sVarName ) && aIt->first.equalsIgnoreAsciiCase( sActProcName ) )
             {
                 return aOtherIt->first;
             }
         }
     }
-    //not a local, search global scope
+    // search global scope
     for( CodeCompleteVarTypes::const_iterator aIt = aGlobalVars.begin(); aIt != aGlobalVars.end(); ++aIt )
     {
         if( aIt->first.equalsIgnoreAsciiCase( sVarName ) )
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index a3fa779..567d26f 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -1790,40 +1790,23 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
 
     while( pParser->Parse() ) {}
     SbiSymPool* pPool = pParser->pPool;
-    //CodeCompleteVarTypes aGlobVarTypes;
     aCache.Clear();
     for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i )
     {
         SbiSymDef* pSymDef = pPool->Get(i);
-        //std::cerr << "i: " << i << ", type: " << pSymDef->GetType() << std::endl;
-        if( pSymDef->GetType() == SbxOBJECT )
-        {
-            if( !pParser->aGblStrings.Find( pSymDef->GetTypeId() ).isEmpty() )
-            {
-                //aGlobVarTypes.insert( CodeCompleteVarTypes::value_type( pSymDef->GetName(), pParser->aGblStrings.Find( pSymDef->GetTypeId() ) ) );
-                aCache.InsertGlobalVar( pSymDef->GetName(), pParser->aGblStrings.Find(pSymDef->GetTypeId()) );
-            }
-        }
+        //std::cerr << "i: " << i << ", type: " << pSymDef->GetType() << "; name:" << pSymDef->GetName() << std::endl;
+        if( (pSymDef->GetType() != SbxEMPTY) || (pSymDef->GetType() != SbxNULL) )
+            aCache.InsertGlobalVar( pSymDef->GetName(), pParser->aGblStrings.Find(pSymDef->GetTypeId()) );
 
         SbiSymPool& pChildPool = pSymDef->GetPool();
-        //CodeCompleteVarTypes aLocVarTypes;
         for(sal_uInt16 j = 0; j < pChildPool.GetSize(); ++j )
         {
             SbiSymDef* pChildSymDef = pChildPool.Get(j);
-            //std::cerr << "j: " << j << ", type: " << pChildSymDef->GetType() << std::endl;
-            if( pChildSymDef->GetType() == SbxOBJECT )
-            {
-                if( !pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ).isEmpty() )
-                {
-                    //aLocVarTypes.insert( CodeCompleteVarTypes::value_type( pChildSymDef->GetName(), pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ) ) );
-                    aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), pParser->aGblStrings.Find(pChildSymDef->GetTypeId()) );
-                }
-            }
+            //std::cerr << "j: " << j << ", type: " << pChildSymDef->GetType() << "; name:" << pChildSymDef->GetName() << std::endl;
+            if( (pChildSymDef->GetType() != SbxEMPTY) || (pChildSymDef->GetType() != SbxNULL) )
+                aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), pParser->aGblStrings.Find(pChildSymDef->GetTypeId()) );
         }
-        //aCache.InsertProcedure( pSymDef->GetName(), aLocVarTypes );
     }
-    //aCache.InsertProcedure( CodeCompleteDataCache::GLOB_KEY, aGlobVarTypes );
-
     delete pParser;
 }
 
diff --git a/include/basic/codecompletecache.hxx b/include/basic/codecompletecache.hxx
index d455fa7..e85b0d8 100644
--- a/include/basic/codecompletecache.hxx
+++ b/include/basic/codecompletecache.hxx
@@ -93,7 +93,7 @@ public:
     void InsertGlobalVar( const OUString& sVarName, const OUString& sVarType );
     void InsertLocalVar( const OUString& sProcName, const OUString& sVarName, const OUString& sVarType );
     OUString GetVarType( const OUString& sVarName ) const;
-    OUString GetCorrectCaseVarName( const OUString& sVarName ) const;
+    OUString GetCorrectCaseVarName( const OUString& sVarName, const OUString& sActProcName ) const;
     void print() const; // wrapper for operator<<, prints to std::cerr
     void Clear();
 };


More information about the Libreoffice-commits mailing list