mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-02 00:29:41 +02:00
Redo CommandManager::DescribeCommandsAndShortcuts with pairs...
... Later we may make other types for the members of that pair.
This commit is contained in:
parent
82952ac998
commit
6967925e48
@ -1310,7 +1310,7 @@ void CommandManager::TellUserWhyDisallowed( const wxString & Name, CommandFlag f
|
||||
}
|
||||
|
||||
wxString CommandManager::DescribeCommandsAndShortcuts
|
||||
(const std::vector<wxString> &commands) const
|
||||
(const LocalizedCommandNameVector &commands) const
|
||||
{
|
||||
wxString mark;
|
||||
// This depends on the language setting and may change in-session after
|
||||
@ -1321,36 +1321,34 @@ wxString CommandManager::DescribeCommandsAndShortcuts
|
||||
|
||||
static const wxString &separatorFormat = wxT("%s / %s");
|
||||
wxString result;
|
||||
auto iter = commands.begin(), end = commands.end();
|
||||
while (iter != end) {
|
||||
for (const auto &pair : commands) {
|
||||
// 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, *iter++);
|
||||
auto piece = wxString::Format(wxT("%s%s"), mark, pair.first);
|
||||
|
||||
if (iter != end) {
|
||||
if (!iter->empty()) {
|
||||
auto keyStr = GetKeyFromName(*iter);
|
||||
if (!keyStr.empty()){
|
||||
auto keyString = KeyStringDisplay(keyStr, true);
|
||||
auto format = wxT("%s %s(%s)");
|
||||
wxString name{ pair.second };
|
||||
if (!name.empty()) {
|
||||
auto keyStr = GetKeyFromName(name);
|
||||
if (!keyStr.empty()){
|
||||
auto keyString = KeyStringDisplay(keyStr, true);
|
||||
auto format = wxT("%s %s(%s)");
|
||||
#ifdef __WXMAC__
|
||||
// The unicode controls push and pop left-to-right embedding.
|
||||
// This keeps the directionally weak characters, such as uparrow
|
||||
// for Shift, left of the key name,
|
||||
// consistently with how menu accelerators appear, even when the
|
||||
// system language is RTL.
|
||||
format = wxT("%s %s(\u202a%s\u202c)");
|
||||
// The unicode controls push and pop left-to-right embedding.
|
||||
// This keeps the directionally weak characters, such as uparrow
|
||||
// for Shift, left of the key name,
|
||||
// consistently with how menu accelerators appear, even when the
|
||||
// system language is RTL.
|
||||
format = wxT("%s %s(\u202a%s\u202c)");
|
||||
#endif
|
||||
// The mark makes correctly placed parentheses for RTL, even
|
||||
// in the case that the piece is untranslated.
|
||||
piece = wxString::Format(format, piece, mark, keyString);
|
||||
}
|
||||
// The mark makes correctly placed parentheses for RTL, even
|
||||
// in the case that the piece is untranslated.
|
||||
piece = wxString::Format(format, piece, mark, keyString);
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
|
||||
if (result.empty())
|
||||
result = piece;
|
||||
else
|
||||
|
@ -278,12 +278,14 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
||||
///
|
||||
/// Formatting summaries that include shortcut keys
|
||||
///
|
||||
using LocalizedCommandName = std::pair<wxString, const wxChar*>;
|
||||
using LocalizedCommandNameVector = std::vector<LocalizedCommandName>;
|
||||
wxString DescribeCommandsAndShortcuts
|
||||
(// An array, alternating user-visible strings, and
|
||||
(// 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 std::vector<wxString> &commands) const;
|
||||
const LocalizedCommandNameVector &commands) const;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -220,56 +220,70 @@ void ControlToolBar::Populate()
|
||||
void ControlToolBar::RegenerateTooltips()
|
||||
{
|
||||
#if wxUSE_TOOLTIPS
|
||||
std::vector<wxString> commands;
|
||||
for (long iWinID = ID_PLAY_BUTTON; iWinID < BUTTON_COUNT; iWinID++)
|
||||
{
|
||||
commands.clear();
|
||||
auto pCtrl = static_cast<AButton*>(this->FindWindow(iWinID));
|
||||
commands.push_back(pCtrl->GetLabel());
|
||||
const wxChar *name = nullptr;
|
||||
switch (iWinID)
|
||||
{
|
||||
case ID_PLAY_BUTTON:
|
||||
// Without shift
|
||||
commands.push_back(wxT("PlayStop"));
|
||||
// With shift
|
||||
commands.push_back(_("Loop Play"));
|
||||
// For the shortcut tooltip.
|
||||
commands.push_back(wxT("PlayLooped"));
|
||||
name = wxT("PlayStop");
|
||||
break;
|
||||
case ID_RECORD_BUTTON:
|
||||
// Without shift
|
||||
//commands.push_back(wxT("Record"));
|
||||
commands.push_back(wxT("Record1stChoice"));
|
||||
//name = wxT("Record");
|
||||
name = wxT("Record1stChoice");
|
||||
break;
|
||||
case ID_PAUSE_BUTTON:
|
||||
name = wxT("Pause");
|
||||
break;
|
||||
case ID_STOP_BUTTON:
|
||||
name = wxT("Stop");
|
||||
break;
|
||||
case ID_FF_BUTTON:
|
||||
name = wxT("CursProjectEnd");
|
||||
break;
|
||||
case ID_REW_BUTTON:
|
||||
name = wxT("CursProjectStart");
|
||||
break;
|
||||
}
|
||||
LocalizedCommandNameVector commands( 1u, { pCtrl->GetLabel(), name } );
|
||||
|
||||
// Some have a second
|
||||
switch (iWinID)
|
||||
{
|
||||
case ID_PLAY_BUTTON:
|
||||
// With shift
|
||||
commands.push_back(
|
||||
LocalizedCommandName( _("Loop Play"), wxT("PlayLooped") ) );
|
||||
break;
|
||||
case ID_RECORD_BUTTON:
|
||||
// With shift
|
||||
{ bool bPreferNewTrack;
|
||||
gPrefs->Read("/GUI/PreferNewTrackRecord",&bPreferNewTrack, false);
|
||||
if( !bPreferNewTrack ){
|
||||
commands.push_back(_("Record New Track"));
|
||||
} else {
|
||||
commands.push_back(_("Append Record"));
|
||||
}
|
||||
// For the shortcut tooltip.
|
||||
commands.push_back(wxT("Record2ndChoice"));
|
||||
commands.push_back( LocalizedCommandName(
|
||||
!bPreferNewTrack
|
||||
? _("Record New Track")
|
||||
: _("Append Record"),
|
||||
wxT("Record2ndChoice")
|
||||
));
|
||||
}
|
||||
break;
|
||||
case ID_PAUSE_BUTTON:
|
||||
commands.push_back(wxT("Pause"));
|
||||
break;
|
||||
case ID_STOP_BUTTON:
|
||||
commands.push_back(wxT("Stop"));
|
||||
break;
|
||||
case ID_FF_BUTTON:
|
||||
commands.push_back(wxT("CursProjectEnd"));
|
||||
// With shift
|
||||
commands.push_back(_("Select to End"));
|
||||
// For the shortcut tooltip.
|
||||
commands.push_back(wxT("SelEnd"));
|
||||
commands.push_back( LocalizedCommandName(
|
||||
_("Select to End"), wxT("SelEnd") ) );
|
||||
break;
|
||||
case ID_REW_BUTTON:
|
||||
commands.push_back(wxT("CursProjectStart"));
|
||||
// With shift
|
||||
commands.push_back(_("Select to Start"));
|
||||
// For the shortcut tooltip.
|
||||
commands.push_back(wxT("SelStart"));
|
||||
commands.push_back( LocalizedCommandName(
|
||||
_("Select to Start"), wxT("SelStart") ) );
|
||||
break;
|
||||
}
|
||||
ToolBar::SetButtonToolTip(*pCtrl, commands);
|
||||
|
@ -269,13 +269,12 @@ void EditToolBar::ForAllButtons(int Action)
|
||||
}
|
||||
|
||||
|
||||
std::vector<wxString> commands;
|
||||
for (const auto &entry : EditToolbarButtonList) {
|
||||
#if wxUSE_TOOLTIPS
|
||||
if( Action & ETBActTooltips ){
|
||||
commands.clear();
|
||||
commands.push_back(wxGetTranslation(entry.untranslatedLabel));
|
||||
commands.push_back(entry.commandName);
|
||||
LocalizedCommandNameVector commands( 1u,
|
||||
{ wxGetTranslation(entry.untranslatedLabel), entry.commandName }
|
||||
);
|
||||
ToolBar::SetButtonToolTip(*mButtons[entry.tool], commands);
|
||||
}
|
||||
#endif
|
||||
|
@ -133,13 +133,10 @@ void ScrubbingToolBar::UpdatePrefs()
|
||||
void ScrubbingToolBar::RegenerateTooltips()
|
||||
{
|
||||
#if wxUSE_TOOLTIPS
|
||||
std::vector<wxString> commands;
|
||||
auto fn = [&]
|
||||
(AButton &button, const wxString &label, const wxString &command)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(label);
|
||||
commands.push_back(command);
|
||||
LocalizedCommandNameVector commands( 1u, { label, command } );
|
||||
ToolBar::SetButtonToolTip(button, commands);
|
||||
};
|
||||
|
||||
|
@ -825,7 +825,7 @@ void ToolBar::MakeAlternateImages(AButton &button, int idx,
|
||||
}
|
||||
|
||||
void ToolBar::SetButtonToolTip
|
||||
(AButton &button, const std::vector<wxString> &commands)
|
||||
(AButton &button, const LocalizedCommandNameVector &commands)
|
||||
{
|
||||
wxString result;
|
||||
const auto project = GetActiveProject();
|
||||
|
@ -156,14 +156,16 @@ class ToolBar /* not final */ : public wxPanelWrapper
|
||||
teBmps eDisabled,
|
||||
wxSize size);
|
||||
|
||||
using LocalizedCommandName = std::pair<wxString, const wxChar*>;
|
||||
using LocalizedCommandNameVector = std::vector<LocalizedCommandName>;
|
||||
static
|
||||
void SetButtonToolTip
|
||||
(AButton &button,
|
||||
// An array, alternating user-visible strings, and
|
||||
// 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 std::vector<wxString> &commands);
|
||||
const LocalizedCommandNameVector &commands);
|
||||
|
||||
protected:
|
||||
void SetButton(bool down, AButton *button);
|
||||
|
@ -137,11 +137,9 @@ void ToolsToolBar::RegenerateTooltips()
|
||||
{ multiTool, wxT("MultiTool"), XO("Multi Tool") },
|
||||
};
|
||||
|
||||
std::vector<wxString> commands;
|
||||
for (const auto &entry : table) {
|
||||
commands.clear();
|
||||
commands.push_back(wxGetTranslation(entry.untranslatedLabel));
|
||||
commands.push_back(entry.commandName);
|
||||
LocalizedCommandNameVector commands( 1u,
|
||||
{ wxGetTranslation(entry.untranslatedLabel), entry.commandName } );
|
||||
ToolBar::SetButtonToolTip(*mTool[entry.tool], commands);
|
||||
}
|
||||
|
||||
|
@ -310,13 +310,15 @@ void TranscriptionToolBar::RegenerateTooltips()
|
||||
},
|
||||
};
|
||||
|
||||
std::vector<wxString> commands;
|
||||
LocalizedCommandNameVector commands;
|
||||
for (const auto &entry : table) {
|
||||
commands.clear();
|
||||
commands.push_back(wxGetTranslation(entry.untranslatedLabel));
|
||||
commands.push_back(entry.commandName);
|
||||
commands.push_back(wxGetTranslation(entry.untranslatedLabel2));
|
||||
commands.push_back(entry.commandName2);
|
||||
commands.push_back( LocalizedCommandName(
|
||||
wxGetTranslation(entry.untranslatedLabel), entry.commandName
|
||||
) );
|
||||
commands.push_back( LocalizedCommandName(
|
||||
wxGetTranslation(entry.untranslatedLabel2), entry.commandName2
|
||||
) );
|
||||
ToolBar::SetButtonToolTip(*mButtons[entry.tool], commands);
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,8 @@ wxString MuteButtonHandle::Tip(const wxMouseState &) const
|
||||
return name;
|
||||
|
||||
auto commandManager = project->GetCommandManager();
|
||||
std::vector<wxString> commands;
|
||||
commands.push_back(name);
|
||||
commands.push_back(wxT("TrackMute"));
|
||||
CommandManager::LocalizedCommandNameVector commands( 1u,
|
||||
{ name, wxT("TrackMute") } );
|
||||
return commandManager->DescribeCommandsAndShortcuts(commands);
|
||||
}
|
||||
|
||||
@ -106,9 +105,8 @@ wxString SoloButtonHandle::Tip(const wxMouseState &) const
|
||||
return name;
|
||||
|
||||
auto commandManager = project->GetCommandManager();
|
||||
std::vector<wxString> commands;
|
||||
commands.push_back(name);
|
||||
commands.push_back(wxT("TrackSolo"));
|
||||
CommandManager::LocalizedCommandNameVector commands( 1u,
|
||||
{ name, wxT("TrackSolo") } );
|
||||
return commandManager->DescribeCommandsAndShortcuts(commands);
|
||||
}
|
||||
|
||||
|
@ -115,9 +115,8 @@ wxString CloseButtonHandle::Tip(const wxMouseState &) const
|
||||
return name;
|
||||
|
||||
auto commandManager = project->GetCommandManager();
|
||||
std::vector<wxString> commands;
|
||||
commands.push_back(name);
|
||||
commands.push_back(wxT("TrackClose"));
|
||||
CommandManager::LocalizedCommandNameVector commands( 1u,
|
||||
{ name, wxT("TrackClose") } );
|
||||
return commandManager->DescribeCommandsAndShortcuts(commands);
|
||||
}
|
||||
|
||||
@ -176,9 +175,8 @@ wxString MenuButtonHandle::Tip(const wxMouseState &) const
|
||||
return name;
|
||||
|
||||
auto commandManager = project->GetCommandManager();
|
||||
std::vector<wxString> commands;
|
||||
commands.push_back(name);
|
||||
commands.push_back(wxT("TrackMenu"));
|
||||
CommandManager::LocalizedCommandNameVector commands( 1u,
|
||||
{ name, wxT("TrackMenu") } );
|
||||
return commandManager->DescribeCommandsAndShortcuts(commands);
|
||||
}
|
||||
|
||||
|
@ -2875,9 +2875,8 @@ void AdornedRulerPanel::UpdateButtonStates()
|
||||
{
|
||||
auto common = [this]
|
||||
(AButton &button, const wxString &commandName, const wxString &label) {
|
||||
std::vector<wxString> commands;
|
||||
commands.push_back(label);
|
||||
commands.push_back(commandName);
|
||||
CommandManager::LocalizedCommandNameVector commands( 1u,
|
||||
{ label, commandName } );
|
||||
ToolBar::SetButtonToolTip(button, commands);
|
||||
button.SetLabel(button.GetToolTipText());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user