2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
Warning.cpp
|
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
|
|
|
|
*******************************************************************//**
|
|
|
|
|
|
|
|
\class WarningDialog
|
|
|
|
\brief Gives a warning message, that can be dismissed, with crucially
|
|
|
|
the ability to not see similar warnings again for this session.
|
|
|
|
|
|
|
|
*//********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-09 15:16:56 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
#include "Warning.h"
|
|
|
|
|
|
|
|
#include "../ShuttleGui.h"
|
|
|
|
|
2013-11-25 04:59:07 +00:00
|
|
|
#include <wx/artprov.h>
|
2010-01-23 19:44:49 +00:00
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/intl.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/stattext.h>
|
2016-07-10 21:10:50 +00:00
|
|
|
#include "wxPanelWrapper.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-07-10 21:10:50 +00:00
|
|
|
class WarningDialog final : public wxDialogWrapper
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructors and destructors
|
2014-06-03 20:30:19 +00:00
|
|
|
WarningDialog(wxWindow *parent,
|
2019-12-05 18:38:07 +00:00
|
|
|
const TranslatableString &message,
|
|
|
|
const TranslatableString &footer,
|
2012-12-17 02:00:32 +00:00
|
|
|
bool showCancelButton);
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
private:
|
|
|
|
void OnOK(wxCommandEvent& event);
|
|
|
|
|
|
|
|
wxCheckBox *mCheckBox;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
2016-07-10 21:10:50 +00:00
|
|
|
BEGIN_EVENT_TABLE(WarningDialog, wxDialogWrapper)
|
2010-01-23 19:44:49 +00:00
|
|
|
EVT_BUTTON(wxID_OK, WarningDialog::OnOK)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2019-12-05 18:38:07 +00:00
|
|
|
const TranslatableString &DefaultWarningFooter()
|
2018-01-17 15:18:49 +00:00
|
|
|
{
|
2020-05-11 15:28:14 +00:00
|
|
|
static auto result = XXO("Don't show this warning again");
|
2019-12-05 18:38:07 +00:00
|
|
|
return result;
|
2018-01-17 15:18:49 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 18:38:07 +00:00
|
|
|
WarningDialog::WarningDialog(wxWindow *parent, const TranslatableString &message,
|
|
|
|
const TranslatableString &footer,
|
2018-01-17 15:18:49 +00:00
|
|
|
bool showCancelButton)
|
2019-12-08 05:25:47 +00:00
|
|
|
: wxDialogWrapper(parent, wxID_ANY, XO("Warning"),
|
2014-06-03 20:30:19 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2012-12-17 02:00:32 +00:00
|
|
|
(showCancelButton ? wxDEFAULT_DIALOG_STYLE : wxCAPTION | wxSYSTEM_MENU)) // Unlike wxDEFAULT_DIALOG_STYLE, no wxCLOSE_BOX.
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2019-12-08 05:25:47 +00:00
|
|
|
SetName();
|
2015-05-12 13:29:27 +00:00
|
|
|
|
2013-11-25 04:59:07 +00:00
|
|
|
SetIcon(wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX));
|
2010-01-23 19:44:49 +00:00
|
|
|
ShuttleGui S(this, eIsCreating);
|
|
|
|
|
|
|
|
S.SetBorder(10);
|
|
|
|
S.StartVerticalLay(false);
|
|
|
|
{
|
2019-12-23 00:55:59 +00:00
|
|
|
S.AddFixedText(message);
|
2019-12-04 18:52:39 +00:00
|
|
|
mCheckBox = S.AddCheckBox(footer, false);
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
2018-04-08 10:48:42 +00:00
|
|
|
S.EndVerticalLay();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
S.SetBorder(0);
|
2012-12-17 02:00:32 +00:00
|
|
|
S.AddStandardButtons(showCancelButton ? eOkButton | eCancelButton : eOkButton);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2020-06-09 12:04:46 +00:00
|
|
|
Layout();
|
|
|
|
GetSizer()->Fit(this);
|
2010-01-23 19:44:49 +00:00
|
|
|
CentreOnParent();
|
|
|
|
}
|
|
|
|
|
2013-08-25 21:51:26 +00:00
|
|
|
void WarningDialog::OnOK(wxCommandEvent& WXUNUSED(event))
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2012-12-17 02:00:32 +00:00
|
|
|
EndModal(mCheckBox->GetValue() ? wxID_NO : wxID_YES); // return YES, if message should be shown again
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 02:00:32 +00:00
|
|
|
int ShowWarningDialog(wxWindow *parent,
|
2016-02-23 02:16:12 +00:00
|
|
|
const wxString &internalDialogName,
|
2019-12-05 18:38:07 +00:00
|
|
|
const TranslatableString &message,
|
2018-01-17 15:18:49 +00:00
|
|
|
bool showCancelButton,
|
2019-12-05 18:38:07 +00:00
|
|
|
const TranslatableString &footer)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2018-01-16 16:52:17 +00:00
|
|
|
auto key = WarningDialogKey(internalDialogName);
|
2010-01-23 19:44:49 +00:00
|
|
|
if (!gPrefs->Read(key, (long) true)) {
|
2012-12-17 02:00:32 +00:00
|
|
|
return wxID_OK;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 15:18:49 +00:00
|
|
|
WarningDialog dlog(parent, message, footer, showCancelButton);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2012-12-17 02:00:32 +00:00
|
|
|
int retCode = dlog.ShowModal();
|
|
|
|
if (retCode == wxID_CANCEL)
|
|
|
|
return retCode;
|
|
|
|
|
|
|
|
gPrefs->Write(key, (retCode == wxID_YES));
|
2012-08-02 06:03:19 +00:00
|
|
|
gPrefs->Flush();
|
2012-12-17 02:00:32 +00:00
|
|
|
return wxID_OK;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|