Audacity  3.0.3
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 *******************************************************************//********************************************************************/
16 
17 
18 #include "ErrorDialog.h"
19 
20 #include <wx/app.h>
21 #include <wx/button.h>
22 #include <wx/collpane.h>
23 #include <wx/icon.h>
24 #include <wx/dialog.h>
25 #include <wx/intl.h>
26 #include <wx/sizer.h>
27 #include <wx/statbmp.h>
28 #include <wx/stattext.h>
29 #include <wx/utils.h>
30 #include <wx/html/htmlwin.h>
31 #include <wx/settings.h>
32 #include <wx/statusbr.h>
33 #include <wx/artprov.h>
34 
35 #include "../AllThemeResources.h"
36 #include "../ShuttleGui.h"
37 #include "../HelpText.h"
38 #include "../Prefs.h"
39 #include "HelpSystem.h"
40 
41 BEGIN_EVENT_TABLE(ErrorDialog, wxDialogWrapper)
42  EVT_COLLAPSIBLEPANE_CHANGED( wxID_ANY, ErrorDialog::OnPane )
43  EVT_BUTTON( wxID_OK, ErrorDialog::OnOk)
44  EVT_BUTTON( wxID_HELP, ErrorDialog::OnHelp)
46 
48  wxWindow *parent,
49  const TranslatableString & dlogTitle,
50  const TranslatableString & message,
51  const wxString & helpPage,
52  const wxString & log,
53  const bool Close, const bool modal)
54 : wxDialogWrapper(parent, wxID_ANY, dlogTitle,
55  wxDefaultPosition, wxDefaultSize,
56  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
57 {
58  SetName();
59 
60  long buttonMask;
61 
62  // only add the help button if we have a URL
63  buttonMask = (helpPage.empty()) ? eOkButton : (eHelpButton | eOkButton);
64  dhelpPage = helpPage;
65  dClose = Close;
66  dModal = modal;
67 
68  ShuttleGui S(this, eIsCreating);
69 
70  S.SetBorder(2);
71  S.StartHorizontalLay(wxEXPAND, 0);
72  {
73  S.SetBorder(20);
74  wxBitmap bitmap = wxArtProvider::GetBitmap(wxART_WARNING);
75  S.AddWindow(safenew wxStaticBitmap(S.GetParent(), -1, bitmap));
76 
77  S.SetBorder(20);
78  S.AddFixedText(message, false, 500);
79  }
80  S.EndHorizontalLay();
81 
82  S.SetBorder(2);
83  if (!log.empty())
84  {
85  S.StartHorizontalLay(wxEXPAND, 1);
86  {
87  S.SetBorder(5);
88 
89  auto pane = safenew wxCollapsiblePane(S.GetParent(),
90  wxID_ANY,
91  XO("Show &Log...").Translation());
92  S.Style(wxEXPAND | wxALIGN_LEFT);
93  S.Prop(1);
94  S.AddWindow(pane);
95 
96  ShuttleGui SI(pane->GetPane(), eIsCreating);
97  auto text = SI.AddTextWindow(log);
98  text->SetInsertionPointEnd();
99  text->ShowPosition(text->GetLastPosition());
100  text->SetMinSize(wxSize(700, 250));
101  }
102  S.EndHorizontalLay();
103  }
104 
105  S.SetBorder(2);
106  S.AddStandardButtons(buttonMask);
107 
108  Layout();
109  GetSizer()->Fit(this);
110  SetMinSize(GetSize());
111  Center();
112 }
113 
114 void ErrorDialog::OnPane(wxCollapsiblePaneEvent & event)
115 {
116  if (!event.GetCollapsed())
117  {
118  Center();
119  }
120 }
121 
122 void ErrorDialog::OnOk(wxCommandEvent & WXUNUSED(event))
123 {
124  if (dModal)
125  EndModal(true);
126  else
127  Destroy();
128 }
129 
130 void ErrorDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
131 {
132  if( dhelpPage.StartsWith(wxT("innerlink:")) )
133  {
135  this,
136  TitleText(dhelpPage.Mid( 10 ) ),
137  HelpText( dhelpPage.Mid( 10 )),
138  false,
139  true );
140  return;
141  }
143  //OpenInDefaultBrowser( dhelpURL );
144  if(dClose)
145  EndModal(true);
146 }
147 
148 void ShowErrorDialog(wxWindow *parent,
149  const TranslatableString &dlogTitle,
150  const TranslatableString &message,
151  const wxString &helpPage,
152  const bool Close,
153  const wxString &log)
154 {
155  ErrorDialog dlog(parent, dlogTitle, message, helpPage, log, Close);
156  dlog.CentreOnParent();
157  dlog.ShowModal();
158 }
159 
160 
161 // unused.
162 void ShowModelessErrorDialog(wxWindow *parent,
163  const TranslatableString &dlogTitle,
164  const TranslatableString &message,
165  const wxString &helpPage,
166  const bool Close,
167  const wxString &log)
168 {
169  // ensure it has some parent.
170  if( !parent )
171  parent = wxTheApp->GetTopWindow();
172  wxASSERT(parent);
173  ErrorDialog *dlog = safenew ErrorDialog(parent, dlogTitle, message, helpPage, log, Close, false);
174  dlog->CentreOnParent();
175  dlog->Show();
176  // ANSWER-ME: Vigilant Sentry flagged this method as not deleting dlog, so
177  // is this actually a mem leak.
178  // PRL: answer is that the parent window guarantees destruction of the dialog
179  // but in practice Destroy() in OnOK does that
180 }
181 
183 {
184  mSetInsertionPointEnd = true;
185 }
186 
188 {
190 
191  if (show && mSetInsertionPointEnd) {
192  // m_textctrl is protected member of wxTextEntryDialog
193  m_textctrl->SetInsertionPointEnd();
194  }
195 
196  return ret;
197 }
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Definition: Types.h:290
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:36
HelpSystem.h
AudacityTextEntryDialog::mSetInsertionPointEnd
bool mSetInsertionPointEnd
Definition: ErrorDialog.h:91
XO
#define XO(s)
Definition: Internat.h:32
ErrorDialog::OnOk
void OnOk(wxCommandEvent &event)
Definition: ErrorDialog.cpp:122
wxTabTraversalWrapper
Definition: wxPanelWrapper.h:24
ErrorDialog::OnHelp
void OnHelp(wxCommandEvent &event)
Definition: ErrorDialog.cpp:130
AudacityTextEntryDialog::SetInsertionPointEnd
void SetInsertionPointEnd()
Definition: ErrorDialog.cpp:182
ShuttleGui::Style
ShuttleGui & Style(long iStyle)
Definition: ShuttleGui.h:734
eOkButton
@ eOkButton
Definition: ShuttleGui.h:607
HelpSystem::ShowHtmlText
static void ShowHtmlText(wxWindow *pParent, const TranslatableString &Title, const wxString &HtmlText, bool bIsFile=false, bool bModal=false)
Definition: HelpSystem.cpp:126
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1170
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1160
eHelpButton
@ eHelpButton
Definition: ShuttleGui.h:611
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:433
AudacityTextEntryDialog::Show
bool Show(bool show=true) override
Definition: ErrorDialog.cpp:187
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:503
ErrorDialog::dClose
bool dClose
Definition: ErrorDialog.h:39
ShuttleGui::Prop
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:732
ShowErrorDialog
void ShowErrorDialog(wxWindow *parent, const TranslatableString &dlogTitle, const TranslatableString &message, const wxString &helpPage, const bool Close, const wxString &log)
Displays an error dialog with a button that offers help.
Definition: ErrorDialog.cpp:148
ErrorDialog::dModal
bool dModal
Definition: ErrorDialog.h:40
ErrorDialog::OnPane
void OnPane(wxCollapsiblePaneEvent &event)
Definition: ErrorDialog.cpp:114
wxDialogWrapper
Definition: wxPanelWrapper.h:81
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow)
Definition: ShuttleGui.cpp:292
HelpSystem::ShowHelp
static void ShowHelp(wxWindow *parent, const wxString &localFileName, const wxString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:238
ErrorDialog.h
ShowModelessErrorDialog
void ShowModelessErrorDialog(wxWindow *parent, const TranslatableString &dlogTitle, const TranslatableString &message, const wxString &helpPage, const bool Close, const wxString &log)
Displays a modeless error dialog with a button that offers help.
Definition: ErrorDialog.cpp:162
ShuttleGuiBase::AddTextWindow
wxTextCtrl * AddTextWindow(const wxString &Value)
Multiline text box that grows.
Definition: ShuttleGui.cpp:705
ErrorDialog
Gives an Error message with an option for help.
Definition: ErrorDialog.h:25
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
HelpText
AUDACITY_DLL_API wxString HelpText(const wxString &Key)
safenew
#define safenew
Definition: MemoryX.h:8
TitleText
AUDACITY_DLL_API TranslatableString TitleText(const wxString &Key)
END_EVENT_TABLE
END_EVENT_TABLE()
ErrorDialog::dhelpPage
wxString dhelpPage
Definition: ErrorDialog.h:38
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:638