diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp
index ccc0e512ad..ed70a4c398 100644
--- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp
+++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp
@@ -59,7 +59,8 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY::DIALOG_EDIT_COMPONENT_IN_LIBRARY( LIB_EDIT_FRA
m_currentAlias( wxNOT_FOUND ),
m_pinNameOffset( aParent, m_nameOffsetLabel, m_nameOffsetCtrl, m_nameOffsetUnits, true ),
m_delayedFocusCtrl( nullptr ),
- m_delayedFocusGrid( nullptr )
+ m_delayedFocusGrid( nullptr ),
+ m_delayedFocusPage( -1 )
{
m_config = Kiface().KifaceSettings();
@@ -95,6 +96,8 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY::DIALOG_EDIT_COMPONENT_IN_LIBRARY( LIB_EDIT_FRA
attr->SetEditor( new GRID_CELL_URL_EDITOR( this ) );
m_aliasGrid->SetAttr( DATASHEET, FDC_VALUE, attr );
+ m_SymbolNameCtrl->SetValidator( SCH_FIELD_VALIDATOR( true, VALUE ) );
+
// Configure button logos
m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
@@ -224,6 +227,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::Validate()
m_delayedFocusGrid = m_grid;
m_delayedFocusColumn = FDC_VALUE;
m_delayedFocusRow = REFERENCE;
+ m_delayedFocusPage = 0;
return false;
}
@@ -243,6 +247,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::Validate()
m_delayedFocusGrid = m_grid;
m_delayedFocusColumn = FDC_NAME;
m_delayedFocusRow = i;
+ m_delayedFocusPage = 0;
return false;
}
@@ -346,18 +351,36 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnGridCellChanging( wxGridEvent& event )
{
event.Veto();
- if( m_NoteBook->GetSelection() != 0 )
- m_NoteBook->SetSelection( 0 );
-
m_delayedFocusGrid = m_grid;
m_delayedFocusRow = event.GetRow();
m_delayedFocusColumn = event.GetCol();
+ m_delayedFocusPage = 0;
}
+ else if( event.GetRow() == VALUE && event.GetCol() == FDC_VALUE )
+ m_SymbolNameCtrl->ChangeValue( event.GetString() );
editor->DecRef();
}
+void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnSymbolNameText( wxCommandEvent& event )
+{
+ m_grid->SetCellValue( VALUE, FDC_VALUE, m_SymbolNameCtrl->GetValue() );
+}
+
+
+void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnSymbolNameKillFocus( wxFocusEvent& event )
+{
+ if( !m_delayedFocusCtrl && !m_SymbolNameCtrl->GetValidator()->Validate( m_SymbolNameCtrl ) )
+ {
+ m_delayedFocusCtrl = m_SymbolNameCtrl;
+ m_delayedFocusPage = 0;
+ }
+
+ event.Skip();
+}
+
+
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAddField( wxCommandEvent& event )
{
if( !m_grid->CommitPendingChanges() )
@@ -481,13 +504,13 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAliasGridCellChanging( wxGridEvent& eve
{
event.Veto();
- if( m_NoteBook->GetSelection() != 1 )
- m_NoteBook->SetSelection( 1 );
-
m_delayedFocusGrid = m_aliasGrid;
m_delayedFocusRow = event.GetRow();
m_delayedFocusColumn = event.GetCol();
+ m_delayedFocusPage = 1;
}
+ else
+ updateAliasName( true, newName );
}
}
@@ -500,20 +523,11 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAliasNameText( wxCommandEvent& event )
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnAliasNameKillFocus( wxFocusEvent& event )
{
- static bool inKillFocus = false;
-
- // If we get an error then we're going to throw up a dialog. Since we haven't yet
- // finished the KillFocus event, we'll end up getting another one. Side-effects may
- // include death.
- if( inKillFocus )
- return;
-
- inKillFocus = true;
-
- if( !checkAliasName( m_AliasNameCtrl->GetValue() ) )
+ if( !m_delayedFocusCtrl && !checkAliasName( m_AliasNameCtrl->GetValue() ) )
+ {
m_delayedFocusCtrl = m_AliasNameCtrl;
-
- inKillFocus = false;
+ m_delayedFocusPage = 1;
+ }
event.Skip();
}
@@ -744,6 +758,19 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnUpdateUI( wxUpdateUIEvent& event )
m_OptionPartsLocked->Enable( m_SelNumberOfUnits->GetValue() > 1 );
m_pinNameOffset.Enable( m_PinsNameInsideButt->GetValue() );
+ if( m_grid->IsCellEditControlShown() )
+ {
+ int row = m_grid->GetGridCursorRow();
+ int col = m_grid->GetGridCursorCol();
+
+ if( row == VALUE && col == FDC_VALUE )
+ {
+ wxGridCellEditor* editor = m_grid->GetCellEditor( row, col );
+ m_SymbolNameCtrl->ChangeValue( editor->GetValue() );
+ editor->DecRef();
+ }
+ }
+
// Synthesize a Select event when the selection is cleared
if( m_aliasListBox->GetSelection() == wxNOT_FOUND && m_currentAlias != wxNOT_FOUND )
{
@@ -762,7 +789,28 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnUpdateUI( wxUpdateUIEvent& event )
adjustGridColumns( m_grid->GetRect().GetWidth() );
}
- // Handle a delayed focus
+ // Handle a delayed focus. The delay allows us to:
+ // a) change focus when the error was triggered from within a killFocus handler
+ // b) show the correct notebook page in the background before the error dialog comes up
+ // when triggered from an OK or a notebook page change
+
+ if( m_delayedFocusPage >= 0 && m_NoteBook->GetSelection() != m_delayedFocusPage )
+ {
+ m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage );
+ m_delayedFocusPage = -1;
+ }
+
+ if( !m_delayedErrorMessage.IsEmpty() )
+ {
+ // We will re-enter this routine when the error dialog is displayed, so make
+ // sure we don't keep putting up more dialogs.
+ wxString msg = m_delayedErrorMessage;
+ m_delayedErrorMessage = wxEmptyString;
+
+ // Do not use DisplayErrorMessage(); it screws up window order on Mac
+ DisplayError( nullptr, msg );
+ }
+
if( m_delayedFocusCtrl )
{
m_delayedFocusCtrl->SetFocus();
@@ -778,21 +826,12 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnUpdateUI( wxUpdateUIEvent& event )
m_delayedFocusGrid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
m_delayedFocusGrid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
- if( !m_delayedErrorMessage.IsEmpty() )
- {
- // We will re-enter this routine when the error dialog is displayed, so make
- // sure we don't keep putting up more dialogs.
- wxString msg = m_delayedErrorMessage;
- m_delayedErrorMessage = wxEmptyString;
-
- // Do not use DisplayErrorMessage(); it screws up window order on Mac
- DisplayError( nullptr, msg );
- }
-
m_delayedFocusGrid->EnableCellEditControl( true );
m_delayedFocusGrid->ShowCellEditControl();
m_delayedFocusGrid = nullptr;
+ m_delayedFocusRow = -1;
+ m_delayedFocusColumn = -1;
}
}
diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.h b/eeschema/dialogs/dialog_edit_component_in_lib.h
index c4bc1640bb..837c72c9f4 100644
--- a/eeschema/dialogs/dialog_edit_component_in_lib.h
+++ b/eeschema/dialogs/dialog_edit_component_in_lib.h
@@ -57,10 +57,12 @@ public:
UNIT_BINDER m_pinNameOffset;
wxControl* m_delayedFocusCtrl;
- wxString m_delayedErrorMessage;
WX_GRID* m_delayedFocusGrid;
int m_delayedFocusRow;
int m_delayedFocusColumn;
+ int m_delayedFocusPage;
+ wxString m_delayedErrorMessage;
+
wxString m_shownColumns;
bool TransferDataToWindow() override;
@@ -80,6 +82,8 @@ private:
void OnDeleteField( wxCommandEvent& event ) override;
void OnMoveUp( wxCommandEvent& event ) override;
void OnMoveDown( wxCommandEvent& event ) override;
+ void OnSymbolNameKillFocus( wxFocusEvent& event ) override;
+ void OnSymbolNameText( wxCommandEvent& event ) override;
void OnSelectAlias( wxCommandEvent& event ) override;
void OnAddAlias( wxCommandEvent& event ) override;
void OnDeleteAlias( 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 b699619c4b..6815170679 100644
--- a/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp
+++ b/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp
@@ -29,7 +29,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx
wxStaticBoxSizer* sbSizer4;
sbSizer4 = new wxStaticBoxSizer( new wxStaticBox( m_PanelBasic, wxID_ANY, _("Fields") ), wxVERTICAL );
- m_grid = new WX_GRID( sbSizer4->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER );
+ m_grid = new WX_GRID( sbSizer4->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid
m_grid->CreateGrid( 4, 11 );
@@ -126,7 +126,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx
fgSizerFPID->Add( staticNameLabel, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_SymbolNameCtrl = new wxTextCtrl( m_PanelBasic, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
- fgSizerFPID->Add( m_SymbolNameCtrl, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
+ fgSizerFPID->Add( m_SymbolNameCtrl, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 );
wxStaticText* staticDescriptionLabel;
staticDescriptionLabel = new wxStaticText( m_PanelBasic, wxID_ANY, _("Description:"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -134,7 +134,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx
fgSizerFPID->Add( staticDescriptionLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_DescCtrl = new wxTextCtrl( m_PanelBasic, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
- fgSizerFPID->Add( m_DescCtrl, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
+ fgSizerFPID->Add( m_DescCtrl, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 );
staticKeywordsLabel = new wxStaticText( m_PanelBasic, wxID_ANY, _("Keywords:"), wxDefaultPosition, wxDefaultSize, 0 );
staticKeywordsLabel->Wrap( -1 );
@@ -301,7 +301,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx
m_staticText12->Wrap( -1 );
bRightBoxSizerPanelAlias->Add( m_staticText12, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
- m_aliasGrid = new WX_GRID( m_PanelAlias, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER );
+ m_aliasGrid = new WX_GRID( m_PanelAlias, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid
m_aliasGrid->CreateGrid( 4, 2 );
@@ -452,6 +452,8 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx
m_bpMoveUp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnMoveUp ), NULL, this );
m_bpMoveDown->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnMoveDown ), NULL, this );
m_bpDelete->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnDeleteField ), NULL, this );
+ m_SymbolNameCtrl->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnSymbolNameKillFocus ), NULL, this );
+ m_SymbolNameCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnSymbolNameText ), NULL, this );
m_aliasListBox->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnSelectAlias ), NULL, this );
m_addAliasButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnAddAlias ), NULL, this );
m_deleteAliasButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnDeleteAlias ), NULL, this );
@@ -472,6 +474,8 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::~DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE()
m_bpMoveUp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnMoveUp ), NULL, this );
m_bpMoveDown->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnMoveDown ), NULL, this );
m_bpDelete->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnDeleteField ), NULL, this );
+ m_SymbolNameCtrl->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnSymbolNameKillFocus ), NULL, this );
+ m_SymbolNameCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnSymbolNameText ), NULL, this );
m_aliasListBox->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnSelectAlias ), NULL, this );
m_addAliasButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnAddAlias ), NULL, this );
m_deleteAliasButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::OnDeleteAlias ), 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 13fe6ced40..2d5aab319b 100644
--- a/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp
+++ b/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp
@@ -365,7 +365,7 @@
- wxSIMPLE_BORDER
+
@@ -818,20 +818,20 @@
-