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

grids: allow editing existing grids

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/16870
This commit is contained in:
Mike Williams 2024-09-12 15:19:09 -04:00
parent c0c8ce087c
commit 337211adea
6 changed files with 156 additions and 3 deletions

View File

@ -47,6 +47,21 @@ DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( wxWindow* aParent, wxWindow* aEventS
Layout();
if( !aGrid.x.IsEmpty() )
{
bool linked = ( aGrid.x == aGrid.y );
VECTOR2D grid = aGrid.ToDouble( aProvider->GetIuScale() );
m_textName->SetValue( aGrid.name );
m_checkLinked->SetValue( linked );
m_gridSizeX.SetDoubleValue( grid.x );
if( !linked )
m_gridSizeY.SetDoubleValue( grid.y );
m_textY->Enable( !linked );
}
// Now all widgets have the size fixed, call FinishDialogSettings
finishDialogSettings();
}

View File

@ -91,6 +91,7 @@ PANEL_GRID_SETTINGS::PANEL_GRID_SETTINGS( wxWindow* aParent, UNITS_PROVIDER* aUn
m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
m_addGridButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
m_editGridButton->SetBitmap( KiBitmapBundle( BITMAPS::edit ) );
m_removeGridButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
@ -270,6 +271,53 @@ void PANEL_GRID_SETTINGS::OnAddGrid( wxCommandEvent& event )
}
void PANEL_GRID_SETTINGS::OnEditGrid( wxCommandEvent& event )
{
onEditGrid();
}
void PANEL_GRID_SETTINGS::OnDoubleClick( wxMouseEvent& event )
{
onEditGrid();
}
void PANEL_GRID_SETTINGS::onEditGrid()
{
int row = m_currentGridCtrl->GetSelection();
if( row < 0 )
return;
GRID newGrid = m_cfg->m_Window.grid.grids[row];
DIALOG_GRID_SETTINGS dlg( wxGetTopLevelParent( this ), m_eventSource, m_unitsProvider,
newGrid );
if( dlg.ShowModal() != wxID_OK )
return;
GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
for( GRID& g : gridCfg.grids )
{
if( newGrid == g )
{
wxWindow* topLevelParent = wxGetTopLevelParent( this );
DisplayError( topLevelParent,
wxString::Format( _( "Grid size '%s' already exists." ),
g.UserUnitsMessageText( m_unitsProvider ) ) );
return;
}
}
gridCfg.grids[row] = newGrid;
RebuildGridSizes();
m_currentGridCtrl->SetSelection( row );
}
void PANEL_GRID_SETTINGS::OnRemoveGrid( wxCommandEvent& event )
{
GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf-dirty)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -37,8 +37,11 @@ PANEL_GRID_SETTINGS_BASE::PANEL_GRID_SETTINGS_BASE( wxWindow* parent, wxWindowID
m_addGridButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
bSizerGridButtons->Add( m_addGridButton, 0, wxRIGHT|wxLEFT, 5 );
m_editGridButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
bSizerGridButtons->Add( m_editGridButton, 0, wxRIGHT, 5 );
m_moveUpButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
bSizerGridButtons->Add( m_moveUpButton, 0, wxRIGHT, 5 );
bSizerGridButtons->Add( m_moveUpButton, 0, wxLEFT|wxRIGHT, 5 );
m_moveDownButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
bSizerGridButtons->Add( m_moveDownButton, 0, 0, 5 );
@ -171,7 +174,9 @@ PANEL_GRID_SETTINGS_BASE::PANEL_GRID_SETTINGS_BASE( wxWindow* parent, wxWindowID
bSizerMain->Fit( this );
// Connect Events
m_currentGridCtrl->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PANEL_GRID_SETTINGS_BASE::OnDoubleClick ), NULL, this );
m_addGridButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnAddGrid ), NULL, this );
m_editGridButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnEditGrid ), NULL, this );
m_moveUpButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnMoveGridUp ), NULL, this );
m_moveDownButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnMoveGridDown ), NULL, this );
m_removeGridButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnRemoveGrid ), NULL, this );
@ -180,7 +185,9 @@ PANEL_GRID_SETTINGS_BASE::PANEL_GRID_SETTINGS_BASE( wxWindow* parent, wxWindowID
PANEL_GRID_SETTINGS_BASE::~PANEL_GRID_SETTINGS_BASE()
{
// Disconnect Events
m_currentGridCtrl->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PANEL_GRID_SETTINGS_BASE::OnDoubleClick ), NULL, this );
m_addGridButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnAddGrid ), NULL, this );
m_editGridButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnEditGrid ), NULL, this );
m_moveUpButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnMoveGridUp ), NULL, this );
m_moveDownButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnMoveGridDown ), NULL, this );
m_removeGridButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_GRID_SETTINGS_BASE::OnRemoveGrid ), NULL, this );

View File

@ -200,6 +200,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnLeftDClick">OnDoubleClick</event>
</object>
</object>
<object class="sizeritem" expanded="true">
@ -290,6 +291,81 @@
<property name="border">5</property>
<property name="flag">wxRIGHT</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"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></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">Edit Grid</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"></property>
<property name="moveable">1</property>
<property name="name">m_editGridButton</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"></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">OnEditGrid</event>
</object>
</object>
<object class="sizeritem" expanded="true">
<property name="border">5</property>
<property name="flag">wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxBitmapButton" expanded="true">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf-dirty)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -45,6 +45,7 @@ class PANEL_GRID_SETTINGS_BASE : public RESETTABLE_PANEL
wxStaticText* m_gridsLabel;
wxListBox* m_currentGridCtrl;
STD_BITMAP_BUTTON* m_addGridButton;
STD_BITMAP_BUTTON* m_editGridButton;
STD_BITMAP_BUTTON* m_moveUpButton;
STD_BITMAP_BUTTON* m_moveDownButton;
STD_BITMAP_BUTTON* m_removeGridButton;
@ -70,7 +71,9 @@ class PANEL_GRID_SETTINGS_BASE : public RESETTABLE_PANEL
wxChoice* m_gridOverrideGraphicsChoice;
// Virtual event handlers, override them in your derived class
virtual void OnDoubleClick( wxMouseEvent& event ) { event.Skip(); }
virtual void OnAddGrid( wxCommandEvent& event ) { event.Skip(); }
virtual void OnEditGrid( wxCommandEvent& event ) { event.Skip(); }
virtual void OnMoveGridUp( wxCommandEvent& event ) { event.Skip(); }
virtual void OnMoveGridDown( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRemoveGrid( wxCommandEvent& event ) { event.Skip(); }

View File

@ -45,12 +45,16 @@ public:
private:
void OnAddGrid( wxCommandEvent& event ) override;
void OnEditGrid( wxCommandEvent& event ) override;
void OnRemoveGrid( wxCommandEvent& event ) override;
void OnMoveGridUp( wxCommandEvent& event ) override;
void OnMoveGridDown( wxCommandEvent& event ) override;
void OnDoubleClick( wxMouseEvent& event ) override;
void RebuildGridSizes();
void onEditGrid();
private:
UNITS_PROVIDER* m_unitsProvider;
APP_SETTINGS_BASE* m_cfg;