GSOC work, code complete option, menu entry fixes

Menu entry is added under View->Enable Code Completition when in Experimental mode.
Fixed the call of funtion SbModule::GetCodeCompleteDataFromParse() to be called only when code completition is enabled.
Replaced the occurences of SvtMiscOptions to CodeCompleteOptions.

Change-Id: If0520123ab5f612d7d24fb98f8e9bf6881af76cb
This commit is contained in:
Gergo Mocsi
2013-07-23 12:42:37 +02:00
parent b0b511e9b5
commit 61ee2598b1
8 changed files with 104 additions and 20 deletions

View File

@@ -35,6 +35,13 @@ shell basctl_Shell
StateMethod = GetState;
ExecMethod = ExecuteCurrent;
]
SID_BASICIDE_CODECOMPLETITION
[
StateMethod = GetState;
ExecMethod = ExecuteCurrent;
]
SID_BASICIDE_HIDECURPAGE
[
ExecMethod = ExecuteCurrent;
@@ -138,12 +145,6 @@ shell basctl_Shell
StateMethod = GetState;
]
SID_BASICIDE_CODECOMPLETITION
[
ExecMethod = ExecuteCurrent;
StateMethod = GetState;
]
SID_BASICIDE_LIBSELECTED
[
ExecMethod = ExecuteGlobal;

View File

@@ -52,6 +52,8 @@
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/msgbox.hxx>
#include <cassert>
#include <basic/codecompletecache.hxx>
#include <svtools/miscopt.hxx>
namespace basctl
{
@@ -1011,7 +1013,8 @@ void ModulWindow::ExecuteCommand (SfxRequest& rReq)
break;
case SID_BASICIDE_CODECOMPLETITION:
{
std::cerr << "code completition enabled" << std::endl;
SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), false);
CodeCompleteOptions::SetCodeCompleteOn( pItem && pItem->GetValue() );
}
break;
case SID_CUT:
@@ -1160,6 +1163,21 @@ void ModulWindow::GetState( SfxItemSet &rSet )
rSet.Put(SfxBoolItem(nWh, bSourceLinesEnabled));
break;
}
case SID_BASICIDE_CODECOMPLETITION:
{
SvtMiscOptions aMiscOptions;
if( aMiscOptions.IsExperimentalMode() )
{
rSet.Put(SfxBoolItem( nWh, CodeCompleteOptions::IsCodeCompleteOn() ));
std::cerr <<"code complete set to: " << CodeCompleteOptions::IsCodeCompleteOn() << std::endl;
}
else
{
rSet.Put( SfxVisibilityItem(nWh, false) );
//CodeCompleteOptions::SetCodeCompleteOn( false );
}
}
break;
}
}
}

View File

@@ -48,7 +48,6 @@
#include <vcl/help.hxx>
#include <vector>
#include <svtools/miscopt.hxx>
#include "com/sun/star/reflection/XIdlReflection.hpp"
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/processfactory.hxx>
@@ -492,7 +491,6 @@ bool EditorWindow::ImpCanModify()
void EditorWindow::KeyInput( const KeyEvent& rKEvt )
{
SvtMiscOptions aMiscOptions;
if ( !pEditView ) // Happens in Win95
return;
@@ -507,7 +505,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
// see if there is an accelerator to be processed first
bool bDone = SfxViewShell::Current()->KeyInput( rKEvt );
if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && aMiscOptions.IsExperimentalMode() )
if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && CodeCompleteOptions::IsCodeCompleteOn() )
{
rModulWindow.UpdateModule();
TextSelection aSel = GetEditView()->GetSelection();
@@ -835,14 +833,20 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
{
ParagraphInsertedDeleted( rTextHint.GetValue(), true );
DoDelayedSyntaxHighlight( rTextHint.GetValue() );
rModulWindow.UpdateModule();
aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
if( CodeCompleteOptions::IsCodeCompleteOn() )
{
rModulWindow.UpdateModule();
aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
}
}
else if( rTextHint.GetId() == TEXT_HINT_PARAREMOVED )
{
ParagraphInsertedDeleted( rTextHint.GetValue(), false );
rModulWindow.UpdateModule();
aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
if( CodeCompleteOptions::IsCodeCompleteOn() )
{
rModulWindow.UpdateModule();
aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());
}
}
else if( rTextHint.GetId() == TEXT_HINT_PARACONTENTCHANGED )
{
@@ -856,7 +860,7 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
pBindings->Invalidate( SID_COPY );
}
}
else if( rTextHint.GetId() == TEXT_HINT_MODIFIED )
else if( rTextHint.GetId() == TEXT_HINT_MODIFIED && CodeCompleteOptions::IsCodeCompleteOn() )
{
rModulWindow.UpdateModule();
aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars());

View File

@@ -19,10 +19,42 @@
#include <basic/codecompletecache.hxx>
#include <iostream>
#include <rtl/instance.hxx>
const OUString CodeCompleteDataCache::GLOB_KEY = OUString("global key");
const OUString CodeCompleteDataCache::NOT_FOUND = OUString("not found");
namespace
{
class theCodeCompleteOptions: public ::rtl::Static< CodeCompleteOptions, theCodeCompleteOptions >{};
}
CodeCompleteOptions::CodeCompleteOptions()
: bIsCodeCompleteOn( false )
{
}
bool CodeCompleteOptions::IsCodeCompleteOn()
{
/*if( !theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() )
return false;
else*/
return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsCodeCompleteOn;
}
void CodeCompleteOptions::SetCodeCompleteOn( const bool& b )
{
if( !theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() )
theCodeCompleteOptions::get().bIsCodeCompleteOn = false;
else
theCodeCompleteOptions::get().bIsCodeCompleteOn = b;
}
bool CodeCompleteOptions::IsExtendedTypeDeclaration()
{
return CodeCompleteOptions::IsCodeCompleteOn();
}
std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache)
{
for( CodeCompleteVarScopes::const_iterator aIt = aCache.aVarScopes.begin(); aIt != aCache.aVarScopes.end(); ++aIt )

View File

@@ -1783,7 +1783,6 @@ IMPL_LINK( ErrorHdlResetter, BasicErrorHdl, StarBASIC *, /*pBasic*/)
CodeCompleteDataCache SbModule::GetCodeCompleteDataFromParse()
{
CodeCompleteDataCache aCache;
ErrorHdlResetter aErrHdl;
SbxBase::ResetError();

View File

@@ -28,6 +28,7 @@
#include "com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp"
#include "com/sun/star/reflection/XIdlMethod.hpp"
#include "com/sun/star/uno/Exception.hpp"
#include <basic/codecompletecache.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -207,7 +208,7 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
bool bSwitchPool = false;
bool bPersistantGlobal = false;
SbiToken eFirstTok = eCurTok;
SvtMiscOptions aMiscOptions;
if( pProc && ( eCurTok == GLOBAL || eCurTok == PUBLIC || eCurTok == PRIVATE ) )
Error( SbERR_NOT_IN_SUBR, eCurTok );
if( eCurTok == PUBLIC || eCurTok == GLOBAL )
@@ -404,9 +405,18 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
if( !bCompatible && !pDef->IsNew() )
{
OUString aTypeName( aGblStrings.Find( pDef->GetTypeId() ) );
if( rTypeArray->Find( aTypeName, SbxCLASS_OBJECT ) == NULL && (aMiscOptions.IsExperimentalMode() && !IsUnoInterface(aTypeName)))
/*std::cerr <<"CodeCompleteOptions::IsExtendedTypeDeclaration():" << CodeCompleteOptions::IsExtendedTypeDeclaration() << std::endl;
std::cerr << "IsUnoInterface("<<aTypeName<<"):"<< IsUnoInterface(aTypeName) << std::endl;
std::cerr << "finally: " << (CodeCompleteOptions::IsExtendedTypeDeclaration() && !IsUnoInterface(aTypeName)) << std::endl;*/
if( rTypeArray->Find( aTypeName, SbxCLASS_OBJECT ) == NULL )
{
Error( SbERR_UNDEF_TYPE, aTypeName );
if(!CodeCompleteOptions::IsExtendedTypeDeclaration())
Error( SbERR_UNDEF_TYPE, aTypeName );
else
{
if(!IsUnoInterface(aTypeName))
Error( SbERR_UNDEF_TYPE, aTypeName );
}
}
}

View File

@@ -24,6 +24,7 @@ class SbiParser;
class SbModule;
#include "opcodes.hxx"
#include "buffer.hxx"
#include <basic/codecompletecache.hxx>
class SbiCodeGen {
SbiParser* pParser; // for error messages, line, column etc.

View File

@@ -26,12 +26,31 @@
#include <boost/utility.hpp>
#include <boost/unordered_map.hpp>
#include <rtl/ustring.hxx>
#include <svtools/miscopt.hxx>
typedef boost::unordered_map< OUString, OUString, OUStringHash > CodeCompleteVarTypes;
/* variable name, type */
typedef boost::unordered_map< OUString, CodeCompleteVarTypes, OUStringHash > CodeCompleteVarScopes;
/* procedure, CodeCompleteVarTypes */
class BASIC_DLLPUBLIC CodeCompleteOptions
{
/*
* class to store basic code completition
* options
* */
private:
bool bIsCodeCompleteOn;
SvtMiscOptions aMiscOptions;
public:
CodeCompleteOptions();
static bool IsCodeCompleteOn();
static void SetCodeCompleteOn( const bool& b );
static bool IsExtendedTypeDeclaration();
};
class BASIC_DLLPUBLIC CodeCompleteDataCache
{
/*
@@ -48,7 +67,7 @@ public:
CodeCompleteDataCache(){}
virtual ~CodeCompleteDataCache(){}
friend std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache);
friend BASIC_DLLPUBLIC std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache);
void SetVars( const CodeCompleteVarScopes& aScopes );
const CodeCompleteVarScopes& GetVars() const;