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

Method OnImport

src/prefs/KeyConfigPrefs.cpp:487–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485}
486
487void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event))
488{
489 wxString file = wxT("Audacity-keys.xml");
490
491 file = SelectFile(FileNames::Operation::Open,
492 XO("Select an XML file containing Audacity keyboard shortcuts..."),
493 wxEmptyString,
494 file,
495 wxT(""),
496 { FileNames::XMLFiles, FileNames::AllFiles },
497 wxRESIZE_BORDER,
498 this);
499
500 if (!file) {
501 return;
502 }
503
504 // this RefreshKeyInfo is here to account for
505 // potential OnSet() function executions before importing
506 RefreshKeyInfo();
507
508 // saving pre-import settings
509 const std::vector<NormalizedKeyString> oldKeys{ mKeys };
510
511 // clearing all pre-import settings
512 ClearAllKeys();
513
514 // getting new settings
515 XMLFileReader reader;
516 if (!reader.Parse(mManager, file)) {
517 AudacityMessageBox(
518 reader.GetErrorStr(),
519 XO("Error Importing Keyboard Shortcuts"),
520 wxOK | wxCENTRE,
521 this);
522 }
523
524 RefreshKeyInfo();
525
526 // checking new setting for duplicates
527 // if there are duplicates, throwing error and returning to pre-import state
528 TranslatableString fMatching;
529 TranslatableString sMatching;
530
531 if (ContainsIllegalDups(fMatching, sMatching))
532 {
533 // restore the old pre-import hotkeys stored in oldKeys
534 for (size_t k{ 0 }; k < mNames.size(); k++)
535 mManager->SetKeyFromName(mNames[k], oldKeys[k]);
536 mKeys = oldKeys;
537
538 // output an error message
539 AudacityMessageBox(
540 XO(
541"The file with the shortcuts contains illegal shortcut duplicates for \"%s\" and \"%s\".\nNothing is imported.")
542 .Format( fMatching, sMatching ),
543 XO("Error Importing Keyboard Shortcuts"),
544 wxICON_ERROR | wxCENTRE, this);

Callers

nothing calls this directly

Calls 7

SelectFileFunction · 0.85
AudacityMessageBoxFunction · 0.85
SetKeyFromNameMethod · 0.80
GetNumberOfKeysReadMethod · 0.80
TranslationMethod · 0.80
ParseMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected