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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <kidialog.h>
22#include <unordered_map>
23
24
25// Set of dialogs that have been chosen not to be shown again
26static std::unordered_map<unsigned long, int> g_doNotShowAgainDlgs;
27
28
29KIDIALOG::KIDIALOG( wxWindow* aParent, const wxString& aMessage, const wxString& aCaption, long aStyle ) :
30 KIDIALOG_BASE( aParent, aMessage, aCaption, aStyle | wxCENTRE | wxSTAY_ON_TOP ),
31 m_hash( 0 ),
33{
34}
35
36
37KIDIALOG::KIDIALOG( wxWindow* aParent, const wxString& aMessage, KD_TYPE aType, const wxString& aCaption ) :
38 KIDIALOG_BASE( aParent, aMessage, getCaption( aType, aCaption ), getStyle( aType ) ),
39 m_hash( 0 ),
41{
42}
43
44
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 g_doNotShowAgainDlgs.count( m_hash ) > 0;
62}
63
64
65bool KIDIALOG::Show( bool aShow )
66{
67 // We should check the do-not-show-again setting only when the dialog is displayed
68 if( aShow )
69 {
70 // Check if this dialog should be shown to the user
71 auto it = g_doNotShowAgainDlgs.find( m_hash );
72
73 if( it != g_doNotShowAgainDlgs.end() )
74 return it->second;
75 }
76
77 int ret = KIDIALOG_BASE::Show( aShow );
78
79 // Has the user asked not to show the dialog again?
80 // Note that we don't save a Cancel value unless the Cancel button is being used for some
81 // other function (which is actually more common than it being used for Cancel).
82 if( IsCheckBoxChecked() && (!m_cancelMeansCancel || ret != wxID_CANCEL ) )
84
85 return ret;
86}
87
88
90{
91 // Check if this dialog should be shown to the user
92 auto it = g_doNotShowAgainDlgs.find( m_hash );
93
94 if( it != g_doNotShowAgainDlgs.end() )
95 return it->second;
96
97 int ret = KIDIALOG_BASE::ShowModal();
98
99 // Has the user asked not to show the dialog again?
100 // Note that we don't save a Cancel value unless the Cancel button is being used for some
101 // other function (which is actually more common than it being used for Cancel).
102 if( IsCheckBoxChecked() && (!m_cancelMeansCancel || ret != wxID_CANCEL ) )
104
105 return ret;
106}
107
108
109wxString KIDIALOG::getCaption( KD_TYPE aType, const wxString& aCaption )
110{
111 if( !aCaption.IsEmpty() )
112 return aCaption;
113
114 switch( aType )
115 {
116 case KD_NONE: /* fall through */
117 case KD_INFO: return _( "Message" );
118 case KD_QUESTION: return _( "Question" );
119 case KD_WARNING: return _( "Warning" );
120 case KD_ERROR: return _( "Error" );
121 }
122
123 return wxEmptyString;
124}
125
126
128{
129 long style = wxOK | wxCENTRE | wxSTAY_ON_TOP;
130
131 switch( aType )
132 {
133 case KD_NONE: break;
134 case KD_INFO: style |= wxICON_INFORMATION; break;
135 case KD_QUESTION: style |= wxICON_QUESTION; break;
136 case KD_WARNING: style |= wxICON_WARNING; break;
137 case KD_ERROR: style |= wxICON_ERROR; break;
138 }
139
140 return style;
141}
142
@ KD_INFO
Definition kidialog.h:43
@ KD_QUESTION
Definition kidialog.h:43
@ KD_ERROR
Definition kidialog.h:43
@ KD_NONE
Definition kidialog.h:43
@ KD_WARNING
Definition kidialog.h:43
bool DoNotShowAgain() const
Checks the 'do not show again' setting for the dialog.
Definition kidialog.cpp:59
bool m_cancelMeansCancel
Definition kidialog.h:70
static long getStyle(KD_TYPE aType)
Definition kidialog.cpp:127
unsigned long m_hash
Definition kidialog.h:69
KIDIALOG(wxWindow *aParent, const wxString &aMessage, const wxString &aCaption, long aStyle=wxOK)
Definition kidialog.cpp:29
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition kidialog.cpp:51
int ShowModal() override
Definition kidialog.cpp:89
static wxString getCaption(KD_TYPE aType, const wxString &aCaption)
Definition kidialog.cpp:109
static void ClearDoNotShowAgainDialogs()
Dialog type. Selects appropriate icon and default dialog title.
Definition kidialog.cpp:45
bool Show(bool aShow=true) override
Definition kidialog.cpp:65
#define _(s)
static std::unordered_map< unsigned long, int > g_doNotShowAgainDlgs
Definition kidialog.cpp:26
#define KIDIALOG_BASE
Definition kidialog.h:30