Audacity 3.2.0
Warning.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Warning.cpp
6
7 Dominic Mazzoni
8
9*******************************************************************//********************************************************************/
16
17
18
19
20#include "Warning.h"
21
22#include "ShuttleGui.h"
23
24#include <wx/artprov.h>
25#include <wx/checkbox.h>
26#include <wx/sizer.h>
27#include <wx/stattext.h>
28#include "wxPanelWrapper.h"
29
30class WarningDialog final : public wxDialogWrapper
31{
32 public:
33 // constructors and destructors
34 WarningDialog(wxWindow *parent,
35 const TranslatableString &message,
36 const TranslatableString &footer,
37 bool showCancelButton);
38
39 private:
40 void OnOK(wxCommandEvent& event);
41
42 wxCheckBox *mCheckBox;
43
44 DECLARE_EVENT_TABLE()
45};
46
47BEGIN_EVENT_TABLE(WarningDialog, wxDialogWrapper)
50
52{
53 static auto result = XXO("Don't show this warning again");
54 return result;
55}
56
57WarningDialog::WarningDialog(wxWindow *parent, const TranslatableString &message,
58 const TranslatableString &footer,
59 bool showCancelButton)
60: wxDialogWrapper(parent, wxID_ANY, XO("Warning"),
61 wxDefaultPosition, wxDefaultSize,
62 (showCancelButton ? wxDEFAULT_DIALOG_STYLE : wxCAPTION | wxSYSTEM_MENU)) // Unlike wxDEFAULT_DIALOG_STYLE, no wxCLOSE_BOX.
63{
64 SetName();
65
66 SetIcon(wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX));
68
69 S.SetBorder(10);
70 S.StartVerticalLay(false);
71 {
72 S.AddFixedText(message);
73 mCheckBox = S.AddCheckBox(footer, false);
74 }
75 S.EndVerticalLay();
76
77 S.SetBorder(0);
78 S.AddStandardButtons(showCancelButton ? eOkButton | eCancelButton : eOkButton);
79
80 Layout();
81 GetSizer()->Fit(this);
82 CentreOnParent();
83}
84
85void WarningDialog::OnOK(wxCommandEvent& WXUNUSED(event))
86{
87 EndModal(mCheckBox->GetValue() ? wxID_NO : wxID_YES); // return YES, if message should be shown again
88}
89
90int ShowWarningDialog(wxWindow *parent,
91 const wxString &internalDialogName,
92 const TranslatableString &message,
93 bool showCancelButton,
94 const TranslatableString &footer)
95{
96 auto key = WarningDialogKey(internalDialogName);
97 if (!gPrefs->Read(key, (long) true)) {
98 return wxID_OK;
99 }
100
101 WarningDialog dlog(parent, message, footer, showCancelButton);
102
103 int retCode = dlog.ShowModal();
104 if (retCode == wxID_CANCEL)
105 return retCode;
106
107 gPrefs->Write(key, (retCode == wxID_YES));
108 gPrefs->Flush();
109 return wxID_OK;
110}
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
static const AudacityProject::AttachedObjects::RegisteredFactory key
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
wxString WarningDialogKey(const wxString &internalDialogName)
Definition: Prefs.cpp:510
@ eIsCreating
Definition: ShuttleGui.h:37
@ eOkButton
Definition: ShuttleGui.h:609
@ eCancelButton
Definition: ShuttleGui.h:610
#define S(N)
Definition: ToChars.cpp:64
const TranslatableString & DefaultWarningFooter()
Definition: Warning.cpp:51
int ShowWarningDialog(wxWindow *parent, const wxString &internalDialogName, const TranslatableString &message, bool showCancelButton, const TranslatableString &footer)
Definition: Warning.cpp:90
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
Holds a msgid for the translation catalog; may also bind format arguments.
Gives a warning message, that can be dismissed, with crucially the ability to not see similar warning...
Definition: Warning.cpp:31
wxCheckBox * mCheckBox
Definition: Warning.cpp:42
WarningDialog(wxWindow *parent, const TranslatableString &message, const TranslatableString &footer, bool showCancelButton)
Definition: Warning.cpp:57
void OnOK(wxCommandEvent &event)
Definition: Warning.cpp:85
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0