audacia/src/widgets/Warning.cpp

113 lines
2.9 KiB
C++
Raw Normal View History

/**********************************************************************
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.
*//********************************************************************/
#include "Warning.h"
#include "../ShuttleGui.h"
#include <wx/artprov.h>
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include "wxPanelWrapper.h"
class WarningDialog final : public wxDialogWrapper
{
public:
// constructors and destructors
2014-06-03 20:30:19 +00:00
WarningDialog(wxWindow *parent,
const TranslatableString &message,
const TranslatableString &footer,
2012-12-17 02:00:32 +00:00
bool showCancelButton);
2014-06-03 20:30:19 +00:00
private:
void OnOK(wxCommandEvent& event);
wxCheckBox *mCheckBox;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(WarningDialog, wxDialogWrapper)
EVT_BUTTON(wxID_OK, WarningDialog::OnOK)
END_EVENT_TABLE()
const TranslatableString &DefaultWarningFooter()
{
static auto result = XXO("Don't show this warning again");
return result;
}
WarningDialog::WarningDialog(wxWindow *parent, const TranslatableString &message,
const TranslatableString &footer,
bool showCancelButton)
: 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.
{
SetName();
SetIcon(wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX));
ShuttleGui S(this, eIsCreating);
S.SetBorder(10);
S.StartVerticalLay(false);
{
S.AddFixedText(message);
mCheckBox = S.AddCheckBox(footer, false);
}
S.EndVerticalLay();
S.SetBorder(0);
2012-12-17 02:00:32 +00:00
S.AddStandardButtons(showCancelButton ? eOkButton | eCancelButton : eOkButton);
2020-06-09 12:04:46 +00:00
Layout();
GetSizer()->Fit(this);
CentreOnParent();
}
void WarningDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
2012-12-17 02:00:32 +00:00
EndModal(mCheckBox->GetValue() ? wxID_NO : wxID_YES); // return YES, if message should be shown again
}
2012-12-17 02:00:32 +00:00
int ShowWarningDialog(wxWindow *parent,
const wxString &internalDialogName,
const TranslatableString &message,
bool showCancelButton,
const TranslatableString &footer)
{
auto key = WarningDialogKey(internalDialogName);
if (!gPrefs->Read(key, (long) true)) {
2012-12-17 02:00:32 +00:00
return wxID_OK;
}
WarningDialog dlog(parent, message, footer, showCancelButton);
2012-12-17 02:00:32 +00:00
int retCode = dlog.ShowModal();
if (retCode == wxID_CANCEL)
return retCode;
gPrefs->Write(key, (retCode == wxID_YES));
gPrefs->Flush();
2012-12-17 02:00:32 +00:00
return wxID_OK;
}