Fix quasi-modal dialog mode in DIALOG_SHIM class.

* Add event handler to check all button clicks for default command event
  IDs and handle them appropriately by either calling EndQuasiModal() or
  passing the event up the event handler chain to allow the default dialog
  handlers to perform their magic.
* Add event handler to handle the close window event properly.
* Add scope brackets so the wxBusyCursor will stop being displayed when
  the footprint library loading is complete in CvPcb.
This commit is contained in:
Wayne Stambaugh 2016-04-11 19:39:43 -04:00
parent 9e3fd5b762
commit f239aee1ad
3 changed files with 69 additions and 2 deletions

View File

@ -3,7 +3,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2012-2016 KiCad Developers, see CHANGELOG.TXT for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -70,6 +70,9 @@ DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& titl
if( h ) if( h )
SetKiway( this, &h->Kiway() ); SetKiway( this, &h->Kiway() );
Bind( wxEVT_CLOSE_WINDOW, &DIALOG_SHIM::OnCloseWindow, this );
Bind( wxEVT_BUTTON, &DIALOG_SHIM::OnButton, this );
#ifdef __WINDOWS__ #ifdef __WINDOWS__
// On Windows, the app top windows can be brought to the foreground // On Windows, the app top windows can be brought to the foreground
// (at least temporary) in certain circumstances, // (at least temporary) in certain circumstances,
@ -535,3 +538,49 @@ void DIALOG_SHIM::EndQuasiModal( int retCode )
Show( false ); Show( false );
} }
void DIALOG_SHIM::OnCloseWindow( wxCloseEvent& aEvent )
{
if( IsQuasiModal() )
{
EndQuasiModal( wxID_CANCEL );
return;
}
// This is mandatory to allow wxDialogBase::OnCloseWindow() to be called.
aEvent.Skip();
}
void DIALOG_SHIM::OnButton( wxCommandEvent& aEvent )
{
if( IsQuasiModal() )
{
const int id = aEvent.GetId();
if( id == GetAffirmativeId() )
{
EndQuasiModal( id );
}
else if( id == wxID_APPLY )
{
if( Validate() )
TransferDataFromWindow();
}
else if( id == GetEscapeId() ||
(id == wxID_CANCEL && GetEscapeId() == wxID_ANY) )
{
EndQuasiModal( wxID_CANCEL );
}
else // not a standard button
{
aEvent.Skip();
}
return;
}
// This is mandatory to allow wxDialogBase::OnButton() to be called.
aEvent.Skip();
}

View File

@ -725,9 +725,11 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles()
return false; return false;
} }
{
wxBusyCursor dummy; // Let the user know something is happening. wxBusyCursor dummy; // Let the user know something is happening.
m_FootprintsList.ReadFootprintFiles( fptbl ); m_FootprintsList.ReadFootprintFiles( fptbl );
}
if( m_FootprintsList.GetErrorCount() ) if( m_FootprintsList.GetErrorCount() )
{ {

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2012-2016 KiCad Developers, see CHANGELOG.TXT for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -52,6 +52,22 @@ class EVENT_LOOP;
**/ **/
class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
{ {
/**
* Function OnCloseWindow
*
* properly handles the wxCloseEvent when in the quasimodal mode when not calling
* EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
*/
void OnCloseWindow( wxCloseEvent& aEvent );
/**
* Function OnCloseWindow
*
* properly handles the default button events when in the quasimodal mode when not
* calling EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
*/
void OnButton( wxCommandEvent& aEvent );
public: public:
DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title, DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,