From 40433e2ca977173ae6909fc5c47601e11ef003e4 Mon Sep 17 00:00:00 2001 From: Gergo Mocsi Date: Thu, 25 Jul 2013 20:15:45 +0200 Subject: GSOC work, implemented "Autoclose Double Quotes" option Feature autoclosing double quotes (strings) implemented. When the user presses the '"' key, it's pair is also being inserted (only when the previous character is also a '"'), and the cursor is being placed inside the two quotes. Also, if the there was a string (like: "aaa""), the second one is not inserted. Change-Id: I3e4a5e426d2d4bdbf56899fe3e36359ae161b52a --- basctl/source/basicide/baside2b.cxx | 19 ++++++++++++++++++- basctl/source/basicide/codecompleteoptionsdlg.cxx | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'basctl') diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index a6acaea0f1ea..cf2530f6e47d 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -505,10 +505,27 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) // see if there is an accelerator to be processed first bool bDone = SfxViewShell::Current()->KeyInput( rKEvt ); + if( rKEvt.GetCharCode() == '"' && CodeCompleteOptions::IsAutoCloseQuotesOn() ) + {//autoclose double quotes + TextSelection aSel = GetEditView()->GetSelection(); + sal_uLong nLine = aSel.GetStart().GetPara(); + OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified + + HighlightPortions aPortions; + aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + if( aLine[aLine.getLength()-1] != '"' && (aPortions[aPortions.size()-1].tokenType != 4) ) + { + GetEditView()->InsertText(OUString("\"")); + //leave the cursor on it's place: inside the two double quotes + TextPaM aEnd(nLine, aSel.GetEnd().GetIndex()); + GetEditView()->SetSelection( TextSelection( aEnd, aEnd ) ); + } + } + if( rKEvt.GetKeyCode().GetCode() == KEY_RETURN && CodeCompleteOptions::IsProcedureAutoCompleteOn() ) {//autoclose implementation TextSelection aSel = GetEditView()->GetSelection(); - sal_uLong nLine = aSel.GetStart().GetPara(); + sal_uLong nLine = aSel.GetStart().GetPara(); OUString sActSub = GetActualSubName( nLine ); IncompleteProcedures aProcData = rModulWindow.GetSbModule()->GetIncompleteProcedures(); for( unsigned int i = 0; i < aProcData.size(); ++i ) diff --git a/basctl/source/basicide/codecompleteoptionsdlg.cxx b/basctl/source/basicide/codecompleteoptionsdlg.cxx index 0f4ab3a8cac8..ac2793f767e4 100644 --- a/basctl/source/basicide/codecompleteoptionsdlg.cxx +++ b/basctl/source/basicide/codecompleteoptionsdlg.cxx @@ -42,9 +42,9 @@ CodeCompleteOptionsDlg::CodeCompleteOptionsDlg( Window* pWindow ) pCodeCompleteChk->Check( CodeCompleteOptions::IsCodeCompleteOn() ); pAutocloseProcChk->Check( CodeCompleteOptions::IsProcedureAutoCompleteOn() ); + pAutocloseQuotesChk->Check( CodeCompleteOptions::IsAutoCloseQuotesOn() ); pAutocloseBracesChk->Enable( false ); - pAutocloseQuotesChk->Enable( false ); } CodeCompleteOptionsDlg::~CodeCompleteOptionsDlg() @@ -55,6 +55,7 @@ IMPL_LINK_NOARG(CodeCompleteOptionsDlg, OkHdl) { CodeCompleteOptions::SetCodeCompleteOn( pCodeCompleteChk->IsChecked() ); CodeCompleteOptions::SetProcedureAutoCompleteOn( pAutocloseProcChk->IsChecked() ); + CodeCompleteOptions::SetAutoCloseQuotesOn( pAutocloseQuotesChk->IsChecked() ); Close(); return 0; } -- cgit