mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
KeyboardMapper: Port to Core::Stream
Port KeyboardMapperWidget to use the new Core::Stream instead of the old IODevice. If you can't beat 'em, join 'em.
This commit is contained in:
parent
9678ff15a8
commit
c00014fa54
3 changed files with 12 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
||||||
|
* Copyright (c) 2021, Rasmus Nylander <RasmusNylander.SerenityOS@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
||||||
|
* Copyright (c) 2021, Rasmus Nylander <RasmusNylander.SerenityOS@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "KeyboardMapperWidget.h"
|
#include "KeyboardMapperWidget.h"
|
||||||
#include "KeyPositions.h"
|
#include "KeyPositions.h"
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/Stream.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/InputBox.h>
|
#include <LibGUI/InputBox.h>
|
||||||
#include <LibGUI/MessageBox.h>
|
#include <LibGUI/MessageBox.h>
|
||||||
|
@ -178,11 +179,9 @@ ErrorOr<void> KeyboardMapperWidget::save_to_file(StringView filename)
|
||||||
|
|
||||||
// Write to file.
|
// Write to file.
|
||||||
String file_content = map_json.to_string();
|
String file_content = map_json.to_string();
|
||||||
auto file = TRY(Core::File::open(filename, Core::OpenMode::WriteOnly));
|
auto file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Write));
|
||||||
|
TRY(file.write(file_content.bytes()));
|
||||||
bool result = file->write(file_content);
|
file.close();
|
||||||
if (!result)
|
|
||||||
return Error::from_errno(file->error());
|
|
||||||
|
|
||||||
m_modified = false;
|
m_modified = false;
|
||||||
m_filename = filename;
|
m_filename = filename;
|
||||||
|
@ -244,6 +243,7 @@ void KeyboardMapperWidget::update_window_title()
|
||||||
window()->set_title(sb.to_string());
|
window()->set_title(sb.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardMapperWidget::show_error_to_user(Error error){
|
void KeyboardMapperWidget::show_error_to_user(Error error)
|
||||||
|
{
|
||||||
GUI::MessageBox::show_error(window(), error.string_literal());
|
GUI::MessageBox::show_error(window(), error.string_literal());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
||||||
|
* Copyright (c) 2021, Rasmus Nylander <RasmusNylander.SerenityOS@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -48,7 +49,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto open_action = GUI::CommonActions::make_open_action(
|
auto open_action = GUI::CommonActions::make_open_action(
|
||||||
[&](auto&) {
|
[&](auto&) {
|
||||||
Optional<String> path = GUI::FilePicker::get_open_filepath(window, "Open", "/res/keymaps/");
|
Optional<String> path = GUI::FilePicker::get_open_filepath(window, "Open", "/res/keymaps/");
|
||||||
if (!path.has_value()) return;
|
if (!path.has_value())
|
||||||
|
return;
|
||||||
|
|
||||||
ErrorOr<void> error_or = keyboard_mapper_widget->load_map_from_file(path.value());
|
ErrorOr<void> error_or = keyboard_mapper_widget->load_map_from_file(path.value());
|
||||||
if (error_or.is_error())
|
if (error_or.is_error())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue