Bring various appearance managers into line over preset editing.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15726
This commit is contained in:
Jeff Young 2023-09-25 12:10:18 +01:00
parent 938001250d
commit 7835b8ddc7
3 changed files with 61 additions and 36 deletions

View File

@ -21,6 +21,7 @@
#include <dialogs/appearance_controls_3D.h>
#include <bitmaps.h>
#include <confirm.h>
#include <pgm_base.h>
#include <dpi_scaling_common.h>
#include <eda_list_dialog.h>
@ -616,6 +617,12 @@ void APPEARANCE_CONTROLS_3D::onLayerPresetChanged( wxCommandEvent& aEvent )
int index = m_cbLayerPresets->GetSelection();
wxString name;
auto resetSelection =
[&]()
{
updateLayerPresetWidget( cfg->m_CurrentPreset );
};
if( index == 0 )
{
name = FOLLOW_PCB;
@ -633,7 +640,7 @@ void APPEARANCE_CONTROLS_3D::onLayerPresetChanged( wxCommandEvent& aEvent )
else if( index == count - 3 )
{
// Separator: reject the selection
updateLayerPresetWidget( cfg->m_CurrentPreset );
resetSelection();
return;
}
else if( index == count - 2 )
@ -642,11 +649,10 @@ void APPEARANCE_CONTROLS_3D::onLayerPresetChanged( wxCommandEvent& aEvent )
if( dlg.ShowModal() != wxID_OK )
{
updateLayerPresetWidget( cfg->m_CurrentPreset );
resetSelection();
return;
}
else
{
std::bitset<LAYER_3D_END> visibleLayers = m_frame->GetAdapter().GetVisibleLayers();
std::map<int, COLOR4D> colors = m_frame->GetAdapter().GetLayerColors();
@ -654,6 +660,12 @@ void APPEARANCE_CONTROLS_3D::onLayerPresetChanged( wxCommandEvent& aEvent )
if( LAYER_PRESET_3D* preset = cfg->FindPreset( name ) )
{
if( !IsOK( this, _( "Overwrite existing preset?" ) ) )
{
resetSelection();
return;
}
preset->layers = visibleLayers;
preset->colors = colors;
m_cbLayerPresets->SetSelection( m_cbLayerPresets->FindString( name ) );
@ -665,7 +677,9 @@ void APPEARANCE_CONTROLS_3D::onLayerPresetChanged( wxCommandEvent& aEvent )
}
cfg->m_CurrentPreset = name;
}
m_presetMRU.Insert( name, 0 );
return;
}
else if( index == count - 1 )
{
@ -703,7 +717,7 @@ void APPEARANCE_CONTROLS_3D::onLayerPresetChanged( wxCommandEvent& aEvent )
m_presetMRU.Remove( name );
}
updateLayerPresetWidget( cfg->m_CurrentPreset );
resetSelection();
return;
}
else if( LAYER_PRESET_3D* preset = cfg->FindPreset( m_cbLayerPresets->GetStringSelection() ) )

View File

@ -1573,16 +1573,15 @@ void DIALOG_SYMBOL_FIELDS_TABLE::onBomPresetChanged( wxCommandEvent& aEvent )
}
else if( preset->readOnly )
{
wxMessageBox( _( "Cannot modify default presets." ), _( "Error" ), wxOK | wxICON_ERROR,
this );
wxMessageBox( _( "Default presets cannot be modified.\nPlease use a different name." ),
_( "Error" ), wxOK | wxICON_ERROR, this );
resetSelection();
return;
}
else
{
// Ask the user if they want to overwrite the existing preset
if( wxMessageBox( _( "Overwrite existing preset?" ), _( "Save BOM Preset" ),
wxYES_NO | wxICON_QUESTION, this )
!= wxYES )
if( !IsOK( this, _( "Overwrite existing preset?" ) ) )
{
resetSelection();
return;
@ -1975,16 +1974,15 @@ void DIALOG_SYMBOL_FIELDS_TABLE::onBomFmtPresetChanged( wxCommandEvent& aEvent )
}
else if( preset->readOnly )
{
wxMessageBox( _( "Cannot modify default presets." ), _( "Error" ), wxOK | wxICON_ERROR,
this );
wxMessageBox( _( "Default presets cannot be modified.\nPlease use a different name." ),
_( "Error" ), wxOK | wxICON_ERROR, this );
resetSelection();
return;
}
else
{
// Ask the user if they want to overwrite the existing preset
if( wxMessageBox( _( "Overwrite existing preset?" ), _( "Save BOM Preset" ),
wxYES_NO | wxICON_QUESTION, this )
!= wxYES )
if( !IsOK( this, _( "Overwrite existing preset?" ) ) )
{
resetSelection();
return;

View File

@ -25,11 +25,11 @@
#include <board_design_settings.h>
#include <pad.h>
#include <pcb_track.h>
#include <dpi_scaling_common.h>
#include <eda_list_dialog.h>
#include <string_utils.h>
#include <footprint_edit_frame.h>
#include <menus_helpers.h>
#include <confirm.h>
#include <pcb_display_options.h>
#include <pcb_edit_frame.h>
#include <pcb_painter.h>
@ -51,7 +51,6 @@
#include <widgets/wx_infobar.h>
#include <widgets/wx_grid.h>
#include <dialogs/eda_view_switcher.h>
#include <wx/bmpbuttn.h>
#include <wx/checkbox.h>
#include <wx/hyperlink.h>
#include <wx/radiobut.h>
@ -2639,20 +2638,33 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
if( !exists )
{
m_layerPresets[name] = LAYER_PRESET( name, getVisibleLayers(),
getVisibleObjects(), UNSELECTED_LAYER );
m_layerPresets[name] = LAYER_PRESET( name, getVisibleLayers(), getVisibleObjects(),
UNSELECTED_LAYER );
}
LAYER_PRESET* preset = &m_layerPresets[name];
m_currentPreset = preset;
if( !exists )
{
index = m_cbLayerPresets->Insert( name, index - 1, static_cast<void*>( preset ) );
preset->flipBoard = m_cbFlipBoard->GetValue();
}
else if( preset->readOnly )
{
wxMessageBox( _( "Default presets cannot be modified.\nPlease use a different name." ),
_( "Error" ), wxOK | wxICON_ERROR, this );
resetSelection();
return;
}
else
{
// Ask the user if they want to overwrite the existing preset
if( !IsOK( this, _( "Overwrite existing preset?" ) ) )
{
resetSelection();
return;
}
preset->layers = getVisibleLayers();
preset->renderLayers = getVisibleObjects();
preset->flipBoard = m_cbFlipBoard->GetValue();
@ -2661,6 +2673,7 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
m_presetMRU.Remove( name );
}
m_currentPreset = preset;
m_cbLayerPresets->SetSelection( index );
m_presetMRU.Insert( name, 0 );