mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-21 08:27:13 +01:00
fixed bug 2396. Set button now accounts for the existence of legal shortcuts duplicates.
This commit is contained in:
committed by
James Crook
parent
223ac3b644
commit
5cec22e8a0
@@ -757,47 +757,70 @@ void KeyConfigPrefs::OnSet(wxCommandEvent & WXUNUSED(event))
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NormalizedKeyString key { mKey->GetValue() };
|
CommandID newCommand{ mView->GetName(mCommandSelected) };
|
||||||
auto oldname = mView->GetNameByKey(key);
|
NormalizedKeyString enteredKey{ mKey->GetValue() };
|
||||||
auto newname = mView->GetName(mCommandSelected);
|
NormalizedKeyString newComDefaultKey{
|
||||||
|
mManager->GetDefaultKeyFromName(newCommand) };
|
||||||
|
CommandIDs oldCommands;
|
||||||
|
|
||||||
// Just ignore it if they are the same
|
// collecting commands competing for the same shortcut
|
||||||
if (oldname == newname) {
|
for (size_t i{ 0 }; i < mNames.size(); i++)
|
||||||
|
{
|
||||||
|
if (mNewKeys[i] == enteredKey)
|
||||||
|
{
|
||||||
|
// ignore the Set button if the same shortcut is used
|
||||||
|
if (mNames[i] == newCommand)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (newComDefaultKey == EMPTY_SHORTCUT ||
|
||||||
|
mDefaultKeys[i] != newComDefaultKey)
|
||||||
|
{
|
||||||
|
oldCommands.push_back(mNames[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent same hotkey combination being used twice.
|
// Prevent same hotkey combination being used twice.
|
||||||
if (!oldname.empty()) {
|
if (!oldCommands.empty()) {
|
||||||
auto oldlabel = Verbatim( wxT("%s - %s") )
|
auto newlabel = Verbatim( wxT("'%s - %s'") )
|
||||||
.Format(
|
.Format(
|
||||||
mManager->GetCategoryFromName(oldname),
|
mManager->GetCategoryFromName(newCommand),
|
||||||
mManager->GetPrefixedLabelFromName(oldname) );
|
mManager->GetPrefixedLabelFromName(newCommand) );
|
||||||
auto newlabel = Verbatim( wxT("%s - %s") )
|
auto oldlabel = Verbatim(wxT("'%s - %s'"))
|
||||||
.Format(
|
.Format(
|
||||||
mManager->GetCategoryFromName(newname),
|
mManager->GetCategoryFromName(oldCommands[0]),
|
||||||
mManager->GetPrefixedLabelFromName(newname) );
|
mManager->GetPrefixedLabelFromName(oldCommands[0]));
|
||||||
|
|
||||||
|
for (size_t i{ 1 }; i < oldCommands.size(); i++)
|
||||||
|
oldlabel += XO("\n\n\t and\n\n\t") +
|
||||||
|
Verbatim(wxT("'%s - %s'")).Format(
|
||||||
|
mManager->GetCategoryFromName(oldCommands[i]),
|
||||||
|
mManager->GetPrefixedLabelFromName(oldCommands[i]));
|
||||||
|
|
||||||
if (wxCANCEL == AudacityMessageBox(
|
if (wxCANCEL == AudacityMessageBox(
|
||||||
XO(
|
XO(
|
||||||
"The keyboard shortcut '%s' is already assigned to:\n\n\t'%s'\n\nClick OK to assign the shortcut to\n\n\t'%s'\n\ninstead. Otherwise, click Cancel.")
|
"The keyboard shortcut '%s' is already assigned to:\n\n\t%s\n\n\nClick OK to assign the shortcut to\n\n\t%s\n\ninstead. Otherwise, click Cancel.")
|
||||||
.Format(
|
.Format(
|
||||||
mKey->GetValue(),
|
mKey->GetValue(),
|
||||||
oldlabel,
|
oldlabel,
|
||||||
newlabel
|
newlabel
|
||||||
),
|
),
|
||||||
XO("Error"),
|
XO("Warning"),
|
||||||
wxOK | wxCANCEL | wxICON_STOP | wxCENTRE,
|
wxOK | wxCANCEL | wxICON_STOP | wxCENTRE,
|
||||||
this))
|
this))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mView->SetKeyByName(oldname, {});
|
for (const auto & command : oldCommands)
|
||||||
mManager->SetKeyFromName(oldname, {});
|
{
|
||||||
mNewKeys[ make_iterator_range( mNames ).index( oldname ) ] = {};
|
mView->SetKeyByName(command, {});
|
||||||
|
mManager->SetKeyFromName(command, {});
|
||||||
|
mNewKeys[make_iterator_range(mNames).index(command)] = {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetKeyForSelected(key);
|
SetKeyForSelected(enteredKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyConfigPrefs::OnClear(wxCommandEvent& WXUNUSED(event))
|
void KeyConfigPrefs::OnClear(wxCommandEvent& WXUNUSED(event))
|
||||||
|
|||||||
Reference in New Issue
Block a user