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="")
 
void DoNotShowCheckbox (wxString file, int line)
 

Shows the 'do not show again' checkbox

More...
 
bool DoNotShowAgain () const
 

Checks the 'do not show again' setting for the dialog

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

Unique identifier of the dialog

More...
 

Detailed Description

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

Definition at line 44 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 48 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 {
43 }
unsigned long m_hash
Unique identifier of the dialog
Definition: confirm.h:67

◆ 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 {
51 }
static wxString getCaption(KD_TYPE aType, const wxString &aCaption)
Definition: confirm.cpp:114
static long getStyle(KD_TYPE aType)
Definition: confirm.cpp:132
unsigned long m_hash
Unique identifier of the dialog
Definition: confirm.h:67

Member Function Documentation

◆ DoNotShowAgain()

bool KIDIALOG::DoNotShowAgain ( ) const

Checks the 'do not show again' setting for the dialog

Definition at line 62 of file confirm.cpp.

63 {
64  return doNotShowAgainDlgs.count( m_hash ) > 0;
65 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:35
unsigned long m_hash
Unique identifier of the dialog
Definition: confirm.h:67

References doNotShowAgainDlgs, and m_hash.

◆ DoNotShowCheckbox()

◆ ForceShowAgain()

void KIDIALOG::ForceShowAgain ( )

Definition at line 68 of file confirm.cpp.

69 {
70  doNotShowAgainDlgs.erase( m_hash );
71 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:35
unsigned long m_hash
Unique identifier of the dialog
Definition: confirm.h:67

References doNotShowAgainDlgs, and m_hash.

◆ getCaption()

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

Definition at line 114 of file confirm.cpp.

115 {
116  if( !aCaption.IsEmpty() )
117  return aCaption;
118 
119  switch( aType )
120  {
121  case KD_NONE: /* fall through */
122  case KD_INFO: return _( "Message" );
123  case KD_QUESTION: return _( "Question" );
124  case KD_WARNING: return _( "Warning" );
125  case KD_ERROR: return _( "Error" );
126  }
127 
128  return wxEmptyString;
129 }
#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 132 of file confirm.cpp.

133 {
134  long style = wxOK | wxCENTRE | wxSTAY_ON_TOP;
135 
136  switch( aType )
137  {
138  case KD_NONE: break;
139  case KD_INFO: style |= wxICON_INFORMATION; break;
140  case KD_QUESTION: style |= wxICON_QUESTION; break;
141  case KD_WARNING: style |= wxICON_WARNING; break;
142  case KD_ERROR: style |= wxICON_ERROR; break;
143  }
144 
145  return style;
146 }

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

◆ Show()

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

Definition at line 74 of file confirm.cpp.

75 {
76  // We should check the do-not-show-again setting only when the dialog is displayed
77  if( aShow )
78  {
79  // Check if this dialog should be shown to the user
80  auto it = doNotShowAgainDlgs.find( m_hash );
81 
82  if( it != doNotShowAgainDlgs.end() )
83  return it->second;
84  }
85 
86  int ret = wxRichMessageDialog::Show( aShow );
87 
88  // Has the user asked not to show the dialog again and it was confirmed
89  if( IsCheckBoxChecked() && ret != wxID_CANCEL )
91 
92  return ret;
93 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:35
unsigned long m_hash
Unique identifier of the dialog
Definition: confirm.h:67

References doNotShowAgainDlgs, and m_hash.

◆ ShowModal()

int KIDIALOG::ShowModal ( )
override

Definition at line 96 of file confirm.cpp.

97 {
98  // Check if this dialog should be shown to the user
99  auto it = doNotShowAgainDlgs.find( m_hash );
100 
101  if( it != doNotShowAgainDlgs.end() )
102  return it->second;
103 
104  int ret = wxRichMessageDialog::ShowModal();
105 
106  // Has the user asked not to show the dialog again
107  if( IsCheckBoxChecked() && ret != wxID_CANCEL )
108  doNotShowAgainDlgs[m_hash] = ret;
109 
110  return ret;
111 }
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: confirm.cpp:35
unsigned long m_hash
Unique identifier of the dialog
Definition: confirm.h:67

References doNotShowAgainDlgs, and m_hash.

Referenced by DIALOG_TRACK_VIA_PROPERTIES::confirmPadChange(), PCB_BASE_EDIT_FRAME::CreateNewLibrary(), LIB_EDIT_FRAME::ExportPart(), ZONE_FILLER::Fill(), KICAD_MANAGER_FRAME::ImportNonKiCadProject(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), LEGACY_PLUGIN::loadZONE_CONTAINER(), KICAD_MANAGER_CONTROL::NewFromTemplate(), DIALOG_CONFIGURE_PATHS::OnGridCellChanging(), PCB_PARSER::parseZONE_CONTAINER(), ROUTER_TOOL::performDragging(), LIB_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_hash

unsigned long KIDIALOG::m_hash
protected

Unique identifier of the dialog

Definition at line 67 of file confirm.h.

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


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