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 );
57 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST | wxFILTER_EMPTY, aValue )
62 wxString illegalChars = wxFileName::GetForbiddenChars( wxPATH_DOS );
63 wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
64 wxArrayString illegalCharList;
66 for(
unsigned i = 0; i < illegalChars.size(); i++ )
68 if( illegalChars[i] ==
'/' )
71#if defined (__WINDOWS__)
72 if( illegalChars[i] ==
'\\' || illegalChars[i] ==
':' )
75 illegalCharList.Add( wxString( illegalChars[i] ) );
78 SetExcludes( illegalCharList );
92 wxValidator::Copy( val );
106 if( !m_validatorWindow )
112 int keyCode = aEvent.GetKeyCode();
115 if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
121 wxUniChar c = (wxUChar) keyCode;
123 if( c == wxT(
'_' ) )
128 else if( wxIsdigit( c ) )
132 GetTextEntry()->GetSelection( &from, &to );
139 else if( wxIsalpha( c ) )
157 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( GetTextEntry() );
161 textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
177 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
181 if( !textCtrl->IsModified() )
184 long insertionPoint = textCtrl->GetInsertionPoint();
185 textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
186 textCtrl->SetInsertionPoint( insertionPoint );
187 textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
197 if( !m_validatorWindow->IsEnabled() )
200 wxTextEntry*
const textEntry = GetTextEntry();
206 const wxString& value = textEntry->GetValue();
211 m_regEx.GetMatch( &start, &len );
213 if( start != 0 || len != value.Length() )
223 m_validatorWindow->SetFocus();
224 DisplayError( aParent, wxString::Format(
_(
"Incorrect value: %s" ), value ) );
234 if( !
m_regEx.Compile( aRegEx, aFlags ) )
236 throw std::runtime_error(
"REGEX_VALIDATOR: Invalid regular expression: "
237 + aRegEx.ToStdString() );
247 m_allowSpaces( false )
253 wxTextValidator( aValidator ),
254 m_allowSpaces( aValidator.m_allowSpaces )
261 m_allowSpaces( aAllowSpaces )
269 if ( !m_validatorWindow->IsEnabled() )
272 wxTextEntry *
const text = GetTextEntry();
277 const wxString& errormsg =
IsValid(
text->GetValue() );
279 if( !errormsg.empty() )
281 m_validatorWindow->SetFocus();
282 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
292 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
293 return _(
"Signal names cannot contain CR or LF characters" );
295 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
296 return _(
"Signal names cannot contain spaces" );
304 wxWindow* ctrl = aValidator.GetWindow();
306 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
308 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
309 aValidator.TransferToWindow();
314 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ), m_fieldId( aFieldId )
317 wxString excludes( wxT(
"\r\n\t" ) );
322 excludes += wxT(
" " );
326 excludes += wxT(
"/" );
329 long style = GetStyle();
334 style |= wxFILTER_EMPTY;
338 SetCharExcludes( excludes );
343 wxTextValidator( aValidator ), m_fieldId( aValidator.m_fieldId )
351 if( !m_validatorWindow->IsEnabled() )
354 wxTextEntry*
const text = GetTextEntry();
359 wxString val(
text->GetValue() );
368 if( HasFlag( wxFILTER_EMPTY ) && aValue.empty() )
369 msg.Printf(
_(
"The value of the field cannot be empty." ) );
371 if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( aValue ) )
373 wxArrayString badCharsFound;
375 for(
const wxUniCharRef& excludeChar : GetCharExcludes() )
377 if( aValue.Find( excludeChar ) != wxNOT_FOUND )
379 if( excludeChar ==
'\r' )
380 badCharsFound.Add(
_(
"carriage return" ) );
381 else if( excludeChar ==
'\n' )
382 badCharsFound.Add(
_(
"line feed" ) );
383 else if( excludeChar ==
'\t' )
384 badCharsFound.Add(
_(
"tab" ) );
385 else if( excludeChar ==
' ' )
386 badCharsFound.Add(
_(
"space" ) );
388 badCharsFound.Add( wxString::Format( wxT(
"'%c'" ), excludeChar ) );
394 for(
size_t i = 0; i < badCharsFound.GetCount(); i++ )
396 if( !badChars.IsEmpty() )
398 if( badCharsFound.GetCount() == 2 )
400 badChars +=
_(
" or " );
404 if( i < badCharsFound.GetCount() - 2 )
405 badChars +=
_(
", or " );
407 badChars += wxT(
", " );
411 badChars += badCharsFound.Item( i );
417 msg.Printf(
_(
"The reference designator cannot contain %s character(s)." ), badChars );
421 msg.Printf(
_(
"The value field cannot contain %s character(s)." ), badChars );
425 msg.Printf(
_(
"The footprint field cannot contain %s character(s)." ), badChars );
429 msg.Printf(
_(
"The datasheet field cannot contain %s character(s)." ), badChars );
433 msg.Printf(
_(
"The sheet name cannot contain %s character(s)." ), badChars );
437 msg.Printf(
_(
"The sheet filename cannot contain %s character(s)." ), badChars );
441 msg.Printf(
_(
"The field cannot contain %s character(s)." ), badChars );
447 msg.Printf(
_(
"The reference designator cannot contain text variable references" ) );
451 msg.Printf(
_(
"References must start with a letter." ) );
456 if( m_validatorWindow )
457 m_validatorWindow->SetFocus();
459 wxMessageBox( msg,
_(
"Field Validation Error" ), wxOK | wxICON_EXCLAMATION, aParent );
This class provides a custom wxValidator object for limiting the allowable characters when defining a...
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.
FIELD_VALIDATOR(int aFieldId, wxString *aValue=nullptr)
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)
FILE_NAME_WITH_PATH_CHAR_VALIDATOR(wxString *aValue=nullptr)
wxString IsValid(const wxString &aVal) const override
virtual bool Validate(wxWindow *aParent) override
NETNAME_VALIDATOR(wxString *aVal=nullptr)
bool Validate(wxWindow *aParent) override
wxString m_regExString
Original compilation flags (for copy constructor)
int m_regExFlags
Compiled regex.
void compileRegEx(const wxString &aRegEx, int aFlags)
< Compiles and stores a regular expression
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
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)
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
Custom text control validator definitions.