From 1f2caa041dcec61c296ab15cf667d14cf8d7060c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 6 Jan 2026 17:00:32 +0000 Subject: [PATCH] Handle quit uniformly in COMMON_CONTROL. Fixes https://gitlab.com/kicad/code/kicad/-/issues/22659 Fixes https://gitlab.com/kicad/code/kicad/-/issues/22660 --- bitmap2component/bitmap2cmp_control.cpp | 8 --- common/tool/common_control.cpp | 14 +++++ eeschema/tools/sch_editor_control.cpp | 8 --- eeschema/tools/simulator_control.cpp | 2 - eeschema/tools/symbol_editor_control.cpp | 2 - include/tool/common_control.h | 1 + pcb_calculator/CMakeLists.txt | 1 - pcb_calculator/pcb_calculator_control.cpp | 54 ------------------- pcb_calculator/pcb_calculator_control.h | 63 ----------------------- pcb_calculator/pcb_calculator_frame.cpp | 8 +-- pcbnew/footprint_wizard_frame.cpp | 2 + pcbnew/tools/pcb_control.cpp | 9 +--- 12 files changed, 19 insertions(+), 153 deletions(-) delete mode 100644 pcb_calculator/pcb_calculator_control.cpp delete mode 100644 pcb_calculator/pcb_calculator_control.h diff --git a/bitmap2component/bitmap2cmp_control.cpp b/bitmap2component/bitmap2cmp_control.cpp index c6df29cab2..784ede4ce8 100644 --- a/bitmap2component/bitmap2cmp_control.cpp +++ b/bitmap2component/bitmap2cmp_control.cpp @@ -48,15 +48,7 @@ int BITMAP2CMP_CONTROL::Open( const TOOL_EVENT& aEvent ) } -int BITMAP2CMP_CONTROL::Close( const TOOL_EVENT& aEvent ) -{ - m_frame->Close(); - return 0; -} - - void BITMAP2CMP_CONTROL::setTransitions() { Go( &BITMAP2CMP_CONTROL::Open, ACTIONS::open.MakeEvent() ); - Go( &BITMAP2CMP_CONTROL::Close, ACTIONS::quit.MakeEvent() ); } diff --git a/common/tool/common_control.cpp b/common/tool/common_control.cpp index 0a2957132e..dc14e67495 100644 --- a/common/tool/common_control.cpp +++ b/common/tool/common_control.cpp @@ -190,6 +190,18 @@ int COMMON_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent ) } +int COMMON_CONTROL::Quit( const TOOL_EVENT& aEvent ) +{ + m_frame->CallAfter( + [this]() + { + m_frame->Kiway().OnKiCadExit(); + } ); + + return 0; +} + + class TERMINATE_HANDLER : public wxProcess { public: @@ -414,6 +426,8 @@ int COMMON_CONTROL::ReportBug( const TOOL_EVENT& aEvent ) void COMMON_CONTROL::setTransitions() { + Go( &COMMON_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); + Go( &COMMON_CONTROL::OpenPreferences, ACTIONS::openPreferences.MakeEvent() ); Go( &COMMON_CONTROL::ConfigurePaths, ACTIONS::configurePaths.MakeEvent() ); Go( &COMMON_CONTROL::ShowLibraryTable, ACTIONS::showSymbolLibTable.MakeEvent() ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index ae03092b97..701c5ea94d 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -648,13 +648,6 @@ int SCH_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent ) } -int SCH_EDITOR_CONTROL::Quit( const TOOL_EVENT& aEvent ) -{ - m_frame->Close( false ); - return 0; -} - - int SCH_EDITOR_CONTROL::CrossProbeToPcb( const TOOL_EVENT& aEvent ) { doCrossProbeSchToPcb( aEvent, false ); @@ -3514,7 +3507,6 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::PageSetup, ACTIONS::pageSettings.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::RescueSymbols, SCH_ACTIONS::rescueSymbols.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::RemapSymbols, SCH_ACTIONS::remapSymbols.MakeEvent() ); diff --git a/eeschema/tools/simulator_control.cpp b/eeschema/tools/simulator_control.cpp index 50f1cb73d2..25bf1be1f5 100644 --- a/eeschema/tools/simulator_control.cpp +++ b/eeschema/tools/simulator_control.cpp @@ -651,8 +651,6 @@ void SIMULATOR_CONTROL::setTransitions() Go( &SIMULATOR_CONTROL::ExportPlotToClipboard, SCH_ACTIONS::exportPlotToClipboard.MakeEvent() ); Go( &SIMULATOR_CONTROL::ExportPlotToSchematic, SCH_ACTIONS::exportPlotToSchematic.MakeEvent() ); - Go( &SIMULATOR_CONTROL::Close, ACTIONS::quit.MakeEvent() ); - Go( &SIMULATOR_CONTROL::ToggleSimConsolePanel, SCH_ACTIONS::toggleSimConsole.MakeEvent() ); Go( &SIMULATOR_CONTROL::ToggleSimSidePanel, SCH_ACTIONS::toggleSimSidePanel.MakeEvent() ); diff --git a/eeschema/tools/symbol_editor_control.cpp b/eeschema/tools/symbol_editor_control.cpp index f5c1200d0d..f640d18d1d 100644 --- a/eeschema/tools/symbol_editor_control.cpp +++ b/eeschema/tools/symbol_editor_control.cpp @@ -987,7 +987,6 @@ int SYMBOL_EDITOR_CONTROL::ShowLibraryTable( const TOOL_EVENT& aEvent ) void SYMBOL_EDITOR_CONTROL::setTransitions() { - // clang-format off Go( &SYMBOL_EDITOR_CONTROL::AddLibrary, ACTIONS::newLibrary.MakeEvent() ); Go( &SYMBOL_EDITOR_CONTROL::AddLibrary, ACTIONS::addLibrary.MakeEvent() ); Go( &SYMBOL_EDITOR_CONTROL::AddSymbol, SCH_ACTIONS::newSymbol.MakeEvent() ); @@ -1036,5 +1035,4 @@ void SYMBOL_EDITOR_CONTROL::setTransitions() Go( &SYMBOL_EDITOR_CONTROL::ChangeUnit, SCH_ACTIONS::previousUnit.MakeEvent() ); Go( &SYMBOL_EDITOR_CONTROL::ChangeUnit, SCH_ACTIONS::nextUnit.MakeEvent() ); - // clang-format on } diff --git a/include/tool/common_control.h b/include/tool/common_control.h index 7988f7a61d..38646a2821 100644 --- a/include/tool/common_control.h +++ b/include/tool/common_control.h @@ -50,6 +50,7 @@ public: int ShowLibraryTable( const TOOL_EVENT& aEvent ); int ShowPlayer( const TOOL_EVENT& aEvent ); + int Quit( const TOOL_EVENT& aEvent ); int Execute( const TOOL_EVENT& aEvent ); int ShowProjectManager( const TOOL_EVENT& aEvent ); diff --git a/pcb_calculator/CMakeLists.txt b/pcb_calculator/CMakeLists.txt index c26173a829..915e4d704f 100644 --- a/pcb_calculator/CMakeLists.txt +++ b/pcb_calculator/CMakeLists.txt @@ -11,7 +11,6 @@ set( PCB_CALCULATOR_SRCS common_data.cpp eseries.cpp params_read_write.cpp - pcb_calculator_control.cpp pcb_calculator_frame.cpp pcb_calculator_settings.cpp datafile_read_write.cpp diff --git a/pcb_calculator/pcb_calculator_control.cpp b/pcb_calculator/pcb_calculator_control.cpp deleted file mode 100644 index fa4e656461..0000000000 --- a/pcb_calculator/pcb_calculator_control.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright The KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include -#include -#include -#include - - -bool PCB_CALCULATOR_CONTROL::Init() -{ - Reset( MODEL_RELOAD ); - return true; -} - - -void PCB_CALCULATOR_CONTROL::Reset( RESET_REASON aReason ) -{ - m_frame = getEditFrame(); -} - - -int PCB_CALCULATOR_CONTROL::Close( const TOOL_EVENT& aEvent ) -{ - m_frame->Close(); - return 0; -} - - -void PCB_CALCULATOR_CONTROL::setTransitions() -{ - Go( &PCB_CALCULATOR_CONTROL::Close, ACTIONS::quit.MakeEvent() ); -} diff --git a/pcb_calculator/pcb_calculator_control.h b/pcb_calculator/pcb_calculator_control.h deleted file mode 100644 index 938d5a8815..0000000000 --- a/pcb_calculator/pcb_calculator_control.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright The KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - - -#ifndef PCB_CALCULATOR_CONTROL_H -#define PCB_CALCULATOR_CONTROL_H - -#include "tool/tool_interactive.h" - -class PCB_CALCULATOR_FRAME; - - -/** - * Handle actions for the various symbol editor and viewers. - */ -class PCB_CALCULATOR_CONTROL : public wxEvtHandler, public TOOL_INTERACTIVE -{ -public: - PCB_CALCULATOR_CONTROL() : - TOOL_INTERACTIVE( "pcb_calculator.Control" ), - m_frame( nullptr ) - { } - - virtual ~PCB_CALCULATOR_CONTROL() { } - - /// @copydoc TOOL_INTERACTIVE::Init() - bool Init() override; - - /// @copydoc TOOL_INTERACTIVE::Reset() - void Reset( RESET_REASON aReason ) override; - - int Close( const TOOL_EVENT& aEvent ); - -private: - ///< Set up handlers for various events. - void setTransitions() override; - -private: - PCB_CALCULATOR_FRAME* m_frame; -}; - - -#endif // PCB_CALCULATOR_CONTROL_H diff --git a/pcb_calculator/pcb_calculator_frame.cpp b/pcb_calculator/pcb_calculator_frame.cpp index 1950854c6d..6545d33f71 100644 --- a/pcb_calculator/pcb_calculator_frame.cpp +++ b/pcb_calculator/pcb_calculator_frame.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -109,7 +108,6 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : // Register tools m_toolManager->RegisterTool( new COMMON_CONTROL ); - m_toolManager->RegisterTool( new PCB_CALCULATOR_CONTROL ); m_toolManager->InitTools(); ReCreateMenuBar(); @@ -155,11 +153,7 @@ PCB_CALCULATOR_FRAME::~PCB_CALCULATOR_FRAME() void PCB_CALCULATOR_FRAME::OnExit( wxCommandEvent& aEvent ) { - if( aEvent.GetId() == wxID_EXIT ) - Kiway().OnKiCadExit(); - - if( aEvent.GetId() == wxID_CLOSE || Kiface().IsSingle() ) - Close( false ); + Close( false ); } diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 2744729988..f9de973cb3 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -146,6 +147,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent m_toolManager->RegisterTool( new PCB_SELECTION_TOOL ); // for std context menus (zoom & grid) m_toolManager->RegisterTool( new SCRIPTING_TOOL ); m_toolManager->RegisterTool( new COMMON_TOOLS ); + m_toolManager->RegisterTool( new COMMON_CONTROL ); m_toolManager->RegisterTool( new FOOTPRINT_WIZARD_TOOLS ); m_toolManager->InitTools(); diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index 5b7e7dbc64..3ee38aaec9 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -27,6 +27,7 @@ #include "convert_basic_shapes_to_polygon.h" #include +#include #include #include #include @@ -201,13 +202,6 @@ int PCB_CONTROL::IterateFootprint( const TOOL_EVENT& aEvent ) } -int PCB_CONTROL::Quit( const TOOL_EVENT& aEvent ) -{ - m_frame->Close( false ); - return 0; -} - - template void Flip( T& aValue ) { @@ -2833,7 +2827,6 @@ void PCB_CONTROL::setTransitions() Go( &PCB_CONTROL::AddLibrary, ACTIONS::newLibrary.MakeEvent() ); Go( &PCB_CONTROL::AddLibrary, ACTIONS::addLibrary.MakeEvent() ); Go( &PCB_CONTROL::Print, ACTIONS::print.MakeEvent() ); - Go( &PCB_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); // Footprint library actions Go( &PCB_CONTROL::SaveFpToBoard, PCB_ACTIONS::saveFpToBoard.MakeEvent() );