26#include <wx/stockitem.h>
27#include <wx/richmsgdlg.h>
28#include <wx/choicdlg.h>
33#include <unordered_map>
43 : wxRichMessageDialog( aParent, aMessage, aCaption, aStyle | wxCENTRE | wxSTAY_ON_TOP ),
45 m_cancelMeansCancel( true )
51 const wxString& aCaption )
52 : wxRichMessageDialog( aParent, aMessage, getCaption( aType, aCaption ), getStyle( aType ) ),
54 m_cancelMeansCancel( true )
61 ShowCheckBox(
_(
"Do not show again" ),
false );
63 m_hash = std::hash<wxString>{}( aUniqueId ) + line;
91 int ret = wxRichMessageDialog::Show( aShow );
111 int ret = wxRichMessageDialog::ShowModal();
125 if( !aCaption.IsEmpty() )
131 case KD_INFO:
return _(
"Message" );
137 return wxEmptyString;
143 long style = wxOK | wxCENTRE | wxSTAY_ON_TOP;
148 case KD_INFO: style |= wxICON_INFORMATION;
break;
150 case KD_WARNING: style |= wxICON_WARNING;
break;
151 case KD_ERROR: style |= wxICON_ERROR;
break;
164 wxRichMessageDialog dlg( aParent, aMessage,
_(
"File Open Warning" ),
165 wxYES_NO | wxICON_WARNING | wxCENTER );
166 dlg.SetExtendedMessage(
_(
"Interleaved saves may produce very unexpected results." )
168 dlg.SetYesNoLabels(
_(
"Cancel" ),
_(
"Open Anyway" ) );
170 wxMessageDialog dlg( aParent, aMessage,
_(
"File Open Warning" ),
171 wxYES_NO | wxICON_ERROR | wxCENTER );
172 dlg.SetExtendedMessage(
_(
"Interleaved saves may produce very unexpected results." ) );
173 dlg.SetYesNoLabels(
_(
"Cancel" ),
_(
"Open Anyway" ) );
176 return dlg.ShowModal() == wxID_NO;
182 static bool s_apply_to_all =
false;
184 wxRichMessageDialog dlg( parent, aMessage,
_(
"Save Changes?" ),
185 wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER );
186 dlg.SetExtendedMessage(
_(
"If you don't save, all your changes will be permanently lost." )
188 dlg.SetYesNoLabels(
_(
"Save" ),
_(
"Discard Changes" ) );
191 dlg.ShowCheckBox(
_(
"Apply to all" ), s_apply_to_all );
193 int ret = dlg.ShowModal();
197 *aApplyToAll = dlg.IsCheckBoxChecked();
198 s_apply_to_all = dlg.IsCheckBoxChecked();
218 wxWindowDisabler disable(
true );
221 wxMessageDialog dlg( parent, aMessage,
_(
"Save Changes?" ),
222 wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER );
223 dlg.SetExtendedMessage(
_(
"If you don't save, all your changes will be permanently lost." ) );
224 dlg.SetYesNoLabels(
_(
"Save" ),
_(
"Discard Changes" ) );
227 return dlg.ShowModal();
234 wxMessageDialog dlg( parent, aMessage, wxEmptyString,
235 wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
236 dlg.SetExtendedMessage(
_(
"Your current changes will be permanently lost." ) );
237 dlg.SetOKCancelLabels(
_(
"Revert" ),
_(
"Cancel" ) );
239 return dlg.ShowModal() == wxID_OK;
244 const std::function<
bool()>& aSaveFunction )
248 case wxID_YES:
return aSaveFunction();
249 case wxID_NO:
return true;
251 case wxID_CANCEL:
return false;
256int OKOrCancelDialog( wxWindow* aParent,
const wxString& aWarning,
const wxString& aMessage,
257 const wxString& aDetailedMessage,
const wxString& aOKLabel,
258 const wxString& aCancelLabel,
bool* aApplyToAll )
260 wxRichMessageDialog dlg( aParent, aMessage, aWarning,
261 wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
263 dlg.SetOKCancelLabels( ( aOKLabel.IsEmpty() ) ?
_(
"OK" ) : aOKLabel,
264 ( aCancelLabel.IsEmpty() ) ?
_(
"Cancel" ) : aCancelLabel );
266 if( !aDetailedMessage.IsEmpty() )
267 dlg.SetExtendedMessage( aDetailedMessage );
270 dlg.ShowCheckBox(
_(
"Apply to all" ),
true );
272 int ret = dlg.ShowModal();
275 *aApplyToAll = dlg.IsCheckBoxChecked();
283void DisplayError( wxWindow* aParent,
const wxString& aText,
int aDisplayTime )
285 if( !wxTheApp || !wxTheApp->IsMainLoopRunning() )
287 wxLogError(
"%s", aText );
293 wxFprintf( stderr, aText );
297 wxMessageDialog* dlg;
298 int icon = aDisplayTime > 0 ? wxICON_INFORMATION : wxICON_ERROR;
300 dlg =
new wxMessageDialog( aParent, aText,
_(
"Warning" ),
301 wxOK | wxCENTRE | wxRESIZE_BORDER | icon | wxSTAY_ON_TOP );
310 if( !wxTheApp || !wxTheApp->IsMainLoopRunning() )
312 wxLogError(
"%s %s", aText, aExtraInfo );
318 wxFprintf( stderr, aText );
322 wxMessageDialog* dlg;
324 dlg =
new wxMessageDialog( aParent, aText,
_(
"Error" ),
325 wxOK | wxCENTRE | wxRESIZE_BORDER | wxICON_ERROR | wxSTAY_ON_TOP );
327 if( !aExtraInfo.IsEmpty() )
328 dlg->SetExtendedMessage( aExtraInfo );
337 if( !wxTheApp || !wxTheApp->GetTopWindow() )
339 wxLogDebug(
"%s %s", aMessage, aExtraInfo );
345 wxFprintf( stdout,
"%s %s", aMessage, aExtraInfo );
349 wxMessageDialog* dlg;
350 int icon = wxICON_INFORMATION;
352 dlg =
new wxMessageDialog( aParent, aMessage,
_(
"Information" ),
353 wxOK | wxCENTRE | wxRESIZE_BORDER | icon | wxSTAY_ON_TOP );
355 if( !aExtraInfo.IsEmpty() )
356 dlg->SetExtendedMessage( aExtraInfo );
363bool IsOK( wxWindow* aParent,
const wxString& aMessage )
373 int icon = wxICON_WARNING;
375 int icon = wxICON_QUESTION;
378#if !defined( __WXGTK__ )
379 wxRichMessageDialog dlg( aParent, aMessage,
_(
"Confirmation" ),
380 wxOK | wxCANCEL | wxOK_DEFAULT | wxCENTRE | icon | wxSTAY_ON_TOP );
382 wxMessageDialog dlg( aParent, aMessage,
_(
"Confirmation" ),
383 wxOK | wxCANCEL | wxOK_DEFAULT | wxCENTRE | icon | wxSTAY_ON_TOP );
386 dlg.SetOKCancelLabels(
_(
"Yes" ),
_(
"No" ) );
388 return dlg.ShowModal() == wxID_OK;
393 const wxString& aMessage,
const wxArrayString& aOptions )
395 wxSingleChoiceDialog dlg( aParent, aMessage, aTitle, aOptions );
397 if( dlg.ShowModal() != wxID_OK )
400 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
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.
bool OverrideLock(wxWindow *aParent, const wxString &aMessage)
Display a dialog indicating the file is already open, with an option to reset the lock.
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.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.