From e9a150c87c606eff8c696faed2dca3d3f2c2628f Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Sat, 30 Jul 2022 07:29:04 -0400 Subject: [PATCH] FontEditor: Add show_error() helper --- .../Applications/FontEditor/MainWidget.cpp | 29 ++++++++++--------- Userland/Applications/FontEditor/MainWidget.h | 2 ++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index ebf53da591..f87e6826e4 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -178,7 +178,7 @@ ErrorOr MainWidget::create_actions() m_open_preview_action = GUI::Action::create("&Preview Font", { Mod_Ctrl, Key_P }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png"sv)), [&](auto&) { if (!m_font_preview_window) { if (auto maybe_window = create_preview_window(); maybe_window.is_error()) - warnln("Failed to create preview window: {}", maybe_window.error()); + show_error("Failed to create preview window"sv, maybe_window.error()); else m_font_preview_window = maybe_window.release_value(); } @@ -715,19 +715,13 @@ bool MainWidget::open_file(String const& path) void MainWidget::push_undo() { auto maybe_state = m_undo_selection->save_state(); - if (maybe_state.is_error()) { - warnln("Failed to save undo state: {}", maybe_state.error()); - return; - } - auto state = maybe_state.release_value(); - auto maybe_command = try_make(*m_undo_selection, move(state)); - if (maybe_command.is_error()) { - warnln("Failed to make undo command: {}", maybe_command.error()); - return; - } - auto command = maybe_command.release_value(); - if (auto maybe_push = m_undo_stack->try_push(move(command)); maybe_push.is_error()) - warnln("Failed to push undo stack: {}", maybe_push.error()); + if (maybe_state.is_error()) + return show_error("Failed to save undo state"sv, maybe_state.error()); + auto maybe_command = try_make(*m_undo_selection, move(maybe_state.value())); + if (maybe_command.is_error()) + return show_error("Failed to make undo command"sv, maybe_command.error()); + if (auto maybe_push = m_undo_stack->try_push(move(maybe_command.value())); maybe_push.is_error()) + show_error("Failed to push undo stack"sv, maybe_push.error()); } void MainWidget::reset_selection_and_push_undo() @@ -993,4 +987,11 @@ void MainWidget::delete_selected_glyphs() update_statusbar(); } +void MainWidget::show_error(StringView preface, Error error) +{ + auto formatted_error = String::formatted("{}: {}", preface, error); + GUI::MessageBox::show_error(window(), formatted_error); + warnln(formatted_error); +} + } diff --git a/Userland/Applications/FontEditor/MainWidget.h b/Userland/Applications/FontEditor/MainWidget.h index 4b7af7c9df..5ee8d8ab30 100644 --- a/Userland/Applications/FontEditor/MainWidget.h +++ b/Userland/Applications/FontEditor/MainWidget.h @@ -78,6 +78,8 @@ private: void push_undo(); void reset_selection_and_push_undo(); + void show_error(StringView preface, Error); + RefPtr m_edited_font; RefPtr m_glyph_map_widget;