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

Gergo Mocsi gmocsi91 at gmail.com
Thu Aug 8 09:11:08 PDT 2013


 basctl/source/basicide/baside2.hxx  |    2 
 basctl/source/basicide/baside2b.cxx |   76 +++++++++++++++++++++++++++---------
 2 files changed, 60 insertions(+), 18 deletions(-)

New commits:
commit 0064a463371d3a41ccd7b01398b2f3a92c61367c
Author: Gergo Mocsi <gmocsi91 at gmail.com>
Date:   Thu Aug 8 18:02:02 2013 +0200

    GSOC work, TAB key inserts match+code fixes
    
    Feature: TAB key now inserts the matching entry. When the TAB key is pressed simultaneously, it selects+inserts the next match.
    Fixed some duplicate code calls.
    Added a function called CodeCompleteListBox::GetParentEditWiew() to shorter the parent's ExtTextView variable access.
    
    Change-Id: I2ae2eaa07fff760d91d05120439c76b215fcd3c1

diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index 8f96116..4c4ac34 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -490,6 +490,7 @@ friend class CodeCompleteWindow;
 friend class EditorWindow;
 private:
     OUStringBuffer aFuncBuffer;
+    OUString aPrevStr;
     /* a buffer to build up function name when typing
      * a function name, used for showing/hiding listbox values
      * */
@@ -497,6 +498,7 @@ private:
 
     void SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable
     void HideAndRestoreFocus();
+    ExtTextView* GetParentEditView();
 
 public:
     CodeCompleteListBox( CodeCompleteWindow* pPar );
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index b9f0cad..49f9058 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -2544,34 +2544,33 @@ IMPL_LINK_NOARG(CodeCompleteListBox, ImplSelectHdl)
     return 0;
 }
 
+ExtTextView* CodeCompleteListBox::GetParentEditView()
+{
+    return pCodeCompleteWindow->pParent->GetEditView();
+}
+
 void CodeCompleteListBox::InsertSelectedEntry()
 {
     if( !aFuncBuffer.toString().isEmpty() )
     {
         // if the user typed in something: remove, and insert
-        TextPaM aEnd(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->GetTextSelection().GetEnd().GetIndex() + aFuncBuffer.getLength());
-        TextPaM aStart(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->GetTextSelection().GetEnd().GetIndex() );
-        pCodeCompleteWindow->pParent->GetEditView()->SetSelection(TextSelection(aStart, aEnd));
-        pCodeCompleteWindow->pParent->GetEditView()->DeleteSelected();
+        TextPaM aEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
+        GetParentEditView()->SetSelection(TextSelection(pCodeCompleteWindow->GetTextSelection().GetStart(), aEnd ) );
+        GetParentEditView()->DeleteSelected();
 
         if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() )
         {//if the user selected something
-            pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
-            HideAndRestoreFocus();
-        }
-        else
-        {
-            HideAndRestoreFocus();
+            GetParentEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
         }
     }
     else
     {
         if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() )
         {//if the user selected something
-            pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
-            HideAndRestoreFocus();
+            GetParentEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
         }
     }
+    HideAndRestoreFocus();
 }
 
 void CodeCompleteListBox::SetMatchingEntries()
@@ -2587,10 +2586,12 @@ void CodeCompleteListBox::SetMatchingEntries()
     }
 }
 
+
 void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
 {
     sal_Unicode aChar = rKeyEvt.GetKeyCode().GetCode();
-    if( ( aChar >= KEY_A ) && ( aChar <= KEY_Z ) )
+    if( (( aChar >= KEY_A ) && ( aChar <= KEY_Z ))
+        || ((aChar >= KEY_0) && (aChar <= KEY_9)) )
     {
         aFuncBuffer.append(rKeyEvt.GetCharCode());
         SetMatchingEntries();
@@ -2602,19 +2603,58 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
             case KEY_ESCAPE: // hide, do nothing
                 HideAndRestoreFocus();
                 break;
-            case KEY_TAB: case KEY_SPACE:
+            case KEY_TAB:
+                if( !aFuncBuffer.isEmpty() )
+                {
+                    sal_uInt16 nInd = GetSelectEntryPos();
+                    if( nInd+1 != 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 )
+                        {
+                            OUString sEntry = (OUString) GetEntry(i);
+                            if( sEntry.startsWithIgnoreAsciiCase( aFuncBuffer.toString() ) )
+                            {
+                                SelectEntry( sEntry );
+                                bFound = true;
+                                break;
+                            }
+                        }
+                        if( !bFound )
+                            SetMatchingEntries();
+
+                        TextPaM aEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
+                        GetParentEditView()->SetSelection(TextSelection(pCodeCompleteWindow->GetTextSelection().GetStart(), aEnd ) );
+                        GetParentEditView()->DeleteSelected();
+                        GetParentEditView()->InsertText( GetSelectEntry(), sal_False );
+                    }
+                }
+                break;
+            case KEY_SPACE:
                 HideAndRestoreFocus();
                 break;
             case KEY_BACKSPACE: case KEY_DELETE:
-                if( aFuncBuffer.toString() != OUString("") )
+                if( !aFuncBuffer.toString().isEmpty() )
                 {
+                    //if there was something inserted by tab: add it to aFuncBuffer
+                    TextSelection aSel( GetParentEditView()->GetSelection() );
+                    TextPaM aEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
+                    GetParentEditView()->SetSelection(TextSelection(pCodeCompleteWindow->GetTextSelection().GetStart(), aEnd ) );
+                    OUString aTabInsertedStr( ((OUString)GetParentEditView()->GetSelected()) );
+                    GetParentEditView()->SetSelection( aSel );
+
+                    if( !aTabInsertedStr.isEmpty() && aTabInsertedStr != aFuncBuffer.toString() )
+                    {
+                        aFuncBuffer.makeStringAndClear();
+                        aFuncBuffer = aFuncBuffer.append(aTabInsertedStr);
+                    }
                     aFuncBuffer = aFuncBuffer.remove(aFuncBuffer.getLength()-1, 1);
                     SetMatchingEntries();
                 }
                 else
-                {
                     pCodeCompleteWindow->ClearAndHide();
-                }
                 break;
             case KEY_RETURN:
                 InsertSelectedEntry();
@@ -2631,7 +2671,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
 void CodeCompleteListBox::HideAndRestoreFocus()
 {
     pCodeCompleteWindow->Hide();
-    pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
+    GetParentEditView()->SetSelection( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
     pCodeCompleteWindow->pParent->GrabFocus();
 }
 


More information about the Libreoffice-commits mailing list