From abe5787126c0f2488dee3f17ebd472cb4129a6ad Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sun, 16 Apr 2023 15:22:41 +0200 Subject: [PATCH] CharacterMap: Propagate errors from `initialize_menubar()` --- .../CharacterMap/CharacterMapWidget.cpp | 19 ++++++++++--------- .../CharacterMap/CharacterMapWidget.h | 2 +- Userland/Applications/CharacterMap/main.cpp | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp index 13a625a5d6a..b6756126819 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp @@ -149,19 +149,20 @@ CharacterMapWidget::CharacterMapWidget() update_statusbar(); } -void CharacterMapWidget::initialize_menubar(GUI::Window& window) +ErrorOr CharacterMapWidget::initialize_menubar(GUI::Window& window) { - auto& file_menu = window.add_menu("&File"_short_string); - file_menu.add_action(GUI::CommonActions::make_quit_action([](GUI::Action&) { + auto file_menu = TRY(window.try_add_menu("&File"_short_string)); + TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([](GUI::Action&) { GUI::Application::the()->quit(); - })); + }))); - auto& help_menu = window.add_menu("&Help"_short_string); - help_menu.add_action(GUI::CommonActions::make_command_palette_action(&window)); - help_menu.add_action(GUI::CommonActions::make_help_action([&](auto&) { + auto help_menu = TRY(window.try_add_menu("&Help"_short_string)); + TRY(help_menu->try_add_action(GUI::CommonActions::make_command_palette_action(&window))); + TRY(help_menu->try_add_action(GUI::CommonActions::make_help_action([&](auto&) { Desktop::Launcher::open(URL::create_with_file_scheme("/usr/share/man/man1/CharacterMap.md"), "/bin/Help"); - })); - help_menu.add_action(GUI::CommonActions::make_about_action("Character Map", GUI::Icon::default_icon("app-character-map"sv), &window)); + }))); + TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Character Map", GUI::Icon::default_icon("app-character-map"sv), &window))); + return {}; } void CharacterMapWidget::did_change_font() diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.h b/Userland/Applications/CharacterMap/CharacterMapWidget.h index 214f6108367..562185a86ff 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.h +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.h @@ -17,7 +17,7 @@ class CharacterMapWidget final : public GUI::Widget { public: virtual ~CharacterMapWidget() override = default; - void initialize_menubar(GUI::Window& window); + ErrorOr initialize_menubar(GUI::Window& window); private: CharacterMapWidget(); diff --git a/Userland/Applications/CharacterMap/main.cpp b/Userland/Applications/CharacterMap/main.cpp index 7be95272da4..d5b8a911a0a 100644 --- a/Userland/Applications/CharacterMap/main.cpp +++ b/Userland/Applications/CharacterMap/main.cpp @@ -70,7 +70,7 @@ ErrorOr serenity_main(Main::Arguments arguments) window->resize(600, 400); auto character_map_widget = TRY(window->set_main_widget()); - character_map_widget->initialize_menubar(*window); + TRY(character_map_widget->initialize_menubar(*window)); auto font_query = Config::read_string("CharacterMap"sv, "History"sv, "Font"sv, Gfx::FontDatabase::the().default_font_query()); character_map_widget->set_font(Gfx::FontDatabase::the().get_by_name(font_query));