27#include <wx/stc/stc.h>
30#include <wx/clipbrd.h>
32#include <wx/settings.h>
36 bool aSingleLine, std::function<
void()> aReturnCallback ) :
42 m_suppressAutocomplete( false ),
43 m_singleLine( aSingleLine ),
44 m_returnCallback( aReturnCallback )
47 m_te->SetEOLMode( wxSTC_EOL_LF );
51 m_te->SetScrollWidth( 1 );
52 m_te->SetScrollWidthTracking(
true );
57 m_te->AutoCompSetIgnoreCase(
true );
59 m_te->AutoCompSetMaxHeight( 20 );
67 m_te->Bind( wxEVT_SYS_COLOUR_CHANGED,
82 wxTextCtrl
dummy(
m_te->GetParent(), wxID_ANY );
85 KIGFX::COLOR4D highlight = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
86 KIGFX::COLOR4D highlightText = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
88 m_te->StyleSetForeground( wxSTC_STYLE_DEFAULT, foreground.ToColour() );
89 m_te->StyleSetBackground( wxSTC_STYLE_DEFAULT, background.ToColour() );
90 m_te->StyleClearAll();
94 highlight = highlight.
Mix( background, highlight.
a ).
WithAlpha( 1.0 );
95 highlightText = highlightText.
Mix( background, highlightText.
a ).
WithAlpha( 1.0 );
97 m_te->SetSelForeground(
true, highlightText.ToColour() );
98 m_te->SetSelBackground(
true, highlight.ToColour() );
99 m_te->SetCaretForeground( foreground.ToColour() );
107 for(
size_t i = 0; i < wxSTC_STYLE_MAX; ++i )
108 m_te->StyleSetFont( i, fixedFont );
110 m_te->SetTabWidth( 4 );
118 m_te->StyleSetForeground( wxSTC_STYLE_BRACELIGHT, highlightText.ToColour() );
119 m_te->StyleSetBackground( wxSTC_STYLE_BRACELIGHT, braceHighlight.ToColour() );
120 m_te->StyleSetForeground( wxSTC_STYLE_BRACEBAD, *wxRED );
126 if( !aEvent.ControlDown() || aEvent.MetaDown() )
129 if( aEvent.GetUnicodeKey() ==
'/' )
147 if( aEvent.ShiftDown() && ( aEvent.GetUnicodeKey() ==
'7' || aEvent.GetUnicodeKey() ==
':' ) )
160 wxString c = aEvent.GetUnicodeKey();
162 if( !isalpha( aEvent.GetKeyCode() ) )
165 if( aEvent.GetKeyCode() == WXK_RETURN && (
m_singleLine || aEvent.ShiftDown() ) )
173 else if( aEvent.GetKeyCode() == WXK_TAB )
175 if( aEvent.ControlDown() )
179 if( !aEvent.ShiftDown() )
180 flags |= wxNavigationKeyEvent::IsForward;
182 wxWindow* parent =
m_te->GetParent();
184 while( parent &&
dynamic_cast<DIALOG_SHIM*
>( parent ) ==
nullptr )
185 parent = parent->GetParent();
188 parent->NavigateIn( flags );
195 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
199 else if( ( aEvent.GetModifiers() == wxMOD_SHIFT+wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Z' )
200 || ( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'Y' ) )
204 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'A' )
208 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'X' )
212 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'C' )
216 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() ==
'V' )
218 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
223 if( wxTheClipboard->Open() )
225 if( wxTheClipboard->IsSupported( wxDF_TEXT ) ||
226 wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
228 wxTextDataObject data;
231 wxTheClipboard->GetData( data );
232 str = data.GetText();
235 m_te->BeginUndoAction();
236 m_te->AddText( str );
237 m_te->EndUndoAction();
240 wxTheClipboard->Close();
243 else if( aEvent.GetKeyCode() == WXK_BACK )
247 else if( aEvent.GetKeyCode() == WXK_DELETE )
249 if(
m_te->GetSelectionEnd() ==
m_te->GetSelectionStart() )
250 m_te->CharRightExtend();
252 if(
m_te->GetSelectionEnd() >
m_te->GetSelectionStart() )
255 else if( aEvent.GetKeyCode() == WXK_ESCAPE )
257 if(
m_te->AutoCompActive() )
259 m_te->AutoCompCancel();
269 int startLine =
m_te->LineFromPosition(
m_te->GetSelectionStart() );
270 int endLine =
m_te->LineFromPosition(
m_te->GetSelectionEnd() );
274 m_te->BeginUndoAction();
276 for(
int ii = startLine; ii <= endLine; ++ii )
279 m_te->InsertText(
m_te->PositionFromLine( ii ), wxT(
"#" ) );
281 m_te->DeleteRange(
m_te->PositionFromLine( ii ) + whitespaceCount, 1 );
284 m_te->SetSelection(
m_te->PositionFromLine( startLine ),
285 m_te->PositionFromLine( endLine ) +
m_te->GetLineLength( endLine ) );
287 m_te->EndUndoAction();
290 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'A' )
294 else if( aEvent.GetModifiers() == wxMOD_RAW_CONTROL && aEvent.GetKeyCode() ==
'E' )
299 else if( aEvent.GetKeyCode() == WXK_SPECIAL20 )
313 int lineStart =
m_te->PositionFromLine( aLine );
315 if( aWhitespaceCharCount )
316 *aWhitespaceCharCount = 0;
318 for(
int ii = 0; ii <
m_te->GetLineLength( aLine ); ++ii )
320 int c =
m_te->GetCharAt( lineStart + ii );
322 if( c ==
' ' || c ==
'\t' )
324 if( aWhitespaceCharCount )
325 *aWhitespaceCharCount += 1;
341 auto isBrace = [
this](
int c ) ->
bool
343 return m_braces.Find( (wxChar) c ) >= 0;
347 int caretPos =
m_te->GetCurrentPos();
348 int selStart =
m_te->GetSelectionStart();
349 int selEnd =
m_te->GetSelectionEnd();
360 if( caretPos > 0 && isBrace(
m_te->GetCharAt( caretPos-1 ) ) )
361 bracePos1 = ( caretPos - 1 );
362 else if( isBrace(
m_te->GetCharAt( caretPos ) ) )
363 bracePos1 = caretPos;
368 bracePos2 =
m_te->BraceMatch( bracePos1 );
370 if( bracePos2 == -1 )
372 m_te->BraceBadLight( bracePos1 );
373 m_te->SetHighlightGuide( 0 );
377 m_te->BraceHighlight( bracePos1, bracePos2 );
378 m_te->SetHighlightGuide(
m_te->GetColumn( bracePos1 ) );
384 m_te->BraceHighlight( -1, -1 );
385 m_te->SetHighlightGuide( 0 );
396 wxArrayString matchedTokens;
398 wxString
filter = wxT(
"*" ) + aPartial.Lower() + wxT(
"*" );
400 for(
const wxString& token : aTokens )
402 if( token.Lower().Matches(
filter ) )
403 matchedTokens.push_back( token );
406 if( matchedTokens.size() > 0 )
410 matchedTokens.Sort( [](
const wxString& first,
const wxString& second ) ->
int
412 return first.CmpNoCase( second );
415 m_te->AutoCompShow( aPartial.size(), wxJoin( matchedTokens,
m_te->AutoCompGetSeparator() ) );
422 m_te->AutoCompCancel();
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
A color representation with 4 components: red, green, blue, alpha.
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
std::function< void()> m_returnCallback
int firstNonWhitespace(int aLine, int *aWhitespaceCount=nullptr)
void onCharHook(wxKeyEvent &aEvent)
SCINTILLA_TRICKS(wxStyledTextCtrl *aScintilla, const wxString &aBraces, bool aSingleLine, std::function< void()> m_enterCallback=[](){ })
void onThemeChanged(wxSysColourChangedEvent &aEvent)
void DoAutocomplete(const wxString &aPartial, const wxArrayString &aTokens)
bool m_suppressAutocomplete
void CancelAutocomplete()
void onScintillaUpdateUI(wxStyledTextEvent &aEvent)
This file is part of the common library.
wxFont GetMonospacedUIFont()
bool isCtrlSlash(wxKeyEvent &aEvent)
std::vector< FAB_LAYER_COLOR > dummy
bool ConvertSmartQuotesAndDashes(wxString *aString)
Convert curly quotes and em/en dashes to straight quotes and dashes.