Work in progress to allow arbitrary chars in references, etc.
This commit is contained in:
parent
eaf3d48260
commit
521183a587
|
@ -39,6 +39,79 @@
|
|||
*/
|
||||
static const char illegalFileNameChars[] = "\\/:\"<>|";
|
||||
|
||||
/**
|
||||
* These Escape/Unescape routines use HTML-entity-reference-style encoding to handle
|
||||
* characters which are:
|
||||
* (a) not legal in filenames
|
||||
* (b) used as control characters in LIB_IDs
|
||||
* (c) used to delineate hierarchical paths
|
||||
*/
|
||||
wxString EscapeString( const wxString& aSource )
|
||||
{
|
||||
wxString converted;
|
||||
|
||||
for( wxUniChar c: aSource )
|
||||
{
|
||||
if( c == '\"' )
|
||||
converted += """;
|
||||
else if( c == '\'' )
|
||||
converted += "'";
|
||||
else if( c == '&' )
|
||||
converted += "&";
|
||||
else if( c == '<' )
|
||||
converted += "<";
|
||||
else if( c == '>' )
|
||||
converted += ">";
|
||||
else if( c == '\\' )
|
||||
converted += "∖";
|
||||
else if( c == '/' )
|
||||
converted += "⁄";
|
||||
else if( c == '|' )
|
||||
converted += "|";
|
||||
else if( c == ':' )
|
||||
converted += ":";
|
||||
else if( c == ' ' )
|
||||
converted += " ";
|
||||
else if( c == '%' )
|
||||
converted += "%";
|
||||
else if( c == '$' )
|
||||
converted += "$";
|
||||
else if( c == '\t' )
|
||||
converted += "&tab;";
|
||||
else if( c == '\n' || c == '\r' )
|
||||
converted += "&Newline;";
|
||||
else
|
||||
converted += c;
|
||||
}
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
|
||||
wxString UnescapeString( const wxString& aSource )
|
||||
{
|
||||
wxString converted = aSource;
|
||||
|
||||
converted.Replace( """, "\"" );
|
||||
converted.Replace( "'", "'" );
|
||||
converted.Replace( "<", "<" );
|
||||
converted.Replace( ">", ">" );
|
||||
converted.Replace( "∖", "\\" );
|
||||
converted.Replace( "⁄", "/" );
|
||||
converted.Replace( "|", "|" );
|
||||
converted.Replace( ":", ":" );
|
||||
converted.Replace( " ", " " );
|
||||
converted.Replace( "%", "%" );
|
||||
converted.Replace( "$", "$" );
|
||||
converted.Replace( "&tab;", "\t" );
|
||||
converted.Replace( "&Newline;", "\n" );
|
||||
|
||||
// must be done last
|
||||
converted.Replace( "&", "&" );
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
|
||||
int ReadDelimitedText( wxString* aDest, const char* aSource )
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <common.h>
|
||||
#include <kiway.h>
|
||||
#include <confirm.h>
|
||||
|
||||
#include <kicad_string.h>
|
||||
#include <sch_base_frame.h>
|
||||
#include <sch_component.h>
|
||||
#include <class_libentry.h>
|
||||
|
@ -40,7 +40,6 @@
|
|||
#include <sch_component.h>
|
||||
#include <template_fieldnames.h>
|
||||
#include <class_library.h>
|
||||
#include <sch_validators.h>
|
||||
|
||||
#include <dialog_edit_one_field.h>
|
||||
|
||||
|
@ -101,12 +100,7 @@ DIALOG_EDIT_ONE_FIELD::DIALOG_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent, const wxS
|
|||
|
||||
void DIALOG_EDIT_ONE_FIELD::init()
|
||||
{
|
||||
wxString msg;
|
||||
|
||||
SetInitialFocus( m_TextValue );
|
||||
SCH_BASE_FRAME* parent = GetParent();
|
||||
bool libedit = parent->IsType( FRAME_SCH_LIB_EDITOR );
|
||||
m_TextValue->SetValidator( SCH_FIELD_VALIDATOR( libedit, m_fieldId, &m_text ) );
|
||||
|
||||
// Disable options for graphic text editing which are not needed for fields.
|
||||
m_CommonConvert->Show( false );
|
||||
|
@ -188,7 +182,7 @@ void DIALOG_EDIT_ONE_FIELD::OnSetFocusText( wxFocusEvent& event )
|
|||
|
||||
bool DIALOG_EDIT_ONE_FIELD::TransferDataToWindow()
|
||||
{
|
||||
m_TextValue->SetValue( m_text );
|
||||
m_TextValue->SetValue( UnescapeString( m_text ) );
|
||||
|
||||
m_posX.SetValue( m_position.x );
|
||||
m_posY.SetValue( m_position.y );
|
||||
|
@ -206,9 +200,8 @@ bool DIALOG_EDIT_ONE_FIELD::TransferDataToWindow()
|
|||
|
||||
bool DIALOG_EDIT_ONE_FIELD::TransferDataFromWindow()
|
||||
{
|
||||
m_text = m_TextValue->GetValue();
|
||||
m_text = EscapeString( m_TextValue->GetValue() );
|
||||
|
||||
// There are lots of specific tests required to validate field text.
|
||||
if( m_fieldId == REFERENCE )
|
||||
{
|
||||
// Test if the reference string is valid:
|
||||
|
@ -218,6 +211,14 @@ bool DIALOG_EDIT_ONE_FIELD::TransferDataFromWindow()
|
|||
return false;
|
||||
}
|
||||
}
|
||||
else if( m_fieldId == VALUE )
|
||||
{
|
||||
if( m_text.IsEmpty() )
|
||||
{
|
||||
DisplayError( this, _( "Value may not be empty." ) );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_isVertical = m_orientChoice->GetSelection() == 1;
|
||||
m_position = wxPoint( m_posX.GetValue(), m_posY.GetValue() );
|
||||
|
|
|
@ -36,6 +36,17 @@
|
|||
#include <wx/filename.h>
|
||||
|
||||
|
||||
/**
|
||||
* These Escape/Unescape routines use HTML-entity-reference-style encoding to handle
|
||||
* characters which are:
|
||||
* (a) not legal in filenames
|
||||
* (b) used as control characters in LIB_IDs
|
||||
* (c) used to delineate hierarchical paths
|
||||
*/
|
||||
wxString EscapeString( const wxString& aSource );
|
||||
|
||||
wxString UnescapeString( const wxString& aSource );
|
||||
|
||||
/**
|
||||
* Function ReadDelimitedText
|
||||
* copies bytes from @a aSource delimited string segment to @a aDest buffer.
|
||||
|
|
Loading…
Reference in New Issue