Do not allow spaces in component name (value field) in component library editor, in dialogs (Edit field, Create component).
In component libraries, a space in name breaks the library, and is not allowed.
This commit is contained in:
parent
7ea120c2a1
commit
c0b1e4cd38
|
@ -878,7 +878,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel()
|
|||
// may only delete user defined fields
|
||||
deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
|
||||
|
||||
fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( field.GetId() ) );
|
||||
fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( false, field.GetId() ) );
|
||||
fieldValueTextCtrl->SetValue( field.GetText() );
|
||||
|
||||
m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT );
|
||||
|
|
|
@ -674,7 +674,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel()
|
|||
// if fieldNdx == REFERENCE, VALUE, then disable delete button
|
||||
deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
|
||||
|
||||
fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( field.GetId() ) );
|
||||
fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( true, field.GetId() ) );
|
||||
fieldValueTextCtrl->SetValue( field.GetText() );
|
||||
|
||||
textSizeTextCtrl->SetValue( EDA_GRAPHIC_TEXT_CTRL::FormatSize( g_UserUnit, field.GetSize().x ) );
|
||||
|
|
|
@ -102,7 +102,10 @@ void DIALOG_EDIT_ONE_FIELD::init()
|
|||
wxString msg;
|
||||
|
||||
m_TextValue->SetFocus();
|
||||
m_TextValue->SetValidator( SCH_FIELD_VALIDATOR( m_fieldId, &m_text ) );
|
||||
SCH_BASE_FRAME* parent = static_cast<SCH_BASE_FRAME*>( GetParent() );
|
||||
m_TextValue->SetValidator( SCH_FIELD_VALIDATOR(
|
||||
parent->IsType( FRAME_SCH_LIB_EDITOR ),
|
||||
m_fieldId, &m_text ) );
|
||||
|
||||
// Disable options for graphic text editing which are not needed for fields.
|
||||
m_CommonConvert->Show( false );
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2009 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
|
||||
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -23,10 +23,15 @@
|
|||
*/
|
||||
|
||||
#include <dialog_lib_new_component.h>
|
||||
#include <sch_validators.h>
|
||||
#include <template_fieldnames.h>
|
||||
|
||||
DIALOG_LIB_NEW_COMPONENT::DIALOG_LIB_NEW_COMPONENT( wxWindow* parent ) :
|
||||
DIALOG_LIB_NEW_COMPONENT_BASE( parent )
|
||||
{
|
||||
m_textName->SetValidator( SCH_FIELD_VALIDATOR( true, VALUE ) );
|
||||
m_textReference->SetValidator( SCH_FIELD_VALIDATOR( true, REFERENCE ) );
|
||||
|
||||
// initial focus should be on first editable field.
|
||||
m_textName->SetFocus();
|
||||
|
||||
|
|
|
@ -30,10 +30,12 @@
|
|||
#include <sch_validators.h>
|
||||
#include <template_fieldnames.h>
|
||||
|
||||
SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( int aFieldId, wxString* aValue ) :
|
||||
SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( bool aIsCmplibEditor,
|
||||
int aFieldId, wxString* aValue ) :
|
||||
wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
|
||||
{
|
||||
m_fieldId = aFieldId;
|
||||
m_isLibEditor = aIsCmplibEditor;
|
||||
|
||||
// Fields cannot contain carriage returns, line feeds, or tabs.
|
||||
wxString excludes( "\r\n\t" );
|
||||
|
@ -41,6 +43,8 @@ SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( int aFieldId, wxString* aValue ) :
|
|||
// The reference field cannot contain spaces.
|
||||
if( aFieldId == REFERENCE )
|
||||
excludes += " ";
|
||||
else if( aFieldId == VALUE && m_isLibEditor )
|
||||
excludes += " ";
|
||||
|
||||
long style = GetStyle();
|
||||
|
||||
|
@ -57,6 +61,7 @@ SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( const SCH_FIELD_VALIDATOR& aValidator
|
|||
wxTextValidator( aValidator )
|
||||
{
|
||||
m_fieldId = aValidator.m_fieldId;
|
||||
m_isLibEditor = aValidator.m_isLibEditor;
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,6 +98,8 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow *aParent )
|
|||
else if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( val ) )
|
||||
{
|
||||
wxArrayString whiteSpace;
|
||||
bool spaceIllegal = ( m_fieldId == REFERENCE ) ||
|
||||
( m_fieldId == VALUE && m_isLibEditor );
|
||||
|
||||
if( val.Find( '\r' ) != wxNOT_FOUND )
|
||||
whiteSpace.Add( _( "carriage return" ) );
|
||||
|
@ -100,7 +107,7 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow *aParent )
|
|||
whiteSpace.Add( _( "line feed" ) );
|
||||
if( val.Find( '\t' ) != wxNOT_FOUND )
|
||||
whiteSpace.Add( _( "tab" ) );
|
||||
if( (m_fieldId == REFERENCE) && (val.Find( ' ' ) != wxNOT_FOUND) )
|
||||
if( spaceIllegal && (val.Find( ' ' ) != wxNOT_FOUND) )
|
||||
whiteSpace.Add( _( "space" ) );
|
||||
|
||||
wxString badChars;
|
||||
|
|
|
@ -38,13 +38,19 @@
|
|||
*
|
||||
* is the text control validator used for validating the text allowed in library and
|
||||
* schematic component fields.
|
||||
* Note
|
||||
* Reference field does not accept spaces
|
||||
* Value field does not accept spaces in Component Library Editor, because in .lib component
|
||||
* libraries, the value field is the component name in lib, and spaces are not allowed
|
||||
* in component names in lib
|
||||
*/
|
||||
class SCH_FIELD_VALIDATOR : public wxTextValidator
|
||||
{
|
||||
int m_fieldId;
|
||||
int m_fieldId;
|
||||
bool m_isLibEditor;
|
||||
|
||||
public:
|
||||
SCH_FIELD_VALIDATOR( int aFieldId, wxString* aValue = NULL );
|
||||
SCH_FIELD_VALIDATOR( bool aIsCmplibEditor, int aFieldId, wxString* aValue = NULL );
|
||||
|
||||
SCH_FIELD_VALIDATOR( const SCH_FIELD_VALIDATOR& aValidator );
|
||||
|
||||
|
|
Loading…
Reference in New Issue