1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-01 08:29:27 +02:00

Transport button tooltips with shortcuts use Mac special chars

This commit is contained in:
Paul Licameli 2016-06-05 13:11:01 -04:00
parent 8dfaa4dcf8
commit 5f8fad4a48
3 changed files with 69 additions and 35 deletions

View File

@ -200,44 +200,38 @@ void ControlToolBar::Populate()
void ControlToolBar::RegenerateToolsTooltips() void ControlToolBar::RegenerateToolsTooltips()
{ {
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
std::vector<wxString> commands;
for (long iWinID = ID_PLAY_BUTTON; iWinID < BUTTON_COUNT; iWinID++) for (long iWinID = ID_PLAY_BUTTON; iWinID < BUTTON_COUNT; iWinID++)
{ {
wxWindow* pCtrl = this->FindWindow(iWinID); commands.clear();
wxString strToolTip = pCtrl->GetLabel(); auto pCtrl = static_cast<AButton*>(this->FindWindow(iWinID));
AudacityProject* pProj = GetActiveProject(); commands.push_back(pCtrl->GetLabel());
CommandManager* pCmdMgr = (pProj) ? pProj->GetCommandManager() : NULL; switch (iWinID)
if (pCmdMgr)
{ {
wxString strKey(wxT(" (")); case ID_PLAY_BUTTON:
switch (iWinID) commands.push_back(wxT("Play"));
{ commands.push_back(_("Loop Play"));
case ID_PLAY_BUTTON: commands.push_back(wxT("PlayLooped"));
strKey += pCmdMgr->GetKeyFromName(wxT("Play")); break;
strKey += _(") / Loop Play ("); case ID_RECORD_BUTTON:
strKey += pCmdMgr->GetKeyFromName(wxT("PlayLooped")); commands.push_back(wxT("Record"));
break; commands.push_back(_("Append Record"));
case ID_RECORD_BUTTON: commands.push_back(wxT("RecordAppend"));
strKey += pCmdMgr->GetKeyFromName(wxT("Record")); break;
strKey += _(") / Append Record ("); case ID_PAUSE_BUTTON:
strKey += pCmdMgr->GetKeyFromName(wxT("RecordAppend")); commands.push_back(wxT("Pause"));
break; break;
case ID_PAUSE_BUTTON: case ID_STOP_BUTTON:
strKey += pCmdMgr->GetKeyFromName(wxT("Pause")); commands.push_back(wxT("Stop"));
break; break;
case ID_STOP_BUTTON: case ID_FF_BUTTON:
strKey += pCmdMgr->GetKeyFromName(wxT("Stop")); commands.push_back(wxT("SkipEnd"));
break; break;
case ID_FF_BUTTON: case ID_REW_BUTTON:
strKey += pCmdMgr->GetKeyFromName(wxT("SkipEnd")); commands.push_back(wxT("SkipStart"));
break; break;
case ID_REW_BUTTON:
strKey += pCmdMgr->GetKeyFromName(wxT("SkipStart"));
break;
}
strKey += wxT(")");
strToolTip += strKey;
} }
pCtrl->SetToolTip(strToolTip); ToolBar::SetButtonToolTip(*pCtrl, commands);
} }
#endif #endif
} }

View File

@ -48,6 +48,7 @@ in which buttons can be placed.
#include "../ImageManipulation.h" #include "../ImageManipulation.h"
#include "../Project.h" #include "../Project.h"
#include "../Theme.h" #include "../Theme.h"
#include "../commands/Keyboard.h"
#include "../widgets/AButton.h" #include "../widgets/AButton.h"
#include "../widgets/Grabber.h" #include "../widgets/Grabber.h"
@ -761,6 +762,33 @@ void ToolBar::MakeAlternateImages(AButton &button, int idx,
button.SetAlternateImages(idx, *up, *hilite, *down, *disable); button.SetAlternateImages(idx, *up, *hilite, *down, *disable);
} }
void ToolBar::SetButtonToolTip
(AButton &button, const std::vector<wxString> &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);
if (keyStr.empty())
keyStr = _("no key");
result += wxT(" ");
result += Internat::Parenthesize(KeyStringDisplay(keyStr, true));
}
}
++iter;
}
if (iter != end)
result += separator;
}
button.SetToolTip(result);
}
// //
// This changes the state a button (from up to down or vice versa) // This changes the state a button (from up to down or vice versa)
// //

View File

@ -15,6 +15,7 @@
#include "../Experimental.h" #include "../Experimental.h"
#include <vector>
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/sizer.h> #include <wx/sizer.h>
@ -149,7 +150,18 @@ class ToolBar /* not final */ : public wxPanel
teBmps eStandardDown, teBmps eStandardDown,
teBmps eDisabled, teBmps eDisabled,
wxSize size); wxSize size);
static
void SetButtonToolTip
(AButton &button,
// 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<wxString> &commands,
// If more than one pair of strings is given, then use this separator.
const wxString &separator = wxT(" / "));
protected: protected:
void SetButton(bool down, AButton *button); void SetButton(bool down, AButton *button);