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/textctrl.h>
34 #include <wx/artprov.h>
35 
36 #include "../AllThemeResources.h"
37 #include "CodeConversions.h"
38 #include "../ShuttleGui.h"
39 #include "../HelpText.h"
40 #include "Prefs.h"
41 #include "HelpSystem.h"
42 
43 BEGIN_EVENT_TABLE(ErrorDialog, wxDialogWrapper)
44  EVT_COLLAPSIBLEPANE_CHANGED( wxID_ANY, ErrorDialog::OnPane )
45  EVT_BUTTON( wxID_OK, ErrorDialog::OnOk)
46  EVT_BUTTON( wxID_HELP, ErrorDialog::OnHelp)
48 
50  wxWindow *parent,
51  const TranslatableString & dlogTitle,
52  const TranslatableString & message,
53  const ManualPageID & helpPage,
54  const std::wstring & log,
55  const bool Close, const bool modal)
56 : wxDialogWrapper(parent, wxID_ANY, dlogTitle,
57  wxDefaultPosition, wxDefaultSize,
58  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
59 {
60  SetName();
61 
62  long buttonMask;
63 
64  // only add the help button if we have a URL
65  buttonMask = (helpPage.empty()) ? eOkButton : (eHelpButton | eOkButton);
66  dhelpPage = helpPage;
67  dClose = Close;
68  dModal = modal;
69 
70  ShuttleGui S(this, eIsCreating);
71 
72  S.SetBorder(2);
73  S.StartHorizontalLay(wxEXPAND, 0);
74  {
75  S.SetBorder(20);
76  wxBitmap bitmap = wxArtProvider::GetBitmap(wxART_WARNING);
77  S.AddWindow(safenew wxStaticBitmap(S.GetParent(), -1, bitmap));
78 
79  S.SetBorder(20);
80  S.AddFixedText(message, false, 500);
81  }
82  S.EndHorizontalLay();
83 
84  S.SetBorder(2);
85  if (!log.empty())
86  {
87  S.StartHorizontalLay(wxEXPAND, 1);
88  {
89  S.SetBorder(5);
90 
91  auto pane = safenew wxCollapsiblePane(S.GetParent(),
92  wxID_ANY,
93  XO("Show &Log...").Translation());
94  S.Style(wxEXPAND | wxALIGN_LEFT);
95  S.Prop(1);
96  S.AddWindow(pane);
97 
98  ShuttleGui SI(pane->GetPane(), eIsCreating);
99  auto text = SI.AddTextWindow(log);
100  text->SetInsertionPointEnd();
101  text->ShowPosition(text->GetLastPosition());
102  text->SetMinSize(wxSize(700, 250));
103  }
104  S.EndHorizontalLay();
105  }
106 
107  S.SetBorder(2);
108  S.AddStandardButtons(buttonMask);
109 
110  Layout();
111  GetSizer()->Fit(this);
112  SetMinSize(GetSize());
113  Center();
114 }
115 
116 void ErrorDialog::OnPane(wxCollapsiblePaneEvent & event)
117 {
118  if (!event.GetCollapsed())
119  {
120  Center();
121  }
122 }
123 
124 void ErrorDialog::OnOk(wxCommandEvent & WXUNUSED(event))
125 {
126  if (dModal)
127  EndModal(true);
128  else
129  Destroy();
130 }
131 
132 void ErrorDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
133 {
134  const auto &str = dhelpPage.GET();
135  if( str.StartsWith(wxT("innerlink:")) )
136  {
138  this,
139  TitleText(str.Mid( 10 ) ),
140  HelpText( str.Mid( 10 )),
141  false,
142  true );
143  return;
144  }
146  //OpenInDefaultBrowser( dhelpURL );
147  if(dClose)
148  EndModal(true);
149 }
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
HelpSystem.h
eHelpButton
@ eHelpButton
Definition: ShuttleGui.h:604
ErrorDialog::dhelpPage
ManualPageID dhelpPage
Definition: ErrorDialog.h:39
XO
#define XO(s)
Definition: Internat.h:31
ErrorDialog::OnOk
void OnOk(wxCommandEvent &event)
Definition: ErrorDialog.cpp:124
HelpSystem::ShowHelp
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:237
ErrorDialog::OnHelp
void OnHelp(wxCommandEvent &event)
Definition: ErrorDialog.cpp:132
ShuttleGui::Style
ShuttleGui & Style(long iStyle)
Definition: ShuttleGui.h:727
HelpSystem::ShowHtmlText
static void ShowHtmlText(wxWindow *pParent, const TranslatableString &Title, const wxString &HtmlText, bool bIsFile=false, bool bModal=false)
Definition: HelpSystem.cpp:125
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:440
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:496
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:299
ErrorDialog::dClose
bool dClose
Definition: ErrorDialog.h:40
ShuttleGui::Prop
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:725
Identifier::GET
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
ErrorDialog::dModal
bool dModal
Definition: ErrorDialog.h:41
ErrorDialog::OnPane
void OnPane(wxCollapsiblePaneEvent &event)
Definition: ErrorDialog.cpp:116
wxDialogWrapper
Definition: wxPanelWrapper.h:81
eOkButton
@ eOkButton
Definition: ShuttleGui.h:600
TaggedIdentifier< ManualPageIDTag >
ErrorDialog.h
ShuttleGuiBase::AddTextWindow
wxTextCtrl * AddTextWindow(const wxString &Value)
Multiline text box that grows.
Definition: ShuttleGui.cpp:712
ErrorDialog
Gives an Error message with an option for help.
Definition: ErrorDialog.h:26
ShuttleGui::AddStandardButtons
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxWindow *extra=NULL)
Definition: ShuttleGui.cpp:2432
Prefs.h
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
CodeConversions.h
Declare functions to preform UTF-8 to std::wstring conversions.
HelpText
AUDACITY_DLL_API wxString HelpText(const wxString &Key)
safenew
#define safenew
Definition: MemoryX.h:10
TitleText
AUDACITY_DLL_API TranslatableString TitleText(const wxString &Key)
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