KiCad PCB EDA Suite
KIDIALOG Class Reference

Helper class to create more flexible dialogs, including 'do not show again' checkbox handling. More...

#include <confirm.h>

Inheritance diagram for KIDIALOG:

Public Types

enum  KD_TYPE {
  KD_NONE, KD_INFO, KD_QUESTION, KD_WARNING,
  KD_ERROR
}
 < Dialog type. Selects appropriate icon and default dialog title More...
 

Public Member Functions

 KIDIALOG (wxWindow *aParent, const wxString &aMessage, const wxString &aCaption, long aStyle=wxOK)
 
 KIDIALOG (wxWindow *aParent, const wxString &aMessage, KD_TYPE aType, const wxString &aCaption="")
 
bool SetOKCancelLabels (const ButtonLabel &ok, const ButtonLabel &cancel) override
 Shows the 'do not show again' checkbox. More...
 
void DoNotShowCheckbox (wxString file, int line)
 Checks the 'do not show again' setting for the dialog. More...
 
bool DoNotShowAgain () const
 
void ForceShowAgain ()
 
bool Show (bool aShow=true) override
 
int ShowModal () override
 

Static Protected Member Functions

static wxString getCaption (KD_TYPE aType, const wxString &aCaption)
 
static long getStyle (KD_TYPE aType)
 

Protected Attributes

unsigned long m_hash
 
bool m_cancelMeansCancel
 

Detailed Description

Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.

Definition at line 45 of file confirm.h.

Member Enumeration Documentation

◆ KD_TYPE

< Dialog type. Selects appropriate icon and default dialog title

Enumerator
KD_NONE 
KD_INFO 
KD_QUESTION 
KD_WARNING 
KD_ERROR 

Definition at line 49 of file confirm.h.

Constructor & Destructor Documentation

◆ KIDIALOG() [1/2]

KIDIALOG::KIDIALOG ( wxWindow *  aParent,
const wxString &  aMessage,
const wxString &  aCaption,
long  aStyle = wxOK 
)

Definition at line 37 of file confirm.cpp.

39  : wxRichMessageDialog( aParent, aMessage, aCaption, aStyle | wxCENTRE | wxSTAY_ON_TOP ),
40  m_hash( 0 ),
41  m_cancelMeansCancel( true )
42 {
43 }
bool m_cancelMeansCancel
Definition: confirm.h:79
unsigned long m_hash
Definition: confirm.h:78

◆ KIDIALOG() [2/2]

KIDIALOG::KIDIALOG ( wxWindow *  aParent,
const wxString &  aMessage,
KD_TYPE  aType,
const wxString &  aCaption = "" 
)

Definition at line 46 of file confirm.cpp.

48  : wxRichMessageDialog( aParent, aMessage, getCaption( aType, aCaption ), getStyle( aType ) ),
49  m_hash( 0 ),
50  m_cancelMeansCancel( true )
51 {
52 }
static wxString getCaption(KD_TYPE aType, const wxString &aCaption)
Definition: confirm.cpp:119
static long getStyle(KD_TYPE aType)
Definition: confirm.cpp:137
bool m_cancelMeansCancel
Definition: confirm.h:79
unsigned long m_hash
Definition: confirm.h:78

Member Function Documentation

◆ DoNotShowAgain()

bool KIDIALOG::DoNotShowAgain ( ) const

Definition at line 63 of file confirm.cpp.

64 {
65  return doNotShowAgainDlgs.count( m_hash ) > 0;
66 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:34
unsigned long m_hash
Definition: confirm.h:78

References doNotShowAgainDlgs, and m_hash.

Referenced by DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP(), and DIALOG_CONFIGURE_PATHS::OnGridCellChanging().

◆ DoNotShowCheckbox()

◆ ForceShowAgain()

void KIDIALOG::ForceShowAgain ( )

Definition at line 69 of file confirm.cpp.

70 {
71  doNotShowAgainDlgs.erase( m_hash );
72 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:34
unsigned long m_hash
Definition: confirm.h:78

References doNotShowAgainDlgs, and m_hash.

◆ getCaption()

wxString KIDIALOG::getCaption ( KD_TYPE  aType,
const wxString &  aCaption 
)
staticprotected

Definition at line 119 of file confirm.cpp.

120 {
121  if( !aCaption.IsEmpty() )
122  return aCaption;
123 
124  switch( aType )
125  {
126  case KD_NONE: /* fall through */
127  case KD_INFO: return _( "Message" );
128  case KD_QUESTION: return _( "Question" );
129  case KD_WARNING: return _( "Warning" );
130  case KD_ERROR: return _( "Error" );
131  }
132 
133  return wxEmptyString;
134 }
#define _(s)

References _, KD_ERROR, KD_INFO, KD_NONE, KD_QUESTION, and KD_WARNING.

◆ getStyle()

long KIDIALOG::getStyle ( KD_TYPE  aType)
staticprotected

Definition at line 137 of file confirm.cpp.

138 {
139  long style = wxOK | wxCENTRE | wxSTAY_ON_TOP;
140 
141  switch( aType )
142  {
143  case KD_NONE: break;
144  case KD_INFO: style |= wxICON_INFORMATION; break;
145  case KD_QUESTION: style |= wxICON_QUESTION; break;
146  case KD_WARNING: style |= wxICON_WARNING; break;
147  case KD_ERROR: style |= wxICON_ERROR; break;
148  }
149 
150  return style;
151 }

References KD_ERROR, KD_INFO, KD_NONE, KD_QUESTION, and KD_WARNING.

◆ SetOKCancelLabels()

bool KIDIALOG::SetOKCancelLabels ( const ButtonLabel &  ok,
const ButtonLabel &  cancel 
)
inlineoverride

Shows the 'do not show again' checkbox.

Definition at line 56 of file confirm.h.

References cancel, and m_cancelMeansCancel.

Referenced by DIALOG_TRACK_VIA_PROPERTIES::confirmPadChange(), ZONE_FILLER::Fill(), and DIALOG_SIM_SETTINGS::TransferDataFromWindow().

◆ Show()

bool KIDIALOG::Show ( bool  aShow = true)
override

Definition at line 75 of file confirm.cpp.

76 {
77  // We should check the do-not-show-again setting only when the dialog is displayed
78  if( aShow )
79  {
80  // Check if this dialog should be shown to the user
81  auto it = doNotShowAgainDlgs.find( m_hash );
82 
83  if( it != doNotShowAgainDlgs.end() )
84  return it->second;
85  }
86 
87  int ret = wxRichMessageDialog::Show( aShow );
88 
89  // Has the user asked not to show the dialog again?
90  // Note that we don't save a Cancel value unless the Cancel button is being used for some
91  // other function (which is actually more common than it being used for Cancel).
92  if( IsCheckBoxChecked() && (!m_cancelMeansCancel || ret != wxID_CANCEL ) )
94 
95  return ret;
96 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:34
bool m_cancelMeansCancel
Definition: confirm.h:79
unsigned long m_hash
Definition: confirm.h:78

References doNotShowAgainDlgs, m_cancelMeansCancel, and m_hash.

◆ ShowModal()

int KIDIALOG::ShowModal ( )
override

Definition at line 99 of file confirm.cpp.

100 {
101  // Check if this dialog should be shown to the user
102  auto it = doNotShowAgainDlgs.find( m_hash );
103 
104  if( it != doNotShowAgainDlgs.end() )
105  return it->second;
106 
107  int ret = wxRichMessageDialog::ShowModal();
108 
109  // Has the user asked not to show the dialog again?
110  // Note that we don't save a Cancel value unless the Cancel button is being used for some
111  // other function (which is actually more common than it being used for Cancel).
112  if( IsCheckBoxChecked() && (!m_cancelMeansCancel || ret != wxID_CANCEL ) )
113  doNotShowAgainDlgs[m_hash] = ret;
114 
115  return ret;
116 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:34
bool m_cancelMeansCancel
Definition: confirm.h:79
unsigned long m_hash
Definition: confirm.h:78

References doNotShowAgainDlgs, m_cancelMeansCancel, and m_hash.

Referenced by DIALOG_TRACK_VIA_PROPERTIES::confirmPadChange(), PCB_BASE_EDIT_FRAME::createNewLibrary(), SYMBOL_EDIT_FRAME::CreateNewSymbol(), DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP(), SYMBOL_EDIT_FRAME::ExportSymbol(), ZONE_FILLER::Fill(), KICAD_MANAGER_FRAME::ImportNonKiCadProject(), SYMBOL_EDIT_FRAME::ImportSymbol(), ROUTER_TOOL::InlineBreakTrack(), LEGACY_PLUGIN::loadZONE_CONTAINER(), KICAD_MANAGER_CONTROL::NewFromTemplate(), DIALOG_CONFIGURE_PATHS::OnGridCellChanging(), PCB_PARSER::parseZONE(), ROUTER_TOOL::performDragging(), SYMBOL_EDITOR_PIN_TOOL::PlacePin(), PCB_IO::Save(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), SYMBOL_EDIT_FRAME::saveSymbolAs(), PNS_KICAD_IFACE_BASE::syncZone(), DIALOG_GENCAD_EXPORT_OPTIONS::TransferDataFromWindow(), DIALOG_SHEET_PROPERTIES::TransferDataFromWindow(), and DIALOG_SIM_SETTINGS::TransferDataFromWindow().

Member Data Documentation

◆ m_cancelMeansCancel

bool KIDIALOG::m_cancelMeansCancel
protected

Definition at line 79 of file confirm.h.

Referenced by SetOKCancelLabels(), Show(), and ShowModal().

◆ m_hash

unsigned long KIDIALOG::m_hash
protected

Definition at line 78 of file confirm.h.

Referenced by DoNotShowAgain(), DoNotShowCheckbox(), ForceShowAgain(), Show(), and ShowModal().


The documentation for this class was generated from the following files: