MCPcopy Create free account
hub / github.com/audacity/audacity / OnSet

Method OnSet

src/prefs/KeyConfigPrefs.cpp:760–835  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

758
759
760void KeyConfigPrefs::OnSet(wxCommandEvent & WXUNUSED(event))
761{
762 if (mCommandSelected == wxNOT_FOUND) {
763 AudacityMessageBox(
764 XO("You must select a binding before assigning a shortcut"),
765 XO("Error"),
766 wxICON_WARNING | wxCENTRE,
767 this);
768 return;
769 }
770
771 CommandID newCommand{ mView->GetName(mCommandSelected) };
772 NormalizedKeyString enteredKey{ mKey->GetValue() };
773 NormalizedKeyString newComDefaultKey{
774 mManager->GetDefaultKeyFromName(newCommand) };
775 CommandIDs oldCommands;
776
777 // collecting commands competing for the same shortcut
778 for (size_t i{ 0 }; i < mNames.size(); i++)
779 {
780 if (mNewKeys[i] == enteredKey)
781 {
782 // ignore the Set button if the same shortcut is used
783 if (mNames[i] == newCommand)
784 return;
785
786 if (newComDefaultKey == EMPTY_SHORTCUT ||
787 mDefaultKeys[i] != newComDefaultKey)
788 {
789 oldCommands.push_back(mNames[i]);
790 }
791 }
792 }
793
794 // Prevent same hotkey combination being used twice.
795 if (!oldCommands.empty()) {
796 auto newlabel = Verbatim( wxT("'%s - %s'") )
797 .Format(
798 mManager->GetCategoryFromName(newCommand),
799 mManager->GetPrefixedLabelFromName(newCommand) );
800 auto oldlabel = Verbatim(wxT("'%s - %s'"))
801 .Format(
802 mManager->GetCategoryFromName(oldCommands[0]),
803 mManager->GetPrefixedLabelFromName(oldCommands[0]));
804
805 for (size_t i{ 1 }; i < oldCommands.size(); i++)
806 oldlabel += XO("\n\n\t and\n\n\t") +
807 Verbatim(wxT("'%s - %s'")).Format(
808 mManager->GetCategoryFromName(oldCommands[i]),
809 mManager->GetPrefixedLabelFromName(oldCommands[i]));
810
811 if (wxCANCEL == AudacityMessageBox(
812 XO(
813"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.")
814 .Format(
815 mKey->GetValue(),
816 oldlabel,
817 newlabel

Callers

nothing calls this directly

Calls 14

AudacityMessageBoxFunction · 0.85
VerbatimFunction · 0.85
make_iterator_rangeFunction · 0.85
GetDefaultKeyFromNameMethod · 0.80
GetCategoryFromNameMethod · 0.80
SetKeyByNameMethod · 0.80
SetKeyFromNameMethod · 0.80
GetNameMethod · 0.45
GetValueMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected