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:
@@ -490,6 +490,7 @@ friend class CodeCompleteWindow;
|
|||||||
friend class EditorWindow;
|
friend class EditorWindow;
|
||||||
private:
|
private:
|
||||||
OUStringBuffer aFuncBuffer;
|
OUStringBuffer aFuncBuffer;
|
||||||
|
OUString aPrevStr;
|
||||||
/* a buffer to build up function name when typing
|
/* a buffer to build up function name when typing
|
||||||
* a function name, used for showing/hiding listbox values
|
* 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 SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable
|
||||||
void HideAndRestoreFocus();
|
void HideAndRestoreFocus();
|
||||||
|
ExtTextView* GetParentEditView();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CodeCompleteListBox( CodeCompleteWindow* pPar );
|
CodeCompleteListBox( CodeCompleteWindow* pPar );
|
||||||
|
@@ -2550,34 +2550,33 @@ IMPL_LINK_NOARG(CodeCompleteListBox, ImplSelectHdl)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExtTextView* CodeCompleteListBox::GetParentEditView()
|
||||||
|
{
|
||||||
|
return pCodeCompleteWindow->pParent->GetEditView();
|
||||||
|
}
|
||||||
|
|
||||||
void CodeCompleteListBox::InsertSelectedEntry()
|
void CodeCompleteListBox::InsertSelectedEntry()
|
||||||
{
|
{
|
||||||
if( !aFuncBuffer.toString().isEmpty() )
|
if( !aFuncBuffer.toString().isEmpty() )
|
||||||
{
|
{
|
||||||
// if the user typed in something: remove, and insert
|
// if the user typed in something: remove, and insert
|
||||||
TextPaM aEnd(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->GetTextSelection().GetEnd().GetIndex() + aFuncBuffer.getLength());
|
TextPaM aEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
|
||||||
TextPaM aStart(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->GetTextSelection().GetEnd().GetIndex() );
|
GetParentEditView()->SetSelection(TextSelection(pCodeCompleteWindow->GetTextSelection().GetStart(), aEnd ) );
|
||||||
pCodeCompleteWindow->pParent->GetEditView()->SetSelection(TextSelection(aStart, aEnd));
|
GetParentEditView()->DeleteSelected();
|
||||||
pCodeCompleteWindow->pParent->GetEditView()->DeleteSelected();
|
|
||||||
|
|
||||||
if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() )
|
if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() )
|
||||||
{//if the user selected something
|
{//if the user selected something
|
||||||
pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
|
GetParentEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
|
||||||
HideAndRestoreFocus();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HideAndRestoreFocus();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() )
|
if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() )
|
||||||
{//if the user selected something
|
{//if the user selected something
|
||||||
pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
|
GetParentEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True );
|
||||||
HideAndRestoreFocus();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
HideAndRestoreFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeCompleteListBox::SetMatchingEntries()
|
void CodeCompleteListBox::SetMatchingEntries()
|
||||||
@@ -2593,10 +2592,12 @@ void CodeCompleteListBox::SetMatchingEntries()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
|
void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
|
||||||
{
|
{
|
||||||
sal_Unicode aChar = rKeyEvt.GetKeyCode().GetCode();
|
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());
|
aFuncBuffer.append(rKeyEvt.GetCharCode());
|
||||||
SetMatchingEntries();
|
SetMatchingEntries();
|
||||||
@@ -2608,19 +2609,58 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
|
|||||||
case KEY_ESCAPE: // hide, do nothing
|
case KEY_ESCAPE: // hide, do nothing
|
||||||
HideAndRestoreFocus();
|
HideAndRestoreFocus();
|
||||||
break;
|
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();
|
HideAndRestoreFocus();
|
||||||
break;
|
break;
|
||||||
case KEY_BACKSPACE: case KEY_DELETE:
|
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);
|
aFuncBuffer = aFuncBuffer.remove(aFuncBuffer.getLength()-1, 1);
|
||||||
SetMatchingEntries();
|
SetMatchingEntries();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
pCodeCompleteWindow->ClearAndHide();
|
pCodeCompleteWindow->ClearAndHide();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case KEY_RETURN:
|
case KEY_RETURN:
|
||||||
InsertSelectedEntry();
|
InsertSelectedEntry();
|
||||||
@@ -2637,7 +2677,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
|
|||||||
void CodeCompleteListBox::HideAndRestoreFocus()
|
void CodeCompleteListBox::HideAndRestoreFocus()
|
||||||
{
|
{
|
||||||
pCodeCompleteWindow->Hide();
|
pCodeCompleteWindow->Hide();
|
||||||
pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
|
GetParentEditView()->SetSelection( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) );
|
||||||
pCodeCompleteWindow->pParent->GrabFocus();
|
pCodeCompleteWindow->pParent->GrabFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user