Kaydet (Commit) 6165d0b4 authored tarafından Gergo Mocsi's avatar Gergo Mocsi

GSOC work, some code fixes

Fixed the link error: declared CodeCompleteDataCache as BASIC_DLLPUBLIC and it worked fine.
Fixed sergmentation fault error in CodeCompleteWindow.
The new cache implementation is fully functional.
CodeCompleteWindow is now being used as boost::scoped_ptr.

Change-Id: I76a0fc7407d589e7f94280fc4d50cea51b9639db
üst 6c1854f9
......@@ -115,9 +115,7 @@ private:
virtual
::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
GetComponentInterface(sal_Bool bCreate = true);
//std::vector< CodeCompleteData > aCodeCompleteCache;
CodeCompleteDataCache aCodeCompleteCache;
//CodeCompleteWindow* pCodeCompleteWnd;
boost::scoped_ptr< CodeCompleteWindow > pCodeCompleteWnd;
OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number
......@@ -474,32 +472,6 @@ private:
} aSyntaxColors;
};
class CodeCompleteWindow: public Window
{
friend class CodeCompleteListBox;
private:
EditorWindow* pParent; // parent window
TextSelection aTextSelection;
CodeCompleteListBox* pListBox;
void InitListBox(); // initialize the ListBox
public:
CodeCompleteWindow( EditorWindow* pPar );
virtual ~CodeCompleteWindow();
void InsertEntry( const OUString& aStr );
void ClearListBox();
void SetTextSelection( const TextSelection& aSel );
const TextSelection& GetTextSelection() const;
void ResizeListBox();
void SelectFirstEntry(); //selects first entry in ListBox
/*protected:
//virtual void KeyInput( const KeyEvent& rKeyEvt );
virtual void LoseFocus();*/
};
class CodeCompleteListBox: public ListBox
{
friend class CodeCompleteWindow;
......@@ -517,16 +489,35 @@ private:
void SetVisibleEntries(); // sets the visible entries based on aFuncBuffer variable
public:
CodeCompleteListBox(CodeCompleteWindow* pPar);
virtual ~CodeCompleteListBox();
CodeCompleteListBox( CodeCompleteWindow* pPar );
void InsertSelectedEntry(); //insert the selected entry
DECL_LINK(ImplDoubleClickHdl, void*);
virtual long PreNotify( NotifyEvent& rNEvt );
/*protected:
virtual void LoseFocus();*/
};
class CodeCompleteWindow: public Window
{
friend class CodeCompleteListBox;
private:
EditorWindow* pParent; // parent window
TextSelection aTextSelection;
CodeCompleteListBox* pListBox;
void InitListBox(); // initialize the ListBox
public:
CodeCompleteWindow( EditorWindow* pPar );
~CodeCompleteWindow(){ delete pListBox; }
void InsertEntry( const OUString& aStr );
void ClearListBox();
void SetTextSelection( const TextSelection& aSel );
const TextSelection& GetTextSelection() const;
void ResizeListBox();
void SelectFirstEntry(); //selects first entry in ListBox
};
......
......@@ -518,15 +518,10 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
aVect.push_back( aLine.copy(r.nBegin, r.nEnd - r.nBegin) );
}
OUString sBaseName = aVect[0];//variable name
OUString sVarType = aCodeCompleteCache.GetVariableType(sBaseName, sActSub);
OUString sVarType = aCodeCompleteCache.GetVariableType(sBaseName, aCodeCompleteCache.GLOB_KEY);
if( sVarType == aCodeCompleteCache.NOT_FOUND )
sVarType = aCodeCompleteCache.GetVariableType(sBaseName, sActSub);
/*for( unsigned int i = 0; i < aCodeCompleteCache.size(); ++i)
{*/
/*if( aCodeCompleteCache[i].sVarName.equalsIgnoreAsciiCase( sBaseName ) &&
( aCodeCompleteCache[i].sVarParent == sActSub || aCodeCompleteCache[i].IsGlobal() ) )
{*/
if( sVarType != aCodeCompleteCache.NOT_FOUND )
{
Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW );
Reference< reflection::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW );
......@@ -573,10 +568,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
}
}
}
}
/*break;
}*/
//}
}
if ( !bDone && ( !TextEngine::DoesKeyChangeText( rKEvt ) || ImpCanModify() ) )
{
......@@ -843,6 +835,7 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
else if( rTextHint.GetId() == TEXT_HINT_PARAREMOVED )
{
ParagraphInsertedDeleted( rTextHint.GetValue(), false );
rModulWindow.UpdateModule();
aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
}
else if( rTextHint.GetId() == TEXT_HINT_PARACONTENTCHANGED )
......@@ -859,6 +852,7 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
}
else if( rTextHint.GetId() == TEXT_HINT_MODIFIED )
{
rModulWindow.UpdateModule();
aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
}
}
......@@ -878,6 +872,7 @@ OUString EditorWindow::GetActualSubName( sal_uLong nLine )
pMeth->GetLineRange(l1,l2);
if( (l1 <= nLine+1) && (nLine+1 <= l2) )
{
//std::cerr << "sName: " << sName << std::endl;
return sName;
}
}
......@@ -2362,16 +2357,11 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped )
CodeCompleteListBox::CodeCompleteListBox( CodeCompleteWindow* pPar )
: ListBox(pPar, WB_SORT | WB_BORDER ),
pCodeCompleteWindow(pPar)
pCodeCompleteWindow( pPar )
{
SetDoubleClickHdl(LINK(this, CodeCompleteListBox, ImplDoubleClickHdl));
}
CodeCompleteListBox::~CodeCompleteListBox()
{
delete pCodeCompleteWindow;
}
IMPL_LINK_NOARG(CodeCompleteListBox, ImplDoubleClickHdl)
{
InsertSelectedEntry();
......@@ -2434,7 +2424,7 @@ long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt )
case KEY_ESCAPE: // hide, do nothing
pCodeCompleteWindow->Hide();
pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
pCodeCompleteWindow->pParent->GrabFocus();
//pCodeCompleteWindow->pParent->GrabFocus();
return 0;
case KEY_TAB: case KEY_SPACE:
/* space, tab the user probably have typed in the whole
......@@ -2462,11 +2452,6 @@ 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 );
}
......@@ -2482,16 +2467,10 @@ void CodeCompleteListBox::SetVisibleEntries()
}
}
/*void CodeCompleteListBox::LoseFocus()
{
std::cerr << "CodeCompleteListBox::LoseFocus" << std::endl;
Window::LoseFocus();
//pCodeCompleteWindow->Hide();
}*/
CodeCompleteWindow::CodeCompleteWindow( EditorWindow* pPar )
: Window( pPar ),
pParent(pPar)
pParent( pPar ),
pListBox( new CodeCompleteListBox(this) )
{
SetSizePixel( Size(151,151) ); //default, later it changes
InitListBox();
......@@ -2499,15 +2478,9 @@ pParent(pPar)
void CodeCompleteWindow::InitListBox()
{
pListBox = new CodeCompleteListBox( this );
pListBox->SetSizePixel( Size(150,150) ); //default, this will adopt the line length
pListBox->Show();
//pListBox->GrabFocus();
}
CodeCompleteWindow::~CodeCompleteWindow()
{
delete pListBox;
pListBox->GrabFocus();
}
void CodeCompleteWindow::InsertEntry( const OUString& aStr )
......@@ -2522,14 +2495,6 @@ void CodeCompleteWindow::ClearListBox()
pListBox->aEntryVect.clear();
pListBox->aFuncBuffer.makeStringAndClear();
}
/*
void CodeCompleteWindow::KeyInput( const KeyEvent& rKeyEvt )
{
if( rKeyEvt.GetKeyCode().GetCode() == KEY_ESCAPE )
{// ESC key closes the window: does not modify anything
Hide();
}
}*/
void CodeCompleteWindow::SetTextSelection( const TextSelection& aSel )
{
......@@ -2563,7 +2528,6 @@ void CodeCompleteWindow::ResizeListBox()
aSize.setHeight( aSize.getHeight() + 1 );
SetSizePixel( aSize );
}
//pListBox->GrabFocus();
}
void CodeCompleteWindow::SelectFirstEntry()
......@@ -2572,15 +2536,8 @@ void CodeCompleteWindow::SelectFirstEntry()
{
pListBox->SelectEntryPos( 0 );
}
//pListBox->GrabFocus();
}
/*void CodeCompleteWindow::LoseFocus()
{
std::cerr << "CodeCompleteWindow::LoseFocus" << std::endl;
Window::LoseFocus();
}*/
} // namespace basctl
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -19,6 +19,21 @@
#include <basic/codecompletecache.hxx>
std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache)
{
for( CodeCompleteVarScopes::const_iterator aIt = aCache.aVarScopes.begin(); aIt != aCache.aVarScopes.end(); ++aIt )
{
aStream << aIt->first << std::endl;
CodeCompleteVarTypes aVarTypes = aIt->second;
for( CodeCompleteVarTypes::const_iterator aOtherIt = aVarTypes.begin(); aOtherIt != aVarTypes.end(); ++aOtherIt )
{
aStream << "\t" << aOtherIt->first << "," << aOtherIt->second << std::endl;
}
}
aStream << "-----------------" << std::endl;
return aStream;
}
const CodeCompleteVarScopes& CodeCompleteDataCache::GetVars() const
{
return aVarScopes;
......@@ -33,7 +48,7 @@ void CodeCompleteDataCache::SetVars( const CodeCompleteVarScopes& aScopes )
aVarScopes = aScopes;
}
const OUString& CodeCompleteDataCache::GetVariableType( const OUString& sVarName, const OUString& sProcName ) 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
......@@ -47,4 +62,9 @@ const OUString& CodeCompleteDataCache::GetVariableType( const OUString& sVarName
return aOtherIt->second;
}
void CodeCompleteDataCache::print() const
{
std::cerr << *this << std::endl;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -1780,7 +1780,6 @@ IMPL_LINK( ErrorHdlResetter, BasicErrorHdl, StarBASIC *, /*pBasic*/)
return 0;
}
//std::vector< CodeCompleteData > SbModule::GetCodeCompleteDataFromParse()
CodeCompleteDataCache SbModule::GetCodeCompleteDataFromParse()
{
CodeCompleteDataCache aCache;
......@@ -1793,55 +1792,38 @@ CodeCompleteDataCache SbModule::GetCodeCompleteDataFromParse()
while( pParser->Parse() ) {}
SbiSymPool* pPool = pParser->pPool;
//std::vector< CodeCompleteData > aRet;
CodeCompleteVarTypes aGlobVarTypes;
for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i )
{
SbiSymDef* pSymDef = pPool->Get(i);
if( pSymDef->GetType() == SbxOBJECT )
{
//CodeCompleteData aCodeCompleteData;
CodeCompleteVarTypes aVarTypes;
/*aCodeCompleteData.sVarName = pSymDef->GetName();
aCodeCompleteData.sVarParent = OUString("");
aCodeCompleteData.sVarType = pParser->aGblStrings.Find( pSymDef->GetTypeId() );
if(!aCodeCompleteData.sVarType.isEmpty())
if( !pParser->aGblStrings.Find( pSymDef->GetTypeId() ).isEmpty() )
{
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 );
//std::cerr << "global " << pSymDef->GetName() << std::endl;
aGlobVarTypes.insert( CodeCompleteVarTypes::value_type( pSymDef->GetName(), pParser->aGblStrings.Find( pSymDef->GetTypeId() ) ) );
}
}
SbiSymPool& pChildPool = pSymDef->GetPool();
CodeCompleteVarTypes aLocVarTypes;
for(sal_uInt16 j = 0; j < pChildPool.GetSize(); ++j )
{
//CodeCompleteData aCodeCompleteData;
CodeCompleteVarTypes aVarTypes;
SbiSymDef* pChildSymDef = pChildPool.Get(j);
if( pChildSymDef->GetType() == SbxOBJECT )
{
/*aCodeCompleteData.sVarName = pChildSymDef->GetName();
aCodeCompleteData.sVarParent = pSymDef->GetName();
aCodeCompleteData.sVarType = pParser->aGblStrings.Find( pChildSymDef->GetTypeId() );
if(!aCodeCompleteData.sVarType.isEmpty())*/
if( pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ).isEmpty() )
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 << "local " << pChildSymDef->GetName() << std::endl;
aLocVarTypes.insert( CodeCompleteVarTypes::value_type( pChildSymDef->GetName(), pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ) ) );
}
}
}
aCache.InsertProcedure( pSymDef->GetName(), aLocVarTypes );
}
//std::cerr << aCache << std::endl;
aCache.InsertProcedure( aCache.GLOB_KEY, aGlobVarTypes );
delete pParser;
//return aRet;
return aCache;
}
......
......@@ -32,7 +32,7 @@ typedef boost::unordered_map< OUString, OUString, OUStringHash > CodeCompleteVar
typedef boost::unordered_map< OUString, CodeCompleteVarTypes, OUStringHash > CodeCompleteVarScopes;
/* procedure, CodeCompleteVarTypes */
class CodeCompleteDataCache
class BASIC_DLLPUBLIC CodeCompleteDataCache
{
/*
* cache to store data for
......@@ -44,16 +44,18 @@ private:
public:
const OUString GLOB_KEY = OUString("global key");
const OUString NOT_FOUND = OUString("not found");
CodeCompleteDataCache(){}
CodeCompleteDataCache(){}
virtual ~CodeCompleteDataCache(){}
friend std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache);
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;
OUString GetVariableType( const OUString& sVarName, const OUString& sProcName ) const;
void print() const; // wrapper for operator<<, prints to std::cerr
};
#endif // CODECOMPLETECACHE_H
......
......@@ -152,7 +152,6 @@ public:
void RemoveVars();
::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > GetUnoModule();
bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject );
//std::vector< CodeCompleteData > GetCodeCompleteDataFromParse();
CodeCompleteDataCache GetCodeCompleteDataFromParse();
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