Minor message box improvements

* Create a generic yes/no/cancel dialog from DIALOG_EXIT.
* Make DIALOG_EXIT return wxID_YES instead of wxID_OK so it is consistent
  with the standard message dialogs.
* Add missing license to confirm.h and confirm.cpp.
* Change Eeschema message dialog when loading a schematic if the current
  schematic is modified to be more consistent with the exit dialog.
* Change Pcbnew message dialog when loading a board if the current board
  is modified to be more consistent with the exit dialog.
* Remove some Eeschema block debug logging code left over from my last
  commit.
This commit is contained in:
Wayne Stambaugh 2013-10-18 09:32:22 -04:00
parent a44e2c821e
commit 612ba67c10
10 changed files with 153 additions and 27 deletions

View File

@ -1,3 +1,27 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2013 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
*/
/** /**
* @file confirm.cpp * @file confirm.cpp
* @brief utilities to display some error, warning and info short messges * @brief utilities to display some error, warning and info short messges
@ -7,6 +31,7 @@
#include <common.h> #include <common.h>
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/html/htmlwin.h> #include <wx/html/htmlwin.h>
#include <wx/stockitem.h>
#include <html_messagebox.h> #include <html_messagebox.h>
#include <dialog_exit_base.h> #include <dialog_exit_base.h>
#include <bitmaps.h> #include <bitmaps.h>
@ -14,22 +39,25 @@
class DIALOG_EXIT: public DIALOG_EXIT_BASE class DIALOG_EXIT: public DIALOG_EXIT_BASE
{ {
public: public:
DIALOG_EXIT( wxWindow * parent, const wxString& aMessage ) : DIALOG_EXIT( wxWindow *aParent, const wxString& aMessage ) :
DIALOG_EXIT_BASE( parent ) DIALOG_EXIT_BASE( aParent )
{ {
m_bitmap->SetBitmap( KiBitmap( dialog_warning_xpm ) ); m_bitmap->SetBitmap( KiBitmap( dialog_warning_xpm ) );
if( ! aMessage.IsEmpty() )
if( !aMessage.IsEmpty() )
m_TextInfo->SetLabel( aMessage ); m_TextInfo->SetLabel( aMessage );
GetSizer()->Fit( this ); GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this ); GetSizer()->SetSizeHints( this );
}; };
private: private:
void OnSaveAndExit( wxCommandEvent& event ) { EndModal( wxID_OK ); } void OnSaveAndExit( wxCommandEvent& event ) { EndModal( wxID_YES ); }
void OnCancel( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); } void OnCancel( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); }
void OnExitNoSave( wxCommandEvent& event ) { EndModal( wxID_NO ); } void OnExitNoSave( wxCommandEvent& event ) { EndModal( wxID_NO ); }
}; };
int DisplayExitDialog( wxWindow* parent, const wxString& aMessage ) int DisplayExitDialog( wxWindow* parent, const wxString& aMessage )
{ {
DIALOG_EXIT dlg( parent, aMessage ); DIALOG_EXIT dlg( parent, aMessage );
@ -38,6 +66,7 @@ int DisplayExitDialog( wxWindow* parent, const wxString& aMessage )
return ret; return ret;
} }
void DisplayError( wxWindow* parent, const wxString& text, int displaytime ) void DisplayError( wxWindow* parent, const wxString& text, int displaytime )
{ {
wxMessageDialog* dialog; wxMessageDialog* dialog;
@ -76,14 +105,52 @@ void DisplayHtmlInfoMessage( wxWindow* parent, const wxString& title,
} }
bool IsOK( wxWindow* parent, const wxString& text ) bool IsOK( wxWindow* aParent, const wxString& aMessage )
{ {
int ii; wxMessageDialog dlg( aParent, aMessage, _( "Confirmation" ),
wxYES_NO | wxCENTRE | wxICON_HAND );
ii = wxMessageBox( text, _( "Confirmation" ), wxYES_NO | wxCENTRE | wxICON_HAND, parent ); return dlg.ShowModal() == wxYES;
}
if( ii == wxYES )
return true;
class DIALOG_YES_NO_CANCEL : public DIALOG_EXIT
return false; {
public:
DIALOG_YES_NO_CANCEL( wxWindow *aParent,
const wxString& aPrimaryMessage,
const wxString& aSecondaryMessage = wxEmptyString,
const wxString& aYesButtonText = wxEmptyString,
const wxString& aNoButtonText = wxEmptyString,
const wxString& aCancelButtonText = wxEmptyString ) :
DIALOG_EXIT( aParent, aSecondaryMessage )
{
m_TextInfo->SetLabel( aPrimaryMessage );
if( aSecondaryMessage.IsEmpty() )
m_staticText2->Hide();
m_buttonSaveAndExit->SetLabel( aYesButtonText.IsEmpty() ? wxGetStockLabel( wxID_YES ) :
aYesButtonText );
m_buttonExitNoSave->SetLabel( aNoButtonText.IsEmpty() ? wxGetStockLabel( wxID_NO ) :
aNoButtonText );
m_buttonCancel->SetLabel( aCancelButtonText.IsEmpty() ? wxGetStockLabel( wxID_CANCEL ) :
aCancelButtonText );
GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this );
};
};
int YesNoCancelDialog( wxWindow* aParent,
const wxString& aPrimaryMessage,
const wxString& aSecondaryMessage,
const wxString& aYesButtonText,
const wxString& aNoButtonText,
const wxString& aCancelButtonText )
{
DIALOG_YES_NO_CANCEL dlg( aParent, aPrimaryMessage, aSecondaryMessage,
aYesButtonText, aNoButtonText, aCancelButtonText );
return dlg.ShowModal();
} }

View File

@ -308,7 +308,6 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
case wxID_NO: case wxID_NO:
break; break;
case wxID_OK:
case wxID_YES: case wxID_YES:
diag = SaveCmpLinkFile( m_NetlistFileName.GetFullPath() ); diag = SaveCmpLinkFile( m_NetlistFileName.GetFullPath() );

View File

@ -193,9 +193,6 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC )
bool zoom_command = false; bool zoom_command = false;
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate; BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
wxLogDebug( wxT( "Block end command %d, state %d, count %d" ),
block->GetCommand(), block->GetState(), block->GetCount() );
if( block->GetCount() ) if( block->GetCount() )
{ {
BLOCK_STATE_T state = block->GetState(); BLOCK_STATE_T state = block->GetState();

View File

@ -258,13 +258,25 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew )
if( screen ) if( screen )
{ {
if( !IsOK( this, _( "Discard changes to the current schematic?" ) ) ) int response = YesNoCancelDialog( this, _( "The current schematic has been modified. Do "
"you wish to save the changes?" ),
wxEmptyString,
_( "Save and Load" ), _( "Load Without Saving" ) );
if( response == wxID_CANCEL )
{
return false; return false;
}
else if( response == wxID_YES )
{
wxCommandEvent dummy;
OnSaveProject( dummy );
}
} }
FullFileName = aFileName; FullFileName = aFileName;
if( ( FullFileName.IsEmpty() ) && !aIsNew ) if( FullFileName.IsEmpty() && !aIsNew )
{ {
wxFileDialog dlg( this, _( "Open Schematic" ), wxGetCwd(), wxFileDialog dlg( this, _( "Open Schematic" ), wxGetCwd(),
wxEmptyString, SchematicFileWildcard, wxEmptyString, SchematicFileWildcard,

View File

@ -351,7 +351,6 @@ void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
case wxID_NO: case wxID_NO:
break; break;
case wxID_OK:
case wxID_YES: case wxID_YES:
if ( this->SaveActiveLibrary( false ) ) if ( this->SaveActiveLibrary( false ) )
break; break;

View File

@ -462,7 +462,6 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
case wxID_NO: case wxID_NO:
break; break;
case wxID_OK:
case wxID_YES: case wxID_YES:
wxCommandEvent tmp( ID_SAVE_PROJECT ); wxCommandEvent tmp( ID_SAVE_PROJECT );
OnSaveProject( tmp ); OnSaveProject( tmp );

View File

@ -1,3 +1,27 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2013 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
*/
/** /**
* This file is part of the common library * This file is part of the common library
* @file confirm.h * @file confirm.h
@ -42,11 +66,37 @@ void DisplayInfoMessage( wxWindow* parent, const wxString& aMessage, int display
/** /**
* Function IsOK * Function IsOK
* gets the user response to \a aMessage. * displays a yes/no dialog with \a aMessage and returns the user response.
*
* @param aParent is the parent window. NULL can be used if the parent is the top level window.
* @param aMessage is the message to display in the dialog box.
* *
* @return True if user selected the yes button, otherwise false. * @return True if user selected the yes button, otherwise false.
*/ */
bool IsOK( wxWindow* parent, const wxString& aMessage ); bool IsOK( wxWindow* aParent, const wxString& aMessage );
/**
* Function YesNoCancelDialog
* displays a yes/no/cancel dialog with \a aMessage and returns the user response.
*
* @param aParent is the parent window. NULL can be used if the parent is the top level window.
* @param aPrimaryMessage is the message to display in the top part of the dialog box using
* a bold font.
* @param aSecondaryMessage is the message to display in the lower part of the dialog box
* using the default system UI font.
* @param aYesButtonText is the text to display in the yes button when defined.
* @param aNoButtonText is the text to display in the no button when defiend.
* @param aCancelButtonText is the text to display in the cancel button when defined.
*
* @return wxID_YES, wxID_NO, or wxID_CANCEL depending on the button the user selected.
*/
int YesNoCancelDialog( wxWindow* aParent,
const wxString& aPrimaryMessage,
const wxString& aSecondaryMessage,
const wxString& aYesButtonText = wxEmptyString,
const wxString& aNoButtonText = wxEmptyString,
const wxString& aCancelButtonText = wxEmptyString );
/** /**
* Function DisplayHtmlInforMessage * Function DisplayHtmlInforMessage

View File

@ -189,10 +189,15 @@ bool PCB_EDIT_FRAME::LoadOnePcbFile( const wxString& aFileName, bool aAppend,
{ {
if( GetScreen()->IsModify() && !aAppend ) if( GetScreen()->IsModify() && !aAppend )
{ {
if( !IsOK( this, int response = YesNoCancelDialog( this, _( "The current board has been modified. Do "
_( "The current board has been modified.\n" "you wish to save the changes?" ),
"Do you wish to discard the changes?" ) ) ) wxEmptyString,
_( "Save and Load" ), _( "Load Without Saving" ) );
if( response == wxID_CANCEL )
return false; return false;
else if( response == wxID_YES )
SavePcbFile( GetBoard()->GetFileName(), true );
} }
if( aAppend ) if( aAppend )

View File

@ -342,7 +342,6 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
case wxID_NO: case wxID_NO:
break; break;
case wxID_OK:
case wxID_YES: case wxID_YES:
// code from FOOTPRINT_EDIT_FRAME::Process_Special_Functions, // code from FOOTPRINT_EDIT_FRAME::Process_Special_Functions,
// at case ID_MODEDIT_SAVE_LIBMODULE // at case ID_MODEDIT_SAVE_LIBMODULE

View File

@ -547,7 +547,6 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
case wxID_NO: case wxID_NO:
break; break;
case wxID_OK:
case wxID_YES: case wxID_YES:
SavePcbFile( GetBoard()->GetFileName() ); SavePcbFile( GetBoard()->GetFileName() );
break; break;