diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index b566c46731..a1ae14b4af 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -123,7 +123,6 @@ PGM_BASE::PGM_BASE() m_locale = nullptr; m_Printing = false; m_Quitting = false; - m_ModalDialogCount = 0; m_argcUtf8 = 0; m_argvUtf8 = nullptr; diff --git a/common/single_top.cpp b/common/single_top.cpp index 4d910a1ccb..bc95336f0a 100644 --- a/common/single_top.cpp +++ b/common/single_top.cpp @@ -215,8 +215,25 @@ struct APP_SINGLE_TOP : public wxApp wxShowEvent& event = static_cast( aEvent ); wxDialog* dialog = dynamic_cast( event.GetEventObject() ); - if( dialog && dialog->IsModal() ) - Pgm().m_ModalDialogCount += event.IsShown() ? 1 : -1; + std::vector& dlgs = Pgm().m_ModalDialogs; + + if( dialog ) + { + if( event.IsShown() && dialog->IsModal() ) + { + dlgs.push_back( dialog ); + } + // Under GTK, sometimes the modal flag is cleared before hiding + else if( !event.IsShown() ) + { + // If we close the expected dialog, remove it from our stack + if( dlgs.back() == dialog ) + dlgs.pop_back(); + // If an out-of-order, remove all dialogs added after the closed one + else if( auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() ) + dlgs.erase( it, dlgs.end() ); + } + } } return Event_Skip; diff --git a/common/widgets/ui_common.cpp b/common/widgets/ui_common.cpp index dd90266f38..b9ce334254 100644 --- a/common/widgets/ui_common.cpp +++ b/common/widgets/ui_common.cpp @@ -314,7 +314,7 @@ bool KIUI::IsInputControlEditable( wxWindow* aFocus ) bool KIUI::IsModalDialogFocused() { - return Pgm().m_ModalDialogCount > 0; + return !Pgm().m_ModalDialogs.empty(); } @@ -350,4 +350,4 @@ void KIUI::Disable( wxWindow* aWindow ) for( wxWindow* child : aWindow->GetChildren() ) Disable( child ); } -} \ No newline at end of file +} diff --git a/include/pgm_base.h b/include/pgm_base.h index 4380cfb450..80d013cad9 100644 --- a/include/pgm_base.h +++ b/include/pgm_base.h @@ -32,6 +32,7 @@ #define PGM_BASE_H_ #include +#include #include #include #include @@ -302,7 +303,7 @@ public: */ bool m_Printing; - int m_ModalDialogCount; + std::vector m_ModalDialogs; bool m_Quitting; diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index 3bb2b6513d..61cd364584 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -476,8 +476,25 @@ struct APP_KICAD : public wxApp wxShowEvent& event = static_cast( aEvent ); wxDialog* dialog = dynamic_cast( event.GetEventObject() ); - if( dialog && dialog->IsModal() ) - Pgm().m_ModalDialogCount += event.IsShown() ? 1 : -1; + std::vector& dlgs = Pgm().m_ModalDialogs; + + if( dialog ) + { + if( event.IsShown() && dialog->IsModal() ) + { + dlgs.push_back( dialog ); + } + // Under GTK, sometimes the modal flag is cleared before hiding + else if( !event.IsShown() ) + { + // If we close the expected dialog, remove it from our stack + if( dlgs.back() == dialog ) + dlgs.pop_back(); + // If an out-of-order, remove all dialogs added after the closed one + else if( auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() ) + dlgs.erase( it, dlgs.end() ); + } + } } return Event_Skip; diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index ee53f018a1..d5ca0e7e0d 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -503,8 +503,25 @@ struct APP_KICAD_CLI : public wxAppConsole wxShowEvent& event = static_cast( aEvent ); wxDialog* dialog = dynamic_cast( event.GetEventObject() ); - if( dialog && dialog->IsModal() ) - Pgm().m_ModalDialogCount += event.IsShown() ? 1 : -1; + std::vector& dlgs = Pgm().m_ModalDialogs; + + if( dialog ) + { + if( event.IsShown() && dialog->IsModal() ) + { + dlgs.push_back( dialog ); + } + // Under GTK, sometimes the modal flag is cleared before hiding + else if( !event.IsShown() ) + { + // If we close the expected dialog, remove it from our stack + if( dlgs.back() == dialog ) + dlgs.pop_back(); + // If an out-of-order, remove all dialogs added after the closed one + else if( auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() ) + dlgs.erase( it, dlgs.end() ); + } + } } return Event_Skip;