From 9a7b942a0a3bb113cf356f2642766f7a9f909bd6 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 ++--- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'basctl') diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 8ae1d5ba7d97..a6acaea0f1ea 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -505,6 +505,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(); @@ -512,7 +535,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; } -- cgit