Audacity  2.2.2
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 #include "../Audacity.h"
20 
21 #include "Warning.h"
22 
23 #include "../Prefs.h"
24 #include "../ShuttleGui.h"
25 
26 #include <wx/artprov.h>
27 #include <wx/button.h>
28 #include <wx/checkbox.h>
29 #include <wx/intl.h>
30 #include <wx/sizer.h>
31 #include <wx/stattext.h>
32 #include "wxPanelWrapper.h"
33 #include "../Internat.h"
34 
35 class WarningDialog final : public wxDialogWrapper
36 {
37  public:
38  // constructors and destructors
39  WarningDialog(wxWindow *parent,
40  const wxString &message,
41  const wxString &footer,
42  bool showCancelButton);
43 
44  private:
45  void OnOK(wxCommandEvent& event);
46 
47  wxCheckBox *mCheckBox;
48 
49  DECLARE_EVENT_TABLE()
50 };
51 
52 BEGIN_EVENT_TABLE(WarningDialog, wxDialogWrapper)
53  EVT_BUTTON(wxID_OK, WarningDialog::OnOK)
55 
56 const wxString &DefaultWarningFooter()
57 {
58  return _("Don't show this warning again");
59 }
60 
61 WarningDialog::WarningDialog(wxWindow *parent, const wxString &message,
62  const wxString &footer,
63  bool showCancelButton)
64 : wxDialogWrapper(parent, wxID_ANY, (wxString)_("Warning"),
65  wxDefaultPosition, wxDefaultSize,
66  (showCancelButton ? wxDEFAULT_DIALOG_STYLE : wxCAPTION | wxSYSTEM_MENU)) // Unlike wxDEFAULT_DIALOG_STYLE, no wxCLOSE_BOX.
67 {
68  SetName(GetTitle());
69 
70  SetIcon(wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX));
71  ShuttleGui S(this, eIsCreating);
72 
73  S.SetBorder(10);
74  S.StartVerticalLay(false);
75  {
76  S.AddUnits(message);
77  mCheckBox = S.AddCheckBox(footer, wxT("false"));
78  }
79 
80  S.SetBorder(0);
81  S.AddStandardButtons(showCancelButton ? eOkButton | eCancelButton : eOkButton);
82 
83  Fit();
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 wxString &message,
95  bool showCancelButton,
96  const wxString &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 }
113 
114 wxString WarningDialogKey(const wxString &internalDialogName)
115 {
116  return wxT("/Warnings/") + internalDialogName;
117 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
wxString WarningDialogKey(const wxString &internalDialogName)
Definition: Warning.cpp:114
int ShowWarningDialog(wxWindow *parent, const wxString &internalDialogName, const wxString &message, bool showCancelButton, const wxString &footer)
Definition: Warning.cpp:92
void AddUnits(const wxString &Prompt)
Left aligned text string.
Definition: ShuttleGui.cpp:229
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
wxCheckBox * AddCheckBox(const wxString &Prompt, const wxString &Selected)
Definition: ShuttleGui.cpp:267
void OnOK(wxCommandEvent &event)
Definition: Warning.cpp:87
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
Gives a warning message, that can be dismissed, with crucially the ability to not see similar warning...
Definition: Warning.cpp:35
WarningDialog(wxWindow *parent, const wxString &message, const wxString &footer, bool showCancelButton)
Definition: Warning.cpp:61
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxButton *extra=NULL)
END_EVENT_TABLE()
wxCheckBox * mCheckBox
Definition: Warning.cpp:47
void SetBorder(int Border)
Definition: ShuttleGui.h:251
const wxString & DefaultWarningFooter()
Definition: Warning.cpp:56
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:982