mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-23 17:30:17 +01:00
Construct MenuItem with untranslated label, so it can be static...
... and other storage of TranslatableString instead of naked wxString, for management of menu items, in CommandManager
This commit is contained in:
@@ -112,7 +112,7 @@ CommandManager. It holds the callback for one command.
|
||||
#define MAX_SUBMENU_LEN 1000
|
||||
#endif
|
||||
|
||||
#define COMMAND _("Command")
|
||||
#define COMMAND XO("Command")
|
||||
|
||||
|
||||
NonKeystrokeInterceptingWindow::~NonKeystrokeInterceptingWindow()
|
||||
@@ -133,17 +133,11 @@ MenuBarListEntry::~MenuBarListEntry()
|
||||
}
|
||||
|
||||
SubMenuListEntry::SubMenuListEntry(
|
||||
const wxString &name_, std::unique_ptr<wxMenu> &&menu_ )
|
||||
const TranslatableString &name_, std::unique_ptr<wxMenu> menu_ )
|
||||
: name(name_), menu( std::move(menu_) )
|
||||
{
|
||||
}
|
||||
|
||||
SubMenuListEntry::SubMenuListEntry(SubMenuListEntry &&that)
|
||||
: name(std::move(that.name))
|
||||
, menu(std::move(that.menu))
|
||||
{
|
||||
}
|
||||
|
||||
SubMenuListEntry::~SubMenuListEntry()
|
||||
{
|
||||
}
|
||||
@@ -371,7 +365,7 @@ void CommandManager::PopMenuBar()
|
||||
///
|
||||
/// This starts a NEW menu
|
||||
///
|
||||
wxMenu *CommandManager::BeginMenu(const wxString & tName)
|
||||
wxMenu *CommandManager::BeginMenu(const TranslatableString & tName)
|
||||
{
|
||||
if ( mCurrentMenu )
|
||||
return BeginSubMenu( tName );
|
||||
@@ -396,7 +390,7 @@ void CommandManager::EndMenu()
|
||||
///
|
||||
/// This starts a NEW menu
|
||||
///
|
||||
wxMenu *CommandManager::BeginMainMenu(const wxString & tName)
|
||||
wxMenu *CommandManager::BeginMainMenu(const TranslatableString & tName)
|
||||
{
|
||||
uCurrentMenu = std::make_unique<wxMenu>();
|
||||
mCurrentMenu = uCurrentMenu.get();
|
||||
@@ -414,7 +408,8 @@ void CommandManager::EndMainMenu()
|
||||
// added to the menu to allow OSX to rearrange special menu
|
||||
// items like Preferences, About, and Quit.
|
||||
wxASSERT(uCurrentMenu);
|
||||
CurrentMenuBar()->Append(uCurrentMenu.release(), mCurrentMenuName);
|
||||
CurrentMenuBar()->Append(
|
||||
uCurrentMenu.release(), mCurrentMenuName.Translation());
|
||||
mCurrentMenu = nullptr;
|
||||
mCurrentMenuName = COMMAND;
|
||||
}
|
||||
@@ -423,7 +418,7 @@ void CommandManager::EndMainMenu()
|
||||
///
|
||||
/// This starts a NEW submenu, and names it according to
|
||||
/// the function's argument.
|
||||
wxMenu* CommandManager::BeginSubMenu(const wxString & tName)
|
||||
wxMenu* CommandManager::BeginSubMenu(const TranslatableString & tName)
|
||||
{
|
||||
mSubMenuList.push_back
|
||||
(std::make_unique< SubMenuListEntry > ( tName, std::make_unique<wxMenu>() ));
|
||||
@@ -445,8 +440,9 @@ void CommandManager::EndSubMenu()
|
||||
mSubMenuList.pop_back();
|
||||
|
||||
//Add the submenu to the current menu
|
||||
CurrentMenu()->Append
|
||||
(0, tmpSubMenu.name, tmpSubMenu.menu.release(), tmpSubMenu.name);
|
||||
auto name = tmpSubMenu.name.Translation();
|
||||
CurrentMenu()->Append(0, name, tmpSubMenu.menu.release(),
|
||||
name /* help string */ );
|
||||
mbSeparatorAllowed = true;
|
||||
}
|
||||
|
||||
@@ -656,7 +652,7 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
||||
{
|
||||
auto entry = std::make_unique<CommandListEntry>();
|
||||
|
||||
wxString labelPrefix;
|
||||
TranslatableString labelPrefix;
|
||||
if (!mSubMenuList.empty()) {
|
||||
labelPrefix = mSubMenuList.back()->name;
|
||||
}
|
||||
@@ -699,7 +695,7 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
||||
entry->key = NormalizedKeyString{ accel.BeforeFirst(wxT('\t')) };
|
||||
entry->defaultKey = entry->key;
|
||||
entry->labelPrefix = labelPrefix;
|
||||
entry->labelTop = wxMenuItem::GetLabelText(mCurrentMenuName);
|
||||
entry->labelTop = wxMenuItem::GetLabelText(mCurrentMenuName.Translation());
|
||||
entry->menu = menu;
|
||||
entry->finder = finder;
|
||||
entry->callback = callback;
|
||||
@@ -1203,7 +1199,7 @@ CommandManager::HandleTextualCommand(const CommandID & Str,
|
||||
// PRL: uh oh, mixing internal string (Str) with user-visible
|
||||
// (labelPrefix, which was initialized from a user-visible
|
||||
// sub-menu name)
|
||||
Str == entry->labelPrefix )
|
||||
Str == entry->labelPrefix.Translation() )
|
||||
{
|
||||
return HandleCommandEntry( entry.get(), flags, alwaysEnabled)
|
||||
? CommandSuccess : CommandFailure;
|
||||
@@ -1292,7 +1288,7 @@ void CommandManager::GetAllCommandData(
|
||||
wxArrayString &labels,
|
||||
wxArrayString &categories,
|
||||
#if defined(EXPERIMENTAL_KEY_VIEW)
|
||||
wxArrayString &prefixes,
|
||||
TranslatableStrings &prefixes,
|
||||
#endif
|
||||
bool includeMultis)
|
||||
{
|
||||
@@ -1352,11 +1348,11 @@ wxString CommandManager::GetPrefixedLabelFromName(const CommandID &name)
|
||||
#if defined(EXPERIMENTAL_KEY_VIEW)
|
||||
wxString prefix;
|
||||
if (!entry->labelPrefix.empty()) {
|
||||
prefix = entry->labelPrefix + wxT(" - ");
|
||||
prefix = entry->labelPrefix.Translation() + wxT(" - ");
|
||||
}
|
||||
return wxMenuItem::GetLabelText(prefix + entry->label);
|
||||
#else
|
||||
return wxString(entry->labelPrefix + wxT(" ") + entry->label).Trim(false).Trim(true);
|
||||
return wxString(entry->labelPrefix.Translation() + wxT(" ") + entry->label).Trim(false).Trim(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,11 @@ struct MenuBarListEntry
|
||||
|
||||
struct SubMenuListEntry
|
||||
{
|
||||
SubMenuListEntry(const wxString &name_, std::unique_ptr<wxMenu> &&menu_);
|
||||
SubMenuListEntry(SubMenuListEntry &&that);
|
||||
SubMenuListEntry(const TranslatableString &name_, std::unique_ptr<wxMenu> menu_);
|
||||
SubMenuListEntry( SubMenuListEntry&& ) = default;
|
||||
~SubMenuListEntry();
|
||||
|
||||
wxString name;
|
||||
TranslatableString name;
|
||||
std::unique_ptr<wxMenu> menu;
|
||||
};
|
||||
|
||||
@@ -64,7 +64,7 @@ struct CommandListEntry
|
||||
NormalizedKeyString key;
|
||||
NormalizedKeyString defaultKey;
|
||||
wxString label;
|
||||
wxString labelPrefix;
|
||||
TranslatableString labelPrefix;
|
||||
wxString labelTop;
|
||||
wxMenu *menu;
|
||||
CommandHandlerFinder finder;
|
||||
@@ -136,7 +136,7 @@ class AUDACITY_DLL_API CommandManager final
|
||||
|
||||
// You may either called SetCurrentMenu later followed by ClearCurrentMenu,
|
||||
// or else BeginMenu followed by EndMenu. Don't mix them.
|
||||
wxMenu *BeginMenu(const wxString & tName);
|
||||
wxMenu *BeginMenu(const TranslatableString & tName);
|
||||
void EndMenu();
|
||||
|
||||
// For specifying unusual arguments in AddItem
|
||||
@@ -259,7 +259,7 @@ class AUDACITY_DLL_API CommandManager final
|
||||
std::vector<NormalizedKeyString> &default_keys,
|
||||
wxArrayString &labels, wxArrayString &categories,
|
||||
#if defined(EXPERIMENTAL_KEY_VIEW)
|
||||
wxArrayString &prefixes,
|
||||
TranslatableStrings &prefixes,
|
||||
#endif
|
||||
bool includeMultis);
|
||||
|
||||
@@ -332,9 +332,9 @@ private:
|
||||
//
|
||||
|
||||
void Enable(CommandListEntry *entry, bool enabled);
|
||||
wxMenu *BeginMainMenu(const wxString & tName);
|
||||
wxMenu *BeginMainMenu(const TranslatableString & tName);
|
||||
void EndMainMenu();
|
||||
wxMenu* BeginSubMenu(const wxString & tName);
|
||||
wxMenu* BeginSubMenu(const TranslatableString & tName);
|
||||
void EndSubMenu();
|
||||
|
||||
//
|
||||
@@ -374,7 +374,7 @@ private:
|
||||
|
||||
bool mbSeparatorAllowed; // false at the start of a menu and immediately after a separator.
|
||||
|
||||
wxString mCurrentMenuName;
|
||||
TranslatableString mCurrentMenuName;
|
||||
std::unique_ptr<wxMenu> uCurrentMenu;
|
||||
wxMenu *mCurrentMenu {};
|
||||
|
||||
@@ -456,16 +456,17 @@ namespace MenuTable {
|
||||
|
||||
struct MenuItem final : GroupItem {
|
||||
// Construction from a previously built-up vector of pointers
|
||||
MenuItem( const wxString &title_, BaseItemPtrs &&items_ );
|
||||
MenuItem( const TranslatableString &title_, BaseItemPtrs &&items_ );
|
||||
// In-line, variadic constructor that doesn't require building a vector
|
||||
template< typename... Args >
|
||||
MenuItem( const wxString &title_, Args&&... args )
|
||||
MenuItem(
|
||||
const TranslatableString &title_, Args&&... args )
|
||||
: GroupItem{ std::forward<Args>(args)... }
|
||||
, title{ title_ }
|
||||
{}
|
||||
~MenuItem() override;
|
||||
|
||||
wxString title; // translated
|
||||
TranslatableString title;
|
||||
};
|
||||
|
||||
struct ConditionalGroupItem final : GroupItem {
|
||||
@@ -552,11 +553,11 @@ namespace MenuTable {
|
||||
// Items will appear in a main toolbar menu or in a sub-menu
|
||||
template< typename... Args >
|
||||
inline BaseItemPtr Menu(
|
||||
const wxString &title, Args&&... args )
|
||||
const TranslatableString &title, Args&&... args )
|
||||
{ return std::make_unique<MenuItem>(
|
||||
title, std::forward<Args>(args)... ); }
|
||||
inline BaseItemPtr Menu(
|
||||
const wxString &title, BaseItemPtrs &&items )
|
||||
const TranslatableString &title, BaseItemPtrs &&items )
|
||||
{ return std::make_unique<MenuItem>( title, std::move( items ) ); }
|
||||
|
||||
// Conditional group items can be constructed two ways, as for group items
|
||||
@@ -575,12 +576,12 @@ namespace MenuTable {
|
||||
// of the title
|
||||
template< typename... Args >
|
||||
inline BaseItemPtr MenuOrItems(
|
||||
const wxString &title, Args&&... args )
|
||||
const TranslatableString &title, Args&&... args )
|
||||
{ if ( title.empty() ) return Items( std::forward<Args>(args)... );
|
||||
else return std::make_unique<MenuItem>(
|
||||
title, std::forward<Args>(args)... ); }
|
||||
inline BaseItemPtr MenuOrItems(
|
||||
const wxString &title, BaseItemPtrs &&items )
|
||||
const TranslatableString &title, BaseItemPtrs &&items )
|
||||
{ if ( title.empty() ) return Items( std::move( items ) );
|
||||
else return std::make_unique<MenuItem>( title, std::move( items ) ); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user