| 885 | } |
| 886 | |
| 887 | bool KeyConfigPrefs::Commit() |
| 888 | { |
| 889 | // On the Mac, preferences may be changed without any active |
| 890 | // projects. This means that the CommandManager isn't available |
| 891 | // either. So we can't attempt to save preferences, otherwise |
| 892 | // NULL ptr dereferences will happen in ShuttleGui because the |
| 893 | // radio buttons are never created. (See Populate() above.) |
| 894 | if ( !mProject ) { |
| 895 | return true; |
| 896 | } |
| 897 | |
| 898 | ShuttleGui S(this, eIsSavingToPrefs); |
| 899 | PopulateOrExchange(S); |
| 900 | |
| 901 | bool bFull = gPrefs->ReadBool(wxT("/GUI/Shortcuts/FullDefaults"), false); |
| 902 | for (size_t i = 0; i < mNames.size(); i++) { |
| 903 | const auto &dkey = bFull ? mDefaultKeys[i] : mStandardDefaultKeys[i]; |
| 904 | // using GET to interpret CommandID as a config path component |
| 905 | auto name = wxT("/NewKeys/") + mNames[i].GET(); |
| 906 | const auto &key = mNewKeys[i]; |
| 907 | |
| 908 | if (gPrefs->HasEntry(name)) { |
| 909 | if (key != NormalizedKeyString{ gPrefs->ReadObject(name, key) } ) { |
| 910 | gPrefs->Write(name, key); |
| 911 | } |
| 912 | if (key == dkey) { |
| 913 | gPrefs->DeleteEntry(name); |
| 914 | } |
| 915 | } |
| 916 | else { |
| 917 | if (key != dkey) { |
| 918 | gPrefs->Write(name, key); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | return gPrefs->Flush(); |
| 924 | } |
| 925 | |
| 926 | void KeyConfigPrefs::Cancel() |
| 927 | { |
no test coverage detected