diff options
author | Gergo Mocsi <gmocsi91@gmail.com> | 2013-08-08 18:02:02 +0200 |
---|---|---|
committer | Gergo Mocsi <gmocsi91@gmail.com> | 2013-09-02 18:16:58 +0200 |
commit | 6cb452f36649762e3cc0e477d0a543eeff741bbd (patch) | |
tree | 188e269cb6288dbd23479ff2d90a899e95b71afc /basctl/source | |
parent | 0861ff9dc0db7d58e73ae0cd7c884f21cf55c4c5 (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
Diffstat (limited to 'basctl/source')
-rw-r--r-- | basctl/source/basicide/baside2.hxx | 2 | ||||
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 76 |
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 6d03c4a6d83f..0b0448196bb2 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -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(); } |