forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarning.cpp
More file actions
113 lines (86 loc) · 2.95 KB
/
Copy pathWarning.cpp
File metadata and controls
113 lines (86 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**********************************************************************
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 "../Audacity.h"
#include "Warning.h"
#include "../Prefs.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
WarningDialog(wxWindow *parent,
const TranslatableString &message,
const TranslatableString &footer,
bool showCancelButton);
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"),
wxDefaultPosition, wxDefaultSize,
(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);
S.AddStandardButtons(showCancelButton ? eOkButton | eCancelButton : eOkButton);
Layout();
GetSizer()->Fit(this);
CentreOnParent();
}
void WarningDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
EndModal(mCheckBox->GetValue() ? wxID_NO : wxID_YES); // return YES, if message should be shown again
}
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)) {
return wxID_OK;
}
WarningDialog dlog(parent, message, footer, showCancelButton);
int retCode = dlog.ShowModal();
if (retCode == wxID_CANCEL)
return retCode;
gPrefs->Write(key, (retCode == wxID_YES));
gPrefs->Flush();
return wxID_OK;
}