diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index c2f1b1bffa5..897ccb2037a 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -646,40 +646,42 @@ void SpreadsheetWidget::clipboard_action(bool is_cut) GUI::Clipboard::the().set_data(text_builder.string_view().bytes(), "text/plain", move(metadata)); } -void SpreadsheetWidget::initialize_menubar(GUI::Window& window) +ErrorOr SpreadsheetWidget::initialize_menubar(GUI::Window& window) { - auto& file_menu = window.add_menu("&File"); - file_menu.add_action(*m_new_action); - file_menu.add_action(*m_open_action); - file_menu.add_action(*m_save_action); - file_menu.add_action(*m_save_as_action); - file_menu.add_separator(); - file_menu.add_action(*m_import_action); - file_menu.add_separator(); - file_menu.add_recent_files_list([&](auto& action) { - if (!request_close()) - return; + auto file_menu = TRY(window.try_add_menu("&File")); + TRY(file_menu->try_add_action(*m_new_action)); + TRY(file_menu->try_add_action(*m_open_action)); + TRY(file_menu->try_add_action(*m_save_action)); + TRY(file_menu->try_add_action(*m_save_as_action)); + TRY(file_menu->try_add_separator()); + TRY(file_menu->try_add_action(*m_import_action)); + TRY(file_menu->try_add_separator()); + TRY(file_menu->add_recent_files_list([&](auto& action) { + if (!request_close()) + return; - auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, action.text()); - if (response.is_error()) - return; - load_file(response.value().filename(), response.value().stream()); - }) - .release_value_but_fixme_should_propagate_errors(); - file_menu.add_action(*m_quit_action); + auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, action.text()); + if (response.is_error()) + return; + load_file(response.value().filename(), response.value().stream()); + })); + TRY(file_menu->try_add_action(*m_quit_action)); - auto& edit_menu = window.add_menu("&Edit"); - edit_menu.add_action(*m_undo_action); - edit_menu.add_action(*m_redo_action); - edit_menu.add_separator(); - edit_menu.add_action(*m_cut_action); - edit_menu.add_action(*m_copy_action); - edit_menu.add_action(*m_paste_action); - edit_menu.add_action(*m_insert_emoji_action); + auto edit_menu = TRY(window.try_add_menu("&Edit")); + TRY(edit_menu->try_add_action(*m_undo_action)); + TRY(edit_menu->try_add_action(*m_redo_action)); + TRY(edit_menu->try_add_separator()); + TRY(edit_menu->try_add_action(*m_cut_action)); + TRY(edit_menu->try_add_action(*m_copy_action)); + TRY(edit_menu->try_add_action(*m_paste_action)); + TRY(edit_menu->try_add_action(*m_insert_emoji_action)); - auto& help_menu = window.add_menu("&Help"); - help_menu.add_action(*m_search_action); - help_menu.add_action(*m_functions_help_action); - help_menu.add_action(*m_about_action); + auto help_menu = TRY(window.try_add_menu("&Help")); + TRY(help_menu->try_add_action(*m_search_action)); + TRY(help_menu->try_add_action(*m_functions_help_action)); + TRY(help_menu->try_add_action(*m_about_action)); + + return {}; } + } diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.h b/Userland/Applications/Spreadsheet/SpreadsheetWidget.h index b27c9604850..856789c8af9 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.h +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.h @@ -45,7 +45,7 @@ public: return current_view()->cursor(); } - void initialize_menubar(GUI::Window&); + ErrorOr initialize_menubar(GUI::Window&); void undo(); void redo(); diff --git a/Userland/Applications/Spreadsheet/main.cpp b/Userland/Applications/Spreadsheet/main.cpp index 5ae81a6aebd..73e1b5ca991 100644 --- a/Userland/Applications/Spreadsheet/main.cpp +++ b/Userland/Applications/Spreadsheet/main.cpp @@ -57,7 +57,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto spreadsheet_widget = TRY(window->set_main_widget(*window, Vector> {}, filename.is_empty())); - spreadsheet_widget->initialize_menubar(*window); + TRY(spreadsheet_widget->initialize_menubar(*window)); spreadsheet_widget->update_window_title(); window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {