From 894b955ac55749f6d118d0595f31c4dc0384daeb Mon Sep 17 00:00:00 2001 From: "RichardAsh1981@gmail.com" Date: Mon, 9 Jun 2014 19:55:14 +0000 Subject: [PATCH] Add a utility overload to open a page from the manual without worrying what it is called (hopefully) in the various copies of the manual --- src/widgets/HelpSystem.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/widgets/HelpSystem.h | 22 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/widgets/HelpSystem.cpp b/src/widgets/HelpSystem.cpp index b64ddd6fc..16c57982a 100644 --- a/src/widgets/HelpSystem.cpp +++ b/src/widgets/HelpSystem.cpp @@ -23,6 +23,7 @@ #include #include +#include "../FileNames.h" #include "LinkingHtmlWindow.h" #include "../Theme.h" #include "../AllThemeResources.h" @@ -34,6 +35,11 @@ #include "ErrorDialog.h" #include "HelpSystem.h" +const wxString HelpSystem::HelpHostname = wxT("manual.audacityteam.org"); +const wxString HelpSystem::HelpServerDir = wxT("/o/man/"); +const wxString HelpSystem::HelpAlphaDir = wxT("/man/"); +const wxString HelpSystem::ReleaseSuffix = wxT(".html"); + /// 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. @@ -215,3 +221,34 @@ void HelpSystem::ShowHelpDialog(wxWindow *parent, ShowHtmlText( parent, wxT(""), localFileName, true ); } } + +void HelpSystem::ShowHelpDialog(wxWindow *parent, const wxString &PageName) +{ + wxString releasePageName(PageName); + wxString localHelpPage; + wxString webHelpPage; + // This bit of code replicates the name transformations performed by the + // clean_filename routine in scripts/mw2html_audacity/mw2html.py: + releasePageName.Replace(wxT("%%"), wxT("_"), true); + releasePageName.Replace(wxT("%25"), wxT("_"), true); + releasePageName.Replace(wxT("%"), wxT("_"), true); + releasePageName.Replace(wxT("-"), wxT("_"), true); + releasePageName.Replace(wxT("__"), wxT("_"), true); + releasePageName.Replace(wxT("_."), wxT("."), true); + releasePageName = releasePageName.Lower()+HelpSystem::ReleaseSuffix; + + localHelpPage = wxFileName(FileNames::HtmlHelpDir()+wxT("/man/"), releasePageName).GetFullPath(); +#if IS_ALPHA + webHelpPage = wxT("http://")+HelpSystem::HelpHostname+HelpSystem::HelpAlphaDir+PageName; +#else + webHelpPage = wxT("http://")+HelpSystem::HelpHostname+HelpSystem::HelpServerDir+releasePageName; +#endif + wxLogMessage(wxT("Help button pressed: PageName %s, releasePageName %s"), + PageName.c_str(), releasePageName.c_str()); + wxLogMessage(wxT("webHelpPage %s, localHelpPage %s"), + webHelpPage.c_str(), localHelpPage.c_str()); + HelpSystem::ShowHelpDialog( + parent, + localHelpPage, + webHelpPage); +} diff --git a/src/widgets/HelpSystem.h b/src/widgets/HelpSystem.h index fe1d89985..90d94cb1e 100644 --- a/src/widgets/HelpSystem.h +++ b/src/widgets/HelpSystem.h @@ -46,6 +46,28 @@ public: static void ShowHelpDialog(wxWindow *parent, const wxString &localFileName, const wxString &remoteURL); + + /// Displays a page from the Audacity manual in your browser, if + /// it's available locally, OR else links to the internet. + /// @param PageName The name of the manual page to display as it is in + /// _development version_ of the manual (i.e. in MediaWiki), _not_ the + /// converted file name used for offline and released manuals + static void ShowHelpDialog(wxWindow *parent, + const wxString &PageName); + + /// Hostname (domain name including subdomain) of the server on which the + /// online help is available + static const wxString HelpHostname; + /// URL path on the help server under which the help pages are located. Must + /// both start and end with '/' characters. + static const wxString HelpServerDir; + /// URL path on the help server under which the development help pages are + /// located. Must both start and end with '/' characters. + static const wxString HelpAlphaDir; + /// The string which is appended to the development manual page name in order + /// obtain the file name in the local and release web copies of the manual + static const wxString ReleaseSuffix; + }; #endif // __AUDACITY_HELPSYSTEM__