diff options
author | Gergo Mocsi <gmocsi91@gmail.com> | 2013-08-07 12:30:14 +0200 |
---|---|---|
committer | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-02 18:16:57 +0200 |
commit | 06e4ed0e6f93e8a36f9f56cb9ce5ced1c4b75601 (patch) | |
tree | fd887e0e450af76ff6da14f0829119b31f36ade2 /basctl | |
parent | GSOC work, code simplification (diff) | |
download | core-06e4ed0e6f93e8a36f9f56cb9ce5ced1c4b75601.tar.gz core-06e4ed0e6f93e8a36f9f56cb9ce5ced1c4b75601.zip |
GSOC work, code simplification+removed unused functions
Removed some unused functions from CodeCompleteListBox/CodeCompleteWindow.
Renamed CodeCompleteListBox::SetVisibleEntries to SetMatchingEntries.
Simplified autocorrect functions.
Change-Id: I29f9653d52fff2c5020243aa5c14f1ea280018d3
Diffstat (limited to 'basctl')
-rw-r--r-- | basctl/source/basicide/baside2.hxx | 5 | ||||
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 216 |
2 files changed, 106 insertions, 115 deletions
diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx index b3114cacc64c..9c162fc6ed1b 100644 --- a/basctl/source/basicide/baside2.hxx +++ b/basctl/source/basicide/baside2.hxx @@ -124,6 +124,7 @@ private: CodeCompleteDataCache aCodeCompleteCache; boost::scoped_ptr< CodeCompleteWindow > pCodeCompleteWnd; OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number + void SetupAndShowCodeCompleteWnd(const std::vector< OUString >& aEntryVect, TextSelection aSel ); void HandleAutoCorrect(); void HandleAutoCloseParen(); void HandleAutoCloseDoubleQuotes(); @@ -494,7 +495,7 @@ private: * */ CodeCompleteWindow* pCodeCompleteWindow; // parent window - void SetVisibleEntries(); // sets the visible entries based on aFuncBuffer variable + void SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable void HideAndRestoreFocus(); public: @@ -533,8 +534,6 @@ public: * clears if typed anything, then hides * the window, clear internal variables * */ - OUStringBuffer& GetListBoxBuffer(); - void SetVisibleEntries(); // sets the visible entries based on aFuncBuffer variable CodeCompleteListBox* GetListBox(){return pListBox;} }; diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 4b313f028bc4..301d2c046298 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -593,23 +593,24 @@ void EditorWindow::HandleAutoCorrect() HighlightPortions aPortions; aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); - if( aPortions.size() > 0 ) + + if( aPortions.size() == 0 ) + return; + + HighlightPortion& r = aPortions[aPortions.size()-1]; + if( r.tokenType == 9 ) // correct the last entered keyword { - 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() ) { - 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 ); - } + //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 ); } } } @@ -637,15 +638,16 @@ void EditorWindow::HandleAutoCloseDoubleQuotes() HighlightPortions aPortions; aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); - if( aPortions.size() != 0 ) + + if( aPortions.size() == 0 ) + return; + + if( aLine.getLength() > 0 && aLine[aLine.getLength()-1] != '"' && (aPortions[aPortions.size()-1].tokenType != 4) ) { - if( aLine.getLength() > 0 && 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 ) ); - } + 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 ) ); } } @@ -654,75 +656,70 @@ void EditorWindow::HandleProcedureCompletition() TextSelection aSel = GetEditView()->GetSelection(); sal_uLong nLine = aSel.GetStart().GetPara(); OUString aLine( pEditEngine->GetText( nLine ) ); - OUString sActSub = GetActualSubName( nLine ); HighlightPortions aPortions; aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + + if( aPortions.size() == 0 ) + return; + OUString sProcType; OUString sProcName; bool bFoundType = false; bool bFoundName = false; - if( aPortions.size() != 0 ) + + for ( size_t i = 0; i < aPortions.size(); i++ ) { - 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")) ) { - 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; - } + sProcType = sTokStr; + bFoundType = true; } - if( bFoundType && bFoundName ) - {// found, search for end - OUString sText("\nEnd "); - if( sProcType.equalsIgnoreAsciiCase("function") ) - sText += OUString( "Function\n" ); - if( sProcType.equalsIgnoreAsciiCase("sub") ) - sText += OUString( "Sub\n" ); - - if( nLine+1 == pEditEngine->GetParagraphCount() ) - { //append to the end - pEditView->InsertText( sText ); - } - else - { - for( sal_uLong i = nLine+1; i < pEditEngine->GetParagraphCount(); ++i ) + if( r.tokenType == 1 && bFoundType ) + { + sProcName = sTokStr; + bFoundName = true; + break; + } + } + + if( !bFoundType || !bFoundName ) + return;// no sub/function keyword or there is no identifier + + OUString sText("\nEnd "); + if( sProcType.equalsIgnoreAsciiCase("function") ) + sText += OUString( "Function\n" ); + if( sProcType.equalsIgnoreAsciiCase("sub") ) + sText += OUString( "Sub\n" ); + + if( nLine+1 == pEditEngine->GetParagraphCount() ) + pEditView->InsertText( sText );//append to the end + else + { + for( sal_uLong i = nLine+1; i < pEditEngine->GetParagraphCount(); ++i ) + {//searching forward for end token, or another sub/function definition + OUString aCurrLine = pEditEngine->GetText( i ); + HighlightPortions aCurrPortions; + aHighlighter.getHighlightPortions( i, aCurrLine, aCurrPortions ); + + if( aCurrPortions.size() >= 3 ) + {//at least 3 tokens: (sub|function) whitespace idetifier .... + HighlightPortion& r = aCurrPortions[0]; + OUString sStr = aCurrLine.copy(r.nBegin, r.nEnd - r.nBegin); + + if( r.tokenType == 9 ) { - OUString aCurrLine = pEditEngine->GetText( i ); - HighlightPortions aCurrPortions; - aHighlighter.getHighlightPortions( i, aCurrLine, aCurrPortions ); - if( aCurrPortions.size() >= 3 ) + if( sStr.equalsIgnoreAsciiCase("sub") || sStr.equalsIgnoreAsciiCase("function") ) { - HighlightPortion& r1 = aCurrPortions[0]; - OUString sStr1 = aCurrLine.copy(r1.nBegin, r1.nEnd - r1.nBegin); - - if( r1.tokenType == 9 ) - { - if( sStr1.equalsIgnoreAsciiCase("sub") ) - { - pEditView->InsertText( sText ); - break; - } - if( sStr1.equalsIgnoreAsciiCase("function") ) - { - pEditView->InsertText( sText ); - break; - } - if( sStr1.equalsIgnoreAsciiCase("end") ) - { - break; - } - } + pEditView->InsertText( sText ); + break; } + if( sStr.equalsIgnoreAsciiCase("end") ) + break; } } } @@ -776,31 +773,36 @@ void EditorWindow::HandleCodeCompletition() } if( aEntryVect.size() > 0 ) { - // calculate position - Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false ); - long nViewYOffset = pEditView->GetStartDocPos().Y(); - Point aPoint = aRect.BottomRight(); - aPoint.Y() = (aPoint.Y() - nViewYOffset) + 2; - aSel.GetStart().GetIndex() += 1; - aSel.GetEnd().GetIndex() += 1; - pCodeCompleteWnd->ClearListBox(); - pCodeCompleteWnd->SetTextSelection(aSel); - //fill the listbox - for(unsigned int l = 0; l < aEntryVect.size(); ++l) - { - pCodeCompleteWnd->InsertEntry( aEntryVect[l] ); - } - //show it - pCodeCompleteWnd->SetPosPixel( aPoint ); - pCodeCompleteWnd->Show(); - pCodeCompleteWnd->ResizeListBox(); - pCodeCompleteWnd->SelectFirstEntry(); - pEditView->GetWindow()->GrabFocus(); + SetupAndShowCodeCompleteWnd( aEntryVect, aSel ); } } } } +void EditorWindow::SetupAndShowCodeCompleteWnd(const std::vector< OUString >& aEntryVect, TextSelection aSel ) +{ + // calculate position + Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false ); + long nViewYOffset = pEditView->GetStartDocPos().Y(); + Point aPoint = aRect.BottomRight(); + aPoint.Y() = (aPoint.Y() - nViewYOffset) + 2; + aSel.GetStart().GetIndex() += 1; + aSel.GetEnd().GetIndex() += 1; + pCodeCompleteWnd->ClearListBox(); + pCodeCompleteWnd->SetTextSelection(aSel); + //fill the listbox + for(unsigned int l = 0; l < aEntryVect.size(); ++l) + { + pCodeCompleteWnd->InsertEntry( aEntryVect[l] ); + } + //show it + pCodeCompleteWnd->SetPosPixel( aPoint ); + pCodeCompleteWnd->Show(); + pCodeCompleteWnd->ResizeListBox(); + pCodeCompleteWnd->SelectFirstEntry(); + pEditView->GetWindow()->GrabFocus(); +} + void EditorWindow::Paint( const Rectangle& rRect ) { if ( !pEditEngine ) // We need it now at latest @@ -2578,7 +2580,7 @@ void CodeCompleteListBox::InsertSelectedEntry() } } -void CodeCompleteListBox::SetVisibleEntries() +void CodeCompleteListBox::SetMatchingEntries() { for(sal_uInt16 i=0; i< GetEntryCount(); ++i) { @@ -2597,7 +2599,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt ) if( ( aChar >= KEY_A ) && ( aChar <= KEY_Z ) ) { aFuncBuffer.append(rKeyEvt.GetCharCode()); - SetVisibleEntries(); + SetMatchingEntries(); } else { @@ -2613,7 +2615,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt ) if( aFuncBuffer.toString() != OUString("") ) { aFuncBuffer = aFuncBuffer.remove(aFuncBuffer.getLength()-1, 1); - SetVisibleEntries(); + SetMatchingEntries(); } else { @@ -2648,11 +2650,6 @@ pListBox( new CodeCompleteListBox(this) ) InitListBox(); } -OUStringBuffer& CodeCompleteWindow::GetListBoxBuffer() -{ - return pListBox->aFuncBuffer; -} - void CodeCompleteWindow::InitListBox() { pListBox->SetSizePixel( Size(150,150) ); //default, this will adopt the line length @@ -2749,11 +2746,6 @@ void CodeCompleteWindow::ClearAndHide() pParent->GrabFocus(); } -void CodeCompleteWindow::SetVisibleEntries() -{ - pListBox->SetVisibleEntries(); -} - UnoTypeCodeCompletetor::UnoTypeCodeCompletetor( const std::vector< OUString >& aVect, const OUString& sVarType ) : bCanComplete( true ) { |