From 9b7ccc4dff20f91a428d6c47d76278f24a281291 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 15 Mar 2018 19:26:20 -0400 Subject: [PATCH] Use TranslatedInternalString for tips of toolbar buttons --- src/commands/CommandManager.cpp | 9 +++---- src/commands/CommandManager.h | 11 ++++----- src/toolbars/ControlToolBar.cpp | 24 +++++++++---------- src/toolbars/EditToolBar.cpp | 7 +++--- src/toolbars/ScrubbingToolBar.cpp | 6 ++--- src/toolbars/ToolBar.cpp | 4 ++-- src/toolbars/ToolBar.h | 10 +++----- src/toolbars/ToolsToolBar.cpp | 6 ++--- src/toolbars/TranscriptionToolBar.cpp | 14 ++++------- .../ui/PlayableTrackButtonHandles.cpp | 10 ++++---- src/tracks/ui/TrackButtonHandles.cpp | 10 ++++---- src/widgets/Ruler.cpp | 5 ++-- 12 files changed, 50 insertions(+), 66 deletions(-) diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index 3a797bc5b..ea910e982 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -1353,7 +1353,7 @@ void CommandManager::TellUserWhyDisallowed( const wxString & Name, CommandFlag f } wxString CommandManager::DescribeCommandsAndShortcuts -(const LocalizedCommandNameVector &commands) const +(const TranslatedInternalString commands[], size_t nCommands) const { wxString mark; // This depends on the language setting and may change in-session after @@ -1364,15 +1364,16 @@ wxString CommandManager::DescribeCommandsAndShortcuts static const wxString &separatorFormat = wxT("%s / %s"); wxString result; - for (const auto &pair : commands) { + for (size_t ii = 0; ii < nCommands; ++ii) { + const auto &pair = commands[ii]; // If RTL, then the control character forces right-to-left sequencing of // "/" -separated command names, and puts any "(...)" shortcuts to the // left, consistently with accelerators in menus (assuming matching // operating system prefernces for language), even if the command name // was missing from the translation file and defaulted to the English. - auto piece = wxString::Format(wxT("%s%s"), mark, pair.first); + auto piece = wxString::Format(wxT("%s%s"), mark, pair.Translated()); - wxString name{ pair.second }; + wxString name{ pair.Internal() }; if (!name.empty()) { auto keyStr = GetKeyFromName(name); if (!keyStr.empty()){ diff --git a/src/commands/CommandManager.h b/src/commands/CommandManager.h index 7668506f2..b3a7370b5 100644 --- a/src/commands/CommandManager.h +++ b/src/commands/CommandManager.h @@ -313,14 +313,11 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler /// /// Formatting summaries that include shortcut keys /// - using LocalizedCommandName = std::pair; - using LocalizedCommandNameVector = std::vector; wxString DescribeCommandsAndShortcuts - (// An array of paired user-visible strings, and - // non-user-visible command names. If a shortcut key is defined - // for the command, then it is appended, parenthesized, after the - // user-visible string. - const LocalizedCommandNameVector &commands) const; + ( + // If a shortcut key is defined for the command, then it is appended, + // parenthesized, after the translated name. + const TranslatedInternalString commands[], size_t nCommands) const; // Sorted list of the shortcut keys to be exluded from the standard defaults static const std::vector &ExcludedList(); diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index 6eae03426..8897c6640 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -249,27 +249,27 @@ void ControlToolBar::RegenerateTooltips() name = wxT("CursProjectStart"); break; } - LocalizedCommandNameVector commands( 1u, { pCtrl->GetLabel(), name } ); + std::vector commands( + 1u, { name, pCtrl->GetLabel() } ); // Some have a second switch (iWinID) { case ID_PLAY_BUTTON: // With shift - commands.push_back( - LocalizedCommandName( _("Loop Play"), wxT("PlayLooped") ) ); + commands.push_back( { wxT("PlayLooped"), _("Loop Play") } ); break; case ID_RECORD_BUTTON: // With shift { bool bPreferNewTrack; gPrefs->Read("/GUI/PreferNewTrackRecord",&bPreferNewTrack, false); // For the shortcut tooltip. - commands.push_back( LocalizedCommandName( + commands.push_back( { + wxT("Record2ndChoice"), !bPreferNewTrack ? _("Record New Track") - : _("Append Record"), - wxT("Record2ndChoice") - )); + : _("Append Record") + } ); } break; case ID_PAUSE_BUTTON: @@ -278,16 +278,16 @@ void ControlToolBar::RegenerateTooltips() break; case ID_FF_BUTTON: // With shift - commands.push_back( LocalizedCommandName( - _("Select to End"), wxT("SelEnd") ) ); + commands.push_back( { + wxT("SelEnd"), _("Select to End") } ); break; case ID_REW_BUTTON: // With shift - commands.push_back( LocalizedCommandName( - _("Select to Start"), wxT("SelStart") ) ); + commands.push_back( { + wxT("SelStart"), _("Select to Start") } ); break; } - ToolBar::SetButtonToolTip(*pCtrl, commands); + ToolBar::SetButtonToolTip(*pCtrl, commands.data(), commands.size()); } #endif } diff --git a/src/toolbars/EditToolBar.cpp b/src/toolbars/EditToolBar.cpp index 0c0024965..622082902 100644 --- a/src/toolbars/EditToolBar.cpp +++ b/src/toolbars/EditToolBar.cpp @@ -277,10 +277,9 @@ void EditToolBar::ForAllButtons(int Action) for (const auto &entry : EditToolbarButtonList) { #if wxUSE_TOOLTIPS if( Action & ETBActTooltips ){ - LocalizedCommandNameVector commands( 1u, - { wxGetTranslation(entry.untranslatedLabel), entry.commandName } - ); - ToolBar::SetButtonToolTip(*mButtons[entry.tool], commands); + TranslatedInternalString command{ + entry.commandName, wxGetTranslation(entry.untranslatedLabel) }; + ToolBar::SetButtonToolTip( *mButtons[entry.tool], &command, 1u ); } #endif if (cm) { diff --git a/src/toolbars/ScrubbingToolBar.cpp b/src/toolbars/ScrubbingToolBar.cpp index 141005e92..4b54ee059 100644 --- a/src/toolbars/ScrubbingToolBar.cpp +++ b/src/toolbars/ScrubbingToolBar.cpp @@ -136,10 +136,10 @@ void ScrubbingToolBar::RegenerateTooltips() { #if wxUSE_TOOLTIPS auto fn = [&] - (AButton &button, const wxString &label, const wxString &command) + (AButton &button, const wxString &label, const wxString &cmd) { - LocalizedCommandNameVector commands( 1u, { label, command } ); - ToolBar::SetButtonToolTip(button, commands); + TranslatedInternalString command{ cmd, label }; + ToolBar::SetButtonToolTip( button, &command, 1u ); }; auto project = GetActiveProject(); diff --git a/src/toolbars/ToolBar.cpp b/src/toolbars/ToolBar.cpp index 3ebeb4e33..f026df7a2 100644 --- a/src/toolbars/ToolBar.cpp +++ b/src/toolbars/ToolBar.cpp @@ -825,7 +825,7 @@ void ToolBar::MakeAlternateImages(AButton &button, int idx, } void ToolBar::SetButtonToolTip -(AButton &button, const LocalizedCommandNameVector &commands) +(AButton &button, const TranslatedInternalString commands[], size_t nCommands) { wxString result; const auto project = GetActiveProject(); @@ -833,7 +833,7 @@ void ToolBar::SetButtonToolTip project ? project->GetCommandManager() : nullptr; if (commandManager) result = - commandManager->DescribeCommandsAndShortcuts(commands); + commandManager->DescribeCommandsAndShortcuts(commands, nCommands); button.SetToolTip(result); } diff --git a/src/toolbars/ToolBar.h b/src/toolbars/ToolBar.h index 4e34463cb..34ebf3a13 100644 --- a/src/toolbars/ToolBar.h +++ b/src/toolbars/ToolBar.h @@ -156,16 +156,12 @@ class ToolBar /* not final */ : public wxPanelWrapper teBmps eDisabled, wxSize size); - using LocalizedCommandName = std::pair; - using LocalizedCommandNameVector = std::vector; static void SetButtonToolTip (AButton &button, - // An array of paired user-visible strings, and - // non-user-visible command names. If a shortcut key is defined - // for the command, then it is appended, parenthesized, after the - // user-visible string. - const LocalizedCommandNameVector &commands); + // If a shortcut key is defined for the command, then it is appended, + // parenthesized, after the translated name. + const TranslatedInternalString commands[], size_t nCommands); protected: void SetButton(bool down, AButton *button); diff --git a/src/toolbars/ToolsToolBar.cpp b/src/toolbars/ToolsToolBar.cpp index f59e73a5e..4c612e758 100644 --- a/src/toolbars/ToolsToolBar.cpp +++ b/src/toolbars/ToolsToolBar.cpp @@ -138,9 +138,9 @@ void ToolsToolBar::RegenerateTooltips() }; for (const auto &entry : table) { - LocalizedCommandNameVector commands( 1u, - { wxGetTranslation(entry.untranslatedLabel), entry.commandName } ); - ToolBar::SetButtonToolTip(*mTool[entry.tool], commands); + TranslatedInternalString command{ + entry.commandName, wxGetTranslation(entry.untranslatedLabel) }; + ToolBar::SetButtonToolTip( *mTool[entry.tool], &command, 1u ); } #endif diff --git a/src/toolbars/TranscriptionToolBar.cpp b/src/toolbars/TranscriptionToolBar.cpp index cabf46b08..1917894f6 100644 --- a/src/toolbars/TranscriptionToolBar.cpp +++ b/src/toolbars/TranscriptionToolBar.cpp @@ -312,16 +312,12 @@ void TranscriptionToolBar::RegenerateTooltips() }, }; - LocalizedCommandNameVector commands; for (const auto &entry : table) { - commands.clear(); - commands.push_back( LocalizedCommandName( - wxGetTranslation(entry.untranslatedLabel), entry.commandName - ) ); - commands.push_back( LocalizedCommandName( - wxGetTranslation(entry.untranslatedLabel2), entry.commandName2 - ) ); - ToolBar::SetButtonToolTip(*mButtons[entry.tool], commands); + TranslatedInternalString commands[] = { + { entry.commandName, wxGetTranslation(entry.untranslatedLabel) }, + { entry.commandName2, wxGetTranslation(entry.untranslatedLabel2) }, + }; + ToolBar::SetButtonToolTip( *mButtons[entry.tool], commands, 2u ); } diff --git a/src/tracks/playabletrack/ui/PlayableTrackButtonHandles.cpp b/src/tracks/playabletrack/ui/PlayableTrackButtonHandles.cpp index 5efafe48e..136fe9209 100644 --- a/src/tracks/playabletrack/ui/PlayableTrackButtonHandles.cpp +++ b/src/tracks/playabletrack/ui/PlayableTrackButtonHandles.cpp @@ -48,9 +48,8 @@ wxString MuteButtonHandle::Tip(const wxMouseState &) const return name; auto commandManager = project->GetCommandManager(); - CommandManager::LocalizedCommandNameVector commands( 1u, - { name, wxT("TrackMute") } ); - return commandManager->DescribeCommandsAndShortcuts(commands); + TranslatedInternalString command{ wxT("TrackMute"), name }; + return commandManager->DescribeCommandsAndShortcuts(&command, 1u); } UIHandlePtr MuteButtonHandle::HitTest @@ -105,9 +104,8 @@ wxString SoloButtonHandle::Tip(const wxMouseState &) const return name; auto commandManager = project->GetCommandManager(); - CommandManager::LocalizedCommandNameVector commands( 1u, - { name, wxT("TrackSolo") } ); - return commandManager->DescribeCommandsAndShortcuts(commands); + TranslatedInternalString command{ wxT("TrackSolo"), name }; + return commandManager->DescribeCommandsAndShortcuts( &command, 1u ); } UIHandlePtr SoloButtonHandle::HitTest diff --git a/src/tracks/ui/TrackButtonHandles.cpp b/src/tracks/ui/TrackButtonHandles.cpp index d11e4409f..caa8265e2 100644 --- a/src/tracks/ui/TrackButtonHandles.cpp +++ b/src/tracks/ui/TrackButtonHandles.cpp @@ -115,9 +115,8 @@ wxString CloseButtonHandle::Tip(const wxMouseState &) const return name; auto commandManager = project->GetCommandManager(); - CommandManager::LocalizedCommandNameVector commands( 1u, - { name, wxT("TrackClose") } ); - return commandManager->DescribeCommandsAndShortcuts(commands); + TranslatedInternalString command{ wxT("TrackClose"), name }; + return commandManager->DescribeCommandsAndShortcuts( &command, 1u ); } UIHandlePtr CloseButtonHandle::HitTest @@ -175,9 +174,8 @@ wxString MenuButtonHandle::Tip(const wxMouseState &) const return name; auto commandManager = project->GetCommandManager(); - CommandManager::LocalizedCommandNameVector commands( 1u, - { name, wxT("TrackMenu") } ); - return commandManager->DescribeCommandsAndShortcuts(commands); + TranslatedInternalString command{ wxT("TrackMenu"), name }; + return commandManager->DescribeCommandsAndShortcuts( &command, 1u ); } UIHandlePtr MenuButtonHandle::HitTest diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 3895bfe36..1a64190b1 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -2897,9 +2897,8 @@ void AdornedRulerPanel::UpdateButtonStates() { auto common = [this] (AButton &button, const wxString &commandName, const wxString &label) { - CommandManager::LocalizedCommandNameVector commands( 1u, - { label, commandName } ); - ToolBar::SetButtonToolTip(button, commands); + TranslatedInternalString command{ commandName, label }; + ToolBar::SetButtonToolTip( button, &command, 1u ); button.SetLabel(button.GetToolTipText()); button.UpdateStatus();