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