Audacity  2.2.2
ErrorDialog.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ErrorDialog.cpp
6 
7  Jimmy Johnson
8  Leland Lucius
9 
10 *******************************************************************//*****************************************************************//********************************************************************/
21 
22 #include "../Audacity.h"
23 
24 #include <wx/button.h>
25 #include <wx/icon.h>
26 #include <wx/dialog.h>
27 #include <wx/intl.h>
28 #include <wx/sizer.h>
29 #include <wx/stattext.h>
30 #include <wx/utils.h>
31 #include <wx/html/htmlwin.h>
32 #include <wx/settings.h>
33 #include <wx/statusbr.h>
34 
35 #include "LinkingHtmlWindow.h"
36 #include "../Theme.h"
37 #include "../AllThemeResources.h"
38 #include "../ShuttleGui.h"
39 #include "../HelpText.h"
40 #include "../Internat.h"
41 #include "../Project.h"
42 #include "../Prefs.h"
43 #include "HelpSystem.h"
44 
45 #include "ErrorDialog.h"
46 
47 // special case for alias missing dialog because we keep track of if it exists.
49 {
50  public:
52  const wxString & dlogTitle,
53  const wxString & message,
54  const wxString & helpURL,
55  const bool Close = true, const bool modal = true);
56  virtual ~AliasedFileMissingDialog();
57 };
58 
59 BEGIN_EVENT_TABLE(ErrorDialog, wxDialogWrapper)
60  EVT_BUTTON( wxID_OK, ErrorDialog::OnOk)
61  EVT_BUTTON( wxID_HELP, ErrorDialog::OnHelp)
63 
64 
66  const wxString & dlogTitle,
67  const wxString & message,
68  const wxString & helpURL,
69  const bool Close, const bool modal):
70 ErrorDialog(parent, dlogTitle, message, helpURL, Close, modal)
71 {
72  parent->SetMissingAliasFileDialog(this);
73 }
74 
76 {
77  ((AudacityProject*)GetParent())->SetMissingAliasFileDialog(NULL);
78 }
79 
81  wxWindow *parent,
82  const wxString & dlogTitle,
83  const wxString & message,
84  const wxString & helpPage,
85  const bool Close, const bool modal):
86  wxDialogWrapper(parent, (wxWindowID)-1, dlogTitle)
87 {
88  SetName(GetTitle());
89 
90  long buttonMask;
91 
92  // only add the help button if we have a URL
93  buttonMask = (helpPage == wxT("")) ? eOkButton : (eHelpButton | eOkButton);
94  dhelpPage = helpPage;
95  dClose = Close;
96  dModal = modal;
97 
98  ShuttleGui S(this, eIsCreating);
99 
100  S.StartVerticalLay();
101  {
102  S.SetBorder( 20 );
103  S.AddFixedText( message );
104  S.SetBorder( 2 );
105  S.AddStandardButtons( buttonMask );
106  }
107  S.EndVerticalLay();
108 
109  Layout();
110  GetSizer()->Fit(this);
111  SetMinSize(GetSize());
112  Center();
113 
114 #if 0
115  // Original non ShuttleGui based code.
116  // Layout did not look good on Windows.
117  wxBoxSizer mainSizer;
118  {
119  auto uMainSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
120  mainSizer = uMainSizer.get();
121  auto vSizer = make_unique<xBoxSizer>(wxVERTICAL);
122 
123  auto hSizer = make_unique<wxBoxSizer>(wxHORIZONTAL);
124 
125  wxStaticText *statText = safenew wxStaticText(this, -1, message);
126  mainSizer->Add(statText, 0, wxALIGN_LEFT|wxALL, 5);
127 
128  wxButton *help = safenew wxButton(this, wxID_HELP, _("Help"));
129  hSizer->Add(help, 0, wxALIGN_LEFT|wxALL, 5);
130 
131  wxButton *ok = safenew wxButton(this, wxID_OK, _("OK"));
132  ok->SetDefault();
133  ok->SetFocus();
134  hSizer->Add(ok, 0, wxALIGN_RIGHT|wxALL, 5);
135 
136  vSizer->Add(hSizer.release(), 0, wxALIGN_CENTER|wxALL, 5);
137 
138  mainSizer->Add(vSizer.release(), 0, wxALL, 15 );
139 
140  SetAutoLayout(true);
141  SetSizer(uMainSizer.release());
142  }
143 
144  mainSizer->Fit(this);
145  mainSizer->SetSizeHints(this);
146 #endif
147 }
148 
149 void ErrorDialog::OnOk(wxCommandEvent & WXUNUSED(event))
150 {
151  if (dModal)
152  EndModal(true);
153  else
154  Destroy();
155 }
156 
157 
158 void ErrorDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
159 {
160  if( dhelpPage.StartsWith(wxT("innerlink:")) )
161  {
163  this,
164  TitleText(dhelpPage.Mid( 10 ) ),
165  HelpText( dhelpPage.Mid( 10 )),
166  false,
167  true );
168  return;
169  }
171  //OpenInDefaultBrowser( dhelpURL );
172  if(dClose)
173  EndModal(true);
174 }
175 
176 void ShowErrorDialog(wxWindow *parent,
177  const wxString &dlogTitle,
178  const wxString &message,
179  const wxString &helpPage,
180  const bool Close)
181 {
182  ErrorDialog dlog(parent, dlogTitle, message, helpPage, Close);
183  dlog.CentreOnParent();
184  dlog.ShowModal();
185 }
186 
187 
188 // unused.
189 void ShowModelessErrorDialog(wxWindow *parent,
190  const wxString &dlogTitle,
191  const wxString &message,
192  const wxString &helpPage,
193  const bool Close)
194 {
195  // ensure it has some parent.
196  if( !parent )
197  parent = wxTheApp->GetTopWindow();
198  wxASSERT(parent);
199  ErrorDialog *dlog = safenew ErrorDialog(parent, dlogTitle, message, helpPage, Close, false);
200  dlog->CentreOnParent();
201  dlog->Show();
202  // ANSWER-ME: Vigilant Sentry flagged this method as not deleting dlog, so
203  // is this actually a mem leak.
204  // PRL: answer is that the parent window guarantees destruction of the dialog
205  // but in practice Destroy() in OnOK does that
206 }
207 
209  const wxString &dlogTitle,
210  const wxString &message,
211  const wxString &helpPage,
212  const bool Close)
213 {
214  wxASSERT(parent); // to justify safenew
215  ErrorDialog *dlog = safenew AliasedFileMissingDialog(parent, dlogTitle, message, helpPage, Close, false);
216  // Don't center because in many cases (effect, export, etc) there will be a progress bar in the center that blocks this.
217  // instead put it just above or on the top of the project.
218  wxPoint point;
219  point.x = 0;
220 
221  point.y = parent ? parent->GetPosition().y - 200 : 100;
222 
223  if (point.y < 100)
224  point.y = 100;
225  dlog->SetPosition(point);
226  dlog->CentreOnParent(wxHORIZONTAL);
227 
228  // This needs to be modeless because user may need to
229  // stop playback AND read dialog's instructions.
230  dlog->Show();
231  // ANSWER-ME: Vigilant Sentry flags this method as not deleting dlog, so a mem leak.
232  // PRL: answer is that the parent window guarantees destruction of the dialog
233  // but in practice Destroy() in OnOK does that
234 }
235 
237 {
238  return _("Message");
239 }
240 
242 {
243  // m_textctrl is protected member of wxTextEntryDialog
244  m_textctrl->SetInsertionPointEnd();
245 }
wxString AudacityMessageBoxCaptionStr()
AliasedFileMissingDialog(AudacityProject *parent, const wxString &dlogTitle, const wxString &message, const wxString &helpURL, const bool Close=true, const bool modal=true)
Definition: ErrorDialog.cpp:65
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
void OnOk(wxCommandEvent &event)
void OnHelp(wxCommandEvent &event)
void ShowErrorDialog(wxWindow *parent, const wxString &dlogTitle, const wxString &message, const wxString &helpPage, const bool Close)
Displays an error dialog with a button that offers help.
#define safenew
Definition: Audacity.h:230
static void ShowHtmlText(wxWindow *pParent, const wxString &Title, const wxString &HtmlText, bool bIsFile=false, bool bModal=false)
Definition: HelpSystem.cpp:89
ErrorDialog(wxWindow *parent, const wxString &dlogTitle, const wxString &message, const wxString &helpPage, const bool Close=true, const bool modal=true)
Definition: ErrorDialog.cpp:80
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
void EndVerticalLay()
void SetInsertionPointEnd()
void ShowModelessErrorDialog(wxWindow *parent, const wxString &dlogTitle, const wxString &message, const wxString &helpPage, const bool Close)
Displays a modeless error dialog with a button that offers help.
wxString HelpText(const wxString &Key)
Definition: HelpText.cpp:298
virtual ~AliasedFileMissingDialog()
Definition: ErrorDialog.cpp:75
static void ShowHelp(wxWindow *parent, const wxString &localFileName, const wxString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:194
void AddFixedText(const wxString &Str, bool bCenter=false)
Definition: ShuttleGui.cpp:397
void ShowAliasMissingDialog(AudacityProject *parent, const wxString &dlogTitle, const wxString &message, const wxString &helpPage, const bool Close)
Displays a custom modeless error dialog for aliased file errors.
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
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxButton *extra=NULL)
END_EVENT_TABLE()
Special case of ErrorDialog for reporting missing alias files.
Definition: ErrorDialog.cpp:48
void SetBorder(int Border)
Definition: ShuttleGui.h:286
Gives an Error message with an option for help.
Definition: ErrorDialog.h:24
wxString TitleText(const wxString &Key)
Definition: HelpText.cpp:139
wxString dhelpPage
Definition: ErrorDialog.h:37
void StartVerticalLay(int iProp=1)