mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
KeyboardMapper: Extract method map_from_name
Extract the mapping of a name to a character map into its own method. This only slightly reduces the number of lines, going from 24 to 17 lines, but makes the code somewhat more readable and reduces repetition.
This commit is contained in:
parent
b2a6c9e5ea
commit
a1531dba91
2 changed files with 25 additions and 32 deletions
|
@ -52,21 +52,7 @@ void KeyboardMapperWidget::create_frame()
|
|||
VERIFY(index > 0);
|
||||
|
||||
tmp_button.set_text(value);
|
||||
u32* map;
|
||||
|
||||
if (m_current_map_name == "map") {
|
||||
map = m_character_map.map;
|
||||
} else if (m_current_map_name == "shift_map") {
|
||||
map = m_character_map.shift_map;
|
||||
} else if (m_current_map_name == "alt_map") {
|
||||
map = m_character_map.alt_map;
|
||||
} else if (m_current_map_name == "altgr_map") {
|
||||
map = m_character_map.altgr_map;
|
||||
} else if (m_current_map_name == "shift_altgr_map") {
|
||||
map = m_character_map.shift_altgr_map;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
u32* map = map_from_name(m_current_map_name);
|
||||
|
||||
if (value.length() == 0)
|
||||
map[index] = '\0'; // Empty string
|
||||
|
@ -100,14 +86,34 @@ void KeyboardMapperWidget::create_frame()
|
|||
bottom_widget.layout()->add_spacer();
|
||||
}
|
||||
|
||||
void KeyboardMapperWidget::add_map_radio_button(const StringView map_name, const StringView button_text) {
|
||||
void KeyboardMapperWidget::add_map_radio_button(const StringView map_name, const StringView button_text)
|
||||
{
|
||||
auto& map_radio_button = m_map_group->add<GUI::RadioButton>(button_text);
|
||||
map_radio_button.set_name(map_name);
|
||||
map_radio_button.on_checked = [map_name, this](bool){
|
||||
map_radio_button.on_checked = [map_name, this](bool) {
|
||||
set_current_map(map_name);
|
||||
};
|
||||
}
|
||||
|
||||
u32* KeyboardMapperWidget::map_from_name(const StringView map_name)
|
||||
{
|
||||
u32* map;
|
||||
if (map_name == "map"sv) {
|
||||
map = m_character_map.map;
|
||||
} else if (map_name == "shift_map"sv) {
|
||||
map = m_character_map.shift_map;
|
||||
} else if (map_name == "alt_map"sv) {
|
||||
map = m_character_map.alt_map;
|
||||
} else if (map_name == "altgr_map"sv) {
|
||||
map = m_character_map.altgr_map;
|
||||
} else if (map_name == "shift_altgr_map"sv) {
|
||||
map = m_character_map.shift_altgr_map;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
void KeyboardMapperWidget::load_from_file(String filename)
|
||||
{
|
||||
auto result = Keyboard::CharacterMapFile::load_from_file(filename);
|
||||
|
@ -230,21 +236,7 @@ void KeyboardMapperWidget::keyup_event(GUI::KeyEvent& event)
|
|||
void KeyboardMapperWidget::set_current_map(const String current_map)
|
||||
{
|
||||
m_current_map_name = current_map;
|
||||
u32* map;
|
||||
|
||||
if (m_current_map_name == "map") {
|
||||
map = m_character_map.map;
|
||||
} else if (m_current_map_name == "shift_map") {
|
||||
map = m_character_map.shift_map;
|
||||
} else if (m_current_map_name == "alt_map") {
|
||||
map = m_character_map.alt_map;
|
||||
} else if (m_current_map_name == "altgr_map") {
|
||||
map = m_character_map.altgr_map;
|
||||
} else if (m_current_map_name == "shift_altgr_map") {
|
||||
map = m_character_map.shift_altgr_map;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
u32* map = map_from_name(m_current_map_name);
|
||||
|
||||
for (unsigned k = 0; k < KEY_COUNT; k++) {
|
||||
auto index = keys[k].map_index;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue