37#include <wx/textctrl.h>
38#include <wx/textentry.h>
46 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
51 wxString illegalChars = wxS(
"%$<>\t\n\r\"\\/:" );
52 SetCharExcludes( illegalChars );
66 wxValidator::Copy( val );
80 if( !m_validatorWindow )
86 int keyCode = aEvent.GetKeyCode();
89 if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
95 wxUniChar c = (wxUChar) keyCode;
102 else if( wxIsdigit( c ) )
106 GetTextEntry()->GetSelection( &from, &to );
113 else if( wxIsalpha( c ) )
131 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( GetTextEntry() );
135 textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
151 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
155 if( !textCtrl->IsModified() )
158 long insertionPoint = textCtrl->GetInsertionPoint();
159 textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
160 textCtrl->SetInsertionPoint( insertionPoint );
161 textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
170 m_allowSpaces( false )
176 wxTextValidator( aValidator ),
177 m_allowSpaces( aValidator.m_allowSpaces )
184 m_allowSpaces( aAllowSpaces )
192 if ( !m_validatorWindow->IsEnabled() )
195 wxTextEntry *
const text = GetTextEntry();
200 const wxString& errormsg =
IsValid(
text->GetValue() );
202 if( !errormsg.empty() )
204 m_validatorWindow->SetFocus();
205 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
215 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
216 return _(
"Signal names cannot contain CR or LF characters" );
218 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
219 return _(
"Signal names cannot contain spaces" );
227 wxWindow* ctrl = aValidator.GetWindow();
229 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
231 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
232 aValidator.TransferToWindow();
237 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ),
238 m_fieldId( aFieldId )
241 wxString excludes( wxT(
"\r\n\t" ) );
244 if( aFieldId == FIELD_T::REFERENCE )
246 excludes += wxT(
" " );
248 else if(
m_fieldId == FIELD_T::SHEET_NAME )
250 excludes += wxT(
"/" );
253 long style = GetStyle();
256 if( aFieldId == FIELD_T::REFERENCE
257 || aFieldId == FIELD_T::SHEET_NAME
258 || aFieldId == FIELD_T::SHEET_FILENAME )
260 style |= wxFILTER_EMPTY;
264 SetCharExcludes( excludes );
269 wxTextValidator( aValidator ),
270 m_fieldId( aValidator.m_fieldId )
278 if( !m_validatorWindow->IsEnabled() )
281 wxTextEntry*
const text = GetTextEntry();
286 wxString val(
text->GetValue() );
296 if( HasFlag( wxFILTER_EMPTY ) && aValue.empty() )
300 case FIELD_T::SHEET_NAME: msg =
_(
"A sheet must have a name." );
break;
301 case FIELD_T::SHEET_FILENAME: msg =
_(
"A sheet must have a file specified." );
break;
302 default: msg =
_(
"The value of the field cannot be empty." );
break;
306 if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( aValue ) )
308 wxArrayString badCharsFound;
310 for(
const wxUniCharRef& excludeChar : GetCharExcludes() )
312 if( aValue.Find( excludeChar ) != wxNOT_FOUND )
314 if( excludeChar ==
'\r' )
315 badCharsFound.Add(
_(
"carriage return" ) );
316 else if( excludeChar ==
'\n' )
317 badCharsFound.Add(
_(
"line feed" ) );
318 else if( excludeChar ==
'\t' )
319 badCharsFound.Add(
_(
"tab" ) );
320 else if( excludeChar ==
' ' )
321 badCharsFound.Add(
_(
"space" ) );
323 badCharsFound.Add( wxString::Format( wxT(
"'%c'" ), excludeChar ) );
329 for(
size_t i = 0; i < badCharsFound.GetCount(); i++ )
331 if( !badChars.IsEmpty() )
333 if( badCharsFound.GetCount() == 2 )
335 badChars +=
_(
" or " );
339 if( i < badCharsFound.GetCount() - 2 )
340 badChars +=
_(
", or " );
342 badChars += wxT(
", " );
346 badChars += badCharsFound.Item( i );
351 case FIELD_T::REFERENCE:
352 msg.Printf(
_(
"The reference designator cannot contain %s character(s)." ), badChars );
356 msg.Printf(
_(
"The value field cannot contain %s character(s)." ), badChars );
359 case FIELD_T::FOOTPRINT:
360 msg.Printf(
_(
"The footprint field cannot contain %s character(s)." ), badChars );
363 case FIELD_T::DATASHEET:
364 msg.Printf(
_(
"The datasheet field cannot contain %s character(s)." ), badChars );
367 case FIELD_T::SHEET_NAME:
368 msg.Printf(
_(
"The sheet name cannot contain %s character(s)." ), badChars );
371 case FIELD_T::SHEET_FILENAME:
372 msg.Printf(
_(
"The sheet filename cannot contain %s character(s)." ), badChars );
376 msg.Printf(
_(
"The field cannot contain %s character(s)." ), badChars );
380 else if(
m_fieldId == FIELD_T::REFERENCE && aValue.Contains( wxT(
"${" ) ) )
382 msg.Printf(
_(
"The reference designator cannot contain text variable references" ) );
386 msg.Printf(
_(
"References must start with a letter." ) );
391 if( m_validatorWindow )
392 m_validatorWindow->SetFocus();
394 wxMessageBox( msg,
_(
"Field Validation Error" ), wxOK | wxICON_EXCLAMATION, aParent );
Provide a custom wxValidator object for limiting the allowable characters when defining an environmen...
virtual ~ENV_VAR_NAME_VALIDATOR()
void OnChar(wxKeyEvent &event)
ENV_VAR_NAME_VALIDATOR(wxString *aValue=nullptr)
void OnTextChanged(wxCommandEvent &event)
A text control validator used for validating the text allowed in fields.
virtual bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...
bool DoValidate(const wxString &aValue, wxWindow *aParent)
FIELD_VALIDATOR(FIELD_T aFieldId, wxString *aValue=nullptr)
wxString IsValid(const wxString &aVal) const override
virtual bool Validate(wxWindow *aParent) override
NETNAME_VALIDATOR(wxString *aVal=nullptr)
This file is part of the common library.
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
Collection of utility functions for component reference designators (refdes)
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
Custom text control validator definitions.