From 2764e594000ef0d9916559ed5e4b5c1b8ac56c97 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Thu, 24 Aug 2023 13:57:22 -0400 Subject: [PATCH] Grids: add buttons to re-order grids --- common/dialogs/dialog_grid_settings.cpp | 32 ++++ common/dialogs/dialog_grid_settings_base.cpp | 13 ++ common/dialogs/dialog_grid_settings_base.fbp | 162 ++++++++++++++++++- common/dialogs/dialog_grid_settings_base.h | 4 + common/eda_draw_frame.cpp | 2 +- common/settings/app_settings.cpp | 2 +- include/dialogs/dialog_grid_settings.h | 2 + 7 files changed, 213 insertions(+), 4 deletions(-) diff --git a/common/dialogs/dialog_grid_settings.cpp b/common/dialogs/dialog_grid_settings.cpp index 6e282da00f..f025f53c7b 100644 --- a/common/dialogs/dialog_grid_settings.cpp +++ b/common/dialogs/dialog_grid_settings.cpp @@ -86,6 +86,8 @@ DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( EDA_DRAW_FRAME* aParent ) : m_addGridButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); m_removeGridButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) ); + m_moveUpButton->SetBitmap( KiBitmap( BITMAPS::small_up ) ); + m_moveDownButton->SetBitmap( KiBitmap( BITMAPS::small_down ) ); SetupStandardButtons(); SetInitialFocus( m_GridOriginXCtrl ); @@ -269,3 +271,33 @@ void DIALOG_GRID_SETTINGS::OnRemoveGrid( wxCommandEvent& event ) } +void DIALOG_GRID_SETTINGS::OnMoveGridUp( wxCommandEvent& event ) +{ + GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid; + int row = m_currentGridCtrl->GetSelection(); + + if( gridCfg.sizes.size() <= 1 || row == 0 ) + return; + + std::swap( gridCfg.sizes[row], gridCfg.sizes[row - 1] ); + RebuildGridSizes(); + + if( row != 0 ) + m_currentGridCtrl->SetSelection( row - 1 ); +} + + +void DIALOG_GRID_SETTINGS::OnMoveGridDown( wxCommandEvent& event ) +{ + GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid; + int row = m_currentGridCtrl->GetSelection(); + + if( gridCfg.sizes.size() <= 1 || row == ( (int) gridCfg.sizes.size() - 1 ) ) + return; + + std::swap( gridCfg.sizes[row], gridCfg.sizes[row + 1] ); + RebuildGridSizes(); + + if( row != 0 ) + m_currentGridCtrl->SetSelection( row + 1 ); +} diff --git a/common/dialogs/dialog_grid_settings_base.cpp b/common/dialogs/dialog_grid_settings_base.cpp index 06221079f4..23a2b34c30 100644 --- a/common/dialogs/dialog_grid_settings_base.cpp +++ b/common/dialogs/dialog_grid_settings_base.cpp @@ -40,6 +40,15 @@ DIALOG_GRID_SETTINGS_BASE::DIALOG_GRID_SETTINGS_BASE( wxWindow* parent, wxWindow bSizer4->Add( m_removeGridButton, 0, 0, 5 ); + bSizer4->Add( 20, 0, 1, wxEXPAND, 5 ); + + m_moveUpButton = new STD_BITMAP_BUTTON( sbCurrentGrid->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); + bSizer4->Add( m_moveUpButton, 0, wxRIGHT, 5 ); + + m_moveDownButton = new STD_BITMAP_BUTTON( sbCurrentGrid->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); + bSizer4->Add( m_moveDownButton, 0, 0, 5 ); + + sbCurrentGrid->Add( bSizer4, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); @@ -247,6 +256,8 @@ DIALOG_GRID_SETTINGS_BASE::DIALOG_GRID_SETTINGS_BASE( wxWindow* parent, wxWindow this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_GRID_SETTINGS_BASE::OnInitDlg ) ); m_addGridButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnAddGrid ), NULL, this ); m_removeGridButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnRemoveGrid ), NULL, this ); + m_moveUpButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnMoveGridUp ), NULL, this ); + m_moveDownButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnMoveGridDown ), NULL, this ); m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnCancelClick ), NULL, this ); m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnOkClick ), NULL, this ); } @@ -257,6 +268,8 @@ DIALOG_GRID_SETTINGS_BASE::~DIALOG_GRID_SETTINGS_BASE() this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_GRID_SETTINGS_BASE::OnInitDlg ) ); m_addGridButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnAddGrid ), NULL, this ); m_removeGridButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnRemoveGrid ), NULL, this ); + m_moveUpButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnMoveGridUp ), NULL, this ); + m_moveDownButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnMoveGridDown ), NULL, this ); m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnCancelClick ), NULL, this ); m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnOkClick ), NULL, this ); diff --git a/common/dialogs/dialog_grid_settings_base.fbp b/common/dialogs/dialog_grid_settings_base.fbp index 1b0629ac75..f8a2b9603a 100644 --- a/common/dialogs/dialog_grid_settings_base.fbp +++ b/common/dialogs/dialog_grid_settings_base.fbp @@ -193,7 +193,7 @@ 0 0 wxID_ANY - MyButton + Add Grid 0 @@ -277,7 +277,7 @@ 0 0 wxID_ANY - Remove Field... + Remove Grid 0 @@ -313,6 +313,164 @@ OnRemoveGrid + + 5 + wxEXPAND + 1 + + 0 + protected + 20 + + + + 5 + wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Move grid up in list + + 0 + + 0 + + + 0 + + 1 + m_moveUpButton + 1 + + + protected + 1 + + + + Resizable + 1 + + + STD_BITMAP_BUTTON; widgets/std_bitmap_button.h; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnMoveGridUp + + + + 5 + + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Move grid up in list + + 0 + + 0 + + + 0 + + 1 + m_moveDownButton + 1 + + + protected + 1 + + + + Resizable + 1 + + + STD_BITMAP_BUTTON; widgets/std_bitmap_button.h; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnMoveGridDown + + diff --git a/common/dialogs/dialog_grid_settings_base.h b/common/dialogs/dialog_grid_settings_base.h index e43a0aeab7..7b7645e07e 100644 --- a/common/dialogs/dialog_grid_settings_base.h +++ b/common/dialogs/dialog_grid_settings_base.h @@ -46,6 +46,8 @@ class DIALOG_GRID_SETTINGS_BASE : public DIALOG_SHIM wxListBox* m_currentGridCtrl; STD_BITMAP_BUTTON* m_addGridButton; STD_BITMAP_BUTTON* m_removeGridButton; + STD_BITMAP_BUTTON* m_moveUpButton; + STD_BITMAP_BUTTON* m_moveDownButton; wxStaticBoxSizer* sbGridOriginSizer; wxStaticText* m_staticTextGridPosX; wxTextCtrl* m_GridOriginXCtrl; @@ -89,6 +91,8 @@ class DIALOG_GRID_SETTINGS_BASE : public DIALOG_SHIM virtual void OnInitDlg( wxInitDialogEvent& event ) { event.Skip(); } virtual void OnAddGrid( wxCommandEvent& event ) { event.Skip(); } virtual void OnRemoveGrid( wxCommandEvent& event ) { event.Skip(); } + virtual void OnMoveGridUp( wxCommandEvent& event ) { event.Skip(); } + virtual void OnMoveGridDown( wxCommandEvent& event ) { event.Skip(); } virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index 93d4cdd14c..a0108c4d83 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -385,7 +385,7 @@ void EDA_DRAW_FRAME::UpdateGridSelectBox() m_gridSelectBox->Append( grid ); m_gridSelectBox->Append( wxT( "---" ) ); - m_gridSelectBox->Append( _( "Edit User Grid..." ) ); + m_gridSelectBox->Append( _( "Edit Grids..." ) ); m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx ); } diff --git a/common/settings/app_settings.cpp b/common/settings/app_settings.cpp index 9b5950de43..85e29f6f9b 100644 --- a/common/settings/app_settings.cpp +++ b/common/settings/app_settings.cpp @@ -386,7 +386,7 @@ void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std: m_params.emplace_back( new PARAM( aJsonPath + ".grid.override_wires", &aWindow->grid.override_wires, false ) ); m_params.emplace_back( new PARAM( aJsonPath + ".grid.override_vias", - &aWindow->grid.override_wires, false ) ); + &aWindow->grid.override_vias, false ) ); m_params.emplace_back( new PARAM( aJsonPath + ".grid.override_text", &aWindow->grid.override_text, false ) ); m_params.emplace_back( new PARAM( aJsonPath + ".grid.override_graphics", diff --git a/include/dialogs/dialog_grid_settings.h b/include/dialogs/dialog_grid_settings.h index 45eb6de676..9e1a076879 100644 --- a/include/dialogs/dialog_grid_settings.h +++ b/include/dialogs/dialog_grid_settings.h @@ -42,6 +42,8 @@ public: private: void OnAddGrid( wxCommandEvent& event ) override; void OnRemoveGrid( wxCommandEvent& event ) override; + void OnMoveGridUp( wxCommandEvent& event ) override; + void OnMoveGridDown( wxCommandEvent& event ) override; void RebuildGridSizes();