diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp index ede0af8818..e403acc1f5 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp @@ -309,67 +309,98 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllAliasOfPart( wxCommandEvent& eve } -/* Add a new name to the alias list box - * New name cannot be the root name, and must not exists - */ -void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& event ) +void DIALOG_EDIT_COMPONENT_IN_LIBRARY::EditAliasOfPart( wxCommandEvent& aEvent ) { - wxString aliasname; - LIB_PART* component = m_Parent->GetCurPart(); - wxString library = m_Parent->GetCurLib(); + int sel = m_PartAliasListCtrl->GetSelection(); - if( component == NULL ) + if( sel == wxNOT_FOUND ) return; + wxString aliasname = m_PartAliasListCtrl->GetString( sel ); + + if( aliasname.CmpNoCase( m_Parent->GetAliasName() ) == 0 ) + { + wxString msg; + msg.Printf( _( "Current alias \"%s\" cannot be edited." ), GetChars( aliasname ) ); + DisplayError( this, msg ); + return; + } + wxTextEntryDialog dlg( this, _( "New Alias:" ), _( "Symbol alias:" ), aliasname ); if( dlg.ShowModal() != wxID_OK ) return; // cancelled by user aliasname = dlg.GetValue( ); - aliasname.Replace( wxT( " " ), wxT( "_" ) ); + if( checkNewAlias( aliasname) ) + m_PartAliasListCtrl->SetString( sel, aliasname ); +} + + +void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& event ) +{ + wxString aliasname; + + wxTextEntryDialog dlg( this, _( "New Alias:" ), _( "Symbol alias:" ), aliasname ); + + if( dlg.ShowModal() != wxID_OK ) + return; // cancelled by user + + aliasname = dlg.GetValue( ); + aliasname.Replace( wxT( " " ), wxT( "_" ) ); + + if( checkNewAlias( aliasname ) ) + m_PartAliasListCtrl->Append( aliasname ); +} + + +bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::checkNewAlias( wxString aliasname ) +{ if( aliasname.IsEmpty() ) - return; + return false; if( m_PartAliasListCtrl->FindString( aliasname ) != wxNOT_FOUND ) { wxString msg; msg.Printf( _( "Alias \"%s\" already exists." ), GetChars( aliasname ) ); DisplayInfoMessage( this, msg ); - return; + return false; } + wxString library = m_Parent->GetCurLib(); + if( !library.empty() && Prj().SchSymbolLibTable()->LoadSymbol( library, aliasname ) != NULL ) { wxString msg; msg.Printf( _( "Symbol name \"%s\" already exists in library \"%s\"." ), aliasname, library ); DisplayErrorMessage( this, msg ); - return; + return false; } - m_PartAliasListCtrl->Append( aliasname ); + return true; } void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAliasOfPart( wxCommandEvent& event ) { - wxString aliasname = m_PartAliasListCtrl->GetStringSelection(); + int sel = m_PartAliasListCtrl->GetSelection(); - if( aliasname.IsEmpty() ) + if( sel == wxNOT_FOUND ) return; + wxString aliasname = m_PartAliasListCtrl->GetString( sel ); + if( aliasname.CmpNoCase( m_Parent->GetAliasName() ) == 0 ) { wxString msg; - msg.Printf( _( "Alias \"%s\" cannot be removed while it is being edited!" ), - GetChars( aliasname ) ); + msg.Printf( _( "Current alias \"%s\" cannot be removed." ), GetChars( aliasname ) ); DisplayError( this, msg ); return; } - m_PartAliasListCtrl->Delete( m_PartAliasListCtrl->GetSelection() ); + m_PartAliasListCtrl->Delete( sel ); } diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.h b/eeschema/dialogs/dialog_edit_component_in_lib.h index dc30ad2a68..ce049cd691 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.h +++ b/eeschema/dialogs/dialog_edit_component_in_lib.h @@ -54,7 +54,9 @@ private: void OnOkClick(wxCommandEvent& event) override; void DeleteAllAliasOfPart(wxCommandEvent& event) override; void DeleteAliasOfPart(wxCommandEvent& event) override; + void EditAliasOfPart(wxCommandEvent& event) override; void AddAliasOfPart(wxCommandEvent& event) override; + bool checkNewAlias( wxString aliasname ); bool ChangeNbUnitsPerPackage(int newUnit); bool SetUnsetConvert(); void CopyDocFromRootToAlias(wxCommandEvent& event) override; diff --git a/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp b/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp index 134a3d9f83..5967737f0d 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp @@ -183,6 +183,9 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx m_ButtonAddeAlias = new wxButton( m_PanelAlias, ID_ADD_ALIAS, _("Add"), wxDefaultPosition, wxDefaultSize, 0 ); bRightBoxSizerPanelAlias->Add( m_ButtonAddeAlias, 0, wxALL|wxEXPAND, 5 ); + m_ButtonEditAlias = new wxButton( m_PanelAlias, wxID_ANY, _("Edit"), wxDefaultPosition, wxDefaultSize, 0 ); + bRightBoxSizerPanelAlias->Add( m_ButtonEditAlias, 0, wxALL, 5 ); + m_ButtonDeleteOneAlias = new wxButton( m_PanelAlias, ID_DELETE_ONE_ALIAS, _("Delete"), wxDefaultPosition, wxDefaultSize, 0 ); bRightBoxSizerPanelAlias->Add( m_ButtonDeleteOneAlias, 0, wxALL|wxEXPAND, 5 ); @@ -264,6 +267,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx m_ButtonCopyDoc->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::CopyDocFromRootToAlias ), NULL, this ); m_buttonBrowseDocFiles->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::BrowseAndSelectDocFile ), NULL, this ); m_ButtonAddeAlias->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::AddAliasOfPart ), NULL, this ); + m_ButtonEditAlias->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::EditAliasOfPart ), NULL, this ); m_ButtonDeleteOneAlias->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DeleteAliasOfPart ), NULL, this ); m_ButtonDeleteAllAlias->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DeleteAllAliasOfPart ), NULL, this ); m_buttonAddFpF->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::AddFootprintFilter ), NULL, this ); @@ -281,6 +285,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::~DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE() m_ButtonCopyDoc->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::CopyDocFromRootToAlias ), NULL, this ); m_buttonBrowseDocFiles->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::BrowseAndSelectDocFile ), NULL, this ); m_ButtonAddeAlias->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::AddAliasOfPart ), NULL, this ); + m_ButtonEditAlias->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::EditAliasOfPart ), NULL, this ); m_ButtonDeleteOneAlias->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DeleteAliasOfPart ), NULL, this ); m_ButtonDeleteAllAlias->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DeleteAllAliasOfPart ), NULL, this ); m_buttonAddFpF->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::AddFootprintFilter ), NULL, this ); diff --git a/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp b/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp index 9648f10a1a..5730fb38b2 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp +++ b/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp @@ -2507,6 +2507,94 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Edit + + 0 + + + 0 + + 1 + m_ButtonEditAlias + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + EditAliasOfPart + + + + + + + + + + + + + + + + + + + + + + + + + 5 wxALL|wxEXPAND diff --git a/eeschema/dialogs/dialog_edit_component_in_lib_base.h b/eeschema/dialogs/dialog_edit_component_in_lib_base.h index 2b3884b7ab..6db1a4467b 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib_base.h +++ b/eeschema/dialogs/dialog_edit_component_in_lib_base.h @@ -80,6 +80,7 @@ class DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE : public DIALOG_SHIM wxStaticText* m_staticTextAlias; wxListBox* m_PartAliasListCtrl; wxButton* m_ButtonAddeAlias; + wxButton* m_ButtonEditAlias; wxButton* m_ButtonDeleteOneAlias; wxButton* m_ButtonDeleteAllAlias; wxPanel* m_PanelFootprintFilter; @@ -98,6 +99,7 @@ class DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE : public DIALOG_SHIM virtual void CopyDocFromRootToAlias( wxCommandEvent& event ) { event.Skip(); } virtual void BrowseAndSelectDocFile( wxCommandEvent& event ) { event.Skip(); } virtual void AddAliasOfPart( wxCommandEvent& event ) { event.Skip(); } + virtual void EditAliasOfPart( wxCommandEvent& event ) { event.Skip(); } virtual void DeleteAliasOfPart( wxCommandEvent& event ) { event.Skip(); } virtual void DeleteAllAliasOfPart( wxCommandEvent& event ) { event.Skip(); } virtual void AddFootprintFilter( wxCommandEvent& event ) { event.Skip(); }