Properties: add support for string escaping
Fixes https://gitlab.com/kicad/code/kicad/-/issues/12975
This commit is contained in:
parent
5061f0556f
commit
611c19016f
|
@ -31,6 +31,7 @@
|
|||
#include <properties/pg_properties.h>
|
||||
#include <properties/property_mgr.h>
|
||||
#include <properties/property.h>
|
||||
#include <string_utils.h>
|
||||
#include <widgets/color_swatch.h>
|
||||
|
||||
// reg-ex describing a signed valid value with a unit
|
||||
|
@ -141,7 +142,7 @@ wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty )
|
|||
}
|
||||
else if( typeId == TYPE_HASH( wxString ) )
|
||||
{
|
||||
ret = new wxStringProperty();
|
||||
ret = new PGPROPERTY_STRING();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -326,3 +327,20 @@ void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect,
|
|||
|
||||
aPaintData.m_drawnWidth = aRect.width;
|
||||
}
|
||||
|
||||
|
||||
wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, int aFlags ) const
|
||||
{
|
||||
if( aValue.GetType() != wxPG_VARIANT_TYPE_STRING )
|
||||
return wxEmptyString;
|
||||
|
||||
return UnescapeString( aValue.GetString() );
|
||||
}
|
||||
|
||||
|
||||
bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
|
||||
int aFlags ) const
|
||||
{
|
||||
aVariant = EscapeString( aString, CTX_QUOTED_STR );
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -146,4 +146,21 @@ protected:
|
|||
std::function<wxColour( const wxString& aChoice )> m_colorFunc;
|
||||
};
|
||||
|
||||
|
||||
class PGPROPERTY_STRING : public wxStringProperty
|
||||
{
|
||||
public:
|
||||
PGPROPERTY_STRING( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
|
||||
const wxString& aValue = wxEmptyString ) :
|
||||
wxStringProperty( aLabel, aName, aValue )
|
||||
{}
|
||||
|
||||
virtual ~PGPROPERTY_STRING() = default;
|
||||
|
||||
wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
|
||||
|
||||
bool StringToValue( wxVariant& aVariant, const wxString& aString,
|
||||
int aFlags = 0 ) const override;
|
||||
};
|
||||
|
||||
#endif /* PG_PROPERTIES_H */
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <pcb_text.h>
|
||||
#include <pcb_track.h>
|
||||
#include <settings/color_settings.h>
|
||||
#include <string_utils.h>
|
||||
|
||||
|
||||
PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* aFrame )
|
||||
|
@ -140,7 +141,7 @@ void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard )
|
|||
// Regenerate nets
|
||||
for( const auto& netinfo : aBoard->GetNetInfo().NetsByNetcode() )
|
||||
{
|
||||
nets.Add( netinfo.second->GetNetname(), netinfo.first );
|
||||
nets.Add( UnescapeString( netinfo.second->GetNetname() ), netinfo.first );
|
||||
}
|
||||
|
||||
auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ),
|
||||
|
|
Loading…
Reference in New Issue