From 812fd2adeaad95c27e439cff99f919608b6f7137 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 15 Jul 2017 11:59:55 -0400 Subject: [PATCH] move function --- src/commands/CommandManager.cpp | 23 +++++++++++++++++++++++ src/commands/CommandManager.h | 12 ++++++++++++ src/toolbars/ToolBar.cpp | 30 ++++++------------------------ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index e140360cc..a71491a45 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -1301,6 +1301,29 @@ void CommandManager::TellUserWhyDisallowed( const wxString & Name, CommandFlag f } } +wxString CommandManager::DescribeCommandsAndShortcuts +(const std::vector &commands, const wxString &separator) const +{ + wxString result; + auto iter = commands.begin(), end = commands.end(); + while (iter != end) { + result += *iter++; + if (iter != end) { + if (!iter->empty()) { + auto keyStr = GetKeyFromName(*iter); + if (!keyStr.empty()){ + result += wxT(" "); + result += Internat::Parenthesize(KeyStringDisplay(keyStr, true)); + } + } + ++iter; + } + if (iter != end) + result += separator; + } + return result; +} + /// /// /// diff --git a/src/commands/CommandManager.h b/src/commands/CommandManager.h index e70320d7d..c6e0579a7 100644 --- a/src/commands/CommandManager.h +++ b/src/commands/CommandManager.h @@ -262,6 +262,18 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler void WriteXML(XMLWriter &xmlFile) const /* not override */; void TellUserWhyDisallowed(const wxString & Name, CommandFlag flagsGot, CommandFlag flagsRequired); + /// + /// Formatting summaries that include shortcut keys + /// + wxString DescribeCommandsAndShortcuts + (// An array, alternating 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 std::vector &commands, + // If more than one pair of strings is given, then use this separator. + const wxString &separator = wxT(" / ")) const; + protected: // diff --git a/src/toolbars/ToolBar.cpp b/src/toolbars/ToolBar.cpp index d6791d233..38bd0612b 100644 --- a/src/toolbars/ToolBar.cpp +++ b/src/toolbars/ToolBar.cpp @@ -834,31 +834,13 @@ void ToolBar::MakeAlternateImages(AButton &button, int idx, void ToolBar::SetButtonToolTip (AButton &button, const std::vector &commands, const wxString &separator) { - const auto project = GetActiveProject(); - const auto commandManager = project ? project->GetCommandManager() : nullptr; wxString result; - auto iter = commands.begin(), end = commands.end(); - while (iter != end) { - result += *iter++; - if (iter != end) { - if (!iter->empty()) { - if (commandManager) { - auto keyStr = commandManager->GetKeyFromName(*iter); - // For DarkAudacity, only add '(shortcut-info)' if there is - // some, rather than as in that case in Audacity saying - // '(no key)'. More users will be confused by the Audacity - // way than helped by it. - if (!keyStr.empty()){ - result += wxT(" "); - result += Internat::Parenthesize(KeyStringDisplay(keyStr, true)); - } - } - } - ++iter; - } - if (iter != end) - result += separator; - } + const auto project = GetActiveProject(); + const auto commandManager = + project ? project->GetCommandManager() : nullptr; + if (commandManager) + result = + commandManager->DescribeCommandsAndShortcuts(commands, separator); button.SetToolTip(result); }