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

Gergo Mocsi gmocsi91 at gmail.com
Tue Aug 13 09:22:15 PDT 2013


 basctl/source/basicide/baside2b.cxx                          |   56 ++++++++---
 basic/source/classes/codecompletecache.cxx                   |    2 
 basic/source/classes/sbxmod.cxx                              |    5 
 basic/source/comp/parser.cxx                                 |    1 
 basic/source/comp/token.cxx                                  |   21 ++++
 basic/source/inc/token.hxx                                   |    1 
 cui/source/options/optbasic.cxx                              |   14 +-
 cui/source/options/optbasic.hxx                              |    2 
 cui/uiconfig/ui/optbasicidepage.ui                           |    5 
 include/basic/sbmod.hxx                                      |    1 
 officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs |    4 
 11 files changed, 87 insertions(+), 25 deletions(-)

New commits:
commit 2795bc817f1e783570c28428cec8e07b35cce7bb
Author: Gergo Mocsi <gmocsi91 at gmail.com>
Date:   Tue Aug 13 18:11:26 2013 +0200

    GSOC work, behavior fixes
    
    Code completition: left/right arrow keys handled. Left arrow dismisses the dialog when reaches the dot. Right arrow dismissed the dialog when reaches the next line.
    ListBox appearance fixed.
    TAB key can insert the first matching entry.
    Autocorrect:
    "Autocorrect Keywords" has been renamed to "Autcorrect" (in the UI, and the config file, after this patch a make dev-install is needed). Keyword case correction is not just capitalizing the first letter ( eg. Elseif -> ElseIf ).
    Autoclose procedures:
    cursor is being placed inside the preocedure.
    
    Change-Id: Ie7e9ae96b49bd94562db83f96e1c4ad63ab3f3d6

diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 49f9058..c0c4046 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -530,8 +530,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
        HandleProcedureCompletition();
     }
 
-    if( rKEvt.GetKeyCode().GetCode() == KEY_POINT &&
-        (CodeCompleteOptions::IsCodeCompleteOn() || CodeCompleteOptions::IsExtendedTypeDeclaration()) )
+    if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && CodeCompleteOptions::IsCodeCompleteOn() )
     {
         HandleCodeCompletition();
     }
@@ -596,9 +595,13 @@ void EditorWindow::HandleAutoCorrect()
         OUString sStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin);
         if( !sStr.isEmpty() )
         {
-            //capitalize first letter and replace
             sStr = sStr.toAsciiLowerCase();
-            sStr = sStr.replaceAt( 0, 1, OUString(sStr[0]).toAsciiUpperCase() );
+            if( !rModulWindow.GetSbModule()->GetKeywordCase(sStr).isEmpty() )
+            // if it is a keyword, get its correct case
+                sStr = rModulWindow.GetSbModule()->GetKeywordCase(sStr);
+            else
+            // else capitalize first letter/select the correct one, and replace
+                sStr = sStr.replaceAt( 0, 1, OUString(sStr[0]).toAsciiUpperCase() );
 
             TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sStr.getLength() );
             TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex()));
@@ -684,13 +687,17 @@ void EditorWindow::HandleProcedureCompletition()
         return;// no sub/function keyword or there is no identifier
 
     OUString sText("\nEnd ");
+    aSel = GetEditView()->GetSelection();
     if( sProcType.equalsIgnoreAsciiCase("function") )
         sText += OUString( "Function\n" );
     if( sProcType.equalsIgnoreAsciiCase("sub") )
         sText += OUString( "Sub\n" );
 
     if( nLine+1 == pEditEngine->GetParagraphCount() )
+    {
         pEditView->InsertText( sText );//append to the end
+        GetEditView()->SetSelection(aSel);
+    }
     else
     {
         for( sal_uLong i = nLine+1; i < pEditEngine->GetParagraphCount(); ++i )
@@ -708,7 +715,8 @@ void EditorWindow::HandleProcedureCompletition()
                 {
                     if( sStr.equalsIgnoreAsciiCase("sub") || sStr.equalsIgnoreAsciiCase("function") )
                     {
-                        pEditView->InsertText( sText );
+                        pEditView->InsertText( sText );//append to the end
+                        GetEditView()->SetSelection(aSel);
                         break;
                     }
                     if( sStr.equalsIgnoreAsciiCase("end") )
@@ -729,15 +737,16 @@ void EditorWindow::HandleCodeCompletition()
     std::vector< OUString > aVect; //vector to hold the base variable+methods for the nested reflection
 
     HighlightPortions aPortions;
+    aLine = aLine.copy(0, aSel.GetEnd().GetIndex());
     aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
     if( aPortions.size() > 0 )
     {//use the syntax highlighter to grab out nested reflection calls, eg. aVar.aMethod("aa").aOtherMethod ..
-        for( auto aIt = aPortions.crbegin(); aIt != aPortions.crend(); ++aIt )
+        for( HighlightPortions::reverse_iterator aIt = aPortions.rbegin(); aIt != aPortions.rend(); ++aIt )
         {
             HighlightPortion r = *aIt;
-            if( r.tokenType == 2 ) // a whitespace: stop; if there is no ws, it goes to the beginning of the line
+            if( r.tokenType == TT_WHITESPACE ) // a whitespace: stop; if there is no ws, it goes to the beginning of the line
                 break;
-            if( r.tokenType == 1 || r.tokenType == 9 ) // extract the identifers(methods, base variable)
+            if( r.tokenType == TT_IDENTIFIER || r.tokenType == TT_KEYWORDS ) // 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(?!)
              * */
@@ -2603,19 +2612,43 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
             case KEY_ESCAPE: // hide, do nothing
                 HideAndRestoreFocus();
                 break;
+            case KEY_RIGHT:
+            {
+                TextSelection aTextSelection( GetParentEditView()->GetSelection() );
+                if( aTextSelection.GetEnd().GetPara() != pCodeCompleteWindow->GetTextSelection().GetEnd().GetPara() )
+                {
+                    HideAndRestoreFocus();
+                }
+                break;
+            }
+            case KEY_LEFT:
+            {
+                TextSelection aTextSelection( GetParentEditView()->GetSelection() );
+                if( aTextSelection.GetStart().GetIndex()-1 < pCodeCompleteWindow->GetTextSelection().GetStart().GetIndex() )
+                {//leave the cursor where it is
+                    pCodeCompleteWindow->Hide();
+                    pCodeCompleteWindow->pParent->GrabFocus();
+                }
+                break;
+            }
             case KEY_TAB:
+            {
+                TextPaM aTextEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
+                TextSelection aTextSelection( pCodeCompleteWindow->GetTextSelection().GetStart(), aTextEnd );
+                OUString sTypedText = pCodeCompleteWindow->pParent->GetEditEngine()->GetText(aTextSelection);
                 if( !aFuncBuffer.isEmpty() )
                 {
                     sal_uInt16 nInd = GetSelectEntryPos();
-                    if( nInd+1 != LISTBOX_ENTRY_NOTFOUND )
+                    if( nInd != LISTBOX_ENTRY_NOTFOUND )
                     {//if there is something selected
                         bool bFound = false;
                         if( nInd == GetEntryCount() )
                             nInd = 0;
-                        for( sal_uInt16 i = nInd+1; i != GetEntryCount(); ++i )
+                        for( sal_uInt16 i = nInd; i != GetEntryCount(); ++i )
                         {
                             OUString sEntry = (OUString) GetEntry(i);
-                            if( sEntry.startsWithIgnoreAsciiCase( aFuncBuffer.toString() ) )
+                            if( sEntry.startsWithIgnoreAsciiCase( aFuncBuffer.toString() )
+                                && (aFuncBuffer.toString() != sTypedText) && (i != nInd) )
                             {
                                 SelectEntry( sEntry );
                                 bFound = true;
@@ -2632,6 +2665,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
                     }
                 }
                 break;
+            }
             case KEY_SPACE:
                 HideAndRestoreFocus();
                 break;
diff --git a/basic/source/classes/codecompletecache.cxx b/basic/source/classes/codecompletecache.cxx
index 1729543..999c324 100644
--- a/basic/source/classes/codecompletecache.cxx
+++ b/basic/source/classes/codecompletecache.cxx
@@ -29,7 +29,7 @@ namespace
 
 CodeCompleteOptions::CodeCompleteOptions()
 {
-    bIsAutoCorrectKeywordsOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::get();
+    bIsAutoCorrectKeywordsOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
     bIsAutoCloseParenthesisOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
     bIsAutoCloseQuotesOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
     bIsProcedureAutoCompleteOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index 053c13e..a3fa779 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -1832,6 +1832,11 @@ SbxArrayRef SbModule::GetMethods()
     return pMethods;
 }
 
+OUString SbModule::GetKeywordCase( const OUString& sKeyword ) const
+{
+    return SbiParser::GetKeywordCase( sKeyword );
+}
+
 bool SbModule::HasExeCode()
 {
     // And empty Image always has the Global Chain set up
diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx
index 348b908..6301d9e 100644
--- a/basic/source/comp/parser.cxx
+++ b/basic/source/comp/parser.cxx
@@ -155,7 +155,6 @@ SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
 
 }
 
-
 // part of the runtime-library?
 SbiSymDef* SbiParser::CheckRTLForSym( const OUString& rSym, SbxDataType eType )
 {
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index 0da1c51..40b1c67 100644
--- a/basic/source/comp/token.cxx
+++ b/basic/source/comp/token.cxx
@@ -547,4 +547,25 @@ bool SbiTokenizer::MayBeLabel( bool bNeedsColon )
     }
 }
 
+
+OUString SbiTokenizer::GetKeywordCase( const OUString& sKeyword )
+{
+    if( !nToken )
+    {
+        TokenTable *tp;
+        for( nToken = 0, tp = pTokTable; tp->t; nToken++, tp++ )
+        {}
+    }
+    TokenTable* tp = pTokTable;
+    for( short i = 0; i < nToken; i++, tp++ )
+    {
+        OUString sStr = OStringToOUString(tp->s, RTL_TEXTENCODING_ASCII_US);
+        if( sStr.equalsIgnoreAsciiCase(sKeyword) )
+        {
+            return sStr;
+        }
+    }
+    return OUString("");
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/inc/token.hxx b/basic/source/inc/token.hxx
index 0ce9cf4..cf127bc 100644
--- a/basic/source/inc/token.hxx
+++ b/basic/source/inc/token.hxx
@@ -167,6 +167,7 @@ public:
         { return t >= FIRSTKWD && t <= LASTKWD; }
     static bool IsExtra( SbiToken t )
         { return t >= FIRSTEXTRA; }
+    static OUString GetKeywordCase( const OUString& sKeyword );
 };
 
 
diff --git a/cui/source/options/optbasic.cxx b/cui/source/options/optbasic.cxx
index 93d8fc5..717f526 100644
--- a/cui/source/options/optbasic.cxx
+++ b/cui/source/options/optbasic.cxx
@@ -39,7 +39,7 @@ SvxBasicIDEOptionsPage::SvxBasicIDEOptionsPage( Window* pParent, const SfxItemSe
     get(pAutocloseProcChk, "autoclose_proc");
     get(pAutocloseParenChk, "autoclose_paren");
     get(pAutocloseQuotesChk, "autoclose_quotes");
-    get(pAutoCorrectKeywordsChk, "autocorrect_keywords");
+    get(pAutoCorrectChk, "autocorrect");
     get(pUseExtendedTypesChk, "extendedtypes_enable");
 
     LoadConfig();
@@ -57,13 +57,13 @@ void SvxBasicIDEOptionsPage::LoadConfig()
     bool bCodeCompleteOn = officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
     bool bParenClose = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
     bool bQuoteClose = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
-    bool bCorrect = officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::get();
+    bool bCorrect = officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
 
     pCodeCompleteChk->Check( bCodeCompleteOn );
     pAutocloseProcChk->Check( bProcClose );
     pAutocloseQuotesChk->Check( bQuoteClose );
     pAutocloseParenChk->Check( bParenClose );
-    pAutoCorrectKeywordsChk->Check( bCorrect );
+    pAutoCorrectChk->Check( bCorrect );
     pUseExtendedTypesChk->Check( bExtended );
 }
 
@@ -75,7 +75,7 @@ void SvxBasicIDEOptionsPage::SaveConfig()
     officecfg::Office::BasicIDE::Autocomplete::UseExtended::set( pUseExtendedTypesChk->IsChecked(), batch );
     officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::set( pAutocloseParenChk->IsChecked(), batch );
     officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::set( pAutocloseQuotesChk->IsChecked(), batch );
-    officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::set( pAutoCorrectKeywordsChk->IsChecked(), batch );
+    officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::set( pAutoCorrectChk->IsChecked(), batch );
     batch->commit();
 }
 
@@ -123,10 +123,10 @@ sal_Bool SvxBasicIDEOptionsPage::FillItemSet( SfxItemSet& /*rCoreSet*/ )
         bModified = sal_True;
     }
 
-    if( pAutoCorrectKeywordsChk->IsChecked() != pAutoCorrectKeywordsChk->GetSavedValue() )
+    if( pAutoCorrectChk->IsChecked() != pAutoCorrectChk->GetSavedValue() )
     {
         boost::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create() );
-        officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::set( pAutoCorrectKeywordsChk->IsChecked(), batch );
+        officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::set( pAutoCorrectChk->IsChecked(), batch );
         batch->commit();
         bModified = sal_True;
     }
@@ -145,7 +145,7 @@ void SvxBasicIDEOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
 
     pAutocloseParenChk->SaveValue();
 
-    pAutoCorrectKeywordsChk->SaveValue();
+    pAutoCorrectChk->SaveValue();
 
     pUseExtendedTypesChk->SaveValue();
 }
diff --git a/cui/source/options/optbasic.hxx b/cui/source/options/optbasic.hxx
index 4265f57..2ca4820 100644
--- a/cui/source/options/optbasic.hxx
+++ b/cui/source/options/optbasic.hxx
@@ -31,7 +31,7 @@ private:
     CheckBox* pAutocloseProcChk;
     CheckBox* pAutocloseParenChk;
     CheckBox* pAutocloseQuotesChk;
-    CheckBox* pAutoCorrectKeywordsChk;
+    CheckBox* pAutoCorrectChk;
     CheckBox* pUseExtendedTypesChk;
 
     void LoadConfig();
diff --git a/cui/uiconfig/ui/optbasicidepage.ui b/cui/uiconfig/ui/optbasicidepage.ui
index 3dde65f..5785ca6 100644
--- a/cui/uiconfig/ui/optbasicidepage.ui
+++ b/cui/uiconfig/ui/optbasicidepage.ui
@@ -126,11 +126,12 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkCheckButton" id="autocorrect_keywords">
-                    <property name="label" translatable="yes">Autocorrect Keywords</property>
+                  <object class="GtkCheckButton" id="autocorrect">
+                    <property name="label" translatable="yes">Autocorrection</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
+                    <property name="relief">none</property>
                     <property name="xalign">0</property>
                     <property name="draw_indicator">True</property>
                   </object>
diff --git a/include/basic/sbmod.hxx b/include/basic/sbmod.hxx
index 543a199..cdeeddf 100644
--- a/include/basic/sbmod.hxx
+++ b/include/basic/sbmod.hxx
@@ -136,6 +136,7 @@ public:
     bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject );
     void GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache);
     SbxArrayRef GetMethods();
+    OUString GetKeywordCase( const OUString& sKeyword ) const;
 };
 
 SV_DECL_IMPL_REF(SbModule)
diff --git a/officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs b/officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs
index 7aecd13..2d8ffc4 100644
--- a/officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs
@@ -56,9 +56,9 @@
             </info>
             <value>false</value>
         </prop>
-        <prop oor:name="AutoCorrectKeywords" oor:type="xs:boolean" oor:nillable="false">
+        <prop oor:name="AutoCorrect" oor:type="xs:boolean" oor:nillable="false">
             <info>
-                <desc>Sets the auto correction of keywords on/off. Default is false.</desc>
+                <desc>Sets the auto correction of keywords, variables, etc. on/off. Default is false.</desc>
             </info>
             <value>false</value>
         </prop>


More information about the Libreoffice-commits mailing list