mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-03 22:54:55 +00:00
KeyboardMapper: Without arguments, load current keymap
This commit is contained in:
parent
dd4e670f72
commit
d9e7e13fb2
|
@ -31,6 +31,7 @@
|
|||
#include <LibGUI/InputBox.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/RadioButton.h>
|
||||
#include <LibKeyboard/CharacterMap.h>
|
||||
#include <LibKeyboard/CharacterMapFile.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
@ -145,9 +146,7 @@ void KeyboardMapperWidget::create_frame()
|
|||
void KeyboardMapperWidget::load_from_file(String file_name)
|
||||
{
|
||||
auto result = Keyboard::CharacterMapFile::load_from_file(file_name);
|
||||
if (!result.has_value()) {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
ASSERT(result.has_value());
|
||||
|
||||
m_file_name = file_name;
|
||||
m_character_map = result.value();
|
||||
|
@ -161,6 +160,23 @@ void KeyboardMapperWidget::load_from_file(String file_name)
|
|||
update_window_title();
|
||||
}
|
||||
|
||||
void KeyboardMapperWidget::load_from_system()
|
||||
{
|
||||
auto result = Keyboard::CharacterMap::fetch_system_map();
|
||||
ASSERT(!result.is_error());
|
||||
|
||||
m_file_name = String::formatted("/res/keymaps/{}.json", result.value().character_map_name());
|
||||
m_character_map = result.value().character_map_data();
|
||||
set_current_map("map");
|
||||
|
||||
for (Widget* widget : m_map_group->child_widgets()) {
|
||||
auto radio_button = (GUI::RadioButton*)widget;
|
||||
radio_button->set_checked(radio_button->name() == "map");
|
||||
}
|
||||
|
||||
update_window_title();
|
||||
}
|
||||
|
||||
void KeyboardMapperWidget::save()
|
||||
{
|
||||
save_to_file(m_file_name);
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
void create_frame();
|
||||
void load_from_file(const String);
|
||||
void load_from_system();
|
||||
void save();
|
||||
void save_to_file(const StringView&);
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ int main(int argc, char** argv)
|
|||
if (path != nullptr) {
|
||||
keyboard_mapper_widget->load_from_file(path);
|
||||
} else {
|
||||
keyboard_mapper_widget->load_from_file("/res/keymaps/en.json");
|
||||
keyboard_mapper_widget->load_from_system();
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
@ -84,8 +84,8 @@ int main(int argc, char** argv)
|
|||
});
|
||||
|
||||
auto save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
|
||||
String m_name = "Unnamed";
|
||||
Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, m_name, "json");
|
||||
String name = "Unnamed";
|
||||
Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, name, "json");
|
||||
if (!save_path.has_value())
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in a new issue