This function tries to add the given shortcuts(keys) "toAdd" to the already existing shortcuts(keys). Shortcuts are added only if 1. the shortcut for the operation isn't defined already 2. the added shortcut doesn't create illegal shortcut duplicate The names of operations for which the second condition was violated are returned in a single error message
| 419 | // The names of operations for which the second condition was violated |
| 420 | // are returned in a single error message |
| 421 | TranslatableString KeyConfigPrefs::MergeWithExistingKeys( |
| 422 | const std::vector<NormalizedKeyString> &toAdd) |
| 423 | { |
| 424 | TranslatableString disabledShortcuts; |
| 425 | |
| 426 | auto searchAddInKeys = [&](size_t index) |
| 427 | { |
| 428 | for (size_t k{ 0 }; k < toAdd.size(); k++) |
| 429 | if (k == index) |
| 430 | continue; |
| 431 | else if (toAdd[index] == mKeys[k] && |
| 432 | (mDefaultKeys[k] == EMPTY_SHORTCUT || |
| 433 | mDefaultKeys[k] != mDefaultKeys[index])) |
| 434 | return (int)k; |
| 435 | |
| 436 | return -1; |
| 437 | }; |
| 438 | |
| 439 | const NormalizedKeyString noKey{ EMPTY_SHORTCUT }; |
| 440 | |
| 441 | for (size_t i{ 0 }; i < toAdd.size(); i++) |
| 442 | { |
| 443 | if (mKeys[i] != NO_SHORTCUT) |
| 444 | continue; |
| 445 | else if (toAdd[i] == EMPTY_SHORTCUT) |
| 446 | mManager->SetKeyFromIndex(i, noKey); |
| 447 | else |
| 448 | { |
| 449 | int sRes{ searchAddInKeys(i) }; |
| 450 | |
| 451 | if (sRes == -1) |
| 452 | mManager->SetKeyFromIndex(i, toAdd[i]); |
| 453 | else |
| 454 | { |
| 455 | TranslatableString name{ mManager->GetKeyFromName(mNames[sRes]).GET(), {} }; |
| 456 | |
| 457 | disabledShortcuts += |
| 458 | XO( |
| 459 | "\n * \"%s\" (because the shortcut \'%s\' is used by \"%s\")\n") |
| 460 | .Format( |
| 461 | mManager->GetPrefixedLabelFromName(mNames[i]), |
| 462 | name, |
| 463 | mManager->GetPrefixedLabelFromName(mNames[sRes]) ); |
| 464 | |
| 465 | mManager->SetKeyFromIndex(i, noKey); |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | return disabledShortcuts; |
| 471 | } |
| 472 | |
| 473 | // See bug #2315 for discussion. This should be reviewed |
| 474 | // and (possibly) removed after wx3.1.3. |
nothing calls this directly
no test coverage detected