2013-10-18 13:32:22 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2013-04-06 12:01:53 +00:00
|
|
|
/**
|
2011-11-08 16:37:25 +00:00
|
|
|
* @file confirm.cpp
|
2013-04-06 12:01:53 +00:00
|
|
|
* @brief utilities to display some error, warning and info short messges
|
2011-11-08 16:37:25 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <wx/html/htmlwin.h>
|
2013-10-18 13:32:22 +00:00
|
|
|
#include <wx/stockitem.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <html_messagebox.h>
|
2012-03-08 17:47:23 +00:00
|
|
|
#include <dialog_exit_base.h>
|
|
|
|
#include <bitmaps.h>
|
2007-12-05 20:54:11 +00:00
|
|
|
|
2012-03-08 17:47:23 +00:00
|
|
|
class DIALOG_EXIT: public DIALOG_EXIT_BASE
|
|
|
|
{
|
|
|
|
public:
|
2013-10-18 13:32:22 +00:00
|
|
|
DIALOG_EXIT( wxWindow *aParent, const wxString& aMessage ) :
|
|
|
|
DIALOG_EXIT_BASE( aParent )
|
2012-03-08 17:47:23 +00:00
|
|
|
{
|
2012-03-09 18:58:58 +00:00
|
|
|
m_bitmap->SetBitmap( KiBitmap( dialog_warning_xpm ) );
|
2013-10-18 13:32:22 +00:00
|
|
|
|
|
|
|
if( !aMessage.IsEmpty() )
|
2012-03-08 17:47:23 +00:00
|
|
|
m_TextInfo->SetLabel( aMessage );
|
2013-10-18 13:32:22 +00:00
|
|
|
|
2012-03-08 17:47:23 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2013-11-20 16:35:03 +00:00
|
|
|
void OnSaveAndExit( wxCommandEvent& event ) { EndModal( wxID_YES ); }
|
|
|
|
void OnCancel( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); }
|
|
|
|
void OnExitNoSave( wxCommandEvent& event ) { EndModal( wxID_NO ); }
|
2012-03-08 17:47:23 +00:00
|
|
|
};
|
|
|
|
|
2013-10-18 13:32:22 +00:00
|
|
|
|
2012-03-08 17:47:23 +00:00
|
|
|
int DisplayExitDialog( wxWindow* parent, const wxString& aMessage )
|
|
|
|
{
|
|
|
|
DIALOG_EXIT dlg( parent, aMessage );
|
|
|
|
|
|
|
|
int ret = dlg.ShowModal();
|
|
|
|
return ret;
|
|
|
|
}
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2013-10-18 13:32:22 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
void DisplayError( wxWindow* parent, const wxString& text, int displaytime )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-12-05 20:54:11 +00:00
|
|
|
wxMessageDialog* dialog;
|
|
|
|
|
|
|
|
if( displaytime > 0 )
|
2011-07-06 16:40:54 +00:00
|
|
|
dialog = new wxMessageDialog( parent, text, _( "Warning" ),
|
2013-11-20 16:35:03 +00:00
|
|
|
wxOK | wxCENTRE | wxICON_INFORMATION
|
|
|
|
| wxRESIZE_BORDER
|
|
|
|
);
|
2007-12-05 20:54:11 +00:00
|
|
|
else
|
2011-07-06 16:40:54 +00:00
|
|
|
dialog = new wxMessageDialog( parent, text, _( "Error" ),
|
2013-11-20 16:35:03 +00:00
|
|
|
wxOK | wxCENTRE | wxICON_ERROR
|
|
|
|
| wxRESIZE_BORDER
|
|
|
|
);
|
2007-12-05 20:54:11 +00:00
|
|
|
|
|
|
|
dialog->ShowModal();
|
|
|
|
dialog->Destroy();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 20:54:11 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
void DisplayInfoMessage( wxWindow* parent, const wxString& text, int displaytime )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-12-05 20:54:11 +00:00
|
|
|
wxMessageDialog* dialog;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-10-04 17:47:28 +00:00
|
|
|
dialog = new wxMessageDialog( parent, text, _( "Info" ),
|
2011-11-08 16:37:25 +00:00
|
|
|
wxOK | wxCENTRE | wxICON_INFORMATION );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-04-06 18:54:57 +00:00
|
|
|
dialog->ShowModal();
|
|
|
|
dialog->Destroy();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 07:02:18 +00:00
|
|
|
void DisplayHtmlInfoMessage( wxWindow* parent, const wxString& title,
|
|
|
|
const wxString& text, const wxSize& size )
|
|
|
|
{
|
2013-12-09 18:09:58 +00:00
|
|
|
HTML_MESSAGE_BOX dlg( parent, title, wxDefaultPosition, size );
|
|
|
|
|
|
|
|
dlg.AddHTML_Text( text );
|
|
|
|
dlg.ShowModal();
|
2011-09-06 07:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-18 13:32:22 +00:00
|
|
|
bool IsOK( wxWindow* aParent, const wxString& aMessage )
|
|
|
|
{
|
|
|
|
wxMessageDialog dlg( aParent, aMessage, _( "Confirmation" ),
|
2015-07-26 17:50:13 +00:00
|
|
|
wxYES_NO | wxCENTRE | wxICON_QUESTION );
|
2013-10-18 13:32:22 +00:00
|
|
|
|
2013-10-19 13:22:24 +00:00
|
|
|
return dlg.ShowModal() == wxID_YES;
|
2013-10-18 13:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DIALOG_YES_NO_CANCEL : public DIALOG_EXIT
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-10-18 13:32:22 +00:00
|
|
|
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 );
|
|
|
|
};
|
|
|
|
};
|
2007-12-05 20:54:11 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2013-10-18 13:32:22 +00:00
|
|
|
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 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-10-18 13:32:22 +00:00
|
|
|
return dlg.ShowModal();
|
2011-11-08 16:37:25 +00:00
|
|
|
}
|