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

Gergo Mocsi gmocsi91 at gmail.com
Mon Jun 24 07:10:51 PDT 2013


 basctl/source/basicide/baside2.hxx  |   14 ++++++++++
 basctl/source/basicide/baside2b.cxx |   46 +++++++++++++++++++++++++++++++-----
 2 files changed, 54 insertions(+), 6 deletions(-)

New commits:
commit 2274cfb182e1c254b1ecd07d93bad6b421734316
Author: Gergo Mocsi <gmocsi91 at gmail.com>
Date:   Mon Jun 24 16:02:24 2013 +0200

    GSOC work week 3, showing methods in a ListBox
    
    This patch allows the Code Completition feature to list methods in a custom ListBox class called CodeCompleteListBox.
    So, when the user presses the dot("."), a ListBox appears, and listed the methods(not just prints on the terminal).
    The user can select one from them, and it is put in the source code (after the dot).
    
    Change-Id: Ie5165e7bdaae1d96bbf40a9b996ca8ebbdb40dea

diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index fb48ae3..774995d 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -41,6 +41,7 @@ class SvxSearchItem;
 #include <vcl/split.hxx>
 #include <svl/lstner.hxx>
 #include <svtools/colorcfg.hxx>
+#include "vcl/lstbox.hxx"
 
 #include <sfx2/progress.hxx>
 #include <unotools/options.hxx>
@@ -57,6 +58,7 @@ namespace basctl
 {
 
 class ObjectCatalog;
+class CodeCompleteListBox;
 
 DBG_NAMEEX( ModulWindow )
 
@@ -109,6 +111,7 @@ private:
     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
     GetComponentInterface(sal_Bool bCreate = true);
     std::vector< CodeCompleteData > aCodeCompleteCache;
+    CodeCompleteListBox* aListBox;
 
 protected:
     virtual void    Paint( const Rectangle& );
@@ -463,6 +466,17 @@ private:
     } aSyntaxColors;
 };
 
+class CodeCompleteListBox: public ListBox
+{
+private:
+    EditorWindow* pParent; // parent window
+    DECL_LINK(ImplSelectHdl, void*);
+
+public:
+    CodeCompleteListBox(EditorWindow* pPar);
+    virtual ~CodeCompleteListBox();
+};
+
 } // namespace basctl
 
 #endif // BASCTL_BASIDE2_HXX
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index afde040..5d9daf2 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -250,6 +250,7 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) :
     s[0] = OUString( "FontHeight" );
     s[1] = OUString( "FontName" );
     n->addPropertiesChangeListener(s, listener_.get());
+    aListBox = new CodeCompleteListBox(this);
 }
 
 
@@ -271,6 +272,7 @@ EditorWindow::~EditorWindow()
         EndListening( *pEditEngine );
         pEditEngine->RemoveView(pEditView.get());
     }
+    delete aListBox;
 }
 
 OUString EditorWindow::GetWordAtCursor()
@@ -507,13 +509,27 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
             {
                 Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW );
                 Reference< reflection::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW );
-                Reference< reflection::XIdlClass > xClass = xRefl->forName(aCodeCompleteCache[j].sVarType);
-                if( !xRefl.is() )
-                    break;
-                Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
-                for(sal_Int32 i = 0; i < aMethods.getLength(); ++i)
+                if( xRefl.is() )
                 {
-                    SAL_WARN("method information",aMethods[i]->getName());
+                    Reference< reflection::XIdlClass > xClass = xRefl->forName(aCodeCompleteCache[j].sVarType);
+                    if( xClass != NULL  )
+                    {
+                        Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
+                        aListBox->Clear();
+                        for(sal_Int32 i = 0; i < aMethods.getLength(); ++i)
+                        {
+                            aListBox->InsertEntry( OUString(aMethods[i]->getName()) );
+                            SAL_WARN("method information", aMethods[i]->getName());
+                        }
+                        aListBox->EnableAutoSize(true);
+                        aListBox->Show();
+                        aListBox->GetFocus();
+                        aListBox->ToggleDropDown();
+                    }
+                    else
+                    {
+                        SAL_WARN("Type does not exist", aCodeCompleteCache[j].sVarType);
+                    }
                 }
                 break;
             }
@@ -2285,6 +2301,24 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped )
     setBasicWatchMode( false );
 }
 
+CodeCompleteListBox::CodeCompleteListBox(EditorWindow* pPar)
+: ListBox(pPar, WB_DROPDOWN),
+pParent(pPar)
+{
+    SetSelectHdl( LINK(this, CodeCompleteListBox, ImplSelectHdl) );
+}
+
+CodeCompleteListBox::~CodeCompleteListBox()
+{
+}
+
+IMPL_LINK_NOARG(CodeCompleteListBox, ImplSelectHdl)
+{
+    TextSelection aSel = this->pParent->GetEditView()->GetSelection();
+    pParent->GetEditEngine()->ReplaceText(aSel, (OUString) GetEntry(GetSelectEntryPos()) );
+    Clear();
+    return 0;
+}
 
 } // namespace basctl
 


More information about the Libreoffice-commits mailing list