1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

HelpSystem.cpp has fewer dependencies...

... There was no reason to store the help location preferences as per-project
state.  Also move the dialog for quick fixes near its only use in
HelpMenus.cpp.

This takes 22 files out of the big strongly connected component, notably
the much used lower level utilities, ErrorDialog and AudacityException.

HelpSystem itself is still in a small cycle with LinkingHtmlWindow.
This commit is contained in:
Paul Licameli 2019-05-11 08:23:07 -04:00
parent 56b1d531b2
commit d68db39b5c
5 changed files with 213 additions and 216 deletions

View File

@ -1473,12 +1473,6 @@ void AudacityProject::UpdatePrefsVariables()
gPrefs->Read(wxT("/AudioFiles/NormalizeOnLoad"),&mNormalizeOnLoad, false);
gPrefs->Read(wxT("/GUI/AutoScroll"), &mViewInfo.bUpdateTrackIndicator, true);
gPrefs->Read(wxT("/GUI/EmptyCanBeDirty"), &mEmptyCanBeDirty, true );
// DA: Default for DA is manual from internet.
#ifdef EXPERIMENTAL_DA
gPrefs->Read(wxT("/GUI/Help"), &mHelpPref, wxT("FromInternet") );
#else
gPrefs->Read(wxT("/GUI/Help"), &mHelpPref, wxT("Local") );
#endif
gPrefs->Read(wxT("/GUI/ShowSplashScreen"), &mShowSplashScreen, true);
gPrefs->Read(wxT("/GUI/Solo"), &mSoloPref, wxT("Simple"));
// Update the old default to the NEW default.

View File

@ -647,7 +647,6 @@ private:
public:
ToolManager *GetToolManager() { return mToolManager.get(); }
bool mShowSplashScreen;
wxString mHelpPref;
wxString mSoloPref;
bool mbBusyImporting{ false }; // used to fix bug 584
int mBatchMode{ 0 };// 0 means not, >0 means in batch mode.

View File

@ -1,18 +1,23 @@
#include "../Audacity.h"
#include "../Experimental.h"
#include <wx/bmpbuttn.h>
#include <wx/textctrl.h>
#include "../AboutDialog.h"
#include "../AllThemeResources.h"
#include "../AudacityLogger.h"
#include "../AudioIO.h"
#include "../CrashReport.h"
#include "../Dependencies.h"
#include "../FileNames.h"
#include "../HelpText.h"
#include "../Menus.h"
#include "../Prefs.h"
#include "../Project.h"
#include "../ShuttleGui.h"
#include "../SplashDialog.h"
#include "../Theme.h"
#include "../commands/CommandContext.h"
#include "../commands/CommandManager.h"
#include "../widgets/ErrorDialog.h"
@ -70,6 +75,203 @@ void ShowDiagnostics(
}
}
/** @brief Class which makes a dialog for displaying quick fixes to common issues.
*
* This class originated with the 'Stuck in a mode' problem, where far too many
* users get into a mode without realising, and don't know how to get out.
* It is a band-aid, and we should do more towards a full and proper solution
* where there are fewer special modes, and they don't persisit.
*/
class QuickFixDialog : public wxDialogWrapper
{
public:
QuickFixDialog(wxWindow * pParent);
void Populate();
void PopulateOrExchange(ShuttleGui & S);
void AddStuck( ShuttleGui & S, bool & bBool, wxString Pref, wxString Prompt, wxString Help );
void OnOk(wxCommandEvent &event);
void OnCancel(wxCommandEvent &event);
void OnHelp(wxCommandEvent &event);
void OnFix(wxCommandEvent &event);
wxString StringFromEvent( wxCommandEvent &event );
int mItem;
bool mbSyncLocked;
bool mbInSnapTo;
bool mbSoundActivated;
DECLARE_EVENT_TABLE()
};
#define FixButtonID 7001
#define HelpButtonID 7011
#define FakeButtonID 7021
BEGIN_EVENT_TABLE(QuickFixDialog, wxDialogWrapper)
EVT_BUTTON(wxID_OK, QuickFixDialog::OnOk)
EVT_BUTTON(wxID_CANCEL, QuickFixDialog::OnCancel)
EVT_BUTTON(wxID_HELP, QuickFixDialog::OnHelp)
EVT_COMMAND_RANGE(FixButtonID, HelpButtonID-1, wxEVT_BUTTON, QuickFixDialog::OnFix)
EVT_COMMAND_RANGE(HelpButtonID, FakeButtonID-1, wxEVT_BUTTON, QuickFixDialog::OnHelp)
END_EVENT_TABLE();
QuickFixDialog::QuickFixDialog(wxWindow * pParent) :
wxDialogWrapper(pParent, wxID_ANY, _("Do you have these problems?"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE )
{
const long SNAP_OFF = 0;
gPrefs->Read(wxT("/GUI/SyncLockTracks"), &mbSyncLocked, false);
mbInSnapTo = gPrefs->Read(wxT("/SnapTo"), SNAP_OFF) !=0;
gPrefs->Read(wxT("/AudioIO/SoundActivatedRecord"), &mbSoundActivated, false);
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
Fit();
auto sz = GetSize();
SetMinSize( sz );
SetMaxSize( sz );
// The close button has the cancel id and acts exactly the same as cancel.
wxButton * pWin = (wxButton*)FindWindowById( wxID_CANCEL );
if( pWin )
pWin->SetFocus( );
Center();
}
void QuickFixDialog::AddStuck( ShuttleGui & S, bool & bBool, wxString Pref, wxString Prompt, wxString Help )
{
mItem++;
if( !bBool)
return;
S.AddFixedText( Prompt );
S.Id(FixButtonID + mItem).AddButton( _("Fix") )->SetClientObject(
safenew wxStringClientData(Pref));
{
// Replace standard Help button with smaller icon button.
// bs->AddButton(safenew wxButton(parent, wxID_HELP));
auto b = safenew wxBitmapButton(S.GetParent(), HelpButtonID+mItem, theTheme.Bitmap( bmpHelpIcon ));
b->SetToolTip( _("Help") );
b->SetLabel(_("Help")); // for screen readers
b->SetClientObject( safenew wxStringClientData( Help ));
S.AddWindow( b );
}
}
void QuickFixDialog::PopulateOrExchange(ShuttleGui & S)
{
S.StartVerticalLay(1);
S.StartStatic( _("Quick Fixes"));
// These aren't all possible modes one can be stuck in, but they are some of them.
bool bStuckInMode = mbSyncLocked || mbInSnapTo || mbSoundActivated;
if( !bStuckInMode ){
SetLabel(_("Nothing to do"));
S.AddFixedText(_("No quick, easily fixed problems were found"));
}
else {
S.StartMultiColumn(3, wxALIGN_CENTER);
{
mItem = -1;
// Use # in the URLs to ensure we go to the online version of help.
// Local help may well not be installed.
AddStuck( S, mbSyncLocked, "/GUI/SyncLockTracks", _("Clocks on the Tracks"), "Quick_Fix#sync_lock" );
AddStuck( S, mbInSnapTo, "/SnapTo", _("Can't select precisely"), "Quick_Fix#snap_to" );
AddStuck( S, mbSoundActivated, "/AudioIO/SoundActivatedRecord", _("Recording stops and starts"), "Quick_Fix#sound_activated_recording" );
}
S.EndMultiColumn();
}
S.EndStatic();
S.StartHorizontalLay(wxALIGN_CENTER_HORIZONTAL, 0);
S.AddStandardButtons(eCloseButton + (bStuckInMode ? 0 : eHelpButton));
S.EndHorizontalLay();
S.EndVerticalLay();
wxButton * pBtn = (wxButton*)FindWindowById( wxID_HELP );
if( pBtn )
pBtn->SetClientObject( safenew wxStringClientData( "Quick_Fix#" ));
}
void QuickFixDialog::OnOk(wxCommandEvent &event)
{
(void)event;// Compiler food
EndModal(wxID_OK);
}
void QuickFixDialog::OnCancel(wxCommandEvent &event)
{
(void)event;// Compiler food
EndModal(wxID_CANCEL);
}
wxString QuickFixDialog::StringFromEvent( wxCommandEvent &event )
{
wxButton * pBtn = (wxButton*)event.GetEventObject();
if( !pBtn ){
wxFAIL_MSG( "Event Object not found");
return "";
}
wxStringClientData * pStrCd = (wxStringClientData*)(pBtn->GetClientObject());
if( !pStrCd ){
wxFAIL_MSG( "Client Data not found");
return "";
}
wxString Str = pStrCd->GetData();
if( Str.empty()){
wxFAIL_MSG( "String data empty");
return "";
}
return Str;
}
void QuickFixDialog::OnHelp(wxCommandEvent &event)
{
HelpSystem::ShowHelp(this, StringFromEvent( event ), true);
}
void QuickFixDialog::OnFix(wxCommandEvent &event)
{
wxString Str = StringFromEvent( event );
gPrefs->Write( Str, 0);
gPrefs->Flush();
if ( auto pProject = GetActiveProject() ) {
// Sadly SnapTo has to be handled specially, as it is not part of the standard
// preference dialogs.
if( Str == "/SnapTo" )
{
pProject->SetSnapTo( 0 );
}
else
{
// This is overkill (aka slow), as all preferences are reloaded and all
// toolbars recreated.
// Overkill probably doesn't matter, as this command is infrequently used.
EditActions::DoReloadPreferences( *pProject );
}
}
// Change the label after doing the fix, as the fix may take a second or two.
wxButton * pBtn = (wxButton*)event.GetEventObject();
if( pBtn )
pBtn->SetLabel( _("Fixed") );
// The close button has the cancel id and acts exactly the same as cancel.
wxButton * pWin = (wxButton*)FindWindowById( wxID_CANCEL );
if( pWin )
pWin->SetFocus( );
}
}
namespace HelpActions {

View File

@ -16,10 +16,12 @@
#include "../Experimental.h"
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/bmpbuttn.h>
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/icon.h>
#include <wx/dialog.h>
#include <wx/intl.h>
#include <wx/log.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
@ -34,8 +36,8 @@
#include "../AllThemeResources.h"
#include "../ShuttleGui.h"
#include "../HelpText.h"
#include "../Project.h"
#include "../Prefs.h"
#include "../wxFileNameWrapper.h"
#ifdef USE_ALPHA_MANUAL
const wxString HelpSystem::HelpHostname = wxT("alphamanual.audacityteam.org");
@ -225,17 +227,20 @@ void HelpSystem::ShowHelp(wxWindow *parent,
bool alwaysDefaultBrowser)
{
wxASSERT(parent); // to justify safenew
AudacityProject * pProj = GetActiveProject();
wxString HelpMode = wxT("Local");
if( pProj )
// DA: Default for DA is manual from internet.
#ifdef EXPERIMENTAL_DA
gPrefs->Read(wxT("/GUI/Help"), &HelpMode, wxT("FromInternet") );
#else
gPrefs->Read(wxT("/GUI/Help"), &HelpMode, wxT("Local") );
#endif
{
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();
}
@ -394,177 +399,3 @@ void HelpSystem::ShowHelp(wxWindow *parent,
bModal
);
}
#include "../ShuttleGui.h"
// These three are all for the OnReloadPreferences command.
#include "../Project.h"
#include "../commands/CommandContext.h"
#include "../Menus.h"
#define FixButtonID 7001
#define HelpButtonID 7011
#define FakeButtonID 7021
BEGIN_EVENT_TABLE(QuickFixDialog, wxDialogWrapper)
EVT_BUTTON(wxID_OK, QuickFixDialog::OnOk)
EVT_BUTTON(wxID_CANCEL, QuickFixDialog::OnCancel)
EVT_BUTTON(wxID_HELP, QuickFixDialog::OnHelp)
EVT_COMMAND_RANGE(FixButtonID, HelpButtonID-1, wxEVT_BUTTON, QuickFixDialog::OnFix)
EVT_COMMAND_RANGE(HelpButtonID, FakeButtonID-1, wxEVT_BUTTON, QuickFixDialog::OnHelp)
END_EVENT_TABLE();
QuickFixDialog::QuickFixDialog(wxWindow * pParent) :
wxDialogWrapper(pParent, wxID_ANY, _("Do you have these problems?"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE )
{
const long SNAP_OFF = 0;
gPrefs->Read(wxT("/GUI/SyncLockTracks"), &mbSyncLocked, false);
mbInSnapTo = gPrefs->Read(wxT("/SnapTo"), SNAP_OFF) !=0;
gPrefs->Read(wxT("/AudioIO/SoundActivatedRecord"), &mbSoundActivated, false);
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
Fit();
auto sz = GetSize();
SetMinSize( sz );
SetMaxSize( sz );
// The close button has the cancel id and acts exactly the same as cancel.
wxButton * pWin = (wxButton*)FindWindowById( wxID_CANCEL );
if( pWin )
pWin->SetFocus( );
Center();
}
void QuickFixDialog::AddStuck( ShuttleGui & S, bool & bBool, wxString Pref, wxString Prompt, wxString Help )
{
mItem++;
if( !bBool)
return;
S.AddFixedText( Prompt );
S.Id(FixButtonID + mItem).AddButton( _("Fix") )->SetClientObject(
safenew wxStringClientData(Pref));
{
// Replace standard Help button with smaller icon button.
// bs->AddButton(safenew wxButton(parent, wxID_HELP));
auto b = safenew wxBitmapButton(S.GetParent(), HelpButtonID+mItem, theTheme.Bitmap( bmpHelpIcon ));
b->SetToolTip( _("Help") );
b->SetLabel(_("Help")); // for screen readers
b->SetClientObject( safenew wxStringClientData( Help ));
S.AddWindow( b );
}
}
void QuickFixDialog::PopulateOrExchange(ShuttleGui & S)
{
S.StartVerticalLay(1);
S.StartStatic( _("Quick Fixes"));
// These aren't all possible modes one can be stuck in, but they are some of them.
bool bStuckInMode = mbSyncLocked || mbInSnapTo || mbSoundActivated;
if( !bStuckInMode ){
SetLabel(_("Nothing to do"));
S.AddFixedText(_("No quick, easily fixed problems were found"));
}
else {
S.StartMultiColumn(3, wxALIGN_CENTER);
{
mItem = -1;
// Use # in the URLs to ensure we go to the online version of help.
// Local help may well not be installed.
AddStuck( S, mbSyncLocked, "/GUI/SyncLockTracks", _("Clocks on the Tracks"), "Quick_Fix#sync_lock" );
AddStuck( S, mbInSnapTo, "/SnapTo", _("Can't select precisely"), "Quick_Fix#snap_to" );
AddStuck( S, mbSoundActivated, "/AudioIO/SoundActivatedRecord", _("Recording stops and starts"), "Quick_Fix#sound_activated_recording" );
}
S.EndMultiColumn();
}
S.EndStatic();
S.StartHorizontalLay(wxALIGN_CENTER_HORIZONTAL, 0);
S.AddStandardButtons(eCloseButton + (bStuckInMode ? 0 : eHelpButton));
S.EndHorizontalLay();
S.EndVerticalLay();
wxButton * pBtn = (wxButton*)FindWindowById( wxID_HELP );
if( pBtn )
pBtn->SetClientObject( safenew wxStringClientData( "Quick_Fix#" ));
}
void QuickFixDialog::OnOk(wxCommandEvent &event)
{
(void)event;// Compiler food
EndModal(wxID_OK);
}
void QuickFixDialog::OnCancel(wxCommandEvent &event)
{
(void)event;// Compiler food
EndModal(wxID_CANCEL);
}
wxString QuickFixDialog::StringFromEvent( wxCommandEvent &event )
{
wxButton * pBtn = (wxButton*)event.GetEventObject();
if( !pBtn ){
wxFAIL_MSG( "Event Object not found");
return "";
}
wxStringClientData * pStrCd = (wxStringClientData*)(pBtn->GetClientObject());
if( !pStrCd ){
wxFAIL_MSG( "Client Data not found");
return "";
}
wxString Str = pStrCd->GetData();
if( Str.empty()){
wxFAIL_MSG( "String data empty");
return "";
}
return Str;
}
void QuickFixDialog::OnHelp(wxCommandEvent &event)
{
HelpSystem::ShowHelp(this, StringFromEvent( event ), true);
}
void QuickFixDialog::OnFix(wxCommandEvent &event)
{
wxString Str = StringFromEvent( event );
gPrefs->Write( Str, 0);
gPrefs->Flush();
if ( auto pProject = GetActiveProject() ) {
// Sadly SnapTo has to be handled specially, as it is not part of the standard
// preference dialogs.
if( Str == "/SnapTo" )
{
pProject->SetSnapTo( 0 );
}
else
{
// This is overkill (aka slow), as all preferences are reloaded and all
// toolbars recreated.
// Overkill probably doesn't matter, as this command is infrequently used.
EditActions::DoReloadPreferences( *pProject );
}
}
// Change the label after doing the fix, as the fix may take a second or two.
wxButton * pBtn = (wxButton*)event.GetEventObject();
if( pBtn )
pBtn->SetLabel( _("Fixed") );
// The close button has the cancel id and acts exactly the same as cancel.
wxButton * pWin = (wxButton*)FindWindowById( wxID_CANCEL );
if( pWin )
pWin->SetFocus( );
}

View File

@ -104,33 +104,4 @@ public:
class ShuttleGui;
/** @brief Class which makes a dialog for displaying quick fixes to common issues.
*
* This class originated with the 'Stuck in a mode' problem, where far too many
* users get into a mode without realising, and don't know how to get out.
* It is a band-aid, and we should do more towards a full and proper solution
* where there are fewer special modes, and they don't persisit.
*/
class QuickFixDialog : public wxDialogWrapper
{
public:
QuickFixDialog(wxWindow * pParent);
void Populate();
void PopulateOrExchange(ShuttleGui & S);
void AddStuck( ShuttleGui & S, bool & bBool, wxString Pref, wxString Prompt, wxString Help );
void OnOk(wxCommandEvent &event);
void OnCancel(wxCommandEvent &event);
void OnHelp(wxCommandEvent &event);
void OnFix(wxCommandEvent &event);
wxString StringFromEvent( wxCommandEvent &event );
int mItem;
bool mbSyncLocked;
bool mbInSnapTo;
bool mbSoundActivated;
DECLARE_EVENT_TABLE()
};
#endif // __AUDACITY_HELPSYSTEM__