42 std::function<
void( wxKeyEvent& )> onAcceptFn,
43 std::function<
void( wxStyledTextEvent& )> onCharAddedFn ) :
55 m_te->SetEOLMode( wxSTC_EOL_LF );
59 m_te->SetScrollWidth( 1 );
60 m_te->SetScrollWidthTracking(
true );
64 m_te->SetUseVerticalScrollBar(
false );
65 m_te->SetUseHorizontalScrollBar(
false );
71 m_te->AutoCompSetIgnoreCase(
true );
72 m_te->AutoCompSetMaxHeight( 20 );
74 if( aBraces.Length() >= 2 )
88 m_te->Bind( wxEVT_SYS_COLOUR_CHANGED,
103 wxTextCtrl
dummy(
m_te->GetParent(), wxID_ANY );
106 KIGFX::COLOR4D highlight = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
107 KIGFX::COLOR4D highlightText = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
109 m_te->StyleSetForeground( wxSTC_STYLE_DEFAULT, foreground.
ToColour() );
110 m_te->StyleSetBackground( wxSTC_STYLE_DEFAULT, background.
ToColour() );
111 m_te->StyleClearAll();
115 highlight = highlight.
Mix( background, highlight.
a ).
WithAlpha( 1.0 );
116 highlightText = highlightText.
Mix( background, highlightText.
a ).
WithAlpha( 1.0 );
118 m_te->SetSelForeground(
true, highlightText.
ToColour() );
128 for(
size_t i = 0; i < wxSTC_STYLE_MAX; ++i )
129 m_te->StyleSetFont( i, fixedFont );
131 m_te->SetTabWidth( 4 );
139 m_te->StyleSetForeground( wxSTC_STYLE_BRACELIGHT, highlightText.
ToColour() );
140 m_te->StyleSetBackground( wxSTC_STYLE_BRACELIGHT, braceHighlight.
ToColour() );
141 m_te->StyleSetForeground( wxSTC_STYLE_BRACEBAD, *wxRED );
255 auto findGridTricks =
258 wxWindow* parent =
m_te->GetParent();
260 while( parent && !
dynamic_cast<WX_GRID*
>( parent ) )
261 parent = parent->GetParent();
265 wxEvtHandler* handler =
grid->GetEventHandler();
267 while( handler && !
dynamic_cast<GRID_TRICKS*
>( handler ) )
268 handler = handler->GetNextHandler();
277 wxString c = aEvent.GetUnicodeKey();
279 if(
m_te->AutoCompActive() )
281 if( aEvent.GetKeyCode() == WXK_ESCAPE )
283 m_te->AutoCompCancel();
286 else if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
288 int start =
m_te->AutoCompPosStart();
290 m_te->AutoCompComplete();
292 int finish =
m_te->GetCurrentPos();
298 int selStart =
m_te->FindText( finish, start,
"<" );
299 int selEnd =
m_te->FindText( finish, start,
">" );
301 if( selStart > start && selEnd <= finish && selEnd > selStart )
302 m_te->SetSelection( selStart, selEnd + 1 );
314 if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() == WXK_SPACE )
316 if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == WXK_SPACE )
321 wxStyledTextEvent event;
323 event.SetModifiers( wxMOD_CONTROL );
329 if( !isalpha( aEvent.GetKeyCode() ) )
332 if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
341 else if( aEvent.GetKeyCode() == WXK_TAB )
343 wxWindow* ancestor =
m_te->GetParent();
345 while( ancestor && !
dynamic_cast<WX_GRID*
>( ancestor ) )
346 ancestor = ancestor->GetParent();
348 if( aEvent.ControlDown() )
352 if( !aEvent.ShiftDown() )
353 flags |= wxNavigationKeyEvent::IsForward;
356 dlg->NavigateIn( flags );
358 else if(
dynamic_cast<WX_GRID*
>( ancestor ) )
361 int row =
grid->GetGridCursorRow();
362 int col =
grid->GetGridCursorCol();
364 if( aEvent.ShiftDown() )
372 col = (int)
grid->GetNumberCols() - 1;
378 if( col < (
int)
grid->GetNumberCols() - 1 )
382 else if( row < grid->GetNumberRows() - 1 )
389 grid->SetGridCursor( row, col );
396 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
400 else if( ( aEvent.GetModifiers() == wxMOD_SHIFT+wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
401 || ( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Y' ) )
405 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'A' )
409 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'X' )
413 if( wxTheClipboard->Open() )
415 wxTheClipboard->Flush();
416 wxTheClipboard->Close();
419 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'C' )
423 if( wxTheClipboard->Open() )
425 wxTheClipboard->Flush();
426 wxTheClipboard->Close();
429 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'V' )
431 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
437 if( wxTheClipboard->Open() )
439 if( wxTheClipboard->IsSupported( wxDF_TEXT ) ||
440 wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
442 wxTextDataObject data;
445 wxTheClipboard->GetData( data );
446 str = data.GetText();
448 if( str.Contains(
'\t' ) )
449 gridTricks = findGridTricks();
457 str.Replace( wxS(
"\n" ), wxEmptyString );
458 str.Replace( wxS(
"\r" ), wxEmptyString );
461 m_te->BeginUndoAction();
462 m_te->AddText( str );
463 m_te->EndUndoAction();
467 wxTheClipboard->Close();
473 else if( aEvent.GetKeyCode() == WXK_BACK )
475 if( aEvent.GetModifiers() == wxMOD_CONTROL )
478 else if( aEvent.GetModifiers() == wxMOD_ALT )
480 m_te->WordLeftExtend();
484 else if( aEvent.GetKeyCode() == WXK_DELETE )
486 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
489 if( aEvent.GetModifiers() == wxMOD_CONTROL )
490 m_te->WordRightExtend();
493 m_te->CharRightExtend();
496 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
501 int startLine =
m_te->LineFromPosition(
m_te->GetSelectionStart() );
502 int endLine =
m_te->LineFromPosition(
m_te->GetSelectionEnd() );
506 m_te->BeginUndoAction();
508 for(
int ii = startLine; ii <= endLine; ++ii )
511 m_te->InsertText(
m_te->PositionFromLine( ii ), wxT(
"#" ) );
513 m_te->DeleteRange(
m_te->PositionFromLine( ii ) + whitespaceCount, 1 );
516 m_te->SetSelection(
m_te->PositionFromLine( startLine ),
517 m_te->PositionFromLine( endLine ) +
m_te->GetLineLength( endLine ) );
519 m_te->EndUndoAction();
522 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'A' )
526 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'E' )
530 else if( ( aEvent.GetModifiers() & wxMOD_RAW_CONTROL ) && aEvent.GetKeyCode() ==
'B' )
532 if( aEvent.GetModifiers() & wxMOD_ALT )
537 else if( ( aEvent.GetModifiers() & wxMOD_RAW_CONTROL ) && aEvent.GetKeyCode() ==
'F' )
539 if( aEvent.GetModifiers() & wxMOD_ALT )
544 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'D' )
546 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
547 m_te->CharRightExtend();
549 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
553 else if( aEvent.GetKeyCode() == WXK_SPECIAL20 )
596 [
this](
int c ) ->
bool
598 return m_braces.Find( (wxChar) c ) >= 0;
602 int caretPos =
m_te->GetCurrentPos();
603 int selStart =
m_te->GetSelectionStart();
604 int selEnd =
m_te->GetSelectionEnd();
615 if( caretPos > 0 && isBrace(
m_te->GetCharAt( caretPos-1 ) ) )
616 bracePos1 = ( caretPos - 1 );
617 else if( isBrace(
m_te->GetCharAt( caretPos ) ) )
618 bracePos1 = caretPos;
623 bracePos2 =
m_te->BraceMatch( bracePos1 );
625 if( bracePos2 == -1 )
627 m_te->BraceBadLight( bracePos1 );
628 m_te->SetHighlightGuide( 0 );
632 m_te->BraceHighlight( bracePos1, bracePos2 );
633 m_te->SetHighlightGuide(
m_te->GetColumn( bracePos1 ) );
639 m_te->BraceHighlight( -1, -1 );
640 m_te->SetHighlightGuide( 0 );
647 wxArrayString* tokens )>& getTokensFn )
649 wxArrayString autocompleteTokens;
650 int text_pos =
m_te->GetCurrentPos();
651 int start =
m_te->WordStartPosition( text_pos,
true );
657 return pos >= 2 &&
m_te->GetCharAt( pos-2 ) ==
'$'
658 &&
m_te->GetCharAt( pos-1 ) ==
'{';
662 if( start > 1 &&
m_te->GetCharAt( start-1 ) ==
':' )
664 int refStart =
m_te->WordStartPosition( start-1,
true );
666 if( textVarRef( refStart ) )
668 partial =
m_te->GetRange( start, text_pos );
669 getTokensFn(
m_te->GetRange( refStart, start-1 ), &autocompleteTokens );
672 else if( textVarRef( start ) )
674 partial =
m_te->GetTextRange( start, text_pos );
675 getTokensFn( wxEmptyString, &autocompleteTokens );