diff options
author | Gergo Mocsi <gmocsi91@gmail.com> | 2013-07-29 22:27:41 +0200 |
---|---|---|
committer | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-02 18:16:52 +0200 |
commit | c149c96cf4c42820f15a0fea14cb7a4927ae4b1e (patch) | |
tree | 03e4e409130cf775a137545a300c1a64ad1f3b78 /basctl/source | |
parent | 92374fb966d35a1f2584c1d4fc1459b350a70474 (diff) |
GSOC work, "autocomplete procedures" fix + new feature
Fixed the procedure autoclose function. Now, autoclose is based on the syntax higlighter: if finds an opening token, starts searching forward to a close token.
If there is another sub/function keyword, or EOF is reached, the procedure is considered incomplete.
If the end token is found, the procedure is considered to be closed.
Added function autocorrect symbol spelling, wich corrects the ascii case of the keywords, and corrects the spelling of the extended types.
Change-Id: Ibd17f319a6d6ff5c3f91f4adb7a10dc701f0468a
Diffstat (limited to 'basctl/source')
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 120 | ||||
-rw-r--r-- | basctl/source/basicide/codecompleteoptionsdlg.cxx | 3 | ||||
-rw-r--r-- | basctl/source/basicide/codecompleteoptionsdlg.hxx | 1 |
3 files changed, 111 insertions, 13 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 3e39f1a5b97e..15ff4260069a 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -508,6 +508,37 @@ 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_SPACE || + rKEvt.GetKeyCode().GetCode() == KEY_TAB || + rKEvt.GetKeyCode().GetCode() == KEY_RETURN ) && CodeCompleteOptions::IsAutoCorrectSpellingOn() ) + { + 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( aPortions.size() > 0 ) + { + HighlightPortion& r = aPortions[aPortions.size()-1]; + if( r.tokenType == 9 ) // correct the last entered keyword + { + OUString sStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin); + if( !sStr.isEmpty() ) + { + //capitalize first letter and replace + sStr = sStr.toAsciiLowerCase(); + sStr = sStr.replaceAt( 0, 1, OUString(sStr[0]).toAsciiUpperCase() ); + + TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sStr.getLength() ); + TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex())); + pEditEngine->ReplaceText( sTextSelection, sStr ); + pEditView->SetSelection( aSel ); + } + } + } + } + if( rKEvt.GetCharCode() == '"' && CodeCompleteOptions::IsAutoCloseQuotesOn() ) {//autoclose double quotes TextSelection aSel = GetEditView()->GetSelection(); @@ -547,21 +578,77 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) {//autoclose implementation TextSelection aSel = GetEditView()->GetSelection(); sal_uLong nLine = aSel.GetStart().GetPara(); + OUString aLine( pEditEngine->GetText( nLine ) ); OUString sActSub = GetActualSubName( nLine ); - IncompleteProcedures aProcData = rModulWindow.GetSbModule()->GetIncompleteProcedures(); - for( unsigned int i = 0; i < aProcData.size(); ++i ) + + HighlightPortions aPortions; + aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + OUString sProcType; + OUString sProcName; + bool bFoundType = false; + bool bFoundName = false; + if( aPortions.size() != 0 ) { - 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; + for ( size_t i = 0; i < aPortions.size(); i++ ) + { + HighlightPortion& r = aPortions[i]; + OUString sTokStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin); + if( r.tokenType == 9 && ( sTokStr.equalsIgnoreAsciiCase("sub") + || sTokStr.equalsIgnoreAsciiCase("function")) ) + { + sProcType = sTokStr; + bFoundType = true; + } + if( r.tokenType == 1 && bFoundType ) + { + sProcName = sTokStr; + bFoundName = true; + break; + } + } + if( bFoundType && bFoundName ) + {// found, search for end + if( nLine+1 == pEditEngine->GetParagraphCount() ) + { //append to the end + OUString sText("\nEnd "); + if( sProcType.equalsIgnoreAsciiCase("function") ) + sText += OUString( "Function\n" ); + if( sProcType.equalsIgnoreAsciiCase("sub") ) + sText += OUString( "Sub\n" ); + pEditView->InsertText( sText ); + } + else + { + for( sal_uLong i = nLine+1; i < pEditEngine->GetParagraphCount(); ++i ) + { + OUString aCurrLine = pEditEngine->GetText( i ); + HighlightPortions aCurrPortions; + aHighlighter.getHighlightPortions( i, aCurrLine, aCurrPortions ); + if( aCurrPortions.size() >= 3 ) + { + HighlightPortion& r1 = aCurrPortions[0]; + OUString sStr1 = aCurrLine.copy(r1.nBegin, r1.nEnd - r1.nBegin); + + if( r1.tokenType == 9 ) + { + if( sStr1.equalsIgnoreAsciiCase("sub") ) + { + pEditView->InsertText( OUString ( "\nEnd Sub\n" ) ); + break; + } + if( sStr1.equalsIgnoreAsciiCase("function") ) + { + pEditView->InsertText( OUString ( "\nEnd Function\n" ) ); + break; + } + if( sStr1.equalsIgnoreAsciiCase("end") ) + { + break; + } + } + } + } + } } } } @@ -588,6 +675,13 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) OUString sBaseName = aVect[0];//variable name OUString sVarType = aCodeCompleteCache.GetVarType( sBaseName ); + if( !sVarType.isEmpty() && CodeCompleteOptions::IsAutoCorrectSpellingOn() )//correct variable name + { + TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sBaseName.getLength() ); + TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex())); + pEditEngine->ReplaceText( sTextSelection, aCodeCompleteCache.GetCorrectCaseVarName(sBaseName) ); + pEditView->SetSelection( aSel ); + } Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW ); Reference< reflection::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW ); diff --git a/basctl/source/basicide/codecompleteoptionsdlg.cxx b/basctl/source/basicide/codecompleteoptionsdlg.cxx index ff4398b1e816..e79190c29088 100644 --- a/basctl/source/basicide/codecompleteoptionsdlg.cxx +++ b/basctl/source/basicide/codecompleteoptionsdlg.cxx @@ -36,6 +36,7 @@ CodeCompleteOptionsDlg::CodeCompleteOptionsDlg( Window* pWindow ) get(pAutocloseProcChk, "autoclose_proc"); get(pAutocloseParenChk, "autoclose_paren"); get(pAutocloseQuotesChk, "autoclose_quotes"); + get(pAutoCorrectSpellingChk, "autocorrect_spelling"); pOkBtn->SetClickHdl( LINK( this, CodeCompleteOptionsDlg, OkHdl ) ); pCancelBtn->SetClickHdl( LINK( this, CodeCompleteOptionsDlg, CancelHdl ) ); @@ -44,6 +45,7 @@ CodeCompleteOptionsDlg::CodeCompleteOptionsDlg( Window* pWindow ) pAutocloseProcChk->Check( CodeCompleteOptions::IsProcedureAutoCompleteOn() ); pAutocloseQuotesChk->Check( CodeCompleteOptions::IsAutoCloseQuotesOn() ); pAutocloseParenChk->Check( CodeCompleteOptions::IsAutoCloseParenthesisOn() ); + pAutoCorrectSpellingChk->Check( CodeCompleteOptions::IsAutoCorrectSpellingOn() ); } CodeCompleteOptionsDlg::~CodeCompleteOptionsDlg() @@ -56,6 +58,7 @@ IMPL_LINK_NOARG(CodeCompleteOptionsDlg, OkHdl) CodeCompleteOptions::SetProcedureAutoCompleteOn( pAutocloseProcChk->IsChecked() ); CodeCompleteOptions::SetAutoCloseQuotesOn( pAutocloseQuotesChk->IsChecked() ); CodeCompleteOptions::SetAutoCloseParenthesisOn( pAutocloseParenChk->IsChecked() ); + CodeCompleteOptions::SetAutoCorrectSpellingOn( pAutoCorrectSpellingChk->IsChecked() ); Close(); return 0; } diff --git a/basctl/source/basicide/codecompleteoptionsdlg.hxx b/basctl/source/basicide/codecompleteoptionsdlg.hxx index 2154c8a00347..4c8b177615d5 100644 --- a/basctl/source/basicide/codecompleteoptionsdlg.hxx +++ b/basctl/source/basicide/codecompleteoptionsdlg.hxx @@ -36,6 +36,7 @@ private: CheckBox* pAutocloseProcChk; CheckBox* pAutocloseParenChk; CheckBox* pAutocloseQuotesChk; + CheckBox* pAutoCorrectSpellingChk; DECL_LINK(OkHdl, void*); DECL_LINK(CancelHdl, void*); |