Browse Source

Escape/unescape symbol name in save as dialog.

SymbolNameInUse() also needed some help.
As did DIALOG_LIB_NEW_SYMBOL.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21170
pull/18/head
Jeff Young 5 months ago
parent
commit
8302b0d6bd
  1. 34
      eeschema/dialogs/dialog_lib_new_symbol.cpp
  2. 24
      eeschema/symbol_editor/symbol_editor.cpp
  3. 5
      eeschema/symbol_library_manager.cpp

34
eeschema/dialogs/dialog_lib_new_symbol.cpp

@ -48,15 +48,15 @@ DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent,
{
if( aSymbolNames.GetCount() )
{
wxArrayString escapedNames;
wxArrayString unescapedNames;
for( const wxString& name : aSymbolNames )
escapedNames.Add( UnescapeString( name ) );
unescapedNames.Add( UnescapeString( name ) );
m_comboInheritanceSelect->SetStringList( escapedNames );
m_comboInheritanceSelect->SetStringList( unescapedNames );
if( !aInheritFromSymbolName.IsEmpty() )
m_comboInheritanceSelect->SetSelectedString( aInheritFromSymbolName );
m_comboInheritanceSelect->SetSelectedString( UnescapeString( aInheritFromSymbolName ) );
}
m_textName->SetValidator( FIELD_VALIDATOR( FIELD_T::VALUE ) );
@ -64,15 +64,15 @@ DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent,
if( !aInheritFromSymbolName.IsEmpty() )
{
m_textName->ChangeValue( getDerivativeName( aInheritFromSymbolName ) );
m_textName->ChangeValue( UnescapeString( getDerivativeName( aInheritFromSymbolName ) ) );
m_nameIsDefaulted = true;
}
m_pinTextPosition.SetValue( schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET ) );
m_comboInheritanceSelect->Connect(
FILTERED_ITEM_SELECTED,
wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ), nullptr, this );
m_comboInheritanceSelect->Connect( FILTERED_ITEM_SELECTED,
wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ),
nullptr, this );
m_textName->Bind( wxEVT_TEXT,
[this]( wxCommandEvent& aEvent )
@ -80,8 +80,9 @@ DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent,
m_nameIsDefaulted = false;
} );
m_checkTransferUserFields->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onCheckTransferUserFields ), nullptr, this );
m_checkTransferUserFields->Connect( wxEVT_CHECKBOX,
wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onCheckTransferUserFields ),
nullptr, this );
// Trigger the event handler to show/hide the info bar message.
wxCommandEvent dummyEvent;
@ -103,11 +104,12 @@ DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent,
DIALOG_LIB_NEW_SYMBOL::~DIALOG_LIB_NEW_SYMBOL()
{
m_comboInheritanceSelect->Disconnect(
FILTERED_ITEM_SELECTED,
wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ), nullptr, this );
m_checkTransferUserFields->Disconnect(
wxEVT_CHECKBOX, wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onCheckTransferUserFields ), nullptr, this );
m_comboInheritanceSelect->Disconnect( FILTERED_ITEM_SELECTED,
wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ),
nullptr, this );
m_checkTransferUserFields->Disconnect( wxEVT_CHECKBOX,
wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onCheckTransferUserFields ),
nullptr, this );
}
bool DIALOG_LIB_NEW_SYMBOL::TransferDataFromWindow()
@ -123,7 +125,7 @@ void DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect( wxCommandEvent& aEvent )
if( !parent.IsEmpty() )
{
m_infoBar->RemoveAllButtons();
m_infoBar->ShowMessage( wxString::Format( _( "Deriving from symbol '%s'." ), parent ),
m_infoBar->ShowMessage( wxString::Format( _( "Deriving from symbol '%s'." ), UnescapeString( parent ) ),
wxICON_INFORMATION );
}
else

24
eeschema/symbol_editor/symbol_editor.cpp

@ -884,7 +884,7 @@ public:
wxStaticText* label = new wxStaticText( this, wxID_ANY, _( "Name:" ) );
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_symbolNameCtrl = new wxTextCtrl( this, wxID_ANY, aSymbolName );
m_symbolNameCtrl = new wxTextCtrl( this, wxID_ANY, UnescapeString( aSymbolName ) );
bNameSizer->Add( m_symbolNameCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
wxButton* newLibraryButton = new wxButton( this, ID_MAKE_NEW_LIBRARY, _( "New Library..." ) );
@ -919,7 +919,7 @@ public:
symbolName.Trim( true );
symbolName.Trim( false );
symbolName.Replace( " ", "_" );
return symbolName;
return EscapeString( symbolName, CTX_LIBID );
}
protected:
@ -980,7 +980,8 @@ void SYMBOL_EDIT_FRAME::saveSymbolCopyAs( bool aOpenCopy )
{
msg = wxString::Format( _( "Library '%s' is read-only. Choose a "
"different library to save the symbol '%s' to." ),
newLib, newName );
newLib,
UnescapeString( newName ) );
wxMessageBox( msg );
return wxID_CANCEL;
}
@ -996,7 +997,8 @@ void SYMBOL_EDIT_FRAME::saveSymbolCopyAs( bool aOpenCopy )
{
msg = wxString::Format( _( "Symbol '%s' cannot replace another symbol '%s' "
"that it descends from" ),
symbolName, newName );
symbolName,
UnescapeString( newName ) );
wxMessageBox( msg );
return wxID_CANCEL;
}
@ -1005,7 +1007,8 @@ void SYMBOL_EDIT_FRAME::saveSymbolCopyAs( bool aOpenCopy )
{
msg = wxString::Format( _( "Symbol '%s' cannot replace another symbol '%s' "
"that is a descendent of it." ),
symbolName, newName );
symbolName,
UnescapeString( newName ) );
wxMessageBox( msg );
return wxID_CANCEL;
}
@ -1018,7 +1021,8 @@ void SYMBOL_EDIT_FRAME::saveSymbolCopyAs( bool aOpenCopy )
// The simplest case is when the symbol itself has a conflict
msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'. "
"Do you want to overwrite it?" ),
newName, newLib );
UnescapeString( newName ),
newLib );
KIDIALOG errorDlg( this, msg, _( "Confirmation" ),
wxOK | wxCANCEL | wxICON_WARNING );
@ -1035,7 +1039,8 @@ void SYMBOL_EDIT_FRAME::saveSymbolCopyAs( bool aOpenCopy )
// existing symbol in the target lib, or rename all the parents somehow.
msg = wxString::Format( _( "The following symbols in the inheritance chain of "
"'%s' already exist in library '%s':\n" ),
symbolName, newLib );
UnescapeString( symbolName ),
newLib );
for( const wxString& conflict : conflicts )
msg += wxString::Format( " %s\n", conflict );
@ -1050,10 +1055,9 @@ void SYMBOL_EDIT_FRAME::saveSymbolCopyAs( bool aOpenCopy )
switch( errorDlg.ShowModal() )
{
case wxID_YES: return ID_OVERWRITE_CONFLICTS;
case wxID_NO: return ID_RENAME_CONFLICTS;
default: break;
case wxID_NO: return ID_RENAME_CONFLICTS;
default: return wxID_CANCEL;
}
return wxID_CANCEL;
}
return wxID_OK;

5
eeschema/symbol_library_manager.cpp

@ -679,11 +679,14 @@ bool SYMBOL_LIBRARY_MANAGER::SymbolNameInUse( const wxString& aName, const wxStr
{
wxArrayString existing;
// NB: GetSymbolNames() is mostly used for GUI stuff, so it returns unescaped names
GetSymbolNames( aLibrary, existing );
wxString unescapedName = UnescapeString( aName );
for( wxString& candidate : existing )
{
if( candidate.CmpNoCase( aName ) == 0 )
if( candidate.CmpNoCase( unescapedName ) == 0 )
return true;
}

Loading…
Cancel
Save