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.AddFixedText(message);
77  mCheckBox = S.AddCheckBox(footer, wxT("false"));
78  }
79  S.EndVerticalLay();
80 
81  S.SetBorder(0);
82  S.AddStandardButtons(showCancelButton ? eOkButton | eCancelButton : eOkButton);
83 
84  Fit();
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 wxString &message,
96  bool showCancelButton,
97  const wxString &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 }
114 
115 wxString WarningDialogKey(const wxString &internalDialogName)
116 {
117  return wxT("/Warnings/") + internalDialogName;
118 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
wxString WarningDialogKey(const wxString &internalDialogName)
Definition: Warning.cpp:115
int ShowWarningDialog(wxWindow *parent, const wxString &internalDialogName, const wxString &message, bool showCancelButton, const wxString &footer)
Definition: Warning.cpp:93
void EndVerticalLay()
wxCheckBox * AddCheckBox(const wxString &Prompt, const wxString &Selected)
Definition: ShuttleGui.cpp:298
void OnOK(wxCommandEvent &event)
Definition: Warning.cpp:88
void AddFixedText(const wxString &Str, bool bCenter=false)
Definition: ShuttleGui.cpp:397
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
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:286
const wxString & DefaultWarningFooter()
Definition: Warning.cpp:56
void StartVerticalLay(int iProp=1)