From 3f8a8754e890a2b85e171d5d10d3b1bafb030429 Mon Sep 17 00:00:00 2001 From: Gergo Mocsi Date: Thu, 25 Jul 2013 19:12:37 +0200 Subject: GSOC work, procedure autoclose implementation Now, function procedure autoclose is working. Created a struct named IncompleteProcData to store the line number, type and name of the inclomplete procedure. Procedures are store in a vector (IncompleteProcedures), and are as a member in SbModule. I've created a function called SbModule::GetIncompleteProcedures() to extract the data. Data extraction uses SbModule::SetSource32, beacuse that one tokenizes sthe source file, and recognizes procedures. Closing procedures is triggered ky pressing the Enter key when typing. It checks the actual sub, and if it's incomplete, adds the correct ending( End Sub/End Function). There is only one problem: function SbModule::SetSource32 is not too often calle, maybe extraction should be done by a timer. Change-Id: Id88daaef329e8b5c194b765c5261d356bfb3a0c9 --- basctl/source/basicide/baside2b.cxx | 24 ++++++++++++++++++- basctl/source/basicide/codecompleteoptionsdlg.cxx | 5 ++-- basic/source/classes/codecompletecache.cxx | 2 +- basic/source/classes/sbxmod.cxx | 29 +++++++++++++++-------- include/basic/codecompletecache.hxx | 16 ++++++++++++- include/basic/sbmod.hxx | 20 ++-------------- 6 files changed, 62 insertions(+), 34 deletions(-) diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index e6aa0b913fd9..5f1af6a0ea8e 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -499,6 +499,29 @@ 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_RETURN && CodeCompleteOptions::IsProcedureAutoCompleteOn() ) + {//autoclose implementation + TextSelection aSel = GetEditView()->GetSelection(); + sal_uLong nLine = aSel.GetStart().GetPara(); + OUString sActSub = GetActualSubName( nLine ); + IncompleteProcedures aProcData = rModulWindow.GetSbModule()->GetIncompleteProcedures(); + for( unsigned int i = 0; i < aProcData.size(); ++i ) + { + if( aProcData[i].sProcName == sActSub ) + {//found the procedure to autocomplete + TextPaM aEnd( aProcData[i].nLine, 0 ); + TextPaM aStart( aProcData[i].nLine, 0 ); + GetEditView()->SetSelection( TextSelection( aStart, aEnd ) ); + if( aProcData[i].aType == AutocompleteType::ACSUB ) + GetEditView()->InsertText( OUString("\nEnd Sub\n") ); + if( aProcData[i].aType == AutocompleteType::ACFUNC ) + GetEditView()->InsertText( OUString("\nEnd Function\n") ); + GetEditView()->SetSelection( aSel ); + break; + } + } + } + if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && CodeCompleteOptions::IsCodeCompleteOn() ) { rModulWindow.UpdateModule(); @@ -506,7 +529,6 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) TextSelection aSel = GetEditView()->GetSelection(); sal_uLong nLine = aSel.GetStart().GetPara(); OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified - //OUString sActSub = GetActualSubName( nLine ); std::vector< OUString > aVect; HighlightPortions aPortions; diff --git a/basctl/source/basicide/codecompleteoptionsdlg.cxx b/basctl/source/basicide/codecompleteoptionsdlg.cxx index 6dcde740f214..0f4ab3a8cac8 100644 --- a/basctl/source/basicide/codecompleteoptionsdlg.cxx +++ b/basctl/source/basicide/codecompleteoptionsdlg.cxx @@ -41,9 +41,8 @@ CodeCompleteOptionsDlg::CodeCompleteOptionsDlg( Window* pWindow ) pCancelBtn->SetClickHdl( LINK( this, CodeCompleteOptionsDlg, CancelHdl ) ); pCodeCompleteChk->Check( CodeCompleteOptions::IsCodeCompleteOn() ); - //pAutocloseProcChk->Check( CodeCompleteOptions::IsProcedureAutoCompleteOn() ); + pAutocloseProcChk->Check( CodeCompleteOptions::IsProcedureAutoCompleteOn() ); - pAutocloseProcChk->Enable( false ); pAutocloseBracesChk->Enable( false ); pAutocloseQuotesChk->Enable( false ); } @@ -55,7 +54,7 @@ CodeCompleteOptionsDlg::~CodeCompleteOptionsDlg() IMPL_LINK_NOARG(CodeCompleteOptionsDlg, OkHdl) { CodeCompleteOptions::SetCodeCompleteOn( pCodeCompleteChk->IsChecked() ); - //CodeCompleteOptions::SetProcedureAutoCompleteOn( pCodeCompleteChk->IsChecked() ); + CodeCompleteOptions::SetProcedureAutoCompleteOn( pAutocloseProcChk->IsChecked() ); Close(); return 0; } diff --git a/basic/source/classes/codecompletecache.cxx b/basic/source/classes/codecompletecache.cxx index 952e4ee7538a..51eee1c84c0a 100644 --- a/basic/source/classes/codecompletecache.cxx +++ b/basic/source/classes/codecompletecache.cxx @@ -28,7 +28,7 @@ namespace CodeCompleteOptions::CodeCompleteOptions() : bIsCodeCompleteOn( false ), -bIsProcedureAutoCompleteOn( false ) +bIsProcedureAutoCompleteOn( true ) { } diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index 694fbf338fe0..fa04809b7c54 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -894,6 +894,10 @@ void SbModule::SetSource32( const OUString& r ) StartDefinitions(); SbiTokenizer aTok( r ); aTok.SetCompatible( IsVBACompat() ); + if( CodeCompleteOptions::IsProcedureAutoCompleteOn() ) + { + aIncompleteProcs.clear(); + } while( !aTok.IsEof() ) { SbiToken eEndTok = NIL; @@ -976,24 +980,29 @@ void SbModule::SetSource32( const OUString& r ) if( aTok.IsEof() ) { pMeth->nLine2 = aTok.GetLine(); - std::cerr << "EOF reached, no end for "<< sMethName <<", line " << aTok.GetLine() << std::endl; - //std::cerr << "write end to: " << aOUSource.getLength() / pMeth->nLine2 << std::endl; - sal_Int32 nPos=0; - sal_Int32 nCounter = 0; - std::cerr << "source length: " << aOUSource.getLength() << std::endl; - for(sal_uInt32 i=0; i < aOUSource.getLength() ; ++i) + if( CodeCompleteOptions::IsProcedureAutoCompleteOn() ) { - nPos++; - if( aOUSource[i] == '\n' && nCounter != aTok.GetLine() ) - nCounter++; + IncompleteProcData aProcData; + aProcData.sProcName = sMethName; + aProcData.nLine = pMeth->nLine2; + + if( eEndTok == ENDSUB ) + aProcData.aType = ACSUB; + if( eEndTok == ENDFUNC ) + aProcData.aType = ACFUNC; + aIncompleteProcs.push_back(aProcData); } - std::cerr << "newline index: " << nPos << std::endl; } } } EndDefinitions( sal_True ); } +IncompleteProcedures SbModule::GetIncompleteProcedures() const +{ + return aIncompleteProcs; +} + // Broadcast of a hint to all Basics static void _SendHint( SbxObject* pObj, sal_uIntPtr nId, SbMethod* p ) diff --git a/include/basic/codecompletecache.hxx b/include/basic/codecompletecache.hxx index 480c3c1dcf4c..e03c0576fdb7 100644 --- a/include/basic/codecompletecache.hxx +++ b/include/basic/codecompletecache.hxx @@ -27,12 +27,26 @@ #include #include #include +#include + +enum BASIC_DLLPUBLIC AutocompleteType +{ + ACSUB, + ACFUNC +}; + +struct IncompleteProcData +{ + OUString sProcName; + sal_uInt16 nLine; + AutocompleteType aType; +}; typedef boost::unordered_map< OUString, OUString, OUStringHash > CodeCompleteVarTypes; /* variable name, type */ typedef boost::unordered_map< OUString, CodeCompleteVarTypes, OUStringHash > CodeCompleteVarScopes; /* procedure, CodeCompleteVarTypes */ - +typedef std::vector< IncompleteProcData > IncompleteProcedures; class BASIC_DLLPUBLIC CodeCompleteOptions { diff --git a/include/basic/sbmod.hxx b/include/basic/sbmod.hxx index b3e694bf624c..dbf3e69fb115 100644 --- a/include/basic/sbmod.hxx +++ b/include/basic/sbmod.hxx @@ -45,24 +45,6 @@ class ModuleInitDependencyMap; struct ClassModuleRunInitItem; struct SbClassData; -/* -struct CodeCompleteData -{ - OUString sVarName; - OUString sVarParent; - OUString sVarType; - - inline bool operator==( const CodeCompleteData& aOther ) - { - return (sVarName == aOther.sVarName && sVarParent == aOther.sVarParent); - } - - inline bool IsGlobal() const - { - return ( sVarParent == OUString("") ); - } -};*/ - class BASIC_DLLPUBLIC SbModule : public SbxObject, private ::boost::noncopyable { friend class SbiCodeGen; @@ -74,6 +56,7 @@ class BASIC_DLLPUBLIC SbModule : public SbxObject, private ::boost::noncopyable std::vector< OUString > mModuleVariableNames; BASIC_DLLPRIVATE void implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC* pDeletedBasic ); + IncompleteProcedures aIncompleteProcs; protected: com::sun::star::uno::Reference< com::sun::star::script::XInvocation > mxWrapper; @@ -155,6 +138,7 @@ public: //CodeCompleteDataCache GetCodeCompleteDataFromParse(); void GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache); SbxArrayRef GetMethods(); + IncompleteProcedures GetIncompleteProcedures() const; }; SV_DECL_IMPL_REF(SbModule) -- cgit v1.2.3