1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

Use type aliases CommandID, CommandIDs...

... for identifiers of menu commands and macros, and for vectors thereof
This commit is contained in:
Paul Licameli
2019-03-10 22:05:37 -04:00
parent a30000cf74
commit 5fd6965925
28 changed files with 159 additions and 144 deletions

View File

@@ -13,6 +13,7 @@
#include <wx/string.h>
#include <wx/event.h>
#include "audacity/Types.h"
#include "../MemoryX.h"
#include "Command.h"
@@ -20,7 +21,7 @@ class AudacityProject;
class AudacityApp;
class wxEvent;
class CommandOutputTargets;
using CommandParameter = wxString;
using CommandParameter = CommandID;
class AUDACITY_DLL_API CommandContext {
public:

View File

@@ -746,7 +746,7 @@ void CommandManager::ClearCurrentMenu()
void CommandManager::AddItem(const wxChar *name,
void CommandManager::AddItem(const CommandID &name,
const wxChar *label_in,
bool hasDialog,
CommandHandlerFinder finder,
@@ -767,7 +767,7 @@ void CommandManager::AddItem(const wxChar *name,
if (mask == NoFlagsSpecified)
mask = flags;
wxString cookedParameter;
CommandParameter cookedParameter;
const auto &parameter = options.parameter;
if( parameter.empty() )
cookedParameter = name;
@@ -804,7 +804,7 @@ void CommandManager::AddItem(const wxChar *name,
/// with its position in the list as the index number.
/// When you call Enable on this command name, it will enable or disable
/// all of the items at once.
void CommandManager::AddItemList(const wxString & name,
void CommandManager::AddItemList(const CommandID & name,
const ComponentInterfaceSymbol items[],
size_t nItems,
CommandHandlerFinder finder,
@@ -835,7 +835,7 @@ void CommandManager::AddItemList(const wxString & name,
///
/// Add a command that doesn't appear in a menu. When the key is pressed, the
/// given function pointer will be called (via the CommandManagerListener)
void CommandManager::AddCommand(const wxChar *name,
void CommandManager::AddCommand(const CommandID &name,
const wxChar *label,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
@@ -844,7 +844,7 @@ void CommandManager::AddCommand(const wxChar *name,
AddCommand(name, label, finder, callback, wxT(""), flags);
}
void CommandManager::AddCommand(const wxChar *name,
void CommandManager::AddCommand(const CommandID &name,
const wxChar *label_in,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
@@ -858,7 +858,7 @@ void CommandManager::AddCommand(const wxChar *name,
SetCommandFlags(name, flags, flags);
}
void CommandManager::AddGlobalCommand(const wxChar *name,
void CommandManager::AddGlobalCommand(const CommandID &name,
const wxChar *label_in,
bool hasDialog,
CommandHandlerFinder finder,
@@ -898,14 +898,14 @@ int CommandManager::NextIdentifier(int ID)
///WARNING: Does this conflict with the identifiers set for controls/windows?
///If it does, a workaround may be to keep controls below wxID_LOWEST
///and keep menus above wxID_HIGHEST
CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
CommandListEntry *CommandManager::NewIdentifier(const CommandID & name,
const wxString & label,
const wxString & longLabel,
bool hasDialog,
wxMenu *menu,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
const wxString &nameSuffix,
const CommandID &nameSuffix,
int index,
int count,
bool bIsEffect)
@@ -925,7 +925,7 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
{});
}
CommandListEntry *CommandManager::NewIdentifier(const wxString & nameIn,
CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
const wxString & label,
const wxString & longLabel,
bool hasDialog,
@@ -933,14 +933,14 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & nameIn,
wxMenu *menu,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
const wxString &nameSuffix,
const CommandID &nameSuffix,
int index,
int count,
bool bIsEffect,
const CommandParameter &parameter)
{
const bool multi = !nameSuffix.empty();
wxString name = nameIn;
auto name = nameIn;
// If we have the identifier already, reuse it.
CommandListEntry *prev = mCommandNameHash[name];
@@ -1201,7 +1201,7 @@ void CommandManager::EnableUsingFlags(CommandFlag flags, CommandMask mask)
}
}
bool CommandManager::GetEnabled(const wxString &name)
bool CommandManager::GetEnabled(const CommandID &name)
{
CommandListEntry *entry = mCommandNameHash[name];
if (!entry || !entry->menu) {
@@ -1212,7 +1212,7 @@ bool CommandManager::GetEnabled(const wxString &name)
return entry->enabled;
}
void CommandManager::Check(const wxString &name, bool checked)
void CommandManager::Check(const CommandID &name, bool checked)
{
CommandListEntry *entry = mCommandNameHash[name];
if (!entry || !entry->menu || entry->isOccult) {
@@ -1231,7 +1231,7 @@ void CommandManager::Modify(const wxString &name, const wxString &newLabel)
}
}
void CommandManager::SetKeyFromName(const wxString &name,
void CommandManager::SetKeyFromName(const CommandID &name,
const NormalizedKeyString &key)
{
CommandListEntry *entry = mCommandNameHash[name];
@@ -1330,7 +1330,7 @@ wxString CommandManager::DescribeCommandsAndShortcuts
// was missing from the translation file and defaulted to the English.
auto piece = wxString::Format(wxT("%s%s"), mark, pair.Translated());
wxString name{ pair.Internal() };
auto name = pair.Internal();
if (!name.empty()) {
auto keyStr = GetKeyFromName(name);
if (!keyStr.empty()){
@@ -1541,7 +1541,7 @@ bool CommandManager::HandleMenuID(int id, CommandFlag flags, CommandMask mask)
/// HandleTextualCommand() allows us a limitted version of script/batch
/// behavior, since we can get from a string command name to the actual
/// code to run.
bool CommandManager::HandleTextualCommand(const wxString & Str, const CommandContext & context, CommandFlag flags, CommandMask mask)
bool CommandManager::HandleTextualCommand(const CommandID & Str, const CommandContext & context, CommandFlag flags, CommandMask mask)
{
if( Str.empty() )
return false;
@@ -1622,7 +1622,7 @@ void CommandManager::GetCategories(wxArrayString &cats)
#endif
}
void CommandManager::GetAllCommandNames(wxArrayString &names,
void CommandManager::GetAllCommandNames(CommandIDs &names,
bool includeMultis) const
{
for(const auto &entry : mCommandList) {
@@ -1655,7 +1655,7 @@ void CommandManager::GetAllCommandLabels(wxArrayString &names,
}
void CommandManager::GetAllCommandData(
wxArrayString &names,
CommandIDs &names,
std::vector<NormalizedKeyString> &keys,
std::vector<NormalizedKeyString> &default_keys,
wxArrayString &labels,
@@ -1695,15 +1695,15 @@ void CommandManager::GetAllCommandData(
}
}
wxString CommandManager::GetNameFromID(int id)
CommandID CommandManager::GetNameFromID(int id)
{
CommandListEntry *entry = mCommandIDHash[id];
if (!entry)
return wxT("");
return {};
return entry->name;
}
wxString CommandManager::GetLabelFromName(const wxString &name)
wxString CommandManager::GetLabelFromName(const CommandID &name)
{
CommandListEntry *entry = mCommandNameHash[name];
if (!entry)
@@ -1712,7 +1712,7 @@ wxString CommandManager::GetLabelFromName(const wxString &name)
return entry->longLabel;
}
wxString CommandManager::GetPrefixedLabelFromName(const wxString &name)
wxString CommandManager::GetPrefixedLabelFromName(const CommandID &name)
{
CommandListEntry *entry = mCommandNameHash[name];
if (!entry)
@@ -1729,7 +1729,7 @@ wxString CommandManager::GetPrefixedLabelFromName(const wxString &name)
#endif
}
wxString CommandManager::GetCategoryFromName(const wxString &name)
wxString CommandManager::GetCategoryFromName(const CommandID &name)
{
CommandListEntry *entry = mCommandNameHash[name];
if (!entry)
@@ -1738,7 +1738,7 @@ wxString CommandManager::GetCategoryFromName(const wxString &name)
return entry->labelTop;
}
NormalizedKeyString CommandManager::GetKeyFromName(const wxString &name) const
NormalizedKeyString CommandManager::GetKeyFromName(const CommandID &name) const
{
CommandListEntry *entry =
// May create a NULL entry
@@ -1749,7 +1749,7 @@ NormalizedKeyString CommandManager::GetKeyFromName(const wxString &name) const
return entry->key;
}
NormalizedKeyString CommandManager::GetDefaultKeyFromName(const wxString &name)
NormalizedKeyString CommandManager::GetDefaultKeyFromName(const CommandID &name)
{
CommandListEntry *entry = mCommandNameHash[name];
if (!entry)
@@ -1847,7 +1847,7 @@ void CommandManager::EndOccultCommands()
mTempMenuBar.reset();
}
void CommandManager::SetCommandFlags(const wxString &name,
void CommandManager::SetCommandFlags(const CommandID &name,
CommandFlag flags, CommandMask mask)
{
CommandListEntry *entry = mCommandNameHash[name];

View File

@@ -14,6 +14,8 @@
#include "../Experimental.h"
#include "audacity/Types.h"
#include "CommandFunctors.h"
#include "CommandFlag.h"
@@ -30,8 +32,8 @@
#include <unordered_map>
using CommandParameter = wxString;
class TranslatedInternalString;
using CommandParameter = CommandID;
struct MenuBarListEntry
{
@@ -62,7 +64,7 @@ struct SubMenuListEntry
struct CommandListEntry
{
int id;
wxString name;
CommandID name;
wxString longLabel;
NormalizedKeyString key;
NormalizedKeyString defaultKey;
@@ -178,7 +180,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
bool global{ false };
};
void AddItemList(const wxString & name,
void AddItemList(const CommandID & name,
const ComponentInterfaceSymbol items[],
size_t nItems,
CommandHandlerFinder finder,
@@ -186,7 +188,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
CommandFlag flags,
bool bIsEffect = false);
void AddItem(const wxChar *name,
void AddItem(const CommandID &name,
const wxChar *label_in,
bool hasDialog,
CommandHandlerFinder finder,
@@ -198,13 +200,13 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
// A command doesn't actually appear in a menu but might have a
// keyboard shortcut.
void AddCommand(const wxChar *name,
void AddCommand(const CommandID &name,
const wxChar *label,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
CommandFlag flags);
void AddCommand(const wxChar *name,
void AddCommand(const CommandID &name,
const wxChar *label,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
@@ -216,7 +218,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
void EndOccultCommands();
void SetCommandFlags(const wxString &name, CommandFlag flags, CommandMask mask);
void SetCommandFlags(const CommandID &name, CommandFlag flags, CommandMask mask);
//
// Modifying menus
@@ -224,7 +226,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
void EnableUsingFlags(CommandFlag flags, CommandMask mask);
void Enable(const wxString &name, bool enabled);
void Check(const wxString &name, bool checked);
void Check(const CommandID &name, bool checked);
void Modify(const wxString &name, const wxString &newLabel);
// You may either called SetCurrentMenu later followed by ClearCurrentMenu,
@@ -236,7 +238,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
// Modifying accelerators
//
void SetKeyFromName(const wxString &name, const NormalizedKeyString &key);
void SetKeyFromName(const CommandID &name, const NormalizedKeyString &key);
void SetKeyFromIndex(int i, const NormalizedKeyString &key);
//
@@ -247,19 +249,19 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
// Lyrics and MixerTrackCluster classes use it.
bool FilterKeyEvent(AudacityProject *project, const wxKeyEvent & evt, bool permit = false);
bool HandleMenuID(int id, CommandFlag flags, CommandMask mask);
bool HandleTextualCommand(const wxString & Str, const CommandContext & context, CommandFlag flags, CommandMask mask);
bool HandleTextualCommand(const CommandID & Str, const CommandContext & context, CommandFlag flags, CommandMask mask);
//
// Accessing
//
void GetCategories(wxArrayString &cats);
void GetAllCommandNames(wxArrayString &names, bool includeMultis) const;
void GetAllCommandNames(CommandIDs &names, bool includeMultis) const;
void GetAllCommandLabels(
wxArrayString &labels, std::vector<bool> &vHasDialog,
bool includeMultis) const;
void GetAllCommandData(
wxArrayString &names,
CommandIDs &names,
std::vector<NormalizedKeyString> &keys,
std::vector<NormalizedKeyString> &default_keys,
wxArrayString &labels, wxArrayString &categories,
@@ -268,14 +270,15 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
#endif
bool includeMultis);
wxString GetNameFromID( int id );
wxString GetLabelFromName(const wxString &name);
wxString GetPrefixedLabelFromName(const wxString &name);
wxString GetCategoryFromName(const wxString &name);
NormalizedKeyString GetKeyFromName(const wxString &name) const;
NormalizedKeyString GetDefaultKeyFromName(const wxString &name);
CommandID GetNameFromID( int id );
bool GetEnabled(const wxString &name);
wxString GetLabelFromName(const CommandID &name);
wxString GetPrefixedLabelFromName(const CommandID &name);
wxString GetCategoryFromName(const CommandID &name);
NormalizedKeyString GetKeyFromName(const CommandID &name) const;
NormalizedKeyString GetDefaultKeyFromName(const CommandID &name);
bool GetEnabled(const CommandID &name);
#if defined(__WXDEBUG__)
void CheckDups();
@@ -307,18 +310,18 @@ private:
//
int NextIdentifier(int ID);
CommandListEntry *NewIdentifier(const wxString & name,
CommandListEntry *NewIdentifier(const CommandID & name,
const wxString & label,
const wxString & longLabel,
bool hasDialog,
wxMenu *menu,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
const wxString &nameSuffix,
const CommandID &nameSuffix,
int index,
int count,
bool bIsEffect);
CommandListEntry *NewIdentifier(const wxString & name,
CommandListEntry *NewIdentifier(const CommandID & name,
const wxString & label,
const wxString & longLabel,
bool hasDialog,
@@ -326,13 +329,13 @@ private:
wxMenu *menu,
CommandHandlerFinder finder,
CommandFunctorPointer callback,
const wxString &nameSuffix,
const CommandID &nameSuffix,
int index,
int count,
bool bIsEffect,
const CommandParameter &parameter);
void AddGlobalCommand(const wxChar *name,
void AddGlobalCommand(const CommandID &name,
const wxChar *label,
bool hasDialog,
CommandHandlerFinder finder,
@@ -508,7 +511,7 @@ namespace MenuTable {
};
struct CommandItem final : BaseItem {
CommandItem(const wxString &name_,
CommandItem(const CommandID &name_,
const wxString &label_in_,
bool hasDialog_,
CommandHandlerFinder finder_,
@@ -517,7 +520,7 @@ namespace MenuTable {
const CommandManager::Options &options_);
~CommandItem() override;
const wxString name;
const CommandID name;
const wxString label_in;
bool hasDialog;
CommandHandlerFinder finder;
@@ -608,7 +611,7 @@ namespace MenuTable {
{ return std::make_unique<SeparatorItem>(); }
inline std::unique_ptr<CommandItem> Command(
const wxString &name, const wxString &label_in, bool hasDialog,
const CommandID &name, const wxString &label_in, bool hasDialog,
CommandHandlerFinder finder, CommandFunctorPointer callback,
CommandFlag flags, const CommandManager::Options &options = {})
{

View File

@@ -411,7 +411,7 @@ void GetInfoCommand::ExploreMenu( const CommandContext &context, wxMenu * pMenu,
wxMenuItem * item;
wxString Label;
wxString Accel;
wxString Name;
CommandID Name;
for (size_t lndx = 0; lndx < lcnt; lndx++) {
item = list.Item(lndx)->GetData();

View File

@@ -442,7 +442,7 @@ void ScreenshotCommand::CapturePreferences(
SetIdleHandler( IdleHandler );
gPrefs->Write(wxT("/Prefs/PrefsCategory"), (long)i);
gPrefs->Flush();
wxString Command = "Preferences";
CommandID Command{ wxT("Preferences") };
const CommandContext projectContext( *pProject );
if( !pMan->HandleTextualCommand( Command, projectContext, AlwaysEnabledFlag, AlwaysEnabledFlag ) )
{