separate out Help system functions into their own source file (pending some extra ones) and change the required includes to accomodate this. As a result, some error class definitions have to move from .cpp file to .h file.

This commit is contained in:
RichardAsh1981@gmail.com 2014-06-06 21:34:36 +00:00
parent 149fcafc1c
commit 59b8cdeaa8
10 changed files with 306 additions and 246 deletions

View File

@ -504,6 +504,8 @@ audacity_SOURCES = \
widgets/Grabber.h \
widgets/Grid.cpp \
widgets/Grid.h \
widgets/HelpSystem.cpp \
widgets/HelpSystem.h \
widgets/HtmlWindow.cpp \
widgets/HtmlWindow.h \
widgets/ImageRoll.cpp \

View File

@ -108,7 +108,7 @@ simplifies construction of menu items.
#include "FileDialog.h"
#include "SplashDialog.h"
#include "widgets/ErrorDialog.h"
#include "widgets/HelpSystem.h"
#include "DeviceManager.h"
#include "CaptureEvents.h"

View File

@ -115,6 +115,7 @@ scroll information. It also has some status flags.
#include "DirManager.h"
#include "effects/Effect.h"
#include "prefs/PrefsDialog.h"
#include "widgets/LinkingHtmlWindow.h"
#include "widgets/ErrorDialog.h"
#include "widgets/Meter.h"
#include "widgets/Ruler.h"

View File

@ -65,6 +65,7 @@
#include "../PlatformCompatibility.h"
#include "../FileNames.h"
#include "../Envelope.h"
#include "../widgets/LinkingHtmlWindow.h"
#include "../widgets/ErrorDialog.h"
#include "../FFT.h"
#include "../Prefs.h"

View File

@ -47,7 +47,7 @@
#include "../Project.h"
#include "../Prefs.h"
#include "../Tags.h"
#include "../widgets/ErrorDialog.h"
#include "../widgets/HelpSystem.h"
/* define our dynamic array of export settings */

View File

@ -35,33 +35,10 @@ Gives an Error message with an option for help.
#include "../Internat.h"
#include "../Project.h"
#include "../Prefs.h"
#include "HelpSystem.h"
#include "ErrorDialog.h"
class ErrorDialog : public wxDialog
{
public:
// constructors and destructors
ErrorDialog(wxWindow *parent,
const wxString & dlogTitle,
const wxString & message,
const wxString & helpURL,
const bool Close = true, const bool modal = true);
virtual ~ErrorDialog(){}
private:
wxString dhelpURL;
bool dClose;
bool dModal;
void OnOk( wxCommandEvent &event );
void OnHelp( wxCommandEvent &event );
DECLARE_EVENT_TABLE()
};
// special case for alias missing dialog because we keep track of if it exists.
class AliasedFileMissingDialog : public ErrorDialog
{
@ -165,109 +142,6 @@ void ErrorDialog::OnOk(wxCommandEvent & WXUNUSED(event))
Destroy();
}
// Helper class to make browser "simulate" a modal dialog
class HtmlTextHelpDialog : public BrowserFrame
{
public:
HtmlTextHelpDialog() : BrowserFrame()
{
MakeModal( true );
}
virtual ~HtmlTextHelpDialog()
{
MakeModal( false );
// On Windows, for some odd reason, the Audacity window will be sent to
// the back. So, make sure that doesn't happen.
GetParent()->Raise();
}
};
void ShowHtmlText(wxWindow *pParent,
const wxString &Title,
const wxString &HtmlText,
bool bIsFile = false, bool bModal = false)
{
LinkingHtmlWindow *html;
BrowserFrame * pWnd;
if( bModal )
pWnd = new HtmlTextHelpDialog();
else
pWnd = new BrowserFrame();
pWnd->Create(pParent, wxID_ANY, Title, wxDefaultPosition, wxDefaultSize,
#if defined(__WXMAC__)
// On OSX, the html frame can go behind the help dialog and if the help
// html frame is modal, you can't get back to it. Pressing escape gets
// you out of this, but it's just easier to add the wxSTAY_ON_TOP flag
// to prevent it from falling behind the dialog. Not the perfect solution
// but acceptable in this case.
wxSTAY_ON_TOP |
#endif
wxDEFAULT_FRAME_STYLE);
ShuttleGui S( pWnd, eIsCreating );
S.SetStyle( wxNO_BORDER | wxTAB_TRAVERSAL );
wxPanel *pPan = S.Prop(true).StartPanel();
{
S.StartHorizontalLay( wxEXPAND, false );
{
wxButton * pWndBackwards = S.Id( wxID_BACKWARD ).AddButton( _("<") );
wxButton * pWndForwards = S.Id( wxID_FORWARD ).AddButton( _(">") );
pWndForwards->Enable( false );
pWndBackwards->Enable( false );
#if wxUSE_TOOLTIPS
pWndForwards->SetToolTip( _("Forwards" ));
pWndBackwards->SetToolTip( _("Backwards" ));
#endif
}
S.EndHorizontalLay();
html = new LinkingHtmlWindow(pPan, wxID_ANY,
wxDefaultPosition,
bIsFile ? wxSize(500, 400) : wxSize(480, 240),
wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
html->SetRelatedFrame( pWnd, wxT("Help: %s") );
if( bIsFile )
html->LoadFile( HtmlText );
else
html->SetPage( HtmlText);
S.Prop(1).AddWindow( html, wxEXPAND );
S.Id( wxID_CANCEL ).AddButton( _("Close") )->SetDefault();
}
S.EndPanel();
// -- START of ICON stuff -----
// If this section (providing an icon) causes compilation errors on linux, comment it out for now.
// it will just mean that the icon is missing. Works OK on Windows.
#ifdef __WXMSW__
wxIcon ic(wxICON(AudacityLogo));
#else
wxIcon ic;
ic.CopyFromBitmap(theTheme.Bitmap(bmpAudacityLogo48x48));
#endif
pWnd->SetIcon( ic );
// -- END of ICON stuff -----
pWnd->mpHtml = html;
pWnd->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
pWnd->CreateStatusBar();
pWnd->Centre();
pWnd->Layout();
pWnd->Fit();
pWnd->SetSizeHints(pWnd->GetSize());
pWnd->Show( true );
html->SetRelatedStatusBar( 0 );
html->SetFocus();
return;
}
void ErrorDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
{
@ -333,99 +207,3 @@ void ShowAliasMissingDialog(AudacityProject *parent,
// ANSWER-ME: Vigilant Sentry flags this method as not deleting dlog, so a mem leak.
// ANSWER-ME: Why is this modeless? Shouldn't it require user action before proceeding?
}
/// Mostly we use this so that we have the code for resizability
/// in one place. Other considerations like screen readers are also
/// handled by having the code in one place.
void ShowInfoDialog( wxWindow *parent,
const wxString &dlogTitle,
const wxString &shortMsg,
const wxString &message,
const int xSize, const int ySize)
{
wxDialog dlog(parent, wxID_ANY,
dlogTitle,
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX /*| wxDEFAULT_FRAME_STYLE */);
ShuttleGui S(&dlog, eIsCreating);
S.StartVerticalLay(1);
{
S.AddTitle( shortMsg);
S.SetStyle( wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH | wxTE_RICH2 |
wxTE_AUTO_URL | wxTE_NOHIDESEL | wxHSCROLL );
S.AddTextWindow(message);
}
S.SetBorder( 0 );
S.StartHorizontalLay(wxALIGN_CENTER|wxALIGN_BOTTOM, 0);
S.AddStandardButtons(eOkButton);
S.EndHorizontalLay();
// Next three lines add a tiny dragger.
wxStatusBar * pBar = new wxStatusBar( &dlog );
pBar->SetSize( 18, 38);
S.AddWindow( pBar, wxALIGN_BOTTOM|wxALIGN_RIGHT );
S.EndVerticalLay();
// Smallest size is half default size. Seems reasonable.
dlog.SetMinSize( wxSize(xSize/2, ySize/2) );
dlog.SetSize( wxSize(xSize, ySize) );
dlog.Center();
dlog.ShowModal();
}
void ShowHelpDialog(wxWindow *parent,
const wxString &localFileName,
const wxString &remoteURL)
{
AudacityProject * pProj = GetActiveProject();
wxString HelpMode = wxT("Local");
if( pProj )
{
HelpMode = pProj->mHelpPref;
// these next lines are for legacy cfg files (pre 2.0) where we had different modes
if( (HelpMode == wxT("Standard")) || (HelpMode == wxT("InBrowser")) )
{
HelpMode = wxT("Local");
pProj->mHelpPref = HelpMode;
gPrefs->Write(wxT("/GUI/Help"), HelpMode);
gPrefs->Flush();
}
}
if( localFileName.Contains(wxT("Quick_Help")) )
// 'Quick_Help' is installed locally
OpenInDefaultBrowser( localFileName );
else if( (HelpMode == wxT("FromInternet")) && !remoteURL.IsEmpty() )
{
// Always go to remote URL. Use External browser.
OpenInDefaultBrowser( remoteURL );
}
else if( !wxFileExists( localFileName ))
{
// If you give an empty remote URL, you should have already ensured
// that the file exists!
wxASSERT( !remoteURL.IsEmpty() );
// I can't find it'.
// Use Built-in browser to suggest you use the remote url.
//use the remote link
wxString Text = HelpText( wxT("remotehelp") );
Text.Replace( wxT("*URL*"), remoteURL );
ShowHtmlText( parent, _("Help on the Internet"), Text );
}
else if( HelpMode == wxT("Local") )
{
// Local file, External browser
OpenInDefaultBrowser( wxString(wxT("file:"))+localFileName );
}
else
{
// Local file, Built-in browser
ShowHtmlText( parent, wxT(""), localFileName, true );
}
}

View File

@ -18,6 +18,45 @@
class AudacityProject;
class ErrorDialog : public wxDialog
{
public:
// constructors and destructors
ErrorDialog(wxWindow *parent,
const wxString & dlogTitle,
const wxString & message,
const wxString & helpURL,
const bool Close = true, const bool modal = true);
virtual ~ErrorDialog(){}
private:
wxString dhelpURL;
bool dClose;
bool dModal;
void OnOk( wxCommandEvent &event );
void OnHelp( wxCommandEvent &event );
DECLARE_EVENT_TABLE()
};
// Helper class to make browser "simulate" a modal dialog
class HtmlTextHelpDialog : public BrowserFrame
{
public:
HtmlTextHelpDialog() : BrowserFrame()
{
MakeModal( true );
}
virtual ~HtmlTextHelpDialog()
{
MakeModal( false );
// On Windows, for some odd reason, the Audacity window will be sent to
// the back. So, make sure that doesn't happen.
GetParent()->Raise();
}
};
/// Displays an error dialog with a button that offers help
void ShowErrorDialog(wxWindow *parent,
const wxString &dlogTitle,
@ -39,25 +78,4 @@ void ShowAliasMissingDialog(AudacityProject *parent,
const wxString &helpURL,
const bool Close = true);
/// Displays cutable information in a text ctrl, with an OK button.
void ShowInfoDialog( wxWindow *parent,
const wxString &dlogTitle,
const wxString &shortMsg,
const wxString &message,
const int xSize, const int ySize);
/// Displays a new window with wxHTML help.
void ShowHtmlText( wxWindow * pParent,
const wxString &Title,
const wxString &HtmlText,
bool bIsFile, bool bModal);
/// Displays a file in your browser, if it's available locally,
/// OR else links to the internet.
void ShowHelpDialog(wxWindow *parent,
const wxString &localFileName,
const wxString &remoteURL);
#endif // __AUDACITY_ERRORDIALOG__

217
src/widgets/HelpSystem.cpp Normal file
View File

@ -0,0 +1,217 @@
/**********************************************************************
Audacity: A Digital Audio Editor
HelpSystem.cpp
Jimmy Johnson
Leland Lucius
Richard Ash
*//********************************************************************/
#include "../Audacity.h"
#include <wx/button.h>
#include <wx/icon.h>
#include <wx/dialog.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/utils.h>
#include <wx/html/htmlwin.h>
#include <wx/settings.h>
#include <wx/statusbr.h>
#include "LinkingHtmlWindow.h"
#include "../Theme.h"
#include "../AllThemeResources.h"
#include "../ShuttleGui.h"
#include "../HelpText.h"
#include "../Project.h"
#include "../Prefs.h"
#include "ErrorDialog.h"
#include "HelpSystem.h"
/// Mostly we use this so that we have the code for resizability
/// in one place. Other considerations like screen readers are also
/// handled by having the code in one place.
void ShowInfoDialog( wxWindow *parent,
const wxString &dlogTitle,
const wxString &shortMsg,
const wxString &message,
const int xSize, const int ySize)
{
wxDialog dlog(parent, wxID_ANY,
dlogTitle,
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX /*| wxDEFAULT_FRAME_STYLE */);
ShuttleGui S(&dlog, eIsCreating);
S.StartVerticalLay(1);
{
S.AddTitle( shortMsg);
S.SetStyle( wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH | wxTE_RICH2 |
wxTE_AUTO_URL | wxTE_NOHIDESEL | wxHSCROLL );
S.AddTextWindow(message);
}
S.SetBorder( 0 );
S.StartHorizontalLay(wxALIGN_CENTER|wxALIGN_BOTTOM, 0);
S.AddStandardButtons(eOkButton);
S.EndHorizontalLay();
// Next three lines add a tiny dragger.
wxStatusBar * pBar = new wxStatusBar( &dlog );
pBar->SetSize( 18, 38);
S.AddWindow( pBar, wxALIGN_BOTTOM|wxALIGN_RIGHT );
S.EndVerticalLay();
// Smallest size is half default size. Seems reasonable.
dlog.SetMinSize( wxSize(xSize/2, ySize/2) );
dlog.SetSize( wxSize(xSize, ySize) );
dlog.Center();
dlog.ShowModal();
}
void ShowHtmlText(wxWindow *pParent,
const wxString &Title,
const wxString &HtmlText,
bool bIsFile = false, bool bModal = false)
{
LinkingHtmlWindow *html;
BrowserFrame * pWnd;
if( bModal )
pWnd = new HtmlTextHelpDialog();
else
pWnd = new BrowserFrame();
pWnd->Create(pParent, wxID_ANY, Title, wxDefaultPosition, wxDefaultSize,
#if defined(__WXMAC__)
// On OSX, the html frame can go behind the help dialog and if the help
// html frame is modal, you can't get back to it. Pressing escape gets
// you out of this, but it's just easier to add the wxSTAY_ON_TOP flag
// to prevent it from falling behind the dialog. Not the perfect solution
// but acceptable in this case.
wxSTAY_ON_TOP |
#endif
wxDEFAULT_FRAME_STYLE);
ShuttleGui S( pWnd, eIsCreating );
S.SetStyle( wxNO_BORDER | wxTAB_TRAVERSAL );
wxPanel *pPan = S.Prop(true).StartPanel();
{
S.StartHorizontalLay( wxEXPAND, false );
{
wxButton * pWndBackwards = S.Id( wxID_BACKWARD ).AddButton( _("<") );
wxButton * pWndForwards = S.Id( wxID_FORWARD ).AddButton( _(">") );
pWndForwards->Enable( false );
pWndBackwards->Enable( false );
#if wxUSE_TOOLTIPS
pWndForwards->SetToolTip( _("Forwards" ));
pWndBackwards->SetToolTip( _("Backwards" ));
#endif
}
S.EndHorizontalLay();
html = new LinkingHtmlWindow(pPan, wxID_ANY,
wxDefaultPosition,
bIsFile ? wxSize(500, 400) : wxSize(480, 240),
wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
html->SetRelatedFrame( pWnd, wxT("Help: %s") );
if( bIsFile )
html->LoadFile( HtmlText );
else
html->SetPage( HtmlText);
S.Prop(1).AddWindow( html, wxEXPAND );
S.Id( wxID_CANCEL ).AddButton( _("Close") )->SetDefault();
}
S.EndPanel();
// -- START of ICON stuff -----
// If this section (providing an icon) causes compilation errors on linux, comment it out for now.
// it will just mean that the icon is missing. Works OK on Windows.
#ifdef __WXMSW__
wxIcon ic(wxICON(AudacityLogo));
#else
wxIcon ic;
ic.CopyFromBitmap(theTheme.Bitmap(bmpAudacityLogo48x48));
#endif
pWnd->SetIcon( ic );
// -- END of ICON stuff -----
pWnd->mpHtml = html;
pWnd->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
pWnd->CreateStatusBar();
pWnd->Centre();
pWnd->Layout();
pWnd->Fit();
pWnd->SetSizeHints(pWnd->GetSize());
pWnd->Show( true );
html->SetRelatedStatusBar( 0 );
html->SetFocus();
return;
}
void ShowHelpDialog(wxWindow *parent,
const wxString &localFileName,
const wxString &remoteURL)
{
AudacityProject * pProj = GetActiveProject();
wxString HelpMode = wxT("Local");
if( pProj )
{
HelpMode = pProj->mHelpPref;
// these next lines are for legacy cfg files (pre 2.0) where we had different modes
if( (HelpMode == wxT("Standard")) || (HelpMode == wxT("InBrowser")) )
{
HelpMode = wxT("Local");
pProj->mHelpPref = HelpMode;
gPrefs->Write(wxT("/GUI/Help"), HelpMode);
gPrefs->Flush();
}
}
if( localFileName.Contains(wxT("Quick_Help")) )
// 'Quick_Help' is installed locally
OpenInDefaultBrowser( localFileName );
else if( (HelpMode == wxT("FromInternet")) && !remoteURL.IsEmpty() )
{
// Always go to remote URL. Use External browser.
OpenInDefaultBrowser( remoteURL );
}
else if( !wxFileExists( localFileName ))
{
// If you give an empty remote URL, you should have already ensured
// that the file exists!
wxASSERT( !remoteURL.IsEmpty() );
// I can't find it'.
// Use Built-in browser to suggest you use the remote url.
//use the remote link
wxString Text = HelpText( wxT("remotehelp") );
Text.Replace( wxT("*URL*"), remoteURL );
ShowHtmlText( parent, _("Help on the Internet"), Text );
}
else if( HelpMode == wxT("Local") )
{
// Local file, External browser
OpenInDefaultBrowser( wxString(wxT("file:"))+localFileName );
}
else
{
// Local file, Built-in browser
ShowHtmlText( parent, wxT(""), localFileName, true );
}
}

42
src/widgets/HelpSystem.h Normal file
View File

@ -0,0 +1,42 @@
/**********************************************************************
Audacity: A Digital Audio Editor
ErrorDialog.h
Jimmy Johnson
James Crook
**********************************************************************/
#ifndef __AUDACITY_HELPSYSTEM__
#define __AUDACITY_HELPSYSTEM__
#include "../Audacity.h"
#include <wx/defs.h>
#include <wx/window.h>
class AudacityProject;
/// Displays cutable information in a text ctrl, with an OK button.
void ShowInfoDialog( wxWindow *parent,
const wxString &dlogTitle,
const wxString &shortMsg,
const wxString &message,
const int xSize, const int ySize);
/// Displays a new window with wxHTML help.
void ShowHtmlText( wxWindow * pParent,
const wxString &Title,
const wxString &HtmlText,
bool bIsFile, bool bModal);
/// Displays a file in your browser, if it's available locally,
/// OR else links to the internet.
void ShowHelpDialog(wxWindow *parent,
const wxString &localFileName,
const wxString &remoteURL);
#endif // __AUDACITY_HELPSYSTEM__

View File

@ -25,6 +25,7 @@
#include "../HelpText.h"
#include "../FileNames.h"
#include "ErrorDialog.h"
#include "HelpSystem.h"
BEGIN_EVENT_TABLE(BrowserFrame, wxFrame)
EVT_BUTTON(wxID_FORWARD, BrowserFrame::OnForward)