7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-04 23:25:30 +00:00

ADDED: fieldname template reordering.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20420
This commit is contained in:
Jeff Young 2025-03-26 11:10:22 +00:00
parent 5f620f0fa1
commit 34f12dc4be
7 changed files with 249 additions and 29 deletions

View File

@ -97,7 +97,6 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aSho
wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 5 );
}
if( !aAuxiliaryAction.IsEmpty() )
{
m_auxiliaryButton = new wxButton( this, wxID_ANY, aAuxiliaryAction );
@ -124,21 +123,13 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aSho
m_hash_key = aTitle;
if( m_auxiliaryButton )
{
m_auxiliaryButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onAuxiliaryAction,
this );
}
m_auxiliaryButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onAuxiliaryAction, this );
if( m_resetButton )
{
m_resetButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onResetButton, this );
}
if( m_openPrefsDirButton )
{
m_openPrefsDirButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
&PAGED_DIALOG::onOpenPreferencesButton, this );
}
m_openPrefsDirButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onOpenPrefsDir, this );
m_treebook->Bind( wxEVT_CHAR_HOOK, &PAGED_DIALOG::onCharHook, this );
m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::onPageChanged, this );
@ -161,6 +152,12 @@ void PAGED_DIALOG::finishInitialization()
m_treebook->Layout();
m_treebook->Fit();
// Add a bit of width to the treeCtrl for scrollbars
wxSize ctrlSize = m_treebook->GetTreeCtrl()->GetSize();
ctrlSize.x += 20;
m_treebook->GetTreeCtrl()->SetMinSize( ctrlSize );
m_treebook->Layout();
finishDialogSettings();
}
@ -195,21 +192,13 @@ PAGED_DIALOG::~PAGED_DIALOG()
g_lastParentPage[ m_title ] = lastParentPage;
if( m_auxiliaryButton )
{
m_auxiliaryButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onAuxiliaryAction,
this );
}
m_auxiliaryButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onAuxiliaryAction, this );
if( m_resetButton )
{
m_resetButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onResetButton, this );
}
if( m_openPrefsDirButton )
{
m_openPrefsDirButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED,
&PAGED_DIALOG::onOpenPreferencesButton, this );
}
m_openPrefsDirButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onOpenPrefsDir, this );
m_treebook->Unbind( wxEVT_CHAR_HOOK, &PAGED_DIALOG::onCharHook, this );
m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::onPageChanged, this );
@ -483,7 +472,7 @@ void PAGED_DIALOG::onResetButton( wxCommandEvent& aEvent )
}
}
void PAGED_DIALOG::onOpenPreferencesButton( wxCommandEvent& aEvent )
void PAGED_DIALOG::onOpenPrefsDir( wxCommandEvent& aEvent )
{
wxString dir( PATHS::GetUserSettingsPath() );
LaunchExternal( dir );

View File

@ -61,6 +61,8 @@ PANEL_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES( wxWindow* aWindow,
m_addFieldButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
m_deleteFieldButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
m_bpMoveUp->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
m_bpMoveDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
m_checkboxColWidth = m_grid->GetColSize( 1 );
@ -105,6 +107,9 @@ void PANEL_TEMPLATE_FIELDNAMES::OnAddButtonClick( wxCommandEvent& event )
// wx documentation is wrong, SetGridCursor does not make visible.
m_grid->MakeCellVisible( row, 0 );
m_grid->SetGridCursor( row, 0 );
m_grid->EnableCellEditControl( true );
m_grid->ShowCellEditControl();
}
@ -122,7 +127,11 @@ void PANEL_TEMPLATE_FIELDNAMES::OnDeleteButtonClick( wxCommandEvent& event )
return;
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
selectedRows.Sort(
[]( int* first, int* second )
{
return *second - *first;
} );
for( int row : selectedRows )
{
@ -135,6 +144,59 @@ void PANEL_TEMPLATE_FIELDNAMES::OnDeleteButtonClick( wxCommandEvent& event )
}
void swapRows( WX_GRID* aGrid, int aRowA, int aRowB )
{
for( int col = 0; col < aGrid->GetNumberCols(); ++col )
{
wxString temp = aGrid->GetCellValue( aRowA, col );
aGrid->SetCellValue( aRowA, col, aGrid->GetCellValue( aRowB, col ) );
aGrid->SetCellValue( aRowB, col, temp );
}
}
void PANEL_TEMPLATE_FIELDNAMES::OnMoveUp( wxCommandEvent& event )
{
if( !m_grid->CommitPendingChanges() )
return;
int i = m_grid->GetGridCursorRow();
if( i > 0 )
{
swapRows( m_grid, i, i - 1 );
m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
}
else
{
wxBell();
}
}
void PANEL_TEMPLATE_FIELDNAMES::OnMoveDown( wxCommandEvent& event )
{
if( !m_grid->CommitPendingChanges() )
return;
int i = m_grid->GetGridCursorRow();
if( i >= 0 && i + 1 < m_grid->GetNumberRows() )
{
swapRows( m_grid, i, i + 1 );
m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
}
else
{
wxBell();
}
}
bool PANEL_TEMPLATE_FIELDNAMES::TransferDataToGrid()
{
m_grid->Freeze();
@ -206,11 +268,10 @@ bool PANEL_TEMPLATE_FIELDNAMES::TransferDataFromWindow()
{
wxString msg;
msg.Printf( _( "The field name \"%s\" contains trailing and/or leading white"
"space." ), field.m_Name );
msg.Printf( _( "The field name '%s' contains trailing and/or leading white space." ),
field.m_Name );
wxMessageDialog dlg( this, msg, _( "Warning" ),
wxOK | wxCANCEL | wxCENTER | wxICON_WARNING );
wxMessageDialog dlg( this, msg, _( "Warning" ), wxOK|wxCANCEL|wxCENTER|wxICON_WARNING );
dlg.SetExtendedMessage( _( "This may result in what appears to be duplicate field "
"names but are actually unique names differing only by "
@ -241,7 +302,7 @@ bool PANEL_TEMPLATE_FIELDNAMES::TransferDataFromWindow()
m_templateMgr->Format( &sf, true );
wxString record = From_UTF8( sf.GetString().c_str() );
record.Replace( wxT(" "), wxT(" "), true ); // double space to single
record.Replace( wxT( " " ), wxT( " " ), true ); // double space to single
cfg->m_Drawing.field_names = record.ToStdString();
}

View File

@ -58,6 +58,8 @@ protected:
private:
void AdjustGridColumns( int aWidth );
void OnMoveUp( wxCommandEvent& event ) override;
void OnMoveDown( wxCommandEvent& event ) override;
void OnSizeGrid( wxSizeEvent& event ) override;
bool TransferDataToWindow() override;

View File

@ -64,6 +64,16 @@ PANEL_TEMPLATE_FIELDNAMES_BASE::PANEL_TEMPLATE_FIELDNAMES_BASE( wxWindow* parent
m_addFieldButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
bSizer10->Add( m_addFieldButton, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
m_bpMoveUp = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
m_bpMoveUp->SetToolTip( _("Move up") );
bSizer10->Add( m_bpMoveUp, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
m_bpMoveDown = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
m_bpMoveDown->SetToolTip( _("Move down") );
bSizer10->Add( m_bpMoveDown, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
bSizer10->Add( 20, 0, 0, wxEXPAND, 5 );
@ -81,6 +91,8 @@ PANEL_TEMPLATE_FIELDNAMES_BASE::PANEL_TEMPLATE_FIELDNAMES_BASE( wxWindow* parent
// Connect Events
m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnSizeGrid ), NULL, this );
m_addFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnAddButtonClick ), NULL, this );
m_bpMoveUp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnMoveUp ), NULL, this );
m_bpMoveDown->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnMoveDown ), NULL, this );
m_deleteFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnDeleteButtonClick ), NULL, this );
}
@ -89,6 +101,8 @@ PANEL_TEMPLATE_FIELDNAMES_BASE::~PANEL_TEMPLATE_FIELDNAMES_BASE()
// Disconnect Events
m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnSizeGrid ), NULL, this );
m_addFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnAddButtonClick ), NULL, this );
m_bpMoveUp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnMoveUp ), NULL, this );
m_bpMoveDown->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnMoveDown ), NULL, this );
m_deleteFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_TEMPLATE_FIELDNAMES_BASE::OnDeleteButtonClick ), NULL, this );
}

View File

@ -306,6 +306,156 @@
<event name="OnButtonClick">OnAddButtonClick</event>
</object>
</object>
<object class="sizeritem" expanded="true">
<property name="border">5</property>
<property name="flag">wxTOP|wxBOTTOM|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBitmapButton" expanded="true">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer">0</property>
<property name="aui_name"></property>
<property name="aui_position">0</property>
<property name="aui_row">0</property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_accept_files">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Move Up</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">-1,-1</property>
<property name="moveable">1</property>
<property name="name">m_bpMoveUp</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">STD_BITMAP_BUTTON; widgets/std_bitmap_button.h; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Move up</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnMoveUp</event>
</object>
</object>
<object class="sizeritem" expanded="true">
<property name="border">5</property>
<property name="flag">wxTOP|wxBOTTOM|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBitmapButton" expanded="true">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer">0</property>
<property name="aui_name"></property>
<property name="aui_position">0</property>
<property name="aui_row">0</property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_accept_files">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Move Down</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">-1,-1</property>
<property name="moveable">1</property>
<property name="name">m_bpMoveDown</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">STD_BITMAP_BUTTON; widgets/std_bitmap_button.h; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Move down</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnMoveDown</event>
</object>
</object>
<object class="sizeritem" expanded="true">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>

View File

@ -41,11 +41,15 @@ class PANEL_TEMPLATE_FIELDNAMES_BASE : public wxPanel
wxStaticText* m_title;
WX_GRID* m_grid;
STD_BITMAP_BUTTON* m_addFieldButton;
STD_BITMAP_BUTTON* m_bpMoveUp;
STD_BITMAP_BUTTON* m_bpMoveDown;
STD_BITMAP_BUTTON* m_deleteFieldButton;
// Virtual event handlers, override them in your derived class
virtual void OnSizeGrid( wxSizeEvent& event ) { event.Skip(); }
virtual void OnAddButtonClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnMoveUp( wxCommandEvent& event ) { event.Skip(); }
virtual void OnMoveDown( wxCommandEvent& event ) { event.Skip(); }
virtual void OnDeleteButtonClick( wxCommandEvent& event ) { event.Skip(); }

View File

@ -60,7 +60,7 @@ protected:
virtual void onAuxiliaryAction( wxCommandEvent& aEvent ) { aEvent.Skip(); }
virtual void onResetButton( wxCommandEvent& aEvent );
virtual void onOpenPreferencesButton( wxCommandEvent& aEvent );
virtual void onOpenPrefsDir( wxCommandEvent& aEvent );
virtual void onPageChanged( wxBookCtrlEvent& aEvent );
virtual void onPageChanging( wxBookCtrlEvent& aEvent );
virtual void onCharHook( wxKeyEvent& aEvent );