Allow both 'save' and 'save as' for layer presets

Fixes https://gitlab.com/kicad/code/kicad/-/issues/5309
This commit is contained in:
Jon Evans 2020-08-23 17:00:49 -04:00
parent 63fb6d49e0
commit e343234c61
2 changed files with 27 additions and 14 deletions

View File

@ -333,6 +333,7 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo
m_focusOwner( aFocusOwner ),
m_board( nullptr ),
m_currentPreset( nullptr ),
m_lastSelectedUserPreset( nullptr ),
m_layerContextMenu( nullptr )
{
int indicatorSize = ConvertDialogToPixels( wxSize( 6, 6 ) ).x;
@ -951,6 +952,9 @@ void APPEARANCE_CONTROLS::ApplyLayerPreset( const LAYER_PRESET& aPreset )
else
m_currentPreset = nullptr;
m_lastSelectedUserPreset = ( m_currentPreset && !m_currentPreset->readOnly ) ? m_currentPreset
: nullptr;
updateLayerPresetSelection( aPreset.name );
doApplyLayerPreset( aPreset );
}
@ -1791,7 +1795,7 @@ void APPEARANCE_CONTROLS::rebuildLayerPresetsWidget()
m_cbLayerPresets->Append( pair.first, static_cast<void*>( &pair.second ) );
m_cbLayerPresets->Append( wxT( "-----" ) );
m_cbLayerPresets->Append( _( "Save new preset..." ) );
m_cbLayerPresets->Append( _( "Save preset..." ) );
m_cbLayerPresets->Append( _( "Delete preset..." ) );
m_cbLayerPresets->SetSelection( 0 );
@ -1818,7 +1822,7 @@ void APPEARANCE_CONTROLS::syncLayerPresetSelection()
} );
if( it != m_layerPresets.end() )
m_cbLayerPresets->SetStringSelection( it->first );
m_cbLayerPresets->SetStringSelection( it->first );
else
m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 ); // separator
@ -1868,7 +1872,12 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
else if( index == count - 2 )
{
// Save current state to new preset
wxTextEntryDialog dlg( this, _( "New layer preset name:" ), _( "Save Layer Preset" ) );
wxString name;
if( m_lastSelectedUserPreset )
name = m_lastSelectedUserPreset->name;
wxTextEntryDialog dlg( this, _( "Layer preset name:" ), _( "Save Layer Preset" ), name );
if( dlg.ShowModal() != wxID_OK )
{
@ -1876,22 +1885,21 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
return;
}
wxString name = dlg.GetValue();
name = dlg.GetValue();
bool exists = m_layerPresets.count( name );
if( m_layerPresets.count( name ) )
{
wxMessageBox( _( "Preset already exists!" ) );
resetSelection();
return;
}
m_layerPresets[name] = LAYER_PRESET( name, board->GetVisibleLayers(),
board->GetVisibleElements(), UNSELECTED_LAYER );
if( !exists )
m_layerPresets[name] = LAYER_PRESET( name, board->GetVisibleLayers(),
board->GetVisibleElements(), UNSELECTED_LAYER );
LAYER_PRESET* preset = &m_layerPresets[name];
m_currentPreset = preset;
index = m_cbLayerPresets->Insert( name, index - 1, static_cast<void*>( preset ) );
if( !exists )
index = m_cbLayerPresets->Insert( name, index - 1, static_cast<void*>( preset ) );
else
index = m_cbLayerPresets->FindString( name );
m_cbLayerPresets->SetSelection( index );
m_presetMRU.Insert( name, 0 );
@ -1939,6 +1947,8 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
LAYER_PRESET* preset = static_cast<LAYER_PRESET*>( m_cbLayerPresets->GetClientData( index ) );
m_currentPreset = preset;
m_lastSelectedUserPreset = ( !preset || preset->readOnly ) ? nullptr : preset;
doApplyLayerPreset( *preset );
if( !m_currentPreset->name.IsEmpty() )

View File

@ -306,6 +306,9 @@ private:
LAYER_PRESET* m_currentPreset;
/// The last user (non-read-only) preset selected by the user
LAYER_PRESET* m_lastSelectedUserPreset;
wxArrayString m_presetMRU;
wxMenu* m_layerContextMenu;