diff --git a/common/dialog_shim.cpp b/common/dialog_shim.cpp index 46a6b3060b..4b82c4d843 100644 --- a/common/dialog_shim.cpp +++ b/common/dialog_shim.cpp @@ -27,7 +27,6 @@ #include #include #include - #include #include @@ -320,9 +319,9 @@ void DIALOG_SHIM::OnPaint( wxPaintEvent &event ) selectAllInTextCtrls( GetChildren() ); if( m_initialFocusTarget ) - m_initialFocusTarget->SetFocus(); + KIPLATFORM::UI::ForceFocus( m_initialFocusTarget ); else - SetFocus(); // Focus the dialog itself + KIPLATFORM::UI::ForceFocus( this ); // Focus the dialog itself m_firstPaintEvent = false; } diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index e764913c93..b082095a3e 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -501,7 +501,9 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent ) { - bool shouldSetFocus = m_lostFocus && m_stealsFocus && !KIUI::IsInputControlFocused(); + bool shouldSetFocus = m_lostFocus && m_stealsFocus + && !KIUI::IsInputControlFocused() + && !KIUI::IsModalDialogFocused(); #if defined( _WIN32 ) // Ensure we are the active foreground window before we attempt to steal focus @@ -523,7 +525,9 @@ void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent ) void EDA_DRAW_PANEL_GAL::onEnter( wxMouseEvent& aEvent ) { - bool shouldSetFocus = m_stealsFocus && !KIUI::IsInputControlFocused(); + bool shouldSetFocus = m_stealsFocus + && !KIUI::IsInputControlFocused() + && !KIUI::IsModalDialogFocused(); #if defined( _WIN32 ) // Ensure we are the active foreground window before we attempt to steal focus diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index c698e17406..85baf81442 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -101,6 +101,7 @@ PGM_BASE::PGM_BASE() m_pgm_checker = NULL; m_locale = NULL; m_Printing = false; + m_ModalDialogCount = 0; m_show_env_var_dialog = true; diff --git a/common/single_top.cpp b/common/single_top.cpp index e747dfe31f..bca81112ed 100644 --- a/common/single_top.cpp +++ b/common/single_top.cpp @@ -226,6 +226,19 @@ struct APP_SINGLE_TOP : public wxApp return ret; } + int FilterEvent( wxEvent& aEvent ) override + { + if( aEvent.GetEventType() == wxEVT_SHOW ) + { + wxShowEvent& event = static_cast( aEvent ); + wxDialog* dialog = dynamic_cast( event.GetEventObject() ); + + if( dialog && dialog->IsModal() ) + Pgm().m_ModalDialogCount += event.IsShown() ? 1 : -1; + } + + return Event_Skip; + } #if defined( DEBUG ) /** diff --git a/common/widgets/ui_common.cpp b/common/widgets/ui_common.cpp index b6601a11f6..44db2e3e6a 100644 --- a/common/widgets/ui_common.cpp +++ b/common/widgets/ui_common.cpp @@ -23,7 +23,8 @@ #include #include -#include +#include +#include int KIUI::GetStdMargin() { @@ -142,4 +143,10 @@ bool KIUI::IsInputControlFocused() wxDataViewCtrl* dataViewCtrl = dynamic_cast( focus ); return ( textEntry || styledText || listBox || dataViewCtrl ); +} + + +bool KIUI::IsModalDialogFocused() +{ + return Pgm().m_ModalDialogCount > 0; } \ No newline at end of file diff --git a/eeschema/dialogs/dialog_update_from_pcb.cpp b/eeschema/dialogs/dialog_update_from_pcb.cpp index e392ee1f3d..46db3f3ce6 100644 --- a/eeschema/dialogs/dialog_update_from_pcb.cpp +++ b/eeschema/dialogs/dialog_update_from_pcb.cpp @@ -159,6 +159,9 @@ void DIALOG_UPDATE_FROM_PCB::OnUpdateClick( wxCommandEvent& event ) if( m_cbRelinkFootprints->GetValue() ) backAnno.PushNewLinksToPCB(); + + m_sdbSizerCancel->SetDefault(); + m_sdbSizerOK->Enable( false ); } m_messagePanel->Flush( false ); diff --git a/include/pgm_base.h b/include/pgm_base.h index 57401319e2..5d4980b7d3 100644 --- a/include/pgm_base.h +++ b/include/pgm_base.h @@ -340,6 +340,8 @@ public: */ bool m_Printing; + int m_ModalDialogCount; + protected: /// Loads internal settings from COMMON_SETTINGS diff --git a/include/widgets/ui_common.h b/include/widgets/ui_common.h index 24647fe204..f803319f55 100644 --- a/include/widgets/ui_common.h +++ b/include/widgets/ui_common.h @@ -74,6 +74,8 @@ void SelectReferenceNumber( wxTextEntry* aTextEntry ); */ bool IsInputControlFocused(); +bool IsModalDialogFocused(); + } // Note: On windows, SEVERITY_ERROR collides with a system declaration, diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index 7dc39c349f..6c5041dee8 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -307,6 +307,20 @@ struct APP_KICAD : public wxApp return -1; } + int FilterEvent( wxEvent& aEvent ) override + { + if( aEvent.GetEventType() == wxEVT_SHOW ) + { + wxShowEvent& event = static_cast( aEvent ); + wxDialog* dialog = dynamic_cast( event.GetEventObject() ); + + if( dialog && dialog->IsModal() ) + Pgm().m_ModalDialogCount += event.IsShown() ? 1 : -1; + } + + return Event_Skip; + } + /** * Set MacOS file associations. * diff --git a/pcbnew/dialogs/dialog_netlist.cpp b/pcbnew/dialogs/dialog_netlist.cpp index 713cd528f0..7d86e6f54d 100644 --- a/pcbnew/dialogs/dialog_netlist.cpp +++ b/pcbnew/dialogs/dialog_netlist.cpp @@ -142,30 +142,24 @@ void DIALOG_NETLIST::OnOpenNetlistClick( wxCommandEvent& event ) void DIALOG_NETLIST::OnUpdatePCB( wxCommandEvent& event ) { - BOARD* pcb = m_parent->GetBoard(); wxFileName fn = m_NetlistFilenameCtrl->GetValue(); if( !fn.IsOk() ) { - wxMessageBox( _("Please, choose a valid netlist file.") ); + wxMessageBox( _( "Please, choose a valid netlist file." ) ); return; } if( !fn.FileExists() ) { - wxMessageBox( _("The netlist file does not exist.") ); + wxMessageBox( _( "The netlist file does not exist." ) ); return; } - // Give the user a chance to bail out when making changes from a netlist. - if( pcb->IsEmpty() || IsOK( this, _( "The changes made cannot be undone. " - "Are you sure you want to update the PCB?" ) ) ) - { - m_MessageWindow->SetLabel( _( "Changes Applied To PCB" ) ); - loadNetlist( false ); + m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) ); + loadNetlist( false ); - m_sdbSizer1Cancel->SetDefault(); - } + m_sdbSizer1Cancel->SetDefault(); } diff --git a/pcbnew/dialogs/dialog_update_pcb.cpp b/pcbnew/dialogs/dialog_update_pcb.cpp index e50cd4d844..2d255b6516 100644 --- a/pcbnew/dialogs/dialog_update_pcb.cpp +++ b/pcbnew/dialogs/dialog_update_pcb.cpp @@ -24,7 +24,6 @@ #include #include #include - #include #include #include @@ -33,7 +32,7 @@ #include #include #include - +#include bool DIALOG_UPDATE_PCB::m_warnForNoNetPads = false; @@ -129,13 +128,20 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) void DIALOG_UPDATE_PCB::OnOptionChanged( wxCommandEvent& event ) { if( m_initialized ) + { PerformUpdate( true ); + m_sdbSizer1OK->Enable( true ); + m_sdbSizer1OK->SetDefault(); + } } void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event ) { - m_messagePanel->SetLabel( _( "Changes Applied To PCB" ) ); + m_messagePanel->SetLabel( _( "Changes Applied to PCB" ) ); PerformUpdate( false ); + m_sdbSizer1Cancel->SetDefault(); + // Widgets has a tendency to keep both buttons highlighted without the following: + m_sdbSizer1OK->Enable( false ); }