| 24 | m_keys[0] = m_keys[1] = -1; |
| 25 | } |
| 26 | void KeyboardShortcuts::Load() |
| 27 | { |
| 28 | ed::Logger::Get().Log("Loading keyboard shortcuts"); |
| 29 | |
| 30 | std::ifstream file(getShortcutsFilePath()); |
| 31 | std::string str; |
| 32 | |
| 33 | // pre setup Editor shortcuts (TODO: improve this... TextEditor::GetDefaultShortcuts()) |
| 34 | std::vector<TextEditor::Shortcut> eds = TextEditor::GetDefaultShortcuts(); |
| 35 | for (int i = 0; i < eds.size(); i++) |
| 36 | Set(std::string("Editor." + std::string(EDITOR_SHORTCUT_NAMES[i])).c_str(), eds[i].Key1, eds[i].Key2, eds[i].Alt, eds[i].Ctrl, eds[i].Shift); |
| 37 | |
| 38 | while (std::getline(file, str)) { |
| 39 | std::stringstream ss(str); |
| 40 | std::string name, token; |
| 41 | |
| 42 | ss >> name; |
| 43 | |
| 44 | if (name.empty()) continue; |
| 45 | |
| 46 | int vk1 = -1, vk2 = -1; |
| 47 | bool alt = false, ctrl = false, shift = false; |
| 48 | while (ss >> token) { |
| 49 | if (token == "CTRL") |
| 50 | ctrl = true; |
| 51 | else if (token == "ALT") |
| 52 | alt = true; |
| 53 | else if (token == "SHIFT") |
| 54 | shift = true; |
| 55 | else if (token == "NONE") |
| 56 | break; |
| 57 | else { |
| 58 | if (vk1 == -1) |
| 59 | vk1 = SDL_GetKeyFromName(token.c_str()); |
| 60 | else if (m_data[name].Key2 == -1) |
| 61 | vk2 = SDL_GetKeyFromName(token.c_str()); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | Set(name, vk1, vk2, alt, ctrl, shift); |
| 66 | } |
| 67 | |
| 68 | ed::Logger::Get().Log("Loaded shortcut information"); |
| 69 | } |
| 70 | void KeyboardShortcuts::Save() |
| 71 | { |
| 72 | ed::Logger::Get().Log("Saving keyboard shortcuts"); |
nothing calls this directly
no test coverage detected