Audacity  3.0.3
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 "../Prefs.h"
23 #include "../ShuttleGui.h"
24 
25 #include <wx/artprov.h>
26 #include <wx/button.h>
27 #include <wx/checkbox.h>
28 #include <wx/intl.h>
29 #include <wx/sizer.h>
30 #include <wx/stattext.h>
31 #include "wxPanelWrapper.h"
32 
33 class WarningDialog final : public wxDialogWrapper
34 {
35  public:
36  // constructors and destructors
37  WarningDialog(wxWindow *parent,
38  const TranslatableString &message,
39  const TranslatableString &footer,
40  bool showCancelButton);
41 
42  private:
43  void OnOK(wxCommandEvent& event);
44 
45  wxCheckBox *mCheckBox;
46 
47  DECLARE_EVENT_TABLE()
48 };
49 
50 BEGIN_EVENT_TABLE(WarningDialog, wxDialogWrapper)
53 
55 {
56  static auto result = XXO("Don't show this warning again");
57  return result;
58 }
59 
60 WarningDialog::WarningDialog(wxWindow *parent, const TranslatableString &message,
61  const TranslatableString &footer,
62  bool showCancelButton)
63 : wxDialogWrapper(parent, wxID_ANY, XO("Warning"),
64  wxDefaultPosition, wxDefaultSize,
65  (showCancelButton ? wxDEFAULT_DIALOG_STYLE : wxCAPTION | wxSYSTEM_MENU)) // Unlike wxDEFAULT_DIALOG_STYLE, no wxCLOSE_BOX.
66 {
67  SetName();
68 
69  SetIcon(wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX));
70  ShuttleGui S(this, eIsCreating);
71 
72  S.SetBorder(10);
73  S.StartVerticalLay(false);
74  {
75  S.AddFixedText(message);
76  mCheckBox = S.AddCheckBox(footer, false);
77  }
78  S.EndVerticalLay();
79 
80  S.SetBorder(0);
81  S.AddStandardButtons(showCancelButton ? eOkButton | eCancelButton : eOkButton);
82 
83  Layout();
84  GetSizer()->Fit(this);
85  CentreOnParent();
86 }
87 
88 void WarningDialog::OnOK(wxCommandEvent& WXUNUSED(event))
89 {
90  EndModal(mCheckBox->GetValue() ? wxID_NO : wxID_YES); // return YES, if message should be shown again
91 }
92 
93 int ShowWarningDialog(wxWindow *parent,
94  const wxString &internalDialogName,
95  const TranslatableString &message,
96  bool showCancelButton,
97  const TranslatableString &footer)
98 {
99  auto key = WarningDialogKey(internalDialogName);
100  if (!gPrefs->Read(key, (long) true)) {
101  return wxID_OK;
102  }
103 
104  WarningDialog dlog(parent, message, footer, showCancelButton);
105 
106  int retCode = dlog.ShowModal();
107  if (retCode == wxID_CANCEL)
108  return retCode;
109 
110  gPrefs->Write(key, (retCode == wxID_YES));
111  gPrefs->Flush();
112  return wxID_OK;
113 }
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Definition: Types.h:290
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:36
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1177
ShuttleGuiBase::AddCheckBox
wxCheckBox * AddCheckBox(const TranslatableString &Prompt, bool Selected)
Definition: ShuttleGui.cpp:302
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:67
WarningDialog::WarningDialog
WarningDialog(wxWindow *parent, const TranslatableString &message, const TranslatableString &footer, bool showCancelButton)
Definition: Warning.cpp:60
ShowWarningDialog
int ShowWarningDialog(wxWindow *parent, const wxString &internalDialogName, const TranslatableString &message, bool showCancelButton, const TranslatableString &footer)
Definition: Warning.cpp:93
XO
#define XO(s)
Definition: Internat.h:32
wxPanelWrapper.h
eCancelButton
@ eCancelButton
Definition: ShuttleGui.h:608
DefaultWarningFooter
const TranslatableString & DefaultWarningFooter()
Definition: Warning.cpp:54
eOkButton
@ eOkButton
Definition: ShuttleGui.h:607
XXO
#define XXO(s)
Definition: Internat.h:45
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1196
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:433
Warning.h
wxDialogWrapper
Definition: wxPanelWrapper.h:81
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:151
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:196
WarningDialogKey
wxString WarningDialogKey(const wxString &internalDialogName)
Definition: Prefs.cpp:368
ShuttleGui::AddStandardButtons
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxWindow *extra=NULL)
Definition: ShuttleGui.cpp:2406
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:497
WarningDialog::mCheckBox
wxCheckBox * mCheckBox
Definition: Warning.cpp:45
wxDialogWrapper::SetName
void SetName()
Definition: wxPanelWrapper.cpp:81
WarningDialog
Gives a warning message, that can be dismissed, with crucially the ability to not see similar warning...
Definition: Warning.cpp:34
END_EVENT_TABLE
END_EVENT_TABLE()
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:638
WarningDialog::OnOK
void OnOK(wxCommandEvent &event)
Definition: Warning.cpp:88