Slightly optimize accelerator token comparing.
This commit is contained in:
parent
534ff5efdb
commit
f091352c56
1 changed files with 11 additions and 16 deletions
|
@ -117,7 +117,12 @@ bool StringToAccelerator(const std::string& description,
|
||||||
int modifiers = ui::EF_NONE;
|
int modifiers = ui::EF_NONE;
|
||||||
ui::KeyboardCode key = ui::VKEY_UNKNOWN;
|
ui::KeyboardCode key = ui::VKEY_UNKNOWN;
|
||||||
for (size_t i = 0; i < tokens.size(); i++) {
|
for (size_t i = 0; i < tokens.size(); i++) {
|
||||||
if (tokens[i] == "ctrl") {
|
if (tokens[i].size() == 1) {
|
||||||
|
bool shifted = false;
|
||||||
|
key = KeyboardCodeFromCharCode(tokens[i][0], &shifted);
|
||||||
|
if (shifted)
|
||||||
|
modifiers |= ui::EF_SHIFT_DOWN;
|
||||||
|
} else if (tokens[i] == "ctrl") {
|
||||||
modifiers |= ui::EF_CONTROL_DOWN;
|
modifiers |= ui::EF_CONTROL_DOWN;
|
||||||
} else if (tokens[i] == "command") {
|
} else if (tokens[i] == "command") {
|
||||||
modifiers |= ui::EF_COMMAND_DOWN;
|
modifiers |= ui::EF_COMMAND_DOWN;
|
||||||
|
@ -125,27 +130,17 @@ bool StringToAccelerator(const std::string& description,
|
||||||
modifiers |= ui::EF_ALT_DOWN;
|
modifiers |= ui::EF_ALT_DOWN;
|
||||||
} else if (tokens[i] == "shift") {
|
} else if (tokens[i] == "shift") {
|
||||||
modifiers |= ui::EF_SHIFT_DOWN;
|
modifiers |= ui::EF_SHIFT_DOWN;
|
||||||
} else if (tokens[i].size() == 1) {
|
|
||||||
if (key != ui::VKEY_UNKNOWN) {
|
|
||||||
// Multiple key assignments.
|
|
||||||
key = ui::VKEY_UNKNOWN;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool shifted = false;
|
|
||||||
key = KeyboardCodeFromCharCode(tokens[i][0], &shifted);
|
|
||||||
if (key == ui::VKEY_UNKNOWN) {
|
|
||||||
LOG(WARNING) << "Invalid accelerator token: " << tokens[i];
|
|
||||||
return false;
|
|
||||||
} else if (shifted) {
|
|
||||||
modifiers |= ui::EF_SHIFT_DOWN;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LOG(WARNING) << "Invalid accelerator token: " << tokens[i];
|
LOG(WARNING) << "Invalid accelerator token: " << tokens[i];
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (key == ui::VKEY_UNKNOWN) {
|
||||||
|
LOG(WARNING) << "The accelerator doesn't contain a valid key";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
*accelerator = ui::Accelerator(key, modifiers);
|
*accelerator = ui::Accelerator(key, modifiers);
|
||||||
SetPlatformAccelerator(accelerator);
|
SetPlatformAccelerator(accelerator);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue