mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Derive KIDIALOG from wxRichMessageDialog
wxRichMessageDialog already offers a dialog with a checkbox, so the custom dialog setup code is not necessary anymore.
This commit is contained in:
parent
1d5df8e975
commit
18167f829a
@ -42,166 +42,110 @@
|
|||||||
static std::unordered_map<unsigned long, int> doNotShowAgainDlgs;
|
static std::unordered_map<unsigned long, int> doNotShowAgainDlgs;
|
||||||
|
|
||||||
|
|
||||||
KIDIALOG::KIDIALOG( wxWindow* aParent, const wxString& aMessage )
|
KIDIALOG::KIDIALOG( wxWindow* aParent, const wxString& aMessage,
|
||||||
: wxDialog( aParent, wxID_ANY, wxEmptyString ),
|
const wxString& aCaption, long aStyle )
|
||||||
m_btnSizer( nullptr ), m_cbDoNotShow( nullptr ), m_icon( nullptr )
|
: wxRichMessageDialog( aParent, aMessage, aCaption, aStyle | wxCENTRE )
|
||||||
{
|
{
|
||||||
SetSizeHints( wxDefaultSize, wxDefaultSize );
|
setHash();
|
||||||
|
|
||||||
m_sizerMain = new wxBoxSizer( wxVERTICAL );
|
|
||||||
m_sizerUpper = new wxBoxSizer( wxHORIZONTAL );
|
|
||||||
|
|
||||||
wxStaticText* message = new wxStaticText( this, wxID_ANY, aMessage );
|
|
||||||
message->Wrap( -1 );
|
|
||||||
//message->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
|
|
||||||
m_sizerUpper->Add( message, 1, wxALL | wxEXPAND | wxALIGN_CENTER_VERTICAL, 5 );
|
|
||||||
m_sizerMain->Add( m_sizerUpper, 1, wxALL | wxEXPAND, 5 );
|
|
||||||
|
|
||||||
Type( KD_NONE );
|
|
||||||
Buttons( wxOK );
|
|
||||||
|
|
||||||
SetSizer( m_sizerMain );
|
|
||||||
Connect( wxEVT_BUTTON, wxCommandEventHandler( KIDIALOG::onButtonClick ), NULL, this );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KIDIALOG& KIDIALOG::Type( KD_TYPE aType )
|
KIDIALOG::KIDIALOG( wxWindow* aParent, const wxString& aMessage,
|
||||||
|
KD_TYPE aType, const wxString& aCaption )
|
||||||
|
: wxRichMessageDialog( aParent, aMessage, getCaption( aType, aCaption ), getStyle( aType ) )
|
||||||
{
|
{
|
||||||
m_type = aType;
|
setHash();
|
||||||
|
|
||||||
const std::unordered_map<int, wxString> stdTitle = {
|
|
||||||
{ KD_NONE, _( "Message" ) }, { KD_INFO, _( "Information" ) }, { KD_QUESTION, _( "Question" ) },
|
|
||||||
{ KD_WARNING, _( "Warning" ) }, { KD_ERROR, _( "Error" ) }
|
|
||||||
};
|
|
||||||
|
|
||||||
const std::unordered_map<int, wxArtID> icons = {
|
|
||||||
{ KD_INFO, wxART_INFORMATION }, { KD_QUESTION, wxART_QUESTION },
|
|
||||||
{ KD_WARNING, wxART_WARNING }, { KD_ERROR, wxART_ERROR }
|
|
||||||
};
|
|
||||||
|
|
||||||
if( m_icon )
|
|
||||||
{
|
|
||||||
m_sizerUpper->Remove( 0 );
|
|
||||||
m_icon->Destroy();
|
|
||||||
m_icon = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( aType != KD_NONE )
|
|
||||||
{
|
|
||||||
m_icon = new wxStaticBitmap( this, wxID_ANY,
|
|
||||||
wxArtProvider::GetBitmap( icons.at( aType ), wxART_CMN_DIALOG ) );
|
|
||||||
m_sizerUpper->Prepend( m_icon, 0, wxALL, 5 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !m_customTitle )
|
|
||||||
SetTitle( stdTitle.at( aType ) );
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
KIDIALOG& KIDIALOG::Title( const wxString& aTitle )
|
|
||||||
{
|
|
||||||
m_customTitle = aTitle;
|
|
||||||
SetTitle( aTitle );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
KIDIALOG& KIDIALOG::Buttons( long aButtons )
|
|
||||||
{
|
|
||||||
wxASSERT( aButtons );
|
|
||||||
|
|
||||||
if( !aButtons )
|
|
||||||
aButtons = wxOK;
|
|
||||||
|
|
||||||
const std::map<long, long> btnTypes = { { wxOK, wxID_OK }, { wxCANCEL, wxID_CANCEL },
|
|
||||||
{ wxYES, wxID_YES }, { wxNO, wxID_NO }, { wxAPPLY, wxID_APPLY }, { wxCLOSE, wxID_CLOSE },
|
|
||||||
{ wxHELP, wxID_HELP } };
|
|
||||||
|
|
||||||
if( m_btnSizer )
|
|
||||||
{
|
|
||||||
m_sizerMain->Remove( m_btnSizer ); // also deletes m_btnSizer
|
|
||||||
|
|
||||||
for( auto btn : m_buttons )
|
|
||||||
btn->Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_btnSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
||||||
|
|
||||||
for( auto type : btnTypes )
|
|
||||||
{
|
|
||||||
if( !( aButtons & type.first ) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
wxButton* btn = new wxButton( this, type.second );
|
|
||||||
m_btnSizer->Add( btn, 1, wxALL | wxEXPAND | wxALIGN_RIGHT );
|
|
||||||
m_buttons.push_back( btn );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sizerMain->Add( m_btnSizer, 0, wxALL | wxALIGN_RIGHT, 5 );
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
KIDIALOG& KIDIALOG::DoNotShowCheckbox()
|
|
||||||
{
|
|
||||||
if( !m_cbDoNotShow )
|
|
||||||
{
|
|
||||||
m_cbDoNotShow = new wxCheckBox( this, wxID_ANY, _( "Do not show again" ) );
|
|
||||||
m_sizerMain->Insert( 1, m_cbDoNotShow, 1, wxALL | wxEXPAND, 5 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KIDIALOG::DoNotShowAgain() const
|
bool KIDIALOG::DoNotShowAgain() const
|
||||||
{
|
{
|
||||||
return doNotShowAgainDlgs.count( hash() ) > 0;
|
return doNotShowAgainDlgs.count( m_hash ) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KIDIALOG::ForceShowAgain()
|
void KIDIALOG::ForceShowAgain()
|
||||||
{
|
{
|
||||||
doNotShowAgainDlgs.erase( hash() );
|
doNotShowAgainDlgs.erase( m_hash );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool KIDIALOG::Show( bool aShow )
|
||||||
|
{
|
||||||
|
// Check if this dialog should be shown to the user
|
||||||
|
auto it = doNotShowAgainDlgs.find( m_hash );
|
||||||
|
|
||||||
|
if( it != doNotShowAgainDlgs.end() )
|
||||||
|
return it->second;
|
||||||
|
|
||||||
|
bool ret = wxRichMessageDialog::Show();
|
||||||
|
|
||||||
|
// Has the user asked not to show the dialog again
|
||||||
|
if( IsCheckBoxChecked() )
|
||||||
|
doNotShowAgainDlgs[m_hash] = ret;
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int KIDIALOG::ShowModal()
|
int KIDIALOG::ShowModal()
|
||||||
{
|
{
|
||||||
// Check if this dialog should be shown to the user
|
// Check if this dialog should be shown to the user
|
||||||
auto it = doNotShowAgainDlgs.find( hash() );
|
auto it = doNotShowAgainDlgs.find( m_hash );
|
||||||
|
|
||||||
if( it != doNotShowAgainDlgs.end() )
|
if( it != doNotShowAgainDlgs.end() )
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|
||||||
Layout();
|
int ret = wxRichMessageDialog::ShowModal();
|
||||||
m_sizerMain->Fit( this );
|
|
||||||
int ret = wxDialog::ShowModal();
|
|
||||||
|
|
||||||
// Has the user asked not to show the dialog again
|
// Has the user asked not to show the dialog again
|
||||||
if( m_cbDoNotShow && m_cbDoNotShow->IsChecked() )
|
if( IsCheckBoxChecked() )
|
||||||
doNotShowAgainDlgs[hash()] = ret;
|
doNotShowAgainDlgs[m_hash] = ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KIDIALOG::onButtonClick( wxCommandEvent& aEvent )
|
void KIDIALOG::setHash()
|
||||||
{
|
{
|
||||||
EndModal( aEvent.GetId() );
|
std::size_t h1 = std::hash<wxString>{}( GetMessage() );
|
||||||
|
std::size_t h2 = std::hash<wxString>{}( GetTitle() );
|
||||||
|
m_hash = h1 ^ ( h2 << 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long KIDIALOG::hash() const
|
wxString KIDIALOG::getCaption( KD_TYPE aType, const wxString& aCaption )
|
||||||
{
|
{
|
||||||
std::size_t h1 = std::hash<wxString>{}( m_message );
|
if( !aCaption.IsEmpty() )
|
||||||
std::size_t h2 = std::hash<wxString>{}( m_customTitle );
|
return aCaption;
|
||||||
std::size_t h3 = std::hash<int>{}( m_type );
|
|
||||||
|
|
||||||
return h1 ^ ( h2 << 1 ) ^ ( h3 << 2 );
|
switch( aType )
|
||||||
|
{
|
||||||
|
case KD_NONE: /* fall through */
|
||||||
|
case KD_INFO: return _( "Message" );
|
||||||
|
case KD_QUESTION: return _( "Question" );
|
||||||
|
case KD_WARNING: return _( "Warning" );
|
||||||
|
case KD_ERROR: return _( "Error" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxEmptyString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long KIDIALOG::getStyle( KD_TYPE aType )
|
||||||
|
{
|
||||||
|
long style = wxOK | wxCENTRE;
|
||||||
|
|
||||||
|
switch( aType )
|
||||||
|
{
|
||||||
|
case KD_NONE: break;
|
||||||
|
case KD_INFO: style |= wxICON_INFORMATION; break;
|
||||||
|
case KD_QUESTION: style |= wxICON_QUESTION; break;
|
||||||
|
case KD_WARNING: style |= wxICON_WARNING; break;
|
||||||
|
case KD_ERROR: style |= wxICON_ERROR; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,67 +31,47 @@
|
|||||||
#ifndef __INCLUDE__CONFIRM_H__
|
#ifndef __INCLUDE__CONFIRM_H__
|
||||||
#define __INCLUDE__CONFIRM_H__
|
#define __INCLUDE__CONFIRM_H__
|
||||||
|
|
||||||
#include <wx/dialog.h>
|
#include <wx/richmsgdlg.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class wxCheckBox;
|
class wxCheckBox;
|
||||||
class wxStaticBitmap;
|
class wxStaticBitmap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to create more flexible dialogs, e.g:
|
* Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
|
||||||
*
|
|
||||||
* KIDIALOG dlg( "Test ");
|
|
||||||
* dlg.Title( "Title" ).Buttons( wxOK | wxCANCEL ).Type( WARNING ).DoNotShowCheckBox();
|
|
||||||
* int res = dlg.ShowModal();
|
|
||||||
*/
|
*/
|
||||||
class KIDIALOG : wxDialog
|
class KIDIALOG : public wxRichMessageDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
///> Dialog type. Selects appropriate icon and default dialog title
|
///> Dialog type. Selects appropriate icon and default dialog title
|
||||||
enum KD_TYPE { KD_NONE, KD_INFO, KD_QUESTION, KD_WARNING, KD_ERROR };
|
enum KD_TYPE { KD_NONE, KD_INFO, KD_QUESTION, KD_WARNING, KD_ERROR };
|
||||||
|
|
||||||
KIDIALOG( wxWindow* aParent, const wxString& aMessage );
|
KIDIALOG( wxWindow* aParent, const wxString& aMessage, const wxString& aCaption, long aStyle = wxOK );
|
||||||
|
KIDIALOG( wxWindow* aParent, const wxString& aMessage, KD_TYPE aType, const wxString& aCaption = "" );
|
||||||
///> Sets the dialog type
|
|
||||||
KIDIALOG& Type( KD_TYPE aType );
|
|
||||||
|
|
||||||
///> Sets the dialog title
|
|
||||||
KIDIALOG& Title( const wxString& aTitle );
|
|
||||||
|
|
||||||
///> Selects the button set (combination of wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE, wxHELP)
|
|
||||||
KIDIALOG& Buttons( long aButtons );
|
|
||||||
|
|
||||||
///> Shows the 'do not show again' checkbox
|
///> Shows the 'do not show again' checkbox
|
||||||
KIDIALOG& DoNotShowCheckbox();
|
void DoNotShowCheckbox()
|
||||||
|
{
|
||||||
|
ShowCheckBox( _( "Do not show again" ), false );
|
||||||
|
}
|
||||||
|
|
||||||
///> Checks the 'do not show again' setting for the dialog
|
///> Checks the 'do not show again' setting for the dialog
|
||||||
bool DoNotShowAgain() const;
|
bool DoNotShowAgain() const;
|
||||||
void ForceShowAgain();
|
void ForceShowAgain();
|
||||||
|
|
||||||
|
bool Show( bool aShow = true ) override;
|
||||||
int ShowModal() override;
|
int ShowModal() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onButtonClick( wxCommandEvent& aEvent );
|
///> Sets the dialog hash value
|
||||||
|
void setHash();
|
||||||
|
|
||||||
///> Unique identifier of the dialog
|
///> Unique identifier of the dialog
|
||||||
unsigned long hash() const;
|
unsigned long m_hash;
|
||||||
|
|
||||||
///> Text message shown in the dialog
|
// Helper functions for wxRichMessageDialog constructor
|
||||||
wxString m_message;
|
static wxString getCaption( KD_TYPE aType, const wxString& aCaption );
|
||||||
|
static long getStyle( KD_TYPE aType );
|
||||||
///> Dialog type
|
|
||||||
KD_TYPE m_type;
|
|
||||||
|
|
||||||
///> Custom title requested, if any was requested
|
|
||||||
wxString m_customTitle;
|
|
||||||
|
|
||||||
// Widgets
|
|
||||||
wxBoxSizer* m_sizerMain;
|
|
||||||
wxBoxSizer* m_sizerUpper;
|
|
||||||
wxBoxSizer* m_btnSizer;
|
|
||||||
wxCheckBox* m_cbDoNotShow;
|
|
||||||
wxStaticBitmap* m_icon;
|
|
||||||
std::vector<wxButton*> m_buttons;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -802,13 +802,12 @@ bool PNS_KICAD_IFACE::syncZone( PNS::NODE* aWorld, ZONE_CONTAINER* aZone )
|
|||||||
|
|
||||||
if( !poly.IsTriangulationUpToDate() )
|
if( !poly.IsTriangulationUpToDate() )
|
||||||
{
|
{
|
||||||
wxString msg = wxString::Format( _( "Malformed keep-out zone at (%d, %d) "
|
KIDIALOG dlg( nullptr, wxString::Format( _( "Malformed keep-out zone at (%d, %d)" ),
|
||||||
"cannot be handled by the track layout tool.\n%s\n"
|
aZone->GetPosition().x, aZone->GetPosition().y ), KIDIALOG::KD_WARNING );
|
||||||
"Please verify it is not a self-intersecting polygon." ),
|
dlg.ShowDetailedText(
|
||||||
aZone->GetPosition().x, aZone->GetPosition().y, aZone->GetSelectMenuText() );
|
wxString::Format( _( "%s\nThis zone cannot be handled by the track layout tool.\n"
|
||||||
|
"Please verify it is not a self-intersecting polygon." ), aZone->GetSelectMenuText() ) );
|
||||||
KIDIALOG dlg( nullptr, msg );
|
dlg.DoNotShowCheckbox();
|
||||||
dlg.Type( KIDIALOG::KD_WARNING ).Title( _( "Malformed keep-out zone" ) ).DoNotShowCheckbox();
|
|
||||||
dlg.ShowModal();
|
dlg.ShowModal();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user