1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:17:35 +00:00

LibGUI: Remove Menu::try_add_action()

And fall back to the infallible add_action().
This commit is contained in:
Andreas Kling 2023-08-14 10:14:27 +02:00
parent eec328e2ab
commit f2faf2767f
51 changed files with 758 additions and 769 deletions

View file

@ -91,15 +91,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto game_menu = TRY(window->try_add_menu("&Game"_string));
TRY(game_menu->try_add_action(GUI::Action::create("&Resign", { Mod_None, Key_F3 }, [&](auto&) {
game_menu->add_action(GUI::Action::create("&Resign", { Mod_None, Key_F3 }, [&](auto&) {
widget->resign();
})));
TRY(game_menu->try_add_action(GUI::Action::create("&Flip Board", { Mod_Ctrl, Key_F }, [&](auto&) {
}));
game_menu->add_action(GUI::Action::create("&Flip Board", { Mod_Ctrl, Key_F }, [&](auto&) {
widget->flip_board();
})));
}));
game_menu->add_separator();
TRY(game_menu->try_add_action(GUI::Action::create("&Import PGN...", { Mod_Ctrl, Key_O }, [&](auto&) {
game_menu->add_action(GUI::Action::create("&Import PGN...", { Mod_Ctrl, Key_O }, [&](auto&) {
FileSystemAccessClient::OpenFileOptions options {
.allowed_file_types = Vector {
GUI::FileTypeFilter { "PGN Files", { { "pgn" } } },
@ -114,8 +114,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
dbgln("Failed to import PGN: {}", maybe_error.release_error());
else
dbgln("Imported PGN file from {}", result.value().filename());
})));
TRY(game_menu->try_add_action(GUI::Action::create("&Export PGN...", { Mod_Ctrl, Key_S }, [&](auto&) {
}));
game_menu->add_action(GUI::Action::create("&Export PGN...", { Mod_Ctrl, Key_S }, [&](auto&) {
auto result = FileSystemAccessClient::Client::the().save_file(window, "Untitled", "pgn");
if (result.is_error())
return;
@ -124,20 +124,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
dbgln("Failed to export PGN: {}", maybe_error.release_error());
else
dbgln("Exported PGN file to {}", result.value().filename());
})));
TRY(game_menu->try_add_action(GUI::Action::create("&Copy FEN", { Mod_Ctrl, Key_C }, [&](auto&) {
}));
game_menu->add_action(GUI::Action::create("&Copy FEN", { Mod_Ctrl, Key_C }, [&](auto&) {
GUI::Clipboard::the().set_data(widget->get_fen().release_value_but_fixme_should_propagate_errors().bytes());
GUI::MessageBox::show(window, "Board state copied to clipboard as FEN."sv, "Copy FEN"sv, GUI::MessageBox::Type::Information);
})));
}));
game_menu->add_separator();
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
game_menu->add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
if (widget->board().game_result() == Chess::Board::Result::NotFinished) {
if (widget->resign() < 0)
return;
}
widget->reset();
})));
}));
game_menu->add_separator();
auto settings_action = GUI::Action::create(
@ -146,7 +146,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
},
window);
settings_action->set_status_tip("Open the Game Settings for Chess"_string);
TRY(game_menu->try_add_action(settings_action));
game_menu->add_action(settings_action);
auto show_available_moves_action = GUI::Action::create_checkable("Show Available Moves", [&](auto& action) {
widget->set_show_available_moves(action.is_checked());
@ -154,12 +154,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Config::write_bool("Games"sv, "Chess"sv, "ShowAvailableMoves"sv, action.is_checked());
});
show_available_moves_action->set_checked(widget->show_available_moves());
TRY(game_menu->try_add_action(show_available_moves_action));
game_menu->add_action(show_available_moves_action);
game_menu->add_separator();
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
game_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
})));
}));
auto engine_menu = TRY(window->try_add_menu("&Engine"_string));
@ -171,7 +171,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
});
human_engine_checkbox->set_checked(true);
engines_action_group.add_action(human_engine_checkbox);
TRY(engine_submenu->try_add_action(human_engine_checkbox));
engine_submenu->add_action(human_engine_checkbox);
for (auto const& engine : engines) {
auto action = GUI::Action::create_checkable(engine.name, [&](auto&) {
@ -190,15 +190,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
widget->input_engine_move();
});
engines_action_group.add_action(*action);
TRY(engine_submenu->try_add_action(*action));
engine_submenu->add_action(*action);
}
auto help_menu = TRY(window->try_add_menu("&Help"_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&) {
help_menu->add_action(GUI::CommonActions::make_command_palette_action(window));
help_menu->add_action(GUI::CommonActions::make_help_action([](auto&) {
Desktop::Launcher::open(URL::create_with_file_scheme("/usr/share/man/man6/Chess.md"), "/bin/Help");
})));
TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Chess", app_icon, window)));
}));
help_menu->add_action(GUI::CommonActions::make_about_action("Chess", app_icon, window));
window->show();
widget->reset();