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