GSOC work, TAB key inserts match+code fixes

Feature: TAB key now inserts the matching entry. When the TAB key is pressed simultaneously, it selects+inserts the next match.
Fixed some duplicate code calls.
Added a function called CodeCompleteListBox::GetParentEditWiew() to shorter the parent's ExtTextView variable access.

Change-Id: I2ae2eaa07fff760d91d05120439c76b215fcd3c1
This commit is contained in:
Gergo Mocsi 2013-08-08 18:02:02 +02:00
parent 0861ff9dc0
commit 6cb452f366
2 changed files with 60 additions and 18 deletions

View File

@ -490,6 +490,7 @@ friend class CodeCompleteWindow;
friend class EditorWindow;
private:
OUStringBuffer aFuncBuffer;
OUString aPrevStr;
/* a buffer to build up function name when typing
* a function name, used for showing/hiding listbox values
* */
@ -497,6 +498,7 @@ private:
void SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable
void HideAndRestoreFocus();
ExtTextView* GetParentEditView();
public:
CodeCompleteListBox( CodeCompleteWindow* pPar );

View File

@ -2550,34 +2550,33 @@ IMPL_LINK_NOARG(CodeCompleteListBox, ImplSelectHdl)
return 0;
}
ExtTextView* CodeCompleteListBox::GetParentEditView()
{
return pCodeCompleteWindow->pParent->GetEditView();
}
void CodeCompleteListBox::InsertSelectedEntry()
{
if( !aFuncBuffer.toString().isEmpty() )
{
// if the user typed in something: remove, and insert
TextPaM aEnd(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->GetTextSelection().GetEnd().GetIndex() + aFuncBuffer.getLength());
TextPaM aStart(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->GetTextSelection().GetEnd().GetIndex() );
pCodeCompleteWindow->pParent->GetEditView()->SetSelection(TextSelection(aStart, aEnd));
pCodeCompleteWindow->pParent->GetEditView()->DeleteSelected();
TextPaM aEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
GetParentEditView()->SetSelection(TextSelection(pCodeCompleteWindow->GetTextSelection().GetStart(), aEnd ) );
GetParentEditView()->DeleteSelected();
if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() )
{//if the user selected something
pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
HideAndRestoreFocus();
}
else
{
HideAndRestoreFocus();
GetParentEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
}
}
else
{
if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() )
{//if the user selected something
pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
HideAndRestoreFocus();
GetParentEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
}
}
HideAndRestoreFocus();
}
void CodeCompleteListBox::SetMatchingEntries()
@ -2593,10 +2592,12 @@ void CodeCompleteListBox::SetMatchingEntries()
}
}
void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
{
sal_Unicode aChar = rKeyEvt.GetKeyCode().GetCode();
if( ( aChar >= KEY_A ) && ( aChar <= KEY_Z ) )
if( (( aChar >= KEY_A ) && ( aChar <= KEY_Z ))
|| ((aChar >= KEY_0) && (aChar <= KEY_9)) )
{
aFuncBuffer.append(rKeyEvt.GetCharCode());
SetMatchingEntries();
@ -2608,19 +2609,58 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
case KEY_ESCAPE: // hide, do nothing
HideAndRestoreFocus();
break;
case KEY_TAB: case KEY_SPACE:
case KEY_TAB:
if( !aFuncBuffer.isEmpty() )
{
sal_uInt16 nInd = GetSelectEntryPos();
if( nInd+1 != LISTBOX_ENTRY_NOTFOUND )
{//if there is something selected
bool bFound = false;
if( nInd == GetEntryCount() )
nInd = 0;
for( sal_uInt16 i = nInd+1; i != GetEntryCount(); ++i )
{
OUString sEntry = (OUString) GetEntry(i);
if( sEntry.startsWithIgnoreAsciiCase( aFuncBuffer.toString() ) )
{
SelectEntry( sEntry );
bFound = true;
break;
}
}
if( !bFound )
SetMatchingEntries();
TextPaM aEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
GetParentEditView()->SetSelection(TextSelection(pCodeCompleteWindow->GetTextSelection().GetStart(), aEnd ) );
GetParentEditView()->DeleteSelected();
GetParentEditView()->InsertText( GetSelectEntry(), sal_False );
}
}
break;
case KEY_SPACE:
HideAndRestoreFocus();
break;
case KEY_BACKSPACE: case KEY_DELETE:
if( aFuncBuffer.toString() != OUString("") )
if( !aFuncBuffer.toString().isEmpty() )
{
//if there was something inserted by tab: add it to aFuncBuffer
TextSelection aSel( GetParentEditView()->GetSelection() );
TextPaM aEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
GetParentEditView()->SetSelection(TextSelection(pCodeCompleteWindow->GetTextSelection().GetStart(), aEnd ) );
OUString aTabInsertedStr( ((OUString)GetParentEditView()->GetSelected()) );
GetParentEditView()->SetSelection( aSel );
if( !aTabInsertedStr.isEmpty() && aTabInsertedStr != aFuncBuffer.toString() )
{
aFuncBuffer.makeStringAndClear();
aFuncBuffer = aFuncBuffer.append(aTabInsertedStr);
}
aFuncBuffer = aFuncBuffer.remove(aFuncBuffer.getLength()-1, 1);
SetMatchingEntries();
}
else
{
pCodeCompleteWindow->ClearAndHide();
}
break;
case KEY_RETURN:
InsertSelectedEntry();
@ -2637,7 +2677,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
void CodeCompleteListBox::HideAndRestoreFocus()
{
pCodeCompleteWindow->Hide();
pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
GetParentEditView()->SetSelection( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
pCodeCompleteWindow->pParent->GrabFocus();
}