GSOC work, code fixes

Small fix in the listbox size: I'm using GetOptimalSize to set the correct width.
EditorWindow::KeyInput: autocomplete/codecomplete functions have been placed into separate functions.
Function autoclose sub/functions: duplicate code removal.

Change-Id: I44678753fc9737fd7a0913af3caa4f1f565aca28
This commit is contained in:
Gergo Mocsi
2013-08-07 09:32:36 +02:00
parent 6b47b09f66
commit 6a2aa97cc1
2 changed files with 280 additions and 259 deletions

View File

@@ -122,6 +122,11 @@ private:
OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number
std::vector< OUString > GetXIdlClassMethods( ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > xClass ) const;
std::vector< OUString > GetXIdlClassFields( ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass > xClass ) const;
void HandleAutoCorrect();
void HandleAutoCloseParen();
void HandleAutoCloseDoubleQuotes();
void HandleCodeCompletition();
void HandleProcedureCompletition();
protected:
virtual void Paint( const Rectangle& );

View File

@@ -521,6 +521,74 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
if( (rKEvt.GetKeyCode().GetCode() == KEY_SPACE ||
rKEvt.GetKeyCode().GetCode() == KEY_TAB ||
rKEvt.GetKeyCode().GetCode() == KEY_RETURN ) && CodeCompleteOptions::IsAutoCorrectKeywordsOn() )
{
HandleAutoCorrect();
}
if( rKEvt.GetCharCode() == '"' && CodeCompleteOptions::IsAutoCloseQuotesOn() )
{//autoclose double quotes
HandleAutoCloseDoubleQuotes();
}
if( rKEvt.GetCharCode() == '(' && CodeCompleteOptions::IsAutoCloseParenthesisOn() )
{//autoclose parenthesis
HandleAutoCloseParen();
}
if( rKEvt.GetKeyCode().GetCode() == KEY_RETURN && CodeCompleteOptions::IsProcedureAutoCompleteOn() )
{//autoclose implementation
HandleProcedureCompletition();
}
if( rKEvt.GetKeyCode().GetCode() == KEY_POINT &&
(CodeCompleteOptions::IsCodeCompleteOn() || CodeCompleteOptions::IsExtendedTypeDeclaration()) )
{
HandleCodeCompletition();
}
if ( !bDone && ( !TextEngine::DoesKeyChangeText( rKEvt ) || ImpCanModify() ) )
{
if ( ( rKEvt.GetKeyCode().GetCode() == KEY_TAB ) && !rKEvt.GetKeyCode().IsMod1() &&
!rKEvt.GetKeyCode().IsMod2() && !GetEditView()->IsReadOnly() )
{
TextSelection aSel( pEditView->GetSelection() );
if ( aSel.GetStart().GetPara() != aSel.GetEnd().GetPara() )
{
bDelayHighlight = false;
if ( !rKEvt.GetKeyCode().IsShift() )
pEditView->IndentBlock();
else
pEditView->UnindentBlock();
bDelayHighlight = true;
bDone = true;
}
}
if ( !bDone )
bDone = pEditView->KeyInput( rKEvt );
}
if ( !bDone )
{
Window::KeyInput( rKEvt );
}
else
{
if (SfxBindings* pBindings = GetBindingsPtr())
{
pBindings->Invalidate( SID_BASICIDE_STAT_POS );
if ( rKEvt.GetKeyCode().GetGroup() == KEYGROUP_CURSOR )
pBindings->Update( SID_BASICIDE_STAT_POS );
if ( !bWasModified && pEditEngine->IsModified() )
{
pBindings->Invalidate( SID_SAVEDOC );
pBindings->Invalidate( SID_DOC_MODIFIED );
pBindings->Invalidate( SID_UNDO );
}
if ( rKEvt.GetKeyCode().GetCode() == KEY_INSERT )
pBindings->Invalidate( SID_ATTR_INSERT );
}
}
}
void EditorWindow::HandleAutoCorrect()
{
TextSelection aSel = GetEditView()->GetSelection();
sal_uLong nLine = aSel.GetStart().GetPara();
@@ -549,8 +617,23 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
}
}
if( rKEvt.GetCharCode() == '"' && CodeCompleteOptions::IsAutoCloseQuotesOn() )
{//autoclose double quotes
void EditorWindow::HandleAutoCloseParen()
{
TextSelection aSel = GetEditView()->GetSelection();
sal_uLong nLine = aSel.GetStart().GetPara();
OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified
if( aLine.getLength() > 0 && aLine[aSel.GetEnd().GetIndex()-1] != '(' )
{
GetEditView()->InsertText(OUString(")"));
//leave the cursor on it's place: inside the parenthesis
TextPaM aEnd(nLine, aSel.GetEnd().GetIndex());
GetEditView()->SetSelection( TextSelection( aEnd, aEnd ) );
}
}
void EditorWindow::HandleAutoCloseDoubleQuotes()
{
TextSelection aSel = GetEditView()->GetSelection();
sal_uLong nLine = aSel.GetStart().GetPara();
OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified
@@ -569,23 +652,8 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
}
}
if( rKEvt.GetCharCode() == '(' && CodeCompleteOptions::IsAutoCloseParenthesisOn() )
{//autoclose parenthesis
TextSelection aSel = GetEditView()->GetSelection();
sal_uLong nLine = aSel.GetStart().GetPara();
OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified
if( aLine.getLength() > 0 && aLine[aSel.GetEnd().GetIndex()-1] != '(' )
void EditorWindow::HandleProcedureCompletition()
{
GetEditView()->InsertText(OUString(")"));
//leave the cursor on it's place: inside the parenthesis
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();
OUString aLine( pEditEngine->GetText( nLine ) );
@@ -618,13 +686,14 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
}
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" );
if( nLine+1 == pEditEngine->GetParagraphCount() )
{ //append to the end
pEditView->InsertText( sText );
}
else
@@ -643,21 +712,11 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
{
if( sStr1.equalsIgnoreAsciiCase("sub") )
{
OUString sText("\nEnd ");
if( sProcType.equalsIgnoreAsciiCase("function") )
sText += OUString( "Function\n" );
if( sProcType.equalsIgnoreAsciiCase("sub") )
sText += OUString( "Sub\n" );
pEditView->InsertText( sText );
break;
}
if( sStr1.equalsIgnoreAsciiCase("function") )
{
OUString sText("\nEnd ");
if( sProcType.equalsIgnoreAsciiCase("function") )
sText += OUString( "Function\n" );
if( sProcType.equalsIgnoreAsciiCase("sub") )
sText += OUString( "Sub\n" );
pEditView->InsertText( sText );
break;
}
@@ -673,8 +732,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
}
}
if( rKEvt.GetKeyCode().GetCode() == KEY_POINT &&
(CodeCompleteOptions::IsCodeCompleteOn() || CodeCompleteOptions::IsExtendedTypeDeclaration()) )
void EditorWindow::HandleCodeCompletition()
{
rModulWindow.UpdateModule();
rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse(aCodeCompleteCache);
@@ -796,48 +854,6 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
}
}
}
if ( !bDone && ( !TextEngine::DoesKeyChangeText( rKEvt ) || ImpCanModify() ) )
{
if ( ( rKEvt.GetKeyCode().GetCode() == KEY_TAB ) && !rKEvt.GetKeyCode().IsMod1() &&
!rKEvt.GetKeyCode().IsMod2() && !GetEditView()->IsReadOnly() )
{
TextSelection aSel( pEditView->GetSelection() );
if ( aSel.GetStart().GetPara() != aSel.GetEnd().GetPara() )
{
bDelayHighlight = false;
if ( !rKEvt.GetKeyCode().IsShift() )
pEditView->IndentBlock();
else
pEditView->UnindentBlock();
bDelayHighlight = true;
bDone = true;
}
}
if ( !bDone )
bDone = pEditView->KeyInput( rKEvt );
}
if ( !bDone )
{
Window::KeyInput( rKEvt );
}
else
{
if (SfxBindings* pBindings = GetBindingsPtr())
{
pBindings->Invalidate( SID_BASICIDE_STAT_POS );
if ( rKEvt.GetKeyCode().GetGroup() == KEYGROUP_CURSOR )
pBindings->Update( SID_BASICIDE_STAT_POS );
if ( !bWasModified && pEditEngine->IsModified() )
{
pBindings->Invalidate( SID_SAVEDOC );
pBindings->Invalidate( SID_DOC_MODIFIED );
pBindings->Invalidate( SID_UNDO );
}
if ( rKEvt.GetKeyCode().GetCode() == KEY_INSERT )
pBindings->Invalidate( SID_ATTR_INSERT );
}
}
}
std::vector< OUString > EditorWindow::GetXIdlClassMethods( Reference< reflection::XIdlClass > xClass ) const
{
@@ -2659,7 +2675,6 @@ void CodeCompleteListBox::SetVisibleEntries()
void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
{
//std::cerr << "CodeCompleteListBox::KeyInput" << std::endl;
sal_Unicode aChar = rKeyEvt.GetKeyCode().GetCode();
if( ( aChar >= KEY_A ) && ( aChar <= KEY_Z ) )
{
@@ -2768,8 +2783,9 @@ void CodeCompleteWindow::ResizeListBox()
const Font& aFont = pListBox->GetUnzoomedControlPointFont();
Rectangle aVisArea( pParent->GetEditView()->GetStartDocPos(), pParent->GetOutputSizePixel() );
Size aSize = pListBox->CalcSize( nColumns+1, nLines );
aSize.setWidth(nWidth+5);
Size aSize = pListBox->GetOptimalSize();//this sets the correct width
aSize.setHeight( pListBox->CalcSize( nColumns, nLines ).getHeight() );
Point aBottomPoint = aVisArea.BottomRight();
Point aTopPoint = aVisArea.TopRight();
long nYDiff = std::abs((aBottomPoint.Y() - aTopPoint.Y()) - GetPosPixel().Y());