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

Move TellUserWhyDisallowed into MenuManager...

... so we don't have MenuManager calling CommandManager which calls it back.
This commit is contained in:
Paul Licameli 2019-06-14 08:35:36 -04:00
parent 76996bf0cd
commit f9b0281b47
4 changed files with 72 additions and 70 deletions

View File

@ -54,6 +54,7 @@
#include "prefs/TracksPrefs.h"
#include "toolbars/ControlToolBar.h"
#include "toolbars/ToolManager.h"
#include "widgets/ErrorDialog.h"
#include <wx/menu.h>
#include <wx/windowptr.h>
@ -941,7 +942,7 @@ bool MenuManager::ReportIfActionNotAllowed(
if( bAllowed )
return true;
auto &cm = CommandManager::Get( project );
cm.TellUserWhyDisallowed( Name, flags & flagsRqd, flagsRqd);
TellUserWhyDisallowed( Name, flags & flagsRqd, flagsRqd);
return false;
}
@ -978,3 +979,70 @@ bool MenuManager::TryToMakeActionAllowed(
}
return (flags & flagsRqd) == flagsRqd;
}
void MenuManager::TellUserWhyDisallowed(
const wxString & Name, CommandFlag flagsGot, CommandFlag flagsRequired )
{
// The default string for 'reason' is a catch all. I hope it won't ever be seen
// and that we will get something more specific.
wxString reason = _("There was a problem with your last action. If you think\nthis is a bug, please tell us exactly where it occurred.");
// The default title string is 'Disallowed'.
wxString title = _("Disallowed");
wxString helpPage;
auto missingFlags = flagsRequired & ~flagsGot;
if( (missingFlags & AudioIONotBusyFlag).any() )
// This reason will not be shown, because options that require it will be greyed our.
reason = _("You can only do this when playing and recording are\nstopped. (Pausing is not sufficient.)");
else if( (missingFlags & StereoRequiredFlag).any() )
// This reason will not be shown, because the stereo-to-mono is greyed out if not allowed.
reason = _("You must first select some stereo audio to perform this\naction. (You cannot use this with mono.)");
// In reporting the issue with cut or copy, we don't tell the user they could also select some text in a label.
else if( (
( missingFlags & TimeSelectedFlag ) |
( missingFlags & CutCopyAvailableFlag )
).any() ){
title = _("No Audio Selected");
#ifdef EXPERIMENTAL_DA
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
reason = wxString::Format( _("You must first select some audio for '%s' to act on.\n\nCtrl + A selects all audio."), Name );
#else
#ifdef __WXMAC__
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
reason = wxString::Format( _("Select the audio for %s to use (for example, Cmd + A to Select All) then try again."
// No need to explain what a help button is for.
// "\n\nClick the Help button to learn more about selection methods."
), Name );
#else
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
reason = wxString::Format( _("Select the audio for %s to use (for example, Ctrl + A to Select All) then try again."
// No need to explain what a help button is for.
// "\n\nClick the Help button to learn more about selection methods."
), Name );
#endif
#endif
helpPage = "Selecting_Audio_-_the_basics";
}
else if( (missingFlags & WaveTracksSelectedFlag).any() )
reason = _("You must first select some audio to perform this action.\n(Selecting other kinds of track won't work.)");
else if ( (missingFlags & TracksSelectedFlag).any() )
// i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
reason = wxString::Format(_("\"%s\" requires one or more tracks to be selected."), Name);
// If the only thing wrong was no tracks, we do nothing and don't report a problem
else if( missingFlags == TracksExistFlag )
return;
// Likewise return if it was just no tracks, and track panel did not have focus. (e.g. up-arrow to move track)
else if( missingFlags == (TracksExistFlag | TrackPanelHasFocus) )
return;
// Likewise as above too...
else if( missingFlags == TrackPanelHasFocus )
return;
// Does not have the warning icon...
ShowErrorDialog(
NULL,
title,
reason,
helpPage);
}

View File

@ -87,6 +87,9 @@ public:
private:
void TellUserWhyDisallowed(const wxString & Name, CommandFlag flagsGot,
CommandFlag flagsRequired);
void OnUndoRedo( wxCommandEvent &evt );
AudacityProject &mProject;

View File

@ -101,7 +101,6 @@ CommandManager. It holds the callback for one command.
#include "../effects/EffectManager.h"
#include "../widgets/LinkingHtmlWindow.h"
#include "../widgets/AudacityMessageBox.h"
#include "../widgets/ErrorDialog.h"
#include "../widgets/HelpSystem.h"
@ -1021,73 +1020,6 @@ void CommandManager::SetKeyFromIndex(int i, const NormalizedKeyString &key)
entry->key = key;
}
void CommandManager::TellUserWhyDisallowed(
const wxString & Name, CommandFlag flagsGot, CommandFlag flagsRequired )
{
// The default string for 'reason' is a catch all. I hope it won't ever be seen
// and that we will get something more specific.
wxString reason = _("There was a problem with your last action. If you think\nthis is a bug, please tell us exactly where it occurred.");
// The default title string is 'Disallowed'.
wxString title = _("Disallowed");
wxString helpPage;
auto missingFlags = flagsRequired & ~flagsGot;
if( (missingFlags & AudioIONotBusyFlag).any() )
// This reason will not be shown, because options that require it will be greyed our.
reason = _("You can only do this when playing and recording are\nstopped. (Pausing is not sufficient.)");
else if( (missingFlags & StereoRequiredFlag).any() )
// This reason will not be shown, because the stereo-to-mono is greyed out if not allowed.
reason = _("You must first select some stereo audio to perform this\naction. (You cannot use this with mono.)");
// In reporting the issue with cut or copy, we don't tell the user they could also select some text in a label.
else if( (
( missingFlags & TimeSelectedFlag ) |
( missingFlags & CutCopyAvailableFlag )
).any() ){
title = _("No Audio Selected");
#ifdef EXPERIMENTAL_DA
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
reason = wxString::Format( _("You must first select some audio for '%s' to act on.\n\nCtrl + A selects all audio."), Name );
#else
#ifdef __WXMAC__
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
reason = wxString::Format( _("Select the audio for %s to use (for example, Cmd + A to Select All) then try again."
// No need to explain what a help button is for.
// "\n\nClick the Help button to learn more about selection methods."
), Name );
#else
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
reason = wxString::Format( _("Select the audio for %s to use (for example, Ctrl + A to Select All) then try again."
// No need to explain what a help button is for.
// "\n\nClick the Help button to learn more about selection methods."
), Name );
#endif
#endif
helpPage = "Selecting_Audio_-_the_basics";
}
else if( (missingFlags & WaveTracksSelectedFlag).any() )
reason = _("You must first select some audio to perform this action.\n(Selecting other kinds of track won't work.)");
else if ( (missingFlags & TracksSelectedFlag).any() )
// i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
reason = wxString::Format(_("\"%s\" requires one or more tracks to be selected."), Name);
// If the only thing wrong was no tracks, we do nothing and don't report a problem
else if( missingFlags == TracksExistFlag )
return;
// Likewise return if it was just no tracks, and track panel did not have focus. (e.g. up-arrow to move track)
else if( missingFlags == (TracksExistFlag | TrackPanelHasFocus) )
return;
// Likewise as above too...
else if( missingFlags == TrackPanelHasFocus )
return;
// Does not have the warning icon...
ShowErrorDialog(
NULL,
title,
reason,
helpPage);
}
wxString CommandManager::DescribeCommandsAndShortcuts
(const TranslatedInternalString commands[], size_t nCommands) const
{

View File

@ -286,7 +286,6 @@ class AUDACITY_DLL_API CommandManager final
//
void WriteXML(XMLWriter &xmlFile) const /* not override */;
void TellUserWhyDisallowed(const wxString & Name, CommandFlag flagsGot, CommandFlag flagsRequired);
///
/// Formatting summaries that include shortcut keys