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
This commit is contained in:
Gergo Mocsi
2013-06-24 16:02:24 +02:00
parent 025e7ff3e1
commit 6f516edc50
2 changed files with 54 additions and 6 deletions

View File

@@ -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

View File

@@ -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()
@@ -513,13 +515,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 );
if( xRefl.is() )
{
Reference< reflection::XIdlClass > xClass = xRefl->forName(aCodeCompleteCache[j].sVarType);
if( !xRefl.is() )
break;
if( xClass != NULL )
{
Sequence< Reference< reflection::XIdlMethod > > aMethods = xClass->getMethods();
aListBox->Clear();
for(sal_Int32 i = 0; i < aMethods.getLength(); ++i)
{
SAL_WARN("method information",aMethods[i]->getName());
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;
}
@@ -2291,6 +2307,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