diff --git a/common/confirm.cpp b/common/confirm.cpp index 2a76b4e6ba..28a3b85d06 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -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 * @brief utilities to display some error, warning and info short messges @@ -7,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -14,22 +39,25 @@ class DIALOG_EXIT: public DIALOG_EXIT_BASE { public: - DIALOG_EXIT( wxWindow * parent, const wxString& aMessage ) : - DIALOG_EXIT_BASE( parent ) + DIALOG_EXIT( wxWindow *aParent, const wxString& aMessage ) : + DIALOG_EXIT_BASE( aParent ) { m_bitmap->SetBitmap( KiBitmap( dialog_warning_xpm ) ); - if( ! aMessage.IsEmpty() ) + + if( !aMessage.IsEmpty() ) m_TextInfo->SetLabel( aMessage ); + GetSizer()->Fit( this ); GetSizer()->SetSizeHints( this ); }; private: - void OnSaveAndExit( wxCommandEvent& event ) { EndModal( wxID_OK ); } + void OnSaveAndExit( wxCommandEvent& event ) { EndModal( wxID_YES ); } void OnCancel( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); } void OnExitNoSave( wxCommandEvent& event ) { EndModal( wxID_NO ); } }; + int DisplayExitDialog( wxWindow* parent, const wxString& aMessage ) { DIALOG_EXIT dlg( parent, aMessage ); @@ -38,6 +66,7 @@ int DisplayExitDialog( wxWindow* parent, const wxString& aMessage ) return ret; } + void DisplayError( wxWindow* parent, const wxString& text, int displaytime ) { 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 ); - - if( ii == wxYES ) - return true; - - return false; + return dlg.ShowModal() == wxYES; +} + + +class DIALOG_YES_NO_CANCEL : public DIALOG_EXIT +{ +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(); } diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index 2c3ac40d53..77e98099b3 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -308,7 +308,6 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) case wxID_NO: break; - case wxID_OK: case wxID_YES: diag = SaveCmpLinkFile( m_NetlistFileName.GetFullPath() ); diff --git a/eeschema/block.cpp b/eeschema/block.cpp index 63859456ec..f4e47bffb9 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -193,9 +193,6 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC ) bool zoom_command = false; 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() ) { BLOCK_STATE_T state = block->GetState(); diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 8dde937bd9..4c05edc058 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -258,13 +258,25 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew ) 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; + } + else if( response == wxID_YES ) + { + wxCommandEvent dummy; + OnSaveProject( dummy ); + } } FullFileName = aFileName; - if( ( FullFileName.IsEmpty() ) && !aIsNew ) + if( FullFileName.IsEmpty() && !aIsNew ) { wxFileDialog dlg( this, _( "Open Schematic" ), wxGetCwd(), wxEmptyString, SchematicFileWildcard, diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index e36debda6d..d4063af6a8 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -351,7 +351,6 @@ void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) case wxID_NO: break; - case wxID_OK: case wxID_YES: if ( this->SaveActiveLibrary( false ) ) break; diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 74bf05697e..48f51eca37 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -462,7 +462,6 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) case wxID_NO: break; - case wxID_OK: case wxID_YES: wxCommandEvent tmp( ID_SAVE_PROJECT ); OnSaveProject( tmp ); diff --git a/include/confirm.h b/include/confirm.h index 8a1ef11758..5a10bb4f8e 100644 --- a/include/confirm.h +++ b/include/confirm.h @@ -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 * @file confirm.h @@ -42,11 +66,37 @@ void DisplayInfoMessage( wxWindow* parent, const wxString& aMessage, int display /** * 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. */ -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 diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 751180a20a..e5b51689b3 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -189,10 +189,15 @@ bool PCB_EDIT_FRAME::LoadOnePcbFile( const wxString& aFileName, bool aAppend, { if( GetScreen()->IsModify() && !aAppend ) { - if( !IsOK( this, - _( "The current board has been modified.\n" - "Do you wish to discard the changes?" ) ) ) + int response = YesNoCancelDialog( this, _( "The current board has been modified. Do " + "you wish to save the changes?" ), + wxEmptyString, + _( "Save and Load" ), _( "Load Without Saving" ) ); + + if( response == wxID_CANCEL ) return false; + else if( response == wxID_YES ) + SavePcbFile( GetBoard()->GetFileName(), true ); } if( aAppend ) diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 4608f37652..0d4b2f052e 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -342,7 +342,6 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) case wxID_NO: break; - case wxID_OK: case wxID_YES: // code from FOOTPRINT_EDIT_FRAME::Process_Special_Functions, // at case ID_MODEDIT_SAVE_LIBMODULE diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index ed6795639b..500c056dd5 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -547,7 +547,6 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) case wxID_NO: break; - case wxID_OK: case wxID_YES: SavePcbFile( GetBoard()->GetFileName() ); break;