summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGergo Mocsi <gmocsi91@gmail.com>2013-08-08 18:02:02 +0200
committerGergo Mocsi <gmocsi91@gmail.com>2013-08-08 18:02:02 +0200
commit0064a463371d3a41ccd7b01398b2f3a92c61367c (patch)
tree63d7ff5369060d90efc1e7c1f4d896a46bd8cbd4
parentf022a4966d838b14cdfb1608ba0999520e3b6e40 (diff)
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
-rw-r--r--basctl/source/basicide/baside2.hxx2
-rw-r--r--basctl/source/basicide/baside2b.cxx76
2 files changed, 60 insertions, 18 deletions
diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index 8f96116e614c..4c4ac343095d 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -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 );
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index b9f0cadf33e7..49f9058ad883 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -2544,34 +2544,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()
@@ -2587,10 +2586,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();
@@ -2602,19 +2603,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();
@@ -2631,7 +2671,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();
}