26#include <wx/stockitem.h>
27#include <wx/richmsgdlg.h>
28#include <wx/choicdlg.h>
32#include <unordered_map>
40 : wxRichMessageDialog( aParent, aMessage, aCaption, aStyle | wxCENTRE | wxSTAY_ON_TOP ),
42 m_cancelMeansCancel( true )
48 const wxString& aCaption )
49 : wxRichMessageDialog( aParent, aMessage, getCaption( aType, aCaption ), getStyle( aType ) ),
51 m_cancelMeansCancel( true )
58 ShowCheckBox(
_(
"Do not show again" ),
false );
60 m_hash = std::hash<wxString>{}( aUniqueId ) + line;
88 int ret = wxRichMessageDialog::Show( aShow );
108 int ret = wxRichMessageDialog::ShowModal();
122 if( !aCaption.IsEmpty() )
128 case KD_INFO:
return _(
"Message" );
134 return wxEmptyString;
140 long style = wxOK | wxCENTRE | wxSTAY_ON_TOP;
145 case KD_INFO: style |= wxICON_INFORMATION;
break;
147 case KD_WARNING: style |= wxICON_WARNING;
break;
148 case KD_ERROR: style |= wxICON_ERROR;
break;
161 wxRichMessageDialog dlg( aParent, aMessage,
_(
"File Open Warning" ),
162 wxYES_NO | wxICON_WARNING | wxCENTER );
163 dlg.SetExtendedMessage(
_(
"Interleaved saves may produce very unexpected results." )
165 dlg.SetYesNoLabels(
_(
"Cancel" ),
_(
"Open Anyway" ) );
167 wxMessageDialog dlg( aParent, aMessage,
_(
"File Open Warning" ),
168 wxYES_NO | wxICON_ERROR | wxCENTER );
169 dlg.SetExtendedMessage(
_(
"Interleaved saves may produce very unexpected results." ) );
170 dlg.SetYesNoLabels(
_(
"Cancel" ),
_(
"Open Anyway" ) );
173 return dlg.ShowModal() == wxID_NO;
179 static bool s_apply_to_all =
false;
181 wxRichMessageDialog dlg( parent, aMessage,
_(
"Save Changes?" ),
182 wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER );
183 dlg.SetExtendedMessage(
_(
"If you don't save, all your changes will be permanently lost." )
185 dlg.SetYesNoLabels(
_(
"Save" ),
_(
"Discard Changes" ) );
188 dlg.ShowCheckBox(
_(
"Apply to all" ), s_apply_to_all );
190 int ret = dlg.ShowModal();
194 *aApplyToAll = dlg.IsCheckBoxChecked();
195 s_apply_to_all = dlg.IsCheckBoxChecked();
215 wxWindowDisabler disable(
true );
218 wxMessageDialog dlg( parent, aMessage,
_(
"Save Changes?" ),
219 wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER );
220 dlg.SetExtendedMessage(
_(
"If you don't save, all your changes will be permanently lost." ) );
221 dlg.SetYesNoLabels(
_(
"Save" ),
_(
"Discard Changes" ) );
224 return dlg.ShowModal();
231 wxMessageDialog dlg( parent, aMessage, wxEmptyString,
232 wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
233 dlg.SetExtendedMessage(
_(
"Your current changes will be permanently lost." ) );
234 dlg.SetOKCancelLabels(
_(
"Revert" ),
_(
"Cancel" ) );
236 return dlg.ShowModal() == wxID_OK;
241 const std::function<
bool()>& aSaveFunction )
245 case wxID_YES:
return aSaveFunction();
246 case wxID_NO:
return true;
248 case wxID_CANCEL:
return false;
253int OKOrCancelDialog( wxWindow* aParent,
const wxString& aWarning,
const wxString& aMessage,
254 const wxString& aDetailedMessage,
const wxString& aOKLabel,
255 const wxString& aCancelLabel,
bool* aApplyToAll )
257 wxRichMessageDialog dlg( aParent, aMessage, aWarning,
258 wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
260 dlg.SetOKCancelLabels( ( aOKLabel.IsEmpty() ) ?
_(
"OK" ) : aOKLabel,
261 ( aCancelLabel.IsEmpty() ) ?
_(
"Cancel" ) : aCancelLabel );
263 if( !aDetailedMessage.IsEmpty() )
264 dlg.SetExtendedMessage( aDetailedMessage );
267 dlg.ShowCheckBox(
_(
"Apply to all" ),
true );
269 int ret = dlg.ShowModal();
272 *aApplyToAll = dlg.IsCheckBoxChecked();
280void DisplayError( wxWindow* aParent,
const wxString& aText,
int aDisplayTime )
282 if( !wxTheApp || !wxTheApp->IsMainLoopRunning() )
284 wxLogError(
"%s", aText );
288 if( !wxTheApp->IsGUI() )
290 wxFprintf( stderr, aText );
294 wxMessageDialog* dlg;
295 int icon = aDisplayTime > 0 ? wxICON_INFORMATION : wxICON_ERROR;
297 dlg =
new wxMessageDialog( aParent, aText,
_(
"Warning" ),
298 wxOK | wxCENTRE | wxRESIZE_BORDER | icon | wxSTAY_ON_TOP );
307 if( !wxTheApp || !wxTheApp->IsMainLoopRunning() )
309 wxLogError(
"%s %s", aText, aExtraInfo );
313 if( !wxTheApp->IsGUI() )
315 wxFprintf( stderr, aText );
319 wxMessageDialog* dlg;
321 dlg =
new wxMessageDialog( aParent, aText,
_(
"Error" ),
322 wxOK | wxCENTRE | wxRESIZE_BORDER | wxICON_ERROR | wxSTAY_ON_TOP );
324 if( !aExtraInfo.IsEmpty() )
325 dlg->SetExtendedMessage( aExtraInfo );
334 if( !wxTheApp || !wxTheApp->GetTopWindow() )
336 wxLogDebug(
"%s %s", aMessage, aExtraInfo );
340 if( !wxTheApp->IsGUI() )
342 wxFprintf( stdout,
"%s %s", aMessage, aExtraInfo );
346 wxMessageDialog* dlg;
347 int icon = wxICON_INFORMATION;
349 dlg =
new wxMessageDialog( aParent, aMessage,
_(
"Information" ),
350 wxOK | wxCENTRE | wxRESIZE_BORDER | icon | wxSTAY_ON_TOP );
352 if( !aExtraInfo.IsEmpty() )
353 dlg->SetExtendedMessage( aExtraInfo );
360bool IsOK( wxWindow* aParent,
const wxString& aMessage )
370 int icon = wxICON_WARNING;
372 int icon = wxICON_QUESTION;
375#if !defined( __WXGTK__ )
376 wxRichMessageDialog dlg( aParent, aMessage,
_(
"Confirmation" ),
377 wxOK | wxCANCEL | wxOK_DEFAULT | wxCENTRE | icon | wxSTAY_ON_TOP );
379 wxMessageDialog dlg( aParent, aMessage,
_(
"Confirmation" ),
380 wxOK | wxCANCEL | wxOK_DEFAULT | wxCENTRE | icon | wxSTAY_ON_TOP );
383 dlg.SetOKCancelLabels(
_(
"Yes" ),
_(
"No" ) );
385 return dlg.ShowModal() == wxID_OK;
390 const wxString& aMessage,
const wxArrayString& aOptions )
392 wxSingleChoiceDialog dlg( aParent, aMessage, aTitle, aOptions );
394 if( dlg.ShowModal() != wxID_OK )
397 return dlg.GetSelection();
KD_TYPE
< Dialog type. Selects appropriate icon and default dialog title
bool DoNotShowAgain() const
static long getStyle(KD_TYPE aType)
KIDIALOG(wxWindow *aParent, const wxString &aMessage, const wxString &aCaption, long aStyle=wxOK)
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
static wxString getCaption(KD_TYPE aType, const wxString &aCaption)
bool Show(bool aShow=true) override
bool AskOverrideLock(wxWindow *aParent, const wxString &aMessage)
Display a dialog indicating the file is already open, with an option to reset the lock.
int SelectSingleOption(wxWindow *aParent, const wxString &aTitle, const wxString &aMessage, const wxArrayString &aOptions)
Display a dialog with radioboxes asking the user to select an option.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
static std::unordered_map< unsigned long, int > doNotShowAgainDlgs
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
int UnsavedChangesDialog(wxWindow *parent, const wxString &aMessage, bool *aApplyToAll)
A specialized version of HandleUnsavedChanges which handles an apply-to-all checkbox.
bool ConfirmRevertDialog(wxWindow *parent, const wxString &aMessage)
Display a confirmation dialog for a revert action.
This file is part of the common library.