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

Gergo Mocsi gmocsi91 at gmail.com
Wed Jul 17 15:34:52 PDT 2013


 basctl/source/basicide/baside2.hxx  |   11 ++++
 basctl/source/basicide/baside2b.cxx |   86 +++++++++++++++++++++++++++---------
 2 files changed, 77 insertions(+), 20 deletions(-)

New commits:
commit 002622077bedfc5e1ec4f65bbb57806221d407ff
Author: Gergo Mocsi <gmocsi91 at gmail.com>
Date:   Thu Jul 18 00:25:16 2013 +0200

    GSOC work ListBox show/hide entries when typing function name
    
    ListBox sorts entries alphabetically.
    When typing, filters the matching function names.
    ListBox closes on key tab and space, beacuse I assume the user typed in the
    whole function name.
    
    Change-Id: I045b1b990b0e0af70de75c32249b7497b51b9e98

diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index 51a130c..8bb34cf 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -498,9 +498,20 @@ protected:
 
 class CodeCompleteListBox: public ListBox
 {
+friend class CodeCompleteWindow;
 private:
+    std::vector< OUString > aEntryVect;
+    /* vector to hold all entries for showing/hiding
+     * when typing a letter/word
+     * */
+    OUStringBuffer aFuncBuffer;
+    /* a buffer to build up function name when typing
+     * a function name, used for showing/hiding listbox values
+     * */
     CodeCompleteWindow* pCodeCompleteWindow; // parent window
 
+    void SetVisibleEntries(); // sets the visible entries based on aFuncBuffer variable
+
 public:
     CodeCompleteListBox(CodeCompleteWindow* pPar);
     virtual ~CodeCompleteListBox();
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 1f134d1..3c8fbbe 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -437,8 +437,6 @@ void EditorWindow::MouseButtonUp( const MouseEvent &rEvt )
         pEditView->MouseButtonUp( rEvt );
         if (SfxBindings* pBindings = GetBindingsPtr())
         {
-            /*pBindings->Invalidate( SID_COPY );
-            pBindings->Invalidate( SID_CUT );*/
             pBindings->Invalidate( SID_BASICIDE_STAT_POS );
         }
     }
@@ -554,7 +552,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
                         if( aMethods.getLength() != 0 )
                         {
                             Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
-                            GetEditView()->EnableCursor( false );
+                            //GetEditView()->EnableCursor( false );
 
                             aSel.GetStart().GetIndex() += 1;
                             aSel.GetEnd().GetIndex() += 1;
@@ -565,11 +563,9 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
                             for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
                             {
                                 pCodeCompleteWnd->InsertEntry( OUString(aMethods[l]->getName()) );
-                                //std::cerr << aMethods[l]->getName() << std::endl;
                             }
                             pCodeCompleteWnd->ResizeListBox();
                             pCodeCompleteWnd->Show();
-                            //pCodeCompleteWnd->GrabFocus();
                             pCodeCompleteWnd->SelectFirstEntry();
                         }
                     }
@@ -2382,11 +2378,16 @@ void CodeCompleteListBox::InsertSelectedEntry()
 {
     if( GetEntry( GetSelectEntryPos() ) != OUString("") )
     {
-        pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->GetTextSelection() );
-        pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()) );
-        pCodeCompleteWindow->pParent->GetEditView()->EnableCursor( true );
-        pCodeCompleteWindow->LoseFocus();
+        // if the user typed in something: remove, and insert
+        TextPaM aEnd(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->aTextSelection.GetEnd().GetIndex() + aFuncBuffer.getLength());
+        TextPaM aStart(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->aTextSelection.GetEnd().GetIndex() );
+        pCodeCompleteWindow->pParent->GetEditView()->SetSelection(TextSelection(aStart, aEnd));
+        pCodeCompleteWindow->pParent->GetEditView()->DeleteSelected();
+
+        pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
         pCodeCompleteWindow->Hide();
+        pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
+        pCodeCompleteWindow->pParent->GrabFocus();
     }
 }
 
@@ -2395,21 +2396,64 @@ long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt )
     if( ( rNEvt.GetType() == EVENT_KEYINPUT ) )
     {
         KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
-        switch( aKeyEvt.GetKeyCode().GetCode() )
+        sal_Unicode aChar = aKeyEvt.GetKeyCode().GetCode();
+        if( ( aChar >= KEY_A ) && ( aChar <= KEY_Z ) )
+        {
+            pCodeCompleteWindow->pParent->GetEditView()->InsertText( OUString(aKeyEvt.GetCharCode()) );
+            aFuncBuffer.append(aKeyEvt.GetCharCode());
+            SetVisibleEntries();
+            return 0;
+        }
+        else
         {
-            case KEY_ESCAPE:
-                pCodeCompleteWindow->pParent->GetEditView()->EnableCursor( true );
-                pCodeCompleteWindow->LoseFocus();
-                pCodeCompleteWindow->Hide();
-                return 0;
-            case KEY_RETURN:
-                InsertSelectedEntry();
-                return 0;
+            switch( aChar )
+            {
+                case KEY_ESCAPE: // hide, do nothing
+                    pCodeCompleteWindow->Hide();
+                    pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
+                    pCodeCompleteWindow->pParent->GrabFocus();
+                    return 0;
+                case KEY_TAB: case KEY_SPACE:
+                /* space, tab the user probably have typed in the whole
+                 * procedure name: hide the window, and insert the tab/space
+                 */
+                    pCodeCompleteWindow->pParent->GetEditView()->InsertText( OUString(aKeyEvt.GetCharCode()) );
+                    pCodeCompleteWindow->Hide();
+                    pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
+                    pCodeCompleteWindow->pParent->GrabFocus();
+                    return 0;
+                case KEY_BACKSPACE: case KEY_DELETE:
+                    if( aFuncBuffer.toString() != OUString("") )
+                    {
+                        TextPaM aEnd(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->aTextSelection.GetEnd().GetIndex() + aFuncBuffer.getLength());
+                        TextPaM aStart(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->aTextSelection.GetEnd().GetIndex() + aFuncBuffer.getLength()-1);
+                        aFuncBuffer.stripEnd(aFuncBuffer[aFuncBuffer.getLength()-1]);
+                        pCodeCompleteWindow->pParent->GetEditView()->SetSelection(TextSelection(aStart, aEnd));
+                        pCodeCompleteWindow->pParent->GetEditView()->DeleteSelected();
+                        SetVisibleEntries();
+                    }
+                    return 0;
+                case KEY_RETURN:
+                    InsertSelectedEntry();
+                    return 0;
+            }
         }
     }
     return ListBox::PreNotify( rNEvt );
 }
 
+void CodeCompleteListBox::SetVisibleEntries()
+{
+    Clear();
+    for( unsigned int j=0; j < aEntryVect.size(); ++j )
+    {
+        if( aEntryVect[j].startsWithIgnoreAsciiCase(aFuncBuffer.toString()) )
+        {
+            InsertEntry(aEntryVect[j]);
+        }
+    }
+}
+
 CodeCompleteWindow::CodeCompleteWindow( EditorWindow* pPar )
 : Window( pPar, WB_BORDER ),
 pParent(pPar)
@@ -2434,19 +2478,21 @@ CodeCompleteWindow::~CodeCompleteWindow()
 void CodeCompleteWindow::InsertEntry( const OUString& aStr )
 {
     pListBox->InsertEntry( aStr );
+    pListBox->aEntryVect.push_back( aStr );
 }
 
 void CodeCompleteWindow::ClearListBox()
 {
     pListBox->Clear();
+    pListBox->aEntryVect.clear();
+    pListBox->aFuncBuffer.makeStringAndClear();
 }
 
 void CodeCompleteWindow::KeyInput( const KeyEvent& rKeyEvt )
 {
-    std::cerr << "CodeCompleteWindow::KeyInput" << std::endl;
     if( rKeyEvt.GetKeyCode().GetCode() == KEY_ESCAPE )
     {// ESC key closes the window: does not modify anything
-        pParent->GetEditView()->EnableCursor( true );
+        //pParent->GetEditView()->EnableCursor( true );
         Hide();
     }
 }


More information about the Libreoffice-commits mailing list