Kaydet (Commit) 6c1854f9 authored tarafından Gergo Mocsi's avatar Gergo Mocsi

GSOC work, code fixes + cache implementation

WARNING: cache implementation gives a link error to it's methods.
Created the cache called CodeCompleteDataCache in file include/basic/codecompletecache.hxx
This class should replace the std::vector< CodeCompleteData > int file baside2b.cxx
When issuing command "make basic", it compiles fine, but, when "make basctl", it gives a link error (ld returned status 1) to CodeCompleteDataCache's methods.

Change-Id: If78c6533b7fb5653cc459d22b80c98d097b886eb
üst 5a615ddf
...@@ -52,6 +52,7 @@ class SvxSearchItem; ...@@ -52,6 +52,7 @@ class SvxSearchItem;
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <vcl/textdata.hxx> #include <vcl/textdata.hxx>
#include <basic/codecompletecache.hxx>
namespace com { namespace sun { namespace star { namespace beans { namespace com { namespace sun { namespace star { namespace beans {
class XMultiPropertySet; class XMultiPropertySet;
...@@ -114,8 +115,10 @@ private: ...@@ -114,8 +115,10 @@ private:
virtual virtual
::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
GetComponentInterface(sal_Bool bCreate = true); GetComponentInterface(sal_Bool bCreate = true);
std::vector< CodeCompleteData > aCodeCompleteCache; //std::vector< CodeCompleteData > aCodeCompleteCache;
CodeCompleteWindow* pCodeCompleteWnd; CodeCompleteDataCache aCodeCompleteCache;
//CodeCompleteWindow* pCodeCompleteWnd;
boost::scoped_ptr< CodeCompleteWindow > pCodeCompleteWnd;
OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number
protected: protected:
...@@ -492,8 +495,9 @@ public: ...@@ -492,8 +495,9 @@ public:
void ResizeListBox(); void ResizeListBox();
void SelectFirstEntry(); //selects first entry in ListBox void SelectFirstEntry(); //selects first entry in ListBox
protected: /*protected:
virtual void KeyInput( const KeyEvent& rKeyEvt ); //virtual void KeyInput( const KeyEvent& rKeyEvt );
virtual void LoseFocus();*/
}; };
class CodeCompleteListBox: public ListBox class CodeCompleteListBox: public ListBox
...@@ -520,6 +524,10 @@ public: ...@@ -520,6 +524,10 @@ public:
DECL_LINK(ImplDoubleClickHdl, void*); DECL_LINK(ImplDoubleClickHdl, void*);
virtual long PreNotify( NotifyEvent& rNEvt ); virtual long PreNotify( NotifyEvent& rNEvt );
/*protected:
virtual void LoseFocus();*/
}; };
} // namespace basctl } // namespace basctl
......
...@@ -232,7 +232,8 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) : ...@@ -232,7 +232,8 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) :
nCurTextWidth(0), nCurTextWidth(0),
bHighlightning(false), bHighlightning(false),
bDoSyntaxHighlight(true), bDoSyntaxHighlight(true),
bDelayHighlight(true) bDelayHighlight(true),
pCodeCompleteWnd(new CodeCompleteWindow(this))
{ {
SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor())); SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
SetPointer( Pointer( POINTER_TEXT ) ); SetPointer( Pointer( POINTER_TEXT ) );
...@@ -250,9 +251,6 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) : ...@@ -250,9 +251,6 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) :
s[0] = OUString( "FontHeight" ); s[0] = OUString( "FontHeight" );
s[1] = OUString( "FontName" ); s[1] = OUString( "FontName" );
n->addPropertiesChangeListener(s, listener_.get()); n->addPropertiesChangeListener(s, listener_.get());
//aListBox = new CodeCompleteListBox(this);
//pCodeCopleteWnd = new CodeCompleteWindow(this);
pCodeCompleteWnd = new CodeCompleteWindow( this );
} }
...@@ -274,8 +272,6 @@ EditorWindow::~EditorWindow() ...@@ -274,8 +272,6 @@ EditorWindow::~EditorWindow()
EndListening( *pEditEngine ); EndListening( *pEditEngine );
pEditEngine->RemoveView(pEditView.get()); pEditEngine->RemoveView(pEditView.get());
} }
delete pCodeCompleteWnd;
} }
OUString EditorWindow::GetWordAtCursor() OUString EditorWindow::GetWordAtCursor()
...@@ -510,7 +506,6 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) ...@@ -510,7 +506,6 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
TextSelection aSel = GetEditView()->GetSelection(); TextSelection aSel = GetEditView()->GetSelection();
sal_uLong nLine = aSel.GetStart().GetPara(); sal_uLong nLine = aSel.GetStart().GetPara();
OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified
OUString aStr = aLine.copy( std::max(aLine.lastIndexOf(" "), aLine.lastIndexOf("\t"))+1 ); // variable name
OUString sActSub = GetActualSubName( nLine ); OUString sActSub = GetActualSubName( nLine );
std::vector< OUString > aVect; std::vector< OUString > aVect;
...@@ -522,18 +517,22 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) ...@@ -522,18 +517,22 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
if( r.tokenType == 1 ) // extract the identifers(methods, base variable) if( r.tokenType == 1 ) // extract the identifers(methods, base variable)
aVect.push_back( aLine.copy(r.nBegin, r.nEnd - r.nBegin) ); aVect.push_back( aLine.copy(r.nBegin, r.nEnd - r.nBegin) );
} }
OUString sBaseName = aVect[0]; OUString sBaseName = aVect[0];//variable name
for( unsigned int i = 0; i < aCodeCompleteCache.size(); ++i) OUString sVarType = aCodeCompleteCache.GetVariableType(sBaseName, sActSub);
{
if( aCodeCompleteCache[i].sVarName.equalsIgnoreAsciiCase( sBaseName ) && /*for( unsigned int i = 0; i < aCodeCompleteCache.size(); ++i)
{*/
/*if( aCodeCompleteCache[i].sVarName.equalsIgnoreAsciiCase( sBaseName ) &&
( aCodeCompleteCache[i].sVarParent == sActSub || aCodeCompleteCache[i].IsGlobal() ) ) ( aCodeCompleteCache[i].sVarParent == sActSub || aCodeCompleteCache[i].IsGlobal() ) )
{*/
if( sVarType != aCodeCompleteCache.NOT_FOUND )
{ {
Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW ); 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::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW );
if( xRefl.is() ) if( xRefl.is() )
{ {
Reference< reflection::XIdlClass > xClass = xRefl->forName(aCodeCompleteCache[i].sVarType);//get the base class for reflection Reference< reflection::XIdlClass > xClass = xRefl->forName(sVarType);//get the base class for reflection
if( xClass != NULL ) if( xClass != NULL )
{ {
unsigned int j = 1; unsigned int j = 1;
...@@ -558,8 +557,6 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) ...@@ -558,8 +557,6 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
if( aMethods.getLength() != 0 ) if( aMethods.getLength() != 0 )
{ {
Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false ); Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
//GetEditView()->EnableCursor( false );
aSel.GetStart().GetIndex() += 1; aSel.GetStart().GetIndex() += 1;
aSel.GetEnd().GetIndex() += 1; aSel.GetEnd().GetIndex() += 1;
pCodeCompleteWnd->ClearListBox(); pCodeCompleteWnd->ClearListBox();
...@@ -570,15 +567,16 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) ...@@ -570,15 +567,16 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
{ {
pCodeCompleteWnd->InsertEntry( OUString(aMethods[l]->getName()) ); pCodeCompleteWnd->InsertEntry( OUString(aMethods[l]->getName()) );
} }
pCodeCompleteWnd->ResizeListBox();
pCodeCompleteWnd->Show(); pCodeCompleteWnd->Show();
pCodeCompleteWnd->ResizeListBox();
pCodeCompleteWnd->SelectFirstEntry(); pCodeCompleteWnd->SelectFirstEntry();
} }
} }
} }
break;
} }
} /*break;
}*/
//}
} }
if ( !bDone && ( !TextEngine::DoesKeyChangeText( rKEvt ) || ImpCanModify() ) ) if ( !bDone && ( !TextEngine::DoesKeyChangeText( rKEvt ) || ImpCanModify() ) )
{ {
...@@ -840,12 +838,12 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) ...@@ -840,12 +838,12 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
ParagraphInsertedDeleted( rTextHint.GetValue(), true ); ParagraphInsertedDeleted( rTextHint.GetValue(), true );
DoDelayedSyntaxHighlight( rTextHint.GetValue() ); DoDelayedSyntaxHighlight( rTextHint.GetValue() );
rModulWindow.UpdateModule(); rModulWindow.UpdateModule();
aCodeCompleteCache = rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse(); aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
} }
else if( rTextHint.GetId() == TEXT_HINT_PARAREMOVED ) else if( rTextHint.GetId() == TEXT_HINT_PARAREMOVED )
{ {
ParagraphInsertedDeleted( rTextHint.GetValue(), false ); ParagraphInsertedDeleted( rTextHint.GetValue(), false );
aCodeCompleteCache = rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse(); aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
} }
else if( rTextHint.GetId() == TEXT_HINT_PARACONTENTCHANGED ) else if( rTextHint.GetId() == TEXT_HINT_PARACONTENTCHANGED )
{ {
...@@ -861,7 +859,7 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) ...@@ -861,7 +859,7 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
} }
else if( rTextHint.GetId() == TEXT_HINT_MODIFIED ) else if( rTextHint.GetId() == TEXT_HINT_MODIFIED )
{ {
aCodeCompleteCache = rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse(); aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
} }
} }
} }
...@@ -884,7 +882,7 @@ OUString EditorWindow::GetActualSubName( sal_uLong nLine ) ...@@ -884,7 +882,7 @@ OUString EditorWindow::GetActualSubName( sal_uLong nLine )
} }
} }
} }
return OUString(""); return aCodeCompleteCache.GLOB_KEY;
} }
void EditorWindow::SetScrollBarRanges() void EditorWindow::SetScrollBarRanges()
...@@ -2363,7 +2361,7 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped ) ...@@ -2363,7 +2361,7 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped )
} }
CodeCompleteListBox::CodeCompleteListBox( CodeCompleteWindow* pPar ) CodeCompleteListBox::CodeCompleteListBox( CodeCompleteWindow* pPar )
: ListBox(pPar, WB_SORT | WB_BORDER), : ListBox(pPar, WB_SORT | WB_BORDER ),
pCodeCompleteWindow(pPar) pCodeCompleteWindow(pPar)
{ {
SetDoubleClickHdl(LINK(this, CodeCompleteListBox, ImplDoubleClickHdl)); SetDoubleClickHdl(LINK(this, CodeCompleteListBox, ImplDoubleClickHdl));
...@@ -2382,7 +2380,7 @@ IMPL_LINK_NOARG(CodeCompleteListBox, ImplDoubleClickHdl) ...@@ -2382,7 +2380,7 @@ IMPL_LINK_NOARG(CodeCompleteListBox, ImplDoubleClickHdl)
void CodeCompleteListBox::InsertSelectedEntry() void CodeCompleteListBox::InsertSelectedEntry()
{ {
if( GetEntry( GetSelectEntryPos() ) != OUString("") ) if( aFuncBuffer.toString() != OUString("") )
{ {
// if the user typed in something: remove, and insert // if the user typed in something: remove, and insert
TextPaM aEnd(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->aTextSelection.GetEnd().GetIndex() + aFuncBuffer.getLength()); TextPaM aEnd(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->aTextSelection.GetEnd().GetIndex() + aFuncBuffer.getLength());
...@@ -2390,16 +2388,35 @@ void CodeCompleteListBox::InsertSelectedEntry() ...@@ -2390,16 +2388,35 @@ void CodeCompleteListBox::InsertSelectedEntry()
pCodeCompleteWindow->pParent->GetEditView()->SetSelection(TextSelection(aStart, aEnd)); pCodeCompleteWindow->pParent->GetEditView()->SetSelection(TextSelection(aStart, aEnd));
pCodeCompleteWindow->pParent->GetEditView()->DeleteSelected(); pCodeCompleteWindow->pParent->GetEditView()->DeleteSelected();
pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True ); if( GetEntry( GetSelectEntryPos() ) != OUString("") )
pCodeCompleteWindow->Hide(); {//if the user selected something
pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) ); pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
pCodeCompleteWindow->pParent->GrabFocus(); pCodeCompleteWindow->Hide();
pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
pCodeCompleteWindow->pParent->GrabFocus();
}
else
{
pCodeCompleteWindow->Hide();
pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
pCodeCompleteWindow->pParent->GrabFocus();
}
}
else
{
if( GetEntry( GetSelectEntryPos() ) != OUString("") )
{//if the user selected something
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();
}
} }
} }
long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt ) long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt )
{ {
if( ( rNEvt.GetType() == EVENT_KEYINPUT ) ) if( rNEvt.GetType() == EVENT_KEYINPUT )
{ {
KeyEvent aKeyEvt = *rNEvt.GetKeyEvent(); KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
sal_Unicode aChar = aKeyEvt.GetKeyCode().GetCode(); sal_Unicode aChar = aKeyEvt.GetKeyCode().GetCode();
...@@ -2445,6 +2462,11 @@ long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt ) ...@@ -2445,6 +2462,11 @@ long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt )
} }
} }
} }
/*if( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
{
//MouseEvent rMEvt = *rNEvt.GetMouseEvent();
std::cerr << "parent active: " << (pCodeCompleteWindow->pParent->IsActive() == sal_True) << std::endl;
}*/
return ListBox::PreNotify( rNEvt ); return ListBox::PreNotify( rNEvt );
} }
...@@ -2460,12 +2482,19 @@ void CodeCompleteListBox::SetVisibleEntries() ...@@ -2460,12 +2482,19 @@ void CodeCompleteListBox::SetVisibleEntries()
} }
} }
/*void CodeCompleteListBox::LoseFocus()
{
std::cerr << "CodeCompleteListBox::LoseFocus" << std::endl;
Window::LoseFocus();
//pCodeCompleteWindow->Hide();
}*/
CodeCompleteWindow::CodeCompleteWindow( EditorWindow* pPar ) CodeCompleteWindow::CodeCompleteWindow( EditorWindow* pPar )
: Window( pPar, WB_BORDER ), : Window( pPar ),
pParent(pPar) pParent(pPar)
{ {
SetSizePixel( Size(151,151) ); //default, later it changes
InitListBox(); InitListBox();
SetSizePixel( Size(150,150) ); //default, later it changes
} }
void CodeCompleteWindow::InitListBox() void CodeCompleteWindow::InitListBox()
...@@ -2473,7 +2502,7 @@ void CodeCompleteWindow::InitListBox() ...@@ -2473,7 +2502,7 @@ void CodeCompleteWindow::InitListBox()
pListBox = new CodeCompleteListBox( this ); pListBox = new CodeCompleteListBox( this );
pListBox->SetSizePixel( Size(150,150) ); //default, this will adopt the line length pListBox->SetSizePixel( Size(150,150) ); //default, this will adopt the line length
pListBox->Show(); pListBox->Show();
pListBox->GrabFocus(); //pListBox->GrabFocus();
} }
CodeCompleteWindow::~CodeCompleteWindow() CodeCompleteWindow::~CodeCompleteWindow()
...@@ -2493,15 +2522,14 @@ void CodeCompleteWindow::ClearListBox() ...@@ -2493,15 +2522,14 @@ void CodeCompleteWindow::ClearListBox()
pListBox->aEntryVect.clear(); pListBox->aEntryVect.clear();
pListBox->aFuncBuffer.makeStringAndClear(); pListBox->aFuncBuffer.makeStringAndClear();
} }
/*
void CodeCompleteWindow::KeyInput( const KeyEvent& rKeyEvt ) void CodeCompleteWindow::KeyInput( const KeyEvent& rKeyEvt )
{ {
if( rKeyEvt.GetKeyCode().GetCode() == KEY_ESCAPE ) if( rKeyEvt.GetKeyCode().GetCode() == KEY_ESCAPE )
{// ESC key closes the window: does not modify anything {// ESC key closes the window: does not modify anything
//pParent->GetEditView()->EnableCursor( true );
Hide(); Hide();
} }
} }*/
void CodeCompleteWindow::SetTextSelection( const TextSelection& aSel ) void CodeCompleteWindow::SetTextSelection( const TextSelection& aSel )
{ {
...@@ -2531,8 +2559,11 @@ void CodeCompleteWindow::ResizeListBox() ...@@ -2531,8 +2559,11 @@ void CodeCompleteWindow::ResizeListBox()
aSize.setWidth( pListBox->CalcSize(aLongestEntry.getLength(),pListBox->GetEntryCount()).getWidth() ); aSize.setWidth( pListBox->CalcSize(aLongestEntry.getLength(),pListBox->GetEntryCount()).getWidth() );
pListBox->SetSizePixel( aSize ); pListBox->SetSizePixel( aSize );
aSize.setWidth( aSize.getWidth() + 1 );
aSize.setHeight( aSize.getHeight() + 1 );
SetSizePixel( aSize ); SetSizePixel( aSize );
} }
//pListBox->GrabFocus();
} }
void CodeCompleteWindow::SelectFirstEntry() void CodeCompleteWindow::SelectFirstEntry()
...@@ -2540,10 +2571,16 @@ void CodeCompleteWindow::SelectFirstEntry() ...@@ -2540,10 +2571,16 @@ void CodeCompleteWindow::SelectFirstEntry()
if( pListBox->GetEntryCount() > 0 ) if( pListBox->GetEntryCount() > 0 )
{ {
pListBox->SelectEntryPos( 0 ); pListBox->SelectEntryPos( 0 );
pListBox->GrabFocus();
} }
//pListBox->GrabFocus();
} }
/*void CodeCompleteWindow::LoseFocus()
{
std::cerr << "CodeCompleteWindow::LoseFocus" << std::endl;
Window::LoseFocus();
}*/
} // namespace basctl } // namespace basctl
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -59,6 +59,7 @@ $(eval $(call gb_Library_add_exception_objects,sb,\ ...@@ -59,6 +59,7 @@ $(eval $(call gb_Library_add_exception_objects,sb,\
basic/source/basmgr/basicmanagerrepository \ basic/source/basmgr/basicmanagerrepository \
basic/source/basmgr/basmgr \ basic/source/basmgr/basmgr \
basic/source/basmgr/vbahelper \ basic/source/basmgr/vbahelper \
basic/source/classes/codecompletecache \
basic/source/classes/errobject \ basic/source/classes/errobject \
basic/source/classes/eventatt \ basic/source/classes/eventatt \
basic/source/classes/global \ basic/source/classes/global \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <basic/codecompletecache.hxx>
const CodeCompleteVarScopes& CodeCompleteDataCache::GetVars() const
{
return aVarScopes;
}
void CodeCompleteDataCache::InsertProcedure( const OUString& sProcName, const CodeCompleteVarTypes& aVarTypes )
{
aVarScopes.insert( CodeCompleteVarScopes::value_type(sProcName, aVarTypes) );
}
void CodeCompleteDataCache::SetVars( const CodeCompleteVarScopes& aScopes )
{
aVarScopes = aScopes;
}
const OUString& CodeCompleteDataCache::GetVariableType( const OUString& sVarName, const OUString& sProcName ) const
{
CodeCompleteVarScopes::const_iterator aIt = aVarScopes.find( sProcName );
if( aIt == aVarScopes.end() )//procedure does not exist
return NOT_FOUND;
CodeCompleteVarTypes aVarTypes = aIt->second;
CodeCompleteVarTypes::const_iterator aOtherIt = aVarTypes.find( sVarName );
if( aOtherIt == aVarTypes.end() )
return NOT_FOUND;
else
return aOtherIt->second;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -90,6 +90,9 @@ typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap; ...@@ -90,6 +90,9 @@ typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap;
::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar ); ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar );
void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue ); void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue );
/*const OUString CodeCompleteDataCache::GLOB_KEY = OUString("global key");
const OUString CodeCompleteDataCache::NOT_FOUND = OUString("not found");*/
class DocObjectWrapper : public DocObjectWrapper_BASE class DocObjectWrapper : public DocObjectWrapper_BASE
{ {
Reference< XAggregation > m_xAggProxy; Reference< XAggregation > m_xAggProxy;
...@@ -1777,9 +1780,11 @@ IMPL_LINK( ErrorHdlResetter, BasicErrorHdl, StarBASIC *, /*pBasic*/) ...@@ -1777,9 +1780,11 @@ IMPL_LINK( ErrorHdlResetter, BasicErrorHdl, StarBASIC *, /*pBasic*/)
return 0; return 0;
} }
//std::vector< CodeCompleteData > SbModule::GetCodeCompleteDataFromParse()
std::vector< CodeCompleteData > SbModule::GetCodeCompleteDataFromParse() CodeCompleteDataCache SbModule::GetCodeCompleteDataFromParse()
{ {
CodeCompleteDataCache aCache;
ErrorHdlResetter aErrHdl; ErrorHdlResetter aErrHdl;
SbxBase::ResetError(); SbxBase::ResetError();
...@@ -1788,37 +1793,56 @@ std::vector< CodeCompleteData > SbModule::GetCodeCompleteDataFromParse() ...@@ -1788,37 +1793,56 @@ std::vector< CodeCompleteData > SbModule::GetCodeCompleteDataFromParse()
while( pParser->Parse() ) {} while( pParser->Parse() ) {}
SbiSymPool* pPool = pParser->pPool; SbiSymPool* pPool = pParser->pPool;
std::vector< CodeCompleteData > aRet; //std::vector< CodeCompleteData > aRet;
for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i ) for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i )
{ {
SbiSymDef* pSymDef = pPool->Get(i); SbiSymDef* pSymDef = pPool->Get(i);
if( pSymDef->GetType() == SbxOBJECT ) if( pSymDef->GetType() == SbxOBJECT )
{ {
CodeCompleteData aCodeCompleteData; //CodeCompleteData aCodeCompleteData;
aCodeCompleteData.sVarName = pSymDef->GetName(); CodeCompleteVarTypes aVarTypes;
/*aCodeCompleteData.sVarName = pSymDef->GetName();
aCodeCompleteData.sVarParent = OUString(""); aCodeCompleteData.sVarParent = OUString("");
aCodeCompleteData.sVarType = pParser->aGblStrings.Find( pSymDef->GetTypeId() ); aCodeCompleteData.sVarType = pParser->aGblStrings.Find( pSymDef->GetTypeId() );
if(!aCodeCompleteData.sVarType.isEmpty()) if(!aCodeCompleteData.sVarType.isEmpty())
{
aRet.push_back(aCodeCompleteData); aRet.push_back(aCodeCompleteData);
aVarTypes.insert(CodeCompleteVarTypes::value_type( pSymDef->GetName(), pParser->aGblStrings.Find( pSymDef->GetTypeId() ) ) );
aCache.InsertProcedure( aCache.GLOB_KEY, aVarTypes );
}*/
if(pParser->aGblStrings.Find( pSymDef->GetTypeId() ).isEmpty() )
{
aVarTypes.insert(CodeCompleteVarTypes::value_type( pSymDef->GetName(), pParser->aGblStrings.Find( pSymDef->GetTypeId() ) ) );
aCache.InsertProcedure( aCache.GLOB_KEY, aVarTypes );
}
} }
SbiSymPool& pChildPool = pSymDef->GetPool(); SbiSymPool& pChildPool = pSymDef->GetPool();
for(sal_uInt16 j = 0; j < pChildPool.GetSize(); ++j ) for(sal_uInt16 j = 0; j < pChildPool.GetSize(); ++j )
{ {
CodeCompleteData aCodeCompleteData; //CodeCompleteData aCodeCompleteData;
CodeCompleteVarTypes aVarTypes;
SbiSymDef* pChildSymDef = pChildPool.Get(j); SbiSymDef* pChildSymDef = pChildPool.Get(j);
if( pChildSymDef->GetType() == SbxOBJECT ) if( pChildSymDef->GetType() == SbxOBJECT )
{ {
aCodeCompleteData.sVarName = pChildSymDef->GetName(); /*aCodeCompleteData.sVarName = pChildSymDef->GetName();
aCodeCompleteData.sVarParent = pSymDef->GetName(); aCodeCompleteData.sVarParent = pSymDef->GetName();
aCodeCompleteData.sVarType = pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ); aCodeCompleteData.sVarType = pParser->aGblStrings.Find( pChildSymDef->GetTypeId() );
if(!aCodeCompleteData.sVarType.isEmpty()) if(!aCodeCompleteData.sVarType.isEmpty())*/
aRet.push_back(aCodeCompleteData); if( pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ).isEmpty() )
{
//aRet.push_back(aCodeCompleteData);
aVarTypes.insert(CodeCompleteVarTypes::value_type( pChildSymDef->GetName(), pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ) ) );
aCache.InsertProcedure( pSymDef->GetName(), aVarTypes );
}
} }
} }
} }
//std::cerr << aCache << std::endl;
delete pParser; delete pParser;
return aRet; //return aRet;
return aCache;
} }
SbxArrayRef SbModule::GetMethods() SbxArrayRef SbModule::GetMethods()
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef CODECOMPLETECACHE_H
#define CODECOMPLETECACHE_H
#include <basic/sbdef.hxx>
#include <basic/sbxobj.hxx>
#include <basic/sbxdef.hxx>
#include <boost/utility.hpp>
#include <boost/unordered_map.hpp>
#include <rtl/ustring.hxx>
typedef boost::unordered_map< OUString, OUString, OUStringHash > CodeCompleteVarTypes;
/* variable name, type */
typedef boost::unordered_map< OUString, CodeCompleteVarTypes, OUStringHash > CodeCompleteVarScopes;
/* procedure, CodeCompleteVarTypes */
class CodeCompleteDataCache
{
/*
* cache to store data for
* code completition
* */
private:
CodeCompleteVarScopes aVarScopes;
public:
const OUString GLOB_KEY = OUString("global key");
const OUString NOT_FOUND = OUString("not found");
CodeCompleteDataCache(){}
virtual ~CodeCompleteDataCache(){}
void SetVars( const CodeCompleteVarScopes& aScopes );
const CodeCompleteVarScopes& GetVars() const;
void InsertProcedure( const OUString& sProcName, const CodeCompleteVarTypes& aVarTypes );
const OUString& GetVariableType( const OUString& sVarName, const OUString& sProcName ) const;
};
#endif // CODECOMPLETECACHE_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <deque> #include <deque>
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include "basicdllapi.h" #include "basicdllapi.h"
#include <basic/codecompletecache.hxx>
class SbMethod; class SbMethod;
class SbProperty; class SbProperty;
...@@ -44,6 +45,7 @@ class ModuleInitDependencyMap; ...@@ -44,6 +45,7 @@ class ModuleInitDependencyMap;
struct ClassModuleRunInitItem; struct ClassModuleRunInitItem;
struct SbClassData; struct SbClassData;
/*
struct CodeCompleteData struct CodeCompleteData
{ {
OUString sVarName; OUString sVarName;
...@@ -59,7 +61,7 @@ struct CodeCompleteData ...@@ -59,7 +61,7 @@ struct CodeCompleteData
{ {
return ( sVarParent == OUString("") ); return ( sVarParent == OUString("") );
} }
}; };*/
class BASIC_DLLPUBLIC SbModule : public SbxObject, private ::boost::noncopyable class BASIC_DLLPUBLIC SbModule : public SbxObject, private ::boost::noncopyable
{ {
...@@ -150,7 +152,8 @@ public: ...@@ -150,7 +152,8 @@ public:
void RemoveVars(); void RemoveVars();
::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > GetUnoModule(); ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > GetUnoModule();
bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject ); bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject );
std::vector< CodeCompleteData > GetCodeCompleteDataFromParse(); //std::vector< CodeCompleteData > GetCodeCompleteDataFromParse();
CodeCompleteDataCache GetCodeCompleteDataFromParse();
SbxArrayRef GetMethods(); SbxArrayRef GetMethods();
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment