1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-30 15:49:41 +02:00

Clarifying name change in CommandManager & simplify PluginMenus...

... The purpose of the boolean field in command entries was to exclude certain
menu commands from being steps in macros, because they require user interaction.

Effects are never meant to be excluded, even though they normally have dialogs,
but in the context of macro execution, the parameters are supplied by other
means.
This commit is contained in:
Paul Licameli 2019-12-12 13:37:33 -05:00
parent db96d1ab10
commit 5cbafc6086
5 changed files with 33 additions and 53 deletions

View File

@ -320,17 +320,17 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
auto &manager = CommandManager::Get( *project );
wxArrayString mLabels;
CommandIDs mNames;
std::vector<bool> vHasDialog;
std::vector<bool> vExcludeFromMacros;
mLabels.clear();
mNames.clear();
manager.GetAllCommandLabels(mLabels, vHasDialog, true);
manager.GetAllCommandLabels(mLabels, vExcludeFromMacros, true);
manager.GetAllCommandNames(mNames, true);
const bool english = wxGetLocale()->GetCanonicalName().StartsWith(wxT("en"));
for(size_t i=0; i<mNames.size(); i++) {
wxString label = mLabels[i];
if( !vHasDialog[i] ){
if( !vExcludeFromMacros[i] ){
wxString label = mLabels[i];
label.Replace( "&", "" );
bool suffix;
if (!english)

View File

@ -134,12 +134,12 @@ SeparatorItem::~SeparatorItem() {}
CommandItem::CommandItem(const CommandID &name_,
const wxString &label_in_,
bool hasDialog_,
bool excludeFromMacros_,
CommandHandlerFinder finder_,
CommandFunctorPointer callback_,
CommandFlag flags_,
const CommandManager::Options &options_)
: name{ name_ }, label_in{ label_in_ }, hasDialog{ hasDialog_ }
: name{ name_ }, label_in{ label_in_ }, excludeFromMacros{ excludeFromMacros_ }
, finder{ finder_ }, callback{ callback_ }
, flags{ flags_ }, options{ options_ }
{}
@ -193,7 +193,7 @@ void VisitItem( AudacityProject &project, MenuTable::BaseItem *pItem )
if (const auto pCommand =
dynamic_cast<CommandItem*>( pItem )) {
manager.AddItem(
pCommand->name, pCommand->label_in, pCommand->hasDialog,
pCommand->name, pCommand->label_in, pCommand->excludeFromMacros,
pCommand->finder, pCommand->callback,
pCommand->flags, pCommand->options
);

View File

@ -505,7 +505,7 @@ void CommandManager::ClearCurrentMenu()
void CommandManager::AddItem(const CommandID &name,
const wxChar *label_in,
bool hasDialog,
bool excludeFromMacros,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
CommandFlag flags,
@ -514,7 +514,7 @@ void CommandManager::AddItem(const CommandID &name,
if (options.global) {
wxASSERT( flags == AlwaysEnabledFlag );
AddGlobalCommand(
name, label_in, hasDialog, finder, callback, options );
name, label_in, excludeFromMacros, finder, callback, options );
return;
}
@ -523,7 +523,7 @@ void CommandManager::AddItem(const CommandID &name,
CommandListEntry *entry =
NewIdentifier(name,
label_in,
hasDialog,
excludeFromMacros,
CurrentMenu(), finder, callback,
{}, 0, 0,
options);
@ -564,7 +564,7 @@ void CommandManager::AddItemList(const CommandID & name,
CommandListEntry *entry =
NewIdentifier(name,
items[i].Translation(),
// No means yet to specify hasDialog !
// No means yet to specify excludeFromMacros !
false,
CurrentMenu(),
finder,
@ -582,13 +582,13 @@ void CommandManager::AddItemList(const CommandID & name,
void CommandManager::AddGlobalCommand(const CommandID &name,
const wxChar *label_in,
bool hasDialog,
bool excludeFromMacros,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
const Options &options)
{
CommandListEntry *entry =
NewIdentifier(name, label_in, hasDialog, NULL, finder, callback,
NewIdentifier(name, label_in, excludeFromMacros, NULL, finder, callback,
{}, 0, 0, options);
entry->enabled = false;
@ -621,7 +621,7 @@ int CommandManager::NextIdentifier(int ID)
///and keep menus above wxID_HIGHEST
CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
const wxString & label,
bool hasDialog,
bool excludeFromMacros,
wxMenu *menu,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
@ -695,7 +695,7 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
// long label is the same as label unless options specified otherwise:
entry->longLabel = longLabel.empty() ? label : longLabel;
entry->hasDialog = hasDialog;
entry->excludeFromMacros = excludeFromMacros;
entry->key = NormalizedKeyString{ accel.BeforeFirst(wxT('\t')) };
entry->defaultKey = entry->key;
entry->labelPrefix = labelPrefix;
@ -1267,10 +1267,10 @@ void CommandManager::GetAllCommandNames(CommandIDs &names,
}
void CommandManager::GetAllCommandLabels(wxArrayString &names,
std::vector<bool> &vHasDialog,
std::vector<bool> &vExcludeFromMacros,
bool includeMultis) const
{
vHasDialog.clear();
vExcludeFromMacros.clear();
for(const auto &entry : mCommandList) {
// This is fetching commands from the menus, for use as batch commands.
// Until we have properly merged EffectManager and CommandManager
@ -1279,9 +1279,9 @@ void CommandManager::GetAllCommandLabels(wxArrayString &names,
if ( entry->isEffect )
continue;
if (!entry->multi)
names.push_back(entry->longLabel), vHasDialog.push_back(entry->hasDialog);
names.push_back(entry->longLabel), vExcludeFromMacros.push_back(entry->excludeFromMacros);
else if( includeMultis )
names.push_back(entry->longLabel), vHasDialog.push_back(entry->hasDialog);
names.push_back(entry->longLabel), vExcludeFromMacros.push_back(entry->excludeFromMacros);
}
}

View File

@ -79,7 +79,7 @@ struct CommandListEntry
bool isGlobal;
bool isOccult;
bool isEffect;
bool hasDialog;
bool excludeFromMacros;
CommandFlag flags;
bool useStrictFlags{ false };
};
@ -184,7 +184,7 @@ class AUDACITY_DLL_API CommandManager final
void AddItem(const CommandID &name,
const wxChar *label_in,
bool hasDialog,
bool excludeFromMacros,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
CommandFlag flags,
@ -247,7 +247,7 @@ class AUDACITY_DLL_API CommandManager final
void GetCategories(wxArrayString &cats);
void GetAllCommandNames(CommandIDs &names, bool includeMultis) const;
void GetAllCommandLabels(
wxArrayString &labels, std::vector<bool> &vHasDialog,
wxArrayString &labels, std::vector<bool> &vExcludeFromMacros,
bool includeMultis) const;
void GetAllCommandData(
CommandIDs &names,
@ -302,7 +302,7 @@ private:
int NextIdentifier(int ID);
CommandListEntry *NewIdentifier(const CommandID & name,
const wxString & label,
bool hasDialog,
bool excludeFromMacros,
wxMenu *menu,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
@ -313,7 +313,7 @@ private:
void AddGlobalCommand(const CommandID &name,
const wxChar *label,
bool hasDialog,
bool excludeFromMacros,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
const Options &options = {});
@ -490,7 +490,7 @@ namespace MenuTable {
struct CommandItem final : BaseItem {
CommandItem(const CommandID &name_,
const wxString &label_in_,
bool hasDialog_,
bool excludeFromMacros_,
CommandHandlerFinder finder_,
CommandFunctorPointer callback_,
CommandFlag flags_,
@ -499,7 +499,7 @@ namespace MenuTable {
const CommandID name;
const wxString label_in;
bool hasDialog;
bool excludeFromMacros;
CommandHandlerFinder finder;
CommandFunctorPointer callback;
CommandFlag flags;
@ -588,12 +588,12 @@ namespace MenuTable {
{ return std::make_unique<SeparatorItem>(); }
inline std::unique_ptr<CommandItem> Command(
const CommandID &name, const wxString &label_in, bool hasDialog,
const CommandID &name, const wxString &label_in, bool excludeFromMacros,
CommandHandlerFinder finder, CommandFunctorPointer callback,
CommandFlag flags, const CommandManager::Options &options = {})
{
return std::make_unique<CommandItem>(
name, label_in, hasDialog, finder, callback, flags, options
name, label_in, excludeFromMacros, finder, callback, flags, options
);
}

View File

@ -182,23 +182,10 @@ bool CompareEffectsByType(const PluginDescriptor *a, const PluginDescriptor *b)
void AddEffectMenuItemGroup(
MenuTable::BaseItemPtrs &table,
const wxArrayString & names,
const std::vector<bool> &vHasDialog,
const PluginIDs & plugs,
const std::vector<CommandFlag> & flags,
bool isDefault);
namespace
{
inline bool HasDialog( const PluginDescriptor *plug )
{
// Un-translated string is expected to follow a certain convention
// Translation, perhaps, uses some other punctuation
return plug->GetSymbol().Msgid().MSGID().GET().Contains("...");
}
}
void AddEffectMenuItems(
MenuTable::BaseItemPtrs &table,
std::vector<const PluginDescriptor*> & plugs,
@ -225,7 +212,6 @@ void AddEffectMenuItems(
return batchflags;
};
std::vector<bool> vHasDialog;
wxArrayString groupNames;
PluginIDs groupPlugs;
std::vector<CommandFlag> groupFlags;
@ -238,7 +224,6 @@ void AddEffectMenuItems(
{
const PluginDescriptor *plug = plugs[i];
bool hasDialog = HasDialog( plug );
auto name = plug->GetSymbol().Translation();
if (plug->IsEffectInteractive())
@ -270,7 +255,7 @@ void AddEffectMenuItems(
bool bInSubmenu = !last.empty() && (groupNames.size() > 1);
AddEffectMenuItemGroup(temp,
groupNames, vHasDialog,
groupNames,
groupPlugs, groupFlags, isDefault);
table.push_back( MenuOrItems(
@ -278,14 +263,12 @@ void AddEffectMenuItems(
) );
groupNames.clear();
vHasDialog.clear();
groupPlugs.clear();
groupFlags.clear();
last = current;
}
groupNames.push_back(name);
vHasDialog.push_back(hasDialog);
groupPlugs.push_back(plug->GetID());
groupFlags.push_back(
plug->IsEffectRealtime() ? realflags : getBatchFlags( plug ) );
@ -298,7 +281,7 @@ void AddEffectMenuItems(
bool bInSubmenu = groupNames.size() > 1;
AddEffectMenuItemGroup(temp,
groupNames, vHasDialog, groupPlugs, groupFlags, isDefault);
groupNames, groupPlugs, groupFlags, isDefault);
table.push_back( MenuOrItems(
( bInSubmenu ? current : wxString{} ), std::move( temp )
@ -311,7 +294,6 @@ void AddEffectMenuItems(
{
const PluginDescriptor *plug = plugs[i];
bool hasDialog = HasDialog( plug );
auto name = plug->GetSymbol().Translation();
if (plug->IsEffectInteractive())
@ -339,7 +321,6 @@ void AddEffectMenuItems(
? name
: wxString::Format(_("%s: %s"), group, name)
);
vHasDialog.push_back(hasDialog);
groupPlugs.push_back(plug->GetID());
groupFlags.push_back(
plug->IsEffectRealtime() ? realflags : getBatchFlags( plug ) );
@ -348,7 +329,7 @@ void AddEffectMenuItems(
if (groupNames.size() > 0)
{
AddEffectMenuItemGroup(
table, groupNames, vHasDialog, groupPlugs, groupFlags, isDefault);
table, groupNames, groupPlugs, groupFlags, isDefault);
}
}
@ -614,7 +595,6 @@ namespace {
void AddEffectMenuItemGroup(
MenuTable::BaseItemPtrs &table,
const wxArrayString & names,
const std::vector<bool> &vHasDialog,
const PluginIDs & plugs,
const std::vector<CommandFlag> & flags,
bool isDefault)
@ -678,7 +658,7 @@ void AddEffectMenuItemGroup(
if( plug->GetPluginType() == PluginTypeEffect )
temp2.push_back( Command( item,
item,
item.Contains("..."),
false,
FN(OnEffect),
flags[i],
CommandManager::Options{}
@ -697,7 +677,7 @@ void AddEffectMenuItemGroup(
if( plug->GetPluginType() == PluginTypeEffect )
pTable->push_back( Command( names[i],
names[i],
vHasDialog[i],
false,
FN(OnEffect),
flags[i],
CommandManager::Options{}