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