KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kidialog.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <kidialog.h>
26#include <unordered_map>
27
28
29// Set of dialogs that have been chosen not to be shown again
30static std::unordered_map<unsigned long, int> doNotShowAgainDlgs;
31
32
33KIDIALOG::KIDIALOG( wxWindow* aParent, const wxString& aMessage, const wxString& aCaption,
34 long aStyle )
35 : wxRichMessageDialog( aParent, aMessage, aCaption, aStyle | wxCENTRE | wxSTAY_ON_TOP ),
36 m_hash( 0 ),
37 m_cancelMeansCancel( true )
38{
39}
40
41
42KIDIALOG::KIDIALOG( wxWindow* aParent, const wxString& aMessage, KD_TYPE aType,
43 const wxString& aCaption )
44 : wxRichMessageDialog( aParent, aMessage, getCaption( aType, aCaption ), getStyle( aType ) ),
45 m_hash( 0 ),
46 m_cancelMeansCancel( true )
47{
48}
49
50
51void KIDIALOG::DoNotShowCheckbox( wxString aUniqueId, int line )
52{
53 ShowCheckBox( _( "Do not show again" ), false );
54
55 m_hash = std::hash<wxString>{}( aUniqueId ) + line;
56}
57
58
60{
61 return doNotShowAgainDlgs.count( m_hash ) > 0;
62}
63
64
66{
68}
69
70
71bool KIDIALOG::Show( bool aShow )
72{
73 // We should check the do-not-show-again setting only when the dialog is displayed
74 if( aShow )
75 {
76 // Check if this dialog should be shown to the user
77 auto it = doNotShowAgainDlgs.find( m_hash );
78
79 if( it != doNotShowAgainDlgs.end() )
80 return it->second;
81 }
82
83 int ret = wxRichMessageDialog::Show( aShow );
84
85 // Has the user asked not to show the dialog again?
86 // Note that we don't save a Cancel value unless the Cancel button is being used for some
87 // other function (which is actually more common than it being used for Cancel).
88 if( IsCheckBoxChecked() && (!m_cancelMeansCancel || ret != wxID_CANCEL ) )
90
91 return ret;
92}
93
94
96{
97 // Check if this dialog should be shown to the user
98 auto it = doNotShowAgainDlgs.find( m_hash );
99
100 if( it != doNotShowAgainDlgs.end() )
101 return it->second;
102
103 int ret = wxRichMessageDialog::ShowModal();
104
105 // Has the user asked not to show the dialog again?
106 // Note that we don't save a Cancel value unless the Cancel button is being used for some
107 // other function (which is actually more common than it being used for Cancel).
108 if( IsCheckBoxChecked() && (!m_cancelMeansCancel || ret != wxID_CANCEL ) )
110
111 return ret;
112}
113
114
115wxString KIDIALOG::getCaption( KD_TYPE aType, const wxString& aCaption )
116{
117 if( !aCaption.IsEmpty() )
118 return aCaption;
119
120 switch( aType )
121 {
122 case KD_NONE: /* fall through */
123 case KD_INFO: return _( "Message" );
124 case KD_QUESTION: return _( "Question" );
125 case KD_WARNING: return _( "Warning" );
126 case KD_ERROR: return _( "Error" );
127 }
128
129 return wxEmptyString;
130}
131
132
134{
135 long style = wxOK | wxCENTRE | wxSTAY_ON_TOP;
136
137 switch( aType )
138 {
139 case KD_NONE: break;
140 case KD_INFO: style |= wxICON_INFORMATION; break;
141 case KD_QUESTION: style |= wxICON_QUESTION; break;
142 case KD_WARNING: style |= wxICON_WARNING; break;
143 case KD_ERROR: style |= wxICON_ERROR; break;
144 }
145
146 return style;
147}
148
KD_TYPE
< Dialog type. Selects appropriate icon and default dialog title
Definition: kidialog.h:46
@ KD_INFO
Definition: kidialog.h:46
@ KD_QUESTION
Definition: kidialog.h:46
@ KD_ERROR
Definition: kidialog.h:46
@ KD_NONE
Definition: kidialog.h:46
@ KD_WARNING
Definition: kidialog.h:46
void ForceShowAgain()
Definition: kidialog.cpp:65
bool DoNotShowAgain() const
Definition: kidialog.cpp:59
bool m_cancelMeansCancel
Definition: kidialog.h:76
static long getStyle(KD_TYPE aType)
Definition: kidialog.cpp:133
unsigned long m_hash
Definition: kidialog.h:75
KIDIALOG(wxWindow *aParent, const wxString &aMessage, const wxString &aCaption, long aStyle=wxOK)
Definition: kidialog.cpp:33
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
Definition: kidialog.cpp:51
int ShowModal() override
Definition: kidialog.cpp:95
static wxString getCaption(KD_TYPE aType, const wxString &aCaption)
Definition: kidialog.cpp:115
bool Show(bool aShow=true) override
Definition: kidialog.cpp:71
#define _(s)
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
Definition: kidialog.cpp:30
This file is part of the common library.