From be35b0783a8fefebbf6b91b3d35aee1050f5bda9 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 30 Apr 2022 09:43:28 +0200 Subject: [PATCH] Cvpcb: fix SaveAssociations. Save association to disk only from the Apply button. Previously, the association was saved to disk also on OK button click. --- cvpcb/cvpcb_mainframe.cpp | 11 ++++++----- cvpcb/menubar.cpp | 2 +- cvpcb/toolbars_cvpcb.cpp | 2 +- cvpcb/tools/cvpcb_actions.cpp | 9 ++++++++- cvpcb/tools/cvpcb_actions.h | 3 ++- cvpcb/tools/cvpcb_control.cpp | 12 ++++++++++-- cvpcb/tools/cvpcb_control.h | 9 ++++++++- 7 files changed, 36 insertions(+), 12 deletions(-) diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 0b3b276e6d..86a0be552d 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -276,9 +276,10 @@ void CVPCB_MAINFRAME::setupUIConditions() #define ENABLE( x ) ACTION_CONDITIONS().Enable( x ) #define CHECK( x ) ACTION_CONDITIONS().Check( x ) - mgr->SetConditions( CVPCB_ACTIONS::saveAssociations, ENABLE( cond.ContentModified() ) ); - mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) ); - mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) ); + mgr->SetConditions( CVPCB_ACTIONS::saveAssociationsToSchematic, ENABLE( cond.ContentModified() ) ); + mgr->SetConditions( CVPCB_ACTIONS::saveAssociationsToFile, ENABLE( cond.ContentModified() ) ); + mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) ); + mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) ); auto compFilter = [this] ( const SELECTION& ) @@ -327,7 +328,7 @@ void CVPCB_MAINFRAME::setupEventHandlers() [this]( wxCommandEvent& ) { // saveAssociations must be run immediately - GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociations, true ); + GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociationsToFile, true ); } ); // Connect the handlers for the ok/cancel buttons @@ -335,7 +336,7 @@ void CVPCB_MAINFRAME::setupEventHandlers() [this]( wxCommandEvent& ) { // saveAssociations must be run immediately, before running Close( true ) - GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociations, true ); + GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociationsToSchematic, true ); Close( true ); }, wxID_OK ); Bind( wxEVT_BUTTON, diff --git a/cvpcb/menubar.cpp b/cvpcb/menubar.cpp index fde1aea277..ea6f9a141a 100644 --- a/cvpcb/menubar.cpp +++ b/cvpcb/menubar.cpp @@ -46,7 +46,7 @@ void CVPCB_MAINFRAME::ReCreateMenuBar() // ACTION_MENU* fileMenu = new ACTION_MENU( false, tool ); - fileMenu->Add( CVPCB_ACTIONS::saveAssociations ); + fileMenu->Add( CVPCB_ACTIONS::saveAssociationsToSchematic ); fileMenu->AppendSeparator(); fileMenu->AddClose( _( "Assign Footprints" ) ); diff --git a/cvpcb/toolbars_cvpcb.cpp b/cvpcb/toolbars_cvpcb.cpp index 26d5c2abb8..b617857fa6 100644 --- a/cvpcb/toolbars_cvpcb.cpp +++ b/cvpcb/toolbars_cvpcb.cpp @@ -46,7 +46,7 @@ void CVPCB_MAINFRAME::ReCreateHToolbar() m_mainToolBar->SetAuiManager( &m_auimgr ); } - m_mainToolBar->Add( CVPCB_ACTIONS::saveAssociations ); + m_mainToolBar->Add( CVPCB_ACTIONS::saveAssociationsToSchematic ); m_mainToolBar->AddScaledSeparator( this ); m_mainToolBar->Add( ACTIONS::showFootprintLibTable ); diff --git a/cvpcb/tools/cvpcb_actions.cpp b/cvpcb/tools/cvpcb_actions.cpp index 67f2d95823..962a345964 100644 --- a/cvpcb/tools/cvpcb_actions.cpp +++ b/cvpcb/tools/cvpcb_actions.cpp @@ -61,13 +61,20 @@ TOOL_ACTION CVPCB_ACTIONS::showEquFileTable( "cvpcb.Control.ShowEquFileTable", _( "Configure footprint association file (.equ) list. These files are " "used to automatically assign footprint names from symbol values." ) ); -TOOL_ACTION CVPCB_ACTIONS::saveAssociations( "cvpcb.Control.SaveAssociations", +TOOL_ACTION CVPCB_ACTIONS::saveAssociationsToSchematic( "cvpcb.Control.SaveAssociationsToSchematic", AS_GLOBAL, MD_CTRL + 'S', LEGACY_HK_NAME( "Save" ), _( "Save to Schematic" ), _( "Save footprint associations in schematic symbol footprint fields" ), BITMAPS::save ); +TOOL_ACTION CVPCB_ACTIONS::saveAssociationsToFile( "cvpcb.Control.SaveAssociationsToFile", + AS_GLOBAL, + MD_CTRL + 'S', LEGACY_HK_NAME( "Save" ), + _( "Save to Schematic and File" ), + _( "Save footprint associations in schematic symbol footprint fields and schematic files" ), + BITMAPS::save ); + // Actions to navigate the display TOOL_ACTION CVPCB_ACTIONS::changeFocusRight( "cvpcb.Control.changeFocusRight", AS_GLOBAL, diff --git a/cvpcb/tools/cvpcb_actions.h b/cvpcb/tools/cvpcb_actions.h index 90a2968239..b1e240eaa9 100644 --- a/cvpcb/tools/cvpcb_actions.h +++ b/cvpcb/tools/cvpcb_actions.h @@ -53,7 +53,8 @@ public: static TOOL_ACTION gotoNextNA; /// Management actions - static TOOL_ACTION saveAssociations; + static TOOL_ACTION saveAssociationsToSchematic; + static TOOL_ACTION saveAssociationsToFile; static TOOL_ACTION showEquFileTable; /// Footprint Association actions diff --git a/cvpcb/tools/cvpcb_control.cpp b/cvpcb/tools/cvpcb_control.cpp index c29a33a50f..05cbc28553 100644 --- a/cvpcb/tools/cvpcb_control.cpp +++ b/cvpcb/tools/cvpcb_control.cpp @@ -210,13 +210,20 @@ int CVPCB_CONTROL::ShowEquFileTable( const TOOL_EVENT& aEvent ) } -int CVPCB_CONTROL::SaveAssociations( const TOOL_EVENT& aEvent ) +int CVPCB_CONTROL::SaveAssociationsToFile( const TOOL_EVENT& aEvent ) { m_frame->SaveFootprintAssociation( true ); return 0; } +int CVPCB_CONTROL::SaveAssociationsToSchematic( const TOOL_EVENT& aEvent ) +{ + m_frame->SaveFootprintAssociation( false ); + return 0; +} + + int CVPCB_CONTROL::ToNA( const TOOL_EVENT& aEvent ) { int tmp = aEvent.Parameter(); @@ -310,7 +317,8 @@ void CVPCB_CONTROL::setTransitions() // Management actions Go( &CVPCB_CONTROL::ShowEquFileTable, CVPCB_ACTIONS::showEquFileTable.MakeEvent() ); - Go( &CVPCB_CONTROL::SaveAssociations, CVPCB_ACTIONS::saveAssociations.MakeEvent() ); + Go( &CVPCB_CONTROL::SaveAssociationsToSchematic, CVPCB_ACTIONS::saveAssociationsToSchematic.MakeEvent() ); + Go( &CVPCB_CONTROL::SaveAssociationsToFile,CVPCB_ACTIONS::saveAssociationsToFile.MakeEvent() ); // Navigation actions Go( &CVPCB_CONTROL::ToNA, CVPCB_ACTIONS::gotoNextNA.MakeEvent() ); diff --git a/cvpcb/tools/cvpcb_control.h b/cvpcb/tools/cvpcb_control.h index d60145d24f..69a124e1d7 100644 --- a/cvpcb/tools/cvpcb_control.h +++ b/cvpcb/tools/cvpcb_control.h @@ -75,7 +75,14 @@ public: * * @param aEvent is the event generated by the tool framework */ - int SaveAssociations( const TOOL_EVENT& aEvent ); + int SaveAssociationsToSchematic( const TOOL_EVENT& aEvent ); + + /** + * Save the associations to the schematic and save schematic to file. + * + * @param aEvent is the event generated by the tool framework + */ + int SaveAssociationsToFile( const TOOL_EVENT& aEvent ); /** * Create or Update the frame showing the current highlighted footprint