34#include <wx/textctrl.h>
35#include <wx/textentry.h>
43 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
59 wxValidator::Copy( val );
73 if( !m_validatorWindow )
79 int keyCode = aEvent.GetKeyCode();
82 if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
88 wxUniChar c = (wxUChar) keyCode;
95 else if( wxIsdigit( c ) )
99 GetTextEntry()->GetSelection( &from, &to );
106 else if( wxIsalpha( c ) )
124 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( GetTextEntry() );
128 textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
144 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
148 if( !textCtrl->IsModified() )
151 long insertionPoint = textCtrl->GetInsertionPoint();
152 textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
153 textCtrl->SetInsertionPoint( insertionPoint );
154 textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
169 wxTextValidator( aValidator ),
185 if ( !m_validatorWindow->IsEnabled() )
188 wxTextEntry *
const text = GetTextEntry();
193 const wxString& errormsg =
IsValid(
text->GetValue() );
195 if( !errormsg.empty() )
197 m_validatorWindow->SetFocus();
198 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
208 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
209 return _(
"Signal names cannot contain CR or LF characters" );
211 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
212 return _(
"Signal names cannot contain spaces" );
220 wxWindow* ctrl = aValidator.GetWindow();
222 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
224 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
225 aValidator.TransferToWindow();
230 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ),
234 wxString excludes( wxT(
"\r\n\t" ) );
239 excludes += wxT(
" " );
243 excludes += wxT(
"/" );
246 long style = GetStyle();
253 style |= wxFILTER_EMPTY;
257 SetCharExcludes( excludes );
262 wxTextValidator( aValidator ),
271 if( !m_validatorWindow->IsEnabled() )
274 wxTextEntry*
const text = GetTextEntry();
279 wxString val(
text->GetValue() );
290 if( validator.HasFlag( wxFILTER_EMPTY ) && aValue.empty() )
296 default: msg =
_(
"The value of the field cannot be empty." );
break;
300 if( msg.empty() && validator.HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) )
302 wxArrayString badCharsFound;
304 for(
const wxUniCharRef& excludeChar : validator.GetCharExcludes() )
306 if( aValue.Find( excludeChar ) != wxNOT_FOUND )
308 if( excludeChar ==
'\r' )
309 badCharsFound.Add(
_(
"carriage return" ) );
310 else if( excludeChar ==
'\n' )
311 badCharsFound.Add(
_(
"line feed" ) );
312 else if( excludeChar ==
'\t' )
313 badCharsFound.Add(
_(
"tab" ) );
314 else if( excludeChar ==
' ' )
315 badCharsFound.Add(
_(
"space" ) );
317 badCharsFound.Add( wxString::Format( wxT(
"'%c'" ), excludeChar ) );
321 if( !badCharsFound.IsEmpty() )
325 for(
size_t i = 0; i < badCharsFound.GetCount(); i++ )
327 if( !badChars.IsEmpty() )
329 if( badCharsFound.GetCount() == 2 )
331 badChars +=
_(
" or " );
335 if( i < badCharsFound.GetCount() - 2 )
336 badChars +=
_(
", or " );
338 badChars += wxT(
", " );
342 badChars += badCharsFound.Item( i );
348 msg.Printf(
_(
"The reference designator cannot contain %s character(s)." ), badChars );
352 msg.Printf(
_(
"The value field cannot contain %s character(s)." ), badChars );
356 msg.Printf(
_(
"The footprint field cannot contain %s character(s)." ), badChars );
360 msg.Printf(
_(
"The datasheet field cannot contain %s character(s)." ), badChars );
364 msg.Printf(
_(
"The sheet name cannot contain %s character(s)." ), badChars );
368 msg.Printf(
_(
"The sheet filename cannot contain %s character(s)." ), badChars );
372 msg.Printf(
_(
"The field cannot contain %s character(s)." ), badChars );
382 msg.Printf(
_(
"The reference designator cannot contain text variable references" ) );
386 msg.Printf(
_(
"References must start with a letter." ) );
400 if( m_validatorWindow )
401 m_validatorWindow->SetFocus();
403 wxMessageBox( msg,
_(
"Field Validation Error" ), wxOK | wxICON_EXCLAMATION, aParent );
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.
const wxString & GetLibFilenameForbiddenChars()
Characters illegal in a footprint library filename.
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...
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
wxString GetFieldValidationErrorMessage(FIELD_T aFieldId, const wxString &aValue)
Return the error message if aValue is invalid for aFieldId.
Custom text control validator definitions.
wxString GetFieldValidationErrorMessage(FIELD_T aFieldId, const wxString &aValue)
Return the error message if aValue is invalid for aFieldId.