mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +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
Notes:
sideshowbarker
2024-07-17 21:32:59 +09:00
Author: https://github.com/RasmusNylander Commit: https://github.com/SerenityOS/serenity/commit/c00014fa548 Pull-request: https://github.com/SerenityOS/serenity/pull/11443 Reviewed-by: https://github.com/awesomekling
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) 2021, Rasmus Nylander <RasmusNylander.SerenityOS@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "KeyboardMapperWidget.h"
|
||||
#include "KeyPositions.h"
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/InputBox.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
|
@ -178,11 +179,9 @@ ErrorOr<void> KeyboardMapperWidget::save_to_file(StringView filename)
|
|||
|
||||
// Write to file.
|
||||
String file_content = map_json.to_string();
|
||||
auto file = TRY(Core::File::open(filename, Core::OpenMode::WriteOnly));
|
||||
|
||||
bool result = file->write(file_content);
|
||||
if (!result)
|
||||
return Error::from_errno(file->error());
|
||||
auto file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Write));
|
||||
TRY(file.write(file_content.bytes()));
|
||||
file.close();
|
||||
|
||||
m_modified = false;
|
||||
m_filename = filename;
|
||||
|
@ -244,6 +243,7 @@ void KeyboardMapperWidget::update_window_title()
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
@ -48,7 +49,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto open_action = GUI::CommonActions::make_open_action(
|
||||
[&](auto&) {
|
||||
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());
|
||||
if (error_or.is_error())
|
||||
|
|
Loading…
Reference in a new issue