CommandManager stores labels as TranslatableString
This commit is contained in:
parent
f16709945b
commit
5639f834c8
|
@ -318,7 +318,7 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
|
|||
}
|
||||
|
||||
auto &manager = CommandManager::Get( *project );
|
||||
wxArrayString mLabels;
|
||||
TranslatableStrings mLabels;
|
||||
CommandIDs mNames;
|
||||
std::vector<bool> vExcludeFromMacros;
|
||||
mLabels.clear();
|
||||
|
@ -330,8 +330,8 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
|
|||
|
||||
for(size_t i=0; i<mNames.size(); i++) {
|
||||
if( !vExcludeFromMacros[i] ){
|
||||
wxString label = mLabels[i];
|
||||
label.Replace( "&", "" );
|
||||
auto label = mLabels[i];
|
||||
label.Strip();
|
||||
bool suffix;
|
||||
if (!english)
|
||||
suffix = false;
|
||||
|
@ -343,7 +343,7 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
|
|||
// Disambiguation is no longer essential as the details box will show it.
|
||||
// PRL: I think this reasoning applies only when locale is English.
|
||||
// For other locales, show the (CamelCaseCodeName) always. Or, never?
|
||||
wxString squashed = label;
|
||||
wxString squashed = label.Translation();
|
||||
squashed.Replace( " ", "" );
|
||||
|
||||
// uh oh, using GET for dubious comparison of (lengths of)
|
||||
|
@ -356,13 +356,16 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
|
|||
// uh oh, using GET to expose CommandID to the user, as a
|
||||
// disambiguating suffix on a name, but this is only ever done if
|
||||
// the locale is English!
|
||||
label = label + " (" + mNames[i].GET() + ")";
|
||||
// PRL: In case this logic does get fixed for other locales,
|
||||
// localize even this punctuation format. I'm told Chinese actually
|
||||
// prefers slightly different parenthesis characters
|
||||
label.Join( XO("(%s)").Format( mNames[i].GET() ), wxT(" ") );
|
||||
|
||||
commands.push_back(
|
||||
{
|
||||
{
|
||||
mNames[i], // Internal name.
|
||||
label // User readable name
|
||||
label.Translation() // User readable name
|
||||
},
|
||||
_("Menu Command (No Parameters)")
|
||||
}
|
||||
|
|
|
@ -324,27 +324,25 @@ void MenuManager::ModifyUndoMenuItems(AudacityProject &project)
|
|||
if (undoManager.UndoAvailable()) {
|
||||
undoManager.GetShortDescription(cur, &desc);
|
||||
commandManager.Modify(wxT("Undo"),
|
||||
wxString::Format(_("&Undo %s"),
|
||||
desc));
|
||||
XO("&Undo %s").Format( desc ));
|
||||
commandManager.Enable(wxT("Undo"),
|
||||
ProjectHistory::Get( project ).UndoAvailable());
|
||||
}
|
||||
else {
|
||||
commandManager.Modify(wxT("Undo"),
|
||||
_("&Undo"));
|
||||
XO("&Undo"));
|
||||
}
|
||||
|
||||
if (undoManager.RedoAvailable()) {
|
||||
undoManager.GetShortDescription(cur+1, &desc);
|
||||
commandManager.Modify(wxT("Redo"),
|
||||
wxString::Format(_("&Redo %s"),
|
||||
desc));
|
||||
XO("&Redo %s").Format( desc));
|
||||
commandManager.Enable(wxT("Redo"),
|
||||
ProjectHistory::Get( project ).RedoAvailable());
|
||||
}
|
||||
else {
|
||||
commandManager.Modify(wxT("Redo"),
|
||||
_("&Redo"));
|
||||
XO("&Redo"));
|
||||
commandManager.Enable(wxT("Redo"), false);
|
||||
}
|
||||
}
|
||||
|
@ -625,7 +623,7 @@ void MenuCreator::RebuildAllMenuBars()
|
|||
}
|
||||
|
||||
bool MenuManager::ReportIfActionNotAllowed(
|
||||
const wxString & Name, CommandFlag & flags, CommandFlag flagsRqd )
|
||||
const TranslatableString & Name, CommandFlag & flags, CommandFlag flagsRqd )
|
||||
{
|
||||
auto &project = mProject;
|
||||
bool bAllowed = TryToMakeActionAllowed( flags, flagsRqd );
|
||||
|
@ -671,7 +669,7 @@ bool MenuManager::TryToMakeActionAllowed(
|
|||
}
|
||||
|
||||
void MenuManager::TellUserWhyDisallowed(
|
||||
const wxString & Name, CommandFlag flagsGot, CommandFlag flagsRequired )
|
||||
const TranslatableString & 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.
|
||||
|
@ -685,7 +683,7 @@ void MenuManager::TellUserWhyDisallowed(
|
|||
|
||||
auto doOption = [&](const CommandFlagOptions &options) {
|
||||
if ( options.message ) {
|
||||
reason = options.message( Name );
|
||||
reason = options.message( Name.Translation() );
|
||||
defaultMessage = false;
|
||||
if ( !options.title.empty() )
|
||||
untranslatedTitle = options.title;
|
||||
|
|
|
@ -84,13 +84,13 @@ public:
|
|||
|
||||
// Command Handling
|
||||
bool ReportIfActionNotAllowed(
|
||||
const wxString & Name, CommandFlag & flags, CommandFlag flagsRqd );
|
||||
const TranslatableString & Name, CommandFlag & flags, CommandFlag flagsRqd );
|
||||
bool TryToMakeActionAllowed(
|
||||
CommandFlag & flags, CommandFlag flagsRqd );
|
||||
|
||||
|
||||
private:
|
||||
void TellUserWhyDisallowed(const wxString & Name, CommandFlag flagsGot,
|
||||
void TellUserWhyDisallowed(const TranslatableString & Name, CommandFlag flagsGot,
|
||||
CommandFlag flagsRequired);
|
||||
|
||||
void OnUndoRedo( wxCommandEvent &evt );
|
||||
|
|
|
@ -611,7 +611,7 @@ int CommandManager::NextIdentifier(int ID)
|
|||
///If it does, a workaround may be to keep controls below wxID_LOWEST
|
||||
///and keep menus above wxID_HIGHEST
|
||||
CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
||||
const TranslatableString & labelIn,
|
||||
const TranslatableString & label,
|
||||
wxMenu *menu,
|
||||
CommandHandlerFinder finder,
|
||||
CommandFunctorPointer callback,
|
||||
|
@ -622,7 +622,7 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
|||
{
|
||||
bool excludeFromMacros =
|
||||
(options.allowInMacros == 0) ||
|
||||
((options.allowInMacros == -1) && labelIn.MSGID().GET().Contains("..."));
|
||||
((options.allowInMacros == -1) && label.MSGID().GET().Contains("..."));
|
||||
|
||||
const wxString & accel = options.accel;
|
||||
bool bIsEffect = options.bIsEffect;
|
||||
|
@ -633,10 +633,8 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
|||
else
|
||||
cookedParameter = parameter;
|
||||
|
||||
auto label = labelIn.Translation();
|
||||
|
||||
// if empty, new identifier's long label will be same as label, below:
|
||||
const auto &longLabel = options.longName.Translation();
|
||||
const auto &longLabel = options.longName;
|
||||
|
||||
const bool multi = !nameSuffix.empty();
|
||||
auto name = nameIn;
|
||||
|
@ -747,14 +745,14 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
|||
wxLogDebug(wxT("Command '%s' defined by '%s' and '%s'"),
|
||||
// using GET in a log message for devs' eyes only
|
||||
entry->name.GET(),
|
||||
prev->label,
|
||||
entry->label);
|
||||
prev->label.Debug(),
|
||||
entry->label.Debug());
|
||||
wxFAIL_MSG(wxString::Format(wxT("Command '%s' defined by '%s' and '%s'"),
|
||||
// using GET in an assertion violation message for devs'
|
||||
// eyes only
|
||||
entry->name.GET(),
|
||||
prev->label,
|
||||
entry->label));
|
||||
prev->label.Debug(),
|
||||
entry->label.Debug()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -769,7 +767,7 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
|||
|
||||
wxString CommandManager::FormatLabelForMenu(const CommandListEntry *entry) const
|
||||
{
|
||||
wxString label = entry->label;
|
||||
auto label = entry->label.Translation();
|
||||
if (!entry->key.empty())
|
||||
{
|
||||
// using GET to compose menu item name for wxWidgets
|
||||
|
@ -786,7 +784,7 @@ wxString CommandManager::FormatLabelForMenu(const CommandListEntry *entry) const
|
|||
// disabled, in fact.
|
||||
wxString CommandManager::FormatLabelWithDisabledAccel(const CommandListEntry *entry) const
|
||||
{
|
||||
wxString label = entry->label;
|
||||
auto label = entry->label.Translation();
|
||||
#if 1
|
||||
wxString Accel;
|
||||
do{
|
||||
|
@ -941,7 +939,7 @@ void CommandManager::Check(const CommandID &name, bool checked)
|
|||
}
|
||||
|
||||
///Changes the label text of a menu item
|
||||
void CommandManager::Modify(const wxString &name, const wxString &newLabel)
|
||||
void CommandManager::Modify(const wxString &name, const TranslatableString &newLabel)
|
||||
{
|
||||
CommandListEntry *entry = mCommandNameHash[name];
|
||||
if (entry && entry->menu) {
|
||||
|
@ -1143,9 +1141,9 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry,
|
|||
if( !proj )
|
||||
return false;
|
||||
|
||||
wxString NiceName = entry->label;
|
||||
NiceName.Replace("&", "");// remove &
|
||||
NiceName.Replace(".","");// remove ...
|
||||
auto NiceName = entry->label;
|
||||
NiceName.Strip(
|
||||
TranslatableString::Ellipses | TranslatableString::MenuCodes );
|
||||
// NB: The call may have the side effect of changing flags.
|
||||
bool allowed =
|
||||
MenuManager::Get(*proj).ReportIfActionNotAllowed(
|
||||
|
@ -1262,7 +1260,7 @@ void CommandManager::GetAllCommandNames(CommandIDs &names,
|
|||
}
|
||||
}
|
||||
|
||||
void CommandManager::GetAllCommandLabels(wxArrayString &names,
|
||||
void CommandManager::GetAllCommandLabels(TranslatableStrings &names,
|
||||
std::vector<bool> &vExcludeFromMacros,
|
||||
bool includeMultis) const
|
||||
{
|
||||
|
@ -1285,7 +1283,7 @@ void CommandManager::GetAllCommandData(
|
|||
CommandIDs &names,
|
||||
std::vector<NormalizedKeyString> &keys,
|
||||
std::vector<NormalizedKeyString> &default_keys,
|
||||
wxArrayString &labels,
|
||||
TranslatableStrings &labels,
|
||||
wxArrayString &categories,
|
||||
#if defined(EXPERIMENTAL_KEY_VIEW)
|
||||
TranslatableStrings &prefixes,
|
||||
|
@ -1330,30 +1328,26 @@ CommandID CommandManager::GetNameFromNumericID(int id)
|
|||
return entry->name;
|
||||
}
|
||||
|
||||
wxString CommandManager::GetLabelFromName(const CommandID &name)
|
||||
TranslatableString CommandManager::GetLabelFromName(const CommandID &name)
|
||||
{
|
||||
CommandListEntry *entry = mCommandNameHash[name];
|
||||
if (!entry)
|
||||
return wxT("");
|
||||
return {};
|
||||
|
||||
return entry->longLabel;
|
||||
}
|
||||
|
||||
wxString CommandManager::GetPrefixedLabelFromName(const CommandID &name)
|
||||
TranslatableString CommandManager::GetPrefixedLabelFromName(const CommandID &name)
|
||||
{
|
||||
CommandListEntry *entry = mCommandNameHash[name];
|
||||
if (!entry)
|
||||
return wxT("");
|
||||
return {};
|
||||
|
||||
#if defined(EXPERIMENTAL_KEY_VIEW)
|
||||
wxString prefix;
|
||||
if (!entry->labelPrefix.empty()) {
|
||||
prefix = entry->labelPrefix.Translation() + wxT(" - ");
|
||||
}
|
||||
return wxMenuItem::GetLabelText(prefix + entry->label);
|
||||
#else
|
||||
return wxString(entry->labelPrefix.Translation() + wxT(" ") + entry->label).Trim(false).Trim(true);
|
||||
#endif
|
||||
if (!entry->labelPrefix.empty())
|
||||
return TranslatableString{wxT("%s - %s")}
|
||||
.Format(entry->labelPrefix, entry->label);
|
||||
else
|
||||
return entry->label;
|
||||
}
|
||||
|
||||
wxString CommandManager::GetCategoryFromName(const CommandID &name)
|
||||
|
@ -1496,8 +1490,8 @@ void CommandManager::CheckDups()
|
|||
msg.Printf(wxT("key combo '%s' assigned to '%s' and '%s'"),
|
||||
// using GET to form debug message
|
||||
mCommandList[i]->key.GET(),
|
||||
mCommandList[i]->label,
|
||||
mCommandList[j]->label);
|
||||
mCommandList[i]->label.Debug(),
|
||||
mCommandList[j]->label.Debug());
|
||||
wxASSERT_MSG(mCommandList[i]->key != mCommandList[j]->key, msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,10 +60,10 @@ struct CommandListEntry
|
|||
{
|
||||
int id;
|
||||
CommandID name;
|
||||
wxString longLabel;
|
||||
TranslatableString longLabel;
|
||||
NormalizedKeyString key;
|
||||
NormalizedKeyString defaultKey;
|
||||
wxString label;
|
||||
TranslatableString label;
|
||||
TranslatableString labelPrefix;
|
||||
wxString labelTop;
|
||||
wxMenu *menu;
|
||||
|
@ -211,7 +211,7 @@ class AUDACITY_DLL_API CommandManager final
|
|||
CommandFlag flags, CommandFlag strictFlags);
|
||||
void Enable(const wxString &name, bool enabled);
|
||||
void Check(const CommandID &name, bool checked);
|
||||
void Modify(const wxString &name, const wxString &newLabel);
|
||||
void Modify(const wxString &name, const TranslatableString &newLabel);
|
||||
|
||||
// You may either called SetCurrentMenu later followed by ClearCurrentMenu,
|
||||
// or else BeginMenu followed by EndMenu. Don't mix them.
|
||||
|
@ -251,13 +251,13 @@ class AUDACITY_DLL_API CommandManager final
|
|||
void GetCategories(wxArrayString &cats);
|
||||
void GetAllCommandNames(CommandIDs &names, bool includeMultis) const;
|
||||
void GetAllCommandLabels(
|
||||
wxArrayString &labels, std::vector<bool> &vExcludeFromMacros,
|
||||
TranslatableStrings &labels, std::vector<bool> &vExcludeFromMacros,
|
||||
bool includeMultis) const;
|
||||
void GetAllCommandData(
|
||||
CommandIDs &names,
|
||||
std::vector<NormalizedKeyString> &keys,
|
||||
std::vector<NormalizedKeyString> &default_keys,
|
||||
wxArrayString &labels, wxArrayString &categories,
|
||||
TranslatableStrings &labels, wxArrayString &categories,
|
||||
#if defined(EXPERIMENTAL_KEY_VIEW)
|
||||
TranslatableStrings &prefixes,
|
||||
#endif
|
||||
|
@ -267,8 +267,8 @@ class AUDACITY_DLL_API CommandManager final
|
|||
// which need not be the same across platforms or sessions
|
||||
CommandID GetNameFromNumericID( int id );
|
||||
|
||||
wxString GetLabelFromName(const CommandID &name);
|
||||
wxString GetPrefixedLabelFromName(const CommandID &name);
|
||||
TranslatableString GetLabelFromName(const CommandID &name);
|
||||
TranslatableString GetPrefixedLabelFromName(const CommandID &name);
|
||||
wxString GetCategoryFromName(const CommandID &name);
|
||||
NormalizedKeyString GetKeyFromName(const CommandID &name) const;
|
||||
NormalizedKeyString GetDefaultKeyFromName(const CommandID &name);
|
||||
|
|
|
@ -3069,7 +3069,7 @@ void EffectUIHost::OnApply(wxCommandEvent & evt)
|
|||
auto flags = AlwaysEnabledFlag;
|
||||
bool allowed =
|
||||
MenuManager::Get(*mProject).ReportIfActionNotAllowed(
|
||||
mEffect->GetTranslatedName(),
|
||||
mEffect->GetUntranslatedName(),
|
||||
flags,
|
||||
WaveTracksSelectedFlag | TimeSelectedFlag);
|
||||
if (!allowed)
|
||||
|
|
|
@ -190,10 +190,9 @@ void EffectManager::UnregisterEffect(const PluginID & ID)
|
|||
if (type == EffectTypeProcess) {
|
||||
wxString shortDesc = em.GetCommandName(ID);
|
||||
MenuManager::Get(project).mLastEffect = ID;
|
||||
wxString lastEffectDesc;
|
||||
/* i18n-hint: %s will be the name of the effect which will be
|
||||
* repeated if this menu item is chosen */
|
||||
lastEffectDesc.Printf(_("Repeat %s"), shortDesc);
|
||||
auto lastEffectDesc = XO("Repeat %s").Format( shortDesc );
|
||||
commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S)
|
|||
|
||||
void KeyConfigPrefs::RefreshBindings(bool bSort)
|
||||
{
|
||||
wxArrayString Labels;
|
||||
TranslatableStrings Labels;
|
||||
wxArrayString Categories;
|
||||
TranslatableStrings Prefixes;
|
||||
|
||||
|
@ -572,18 +572,23 @@ void KeyConfigPrefs::OnSet(wxCommandEvent & WXUNUSED(event))
|
|||
|
||||
// Prevent same hotkey combination being used twice.
|
||||
if (!oldname.empty()) {
|
||||
auto oldlabel = wxString::Format( _("%s - %s"),
|
||||
mManager->GetCategoryFromName(oldname),
|
||||
mManager->GetPrefixedLabelFromName(oldname) );
|
||||
auto newlabel = wxString::Format( _("%s - %s"),
|
||||
mManager->GetCategoryFromName(newname),
|
||||
mManager->GetPrefixedLabelFromName(newname) );
|
||||
auto oldlabel = TranslatableString{wxT("%s - %s")}
|
||||
.Format(
|
||||
mManager->GetCategoryFromName(oldname),
|
||||
mManager->GetPrefixedLabelFromName(oldname) );
|
||||
auto newlabel = TranslatableString{wxT("%s - %s")}
|
||||
.Format(
|
||||
mManager->GetCategoryFromName(newname),
|
||||
mManager->GetPrefixedLabelFromName(newname) );
|
||||
if (AudacityMessageBox(
|
||||
wxString::Format(
|
||||
_("The keyboard shortcut '%s' is already assigned to:\n\n\t'%s'\n\nClick OK to assign the shortcut to\n\n\t'%s'\n\ninstead. Otherwise, click Cancel."),
|
||||
mKey->GetValue(),
|
||||
oldlabel,
|
||||
newlabel),
|
||||
XO(
|
||||
"The keyboard shortcut '%s' is already assigned to:\n\n\t'%s'\n\nClick OK to assign the shortcut to\n\n\t'%s'\n\ninstead. Otherwise, click Cancel.")
|
||||
.Format(
|
||||
mKey->GetValue(),
|
||||
oldlabel,
|
||||
newlabel
|
||||
)
|
||||
.Translation(),
|
||||
_("Error"), wxOK | wxCANCEL | wxICON_STOP | wxCENTRE, this) == wxCANCEL)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -636,7 +636,7 @@ void
|
|||
KeyView::RefreshBindings(const CommandIDs & names,
|
||||
const wxArrayString & categories,
|
||||
const TranslatableStrings & prefixes,
|
||||
const wxArrayString & labels,
|
||||
const TranslatableStrings & labels,
|
||||
const std::vector<NormalizedKeyString> & keys,
|
||||
bool bSort
|
||||
)
|
||||
|
@ -776,7 +776,7 @@ KeyView::RefreshBindings(const CommandIDs & names,
|
|||
}
|
||||
else
|
||||
{
|
||||
node.label = labels[i];
|
||||
node.label = labels[i].Translation();
|
||||
}
|
||||
|
||||
// Fill in remaining info
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
void RefreshBindings(const CommandIDs & names,
|
||||
const wxArrayString & categories,
|
||||
const TranslatableStrings & prefixes,
|
||||
const wxArrayString & labels,
|
||||
const TranslatableStrings & labels,
|
||||
const std::vector<NormalizedKeyString> & keys,
|
||||
bool bSort);
|
||||
|
||||
|
|
Loading…
Reference in New Issue