CharacterMap: Propagate errors from initialize_menubar()

This commit is contained in:
Karol Kosek 2023-04-16 15:22:41 +02:00 committed by Sam Atkins
parent b4f78760f2
commit abe5787126
Notes: sideshowbarker 2024-07-17 20:33:50 +09:00
3 changed files with 12 additions and 11 deletions

View File

@ -149,19 +149,20 @@ CharacterMapWidget::CharacterMapWidget()
update_statusbar();
}
void CharacterMapWidget::initialize_menubar(GUI::Window& window)
ErrorOr<void> 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()

View File

@ -17,7 +17,7 @@ class CharacterMapWidget final : public GUI::Widget {
public:
virtual ~CharacterMapWidget() override = default;
void initialize_menubar(GUI::Window& window);
ErrorOr<void> initialize_menubar(GUI::Window& window);
private:
CharacterMapWidget();

View File

@ -70,7 +70,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->resize(600, 400);
auto character_map_widget = TRY(window->set_main_widget<CharacterMapWidget>());
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));