1 /**********************************************************************
2 
3   Audacity: A Digital Audio Editor
4 
5   ErrorDialog.cpp
6 
7   Jimmy Johnson
8   Leland Lucius
9 
10 *******************************************************************//**
11 
12 \class ErrorDialog
13 \brief Gives an Error message with an option for help.
14 
15 *//********************************************************************/
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 
BEGIN_EVENT_TABLE(ErrorDialog,wxDialogWrapper)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)
47 END_EVENT_TABLE()
48 
49 ErrorDialog::ErrorDialog(
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 
OnPane(wxCollapsiblePaneEvent & event)116 void ErrorDialog::OnPane(wxCollapsiblePaneEvent & event)
117 {
118    if (!event.GetCollapsed())
119    {
120       Center();
121    }
122 }
123 
OnOk(wxCommandEvent & WXUNUSED (event))124 void ErrorDialog::OnOk(wxCommandEvent & WXUNUSED(event))
125 {
126    if (dModal)
127       EndModal(true);
128    else
129       Destroy();
130 }
131 
OnHelp(wxCommandEvent & WXUNUSED (event))132 void ErrorDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
133 {
134    const auto &str = dhelpPage.GET();
135    if( str.StartsWith(wxT("innerlink:")) )
136    {
137       HelpSystem::ShowHtmlText(
138          this,
139          TitleText(str.Mid( 10 ) ),
140          HelpText( str.Mid( 10 )),
141          false,
142          true );
143       return;
144    }
145    HelpSystem::ShowHelp( this, dhelpPage, dClose );
146    //OpenInDefaultBrowser( dhelpURL );
147    if(dClose)
148       EndModal(true);
149 }
150