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 38 of file confirm.cpp.

40  : wxRichMessageDialog( aParent, aMessage, aCaption, aStyle | wxCENTRE | wxSTAY_ON_TOP ),
41  m_hash( 0 ),
42  m_cancelMeansCancel( true )
43 {
44 }
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 47 of file confirm.cpp.

49  : wxRichMessageDialog( aParent, aMessage, getCaption( aType, aCaption ), getStyle( aType ) ),
50  m_hash( 0 ),
51  m_cancelMeansCancel( true )
52 {
53 }
static wxString getCaption(KD_TYPE aType, const wxString &aCaption)
Definition: confirm.cpp:120
static long getStyle(KD_TYPE aType)
Definition: confirm.cpp:138
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 64 of file confirm.cpp.

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

References doNotShowAgainDlgs, and m_hash.

◆ DoNotShowCheckbox()

◆ ForceShowAgain()

void KIDIALOG::ForceShowAgain ( )

Definition at line 70 of file confirm.cpp.

71 {
72  doNotShowAgainDlgs.erase( m_hash );
73 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:35
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 120 of file confirm.cpp.

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

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

◆ getStyle()

long KIDIALOG::getStyle ( KD_TYPE  aType)
staticprotected

Definition at line 138 of file confirm.cpp.

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

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 m_cancelMeansCancel.

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

◆ Show()

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

Definition at line 76 of file confirm.cpp.

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

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