mirror of
https://github.com/RGBCube/serenity
synced 2025-07-30 06:17:35 +00:00
LibGUI+Everywhere: Use fallible Window::set_main_widget() everywhere :^)
Rip that bandaid off! This does the following, in one big, awkward jump: - Replace all uses of `set_main_widget<Foo>()` with the `try` version. - Remove `set_main_widget<Foo>()`. - Rename the `try` version to just be `set_main_widget` because it's now the only one. The majority of places that call `set_main_widget<Foo>()` are inside constructors, so this unfortunately gives us a big batch of new `release_value_but_fixme_should_propagate_errors()` calls.
This commit is contained in:
parent
d223477bc6
commit
0c24522635
121 changed files with 441 additions and 449 deletions
|
@ -25,16 +25,16 @@ GameSizeDialog::GameSizeDialog(GUI::Window* parent, size_t board_size, size_t ta
|
|||
set_icon(parent->icon());
|
||||
set_resizable(false);
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(game_size_dialog_gml))
|
||||
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
if (!main_widget->load_from_gml(game_size_dialog_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto board_size_spinbox = main_widget.find_descendant_of_type_named<GUI::SpinBox>("board_size_spinbox");
|
||||
auto board_size_spinbox = main_widget->find_descendant_of_type_named<GUI::SpinBox>("board_size_spinbox");
|
||||
board_size_spinbox->set_value(m_board_size);
|
||||
|
||||
auto tile_value_label = main_widget.find_descendant_of_type_named<GUI::Label>("tile_value_label");
|
||||
auto tile_value_label = main_widget->find_descendant_of_type_named<GUI::Label>("tile_value_label");
|
||||
tile_value_label->set_text(DeprecatedString::number(target_tile()));
|
||||
auto target_spinbox = main_widget.find_descendant_of_type_named<GUI::SpinBox>("target_spinbox");
|
||||
auto target_spinbox = main_widget->find_descendant_of_type_named<GUI::SpinBox>("target_spinbox");
|
||||
target_spinbox->set_max(Game::max_power_for_board(m_board_size));
|
||||
target_spinbox->set_value(m_target_tile_power);
|
||||
|
||||
|
@ -48,20 +48,20 @@ GameSizeDialog::GameSizeDialog(GUI::Window* parent, size_t board_size, size_t ta
|
|||
tile_value_label->set_text(DeprecatedString::number(target_tile()));
|
||||
};
|
||||
|
||||
auto evil_ai_checkbox = main_widget.find_descendant_of_type_named<GUI::CheckBox>("evil_ai_checkbox");
|
||||
auto evil_ai_checkbox = main_widget->find_descendant_of_type_named<GUI::CheckBox>("evil_ai_checkbox");
|
||||
evil_ai_checkbox->set_checked(m_evil_ai);
|
||||
evil_ai_checkbox->on_checked = [this](auto checked) { m_evil_ai = checked; };
|
||||
|
||||
auto temporary_checkbox = main_widget.find_descendant_of_type_named<GUI::CheckBox>("temporary_checkbox");
|
||||
auto temporary_checkbox = main_widget->find_descendant_of_type_named<GUI::CheckBox>("temporary_checkbox");
|
||||
temporary_checkbox->set_checked(m_temporary);
|
||||
temporary_checkbox->on_checked = [this](auto checked) { m_temporary = checked; };
|
||||
|
||||
auto cancel_button = main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
auto cancel_button = main_widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
cancel_button->on_click = [this](auto) {
|
||||
done(ExecResult::Cancel);
|
||||
};
|
||||
|
||||
auto ok_button = main_widget.find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
auto ok_button = main_widget->find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
ok_button->on_click = [this](auto) {
|
||||
done(ExecResult::OK);
|
||||
};
|
||||
|
|
|
@ -66,15 +66,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->set_title("2048");
|
||||
window->resize(315, 336);
|
||||
|
||||
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(game_window_gml))
|
||||
auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
if (!main_widget->load_from_gml(game_window_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
Game game { board_size, target_tile, evil_ai };
|
||||
|
||||
auto board_view = TRY(main_widget.find_descendant_of_type_named<GUI::Widget>("board_view_container")->try_add<BoardView>(&game.board()));
|
||||
auto board_view = TRY(main_widget->find_descendant_of_type_named<GUI::Widget>("board_view_container")->try_add<BoardView>(&game.board()));
|
||||
board_view->set_focus(true);
|
||||
auto statusbar = main_widget.find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||
auto statusbar = main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||
|
||||
app->on_action_enter = [&](GUI::Action& action) {
|
||||
auto text = action.status_tip();
|
||||
|
|
|
@ -49,7 +49,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->resize(360, 462);
|
||||
window->set_resizable(false);
|
||||
|
||||
auto game = TRY(window->try_set_main_widget<BrickGame>(app_name));
|
||||
auto game = TRY(window->set_main_widget<BrickGame>(app_name));
|
||||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
|
|
|
@ -17,13 +17,13 @@ PromotionDialog::PromotionDialog(ChessWidget& chess_widget)
|
|||
set_icon(chess_widget.window()->icon());
|
||||
resize(70 * 4, 70);
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Frame>();
|
||||
main_widget.set_frame_shape(Gfx::FrameShape::Container);
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
main_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
auto main_widget = set_main_widget<GUI::Frame>().release_value_but_fixme_should_propagate_errors();
|
||||
main_widget->set_frame_shape(Gfx::FrameShape::Container);
|
||||
main_widget->set_fill_with_background_color(true);
|
||||
main_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
for (auto const& type : { Chess::Type::Queen, Chess::Type::Knight, Chess::Type::Rook, Chess::Type::Bishop }) {
|
||||
auto& button = main_widget.add<GUI::Button>("");
|
||||
auto& button = main_widget->add<GUI::Button>("");
|
||||
button.set_fixed_height(70);
|
||||
button.set_icon(chess_widget.get_piece_graphic({ chess_widget.board().turn(), type }));
|
||||
button.on_click = [this, type](auto) {
|
||||
|
|
|
@ -34,7 +34,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-chess"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
auto widget = TRY(window->try_set_main_widget<ChessWidget>());
|
||||
auto widget = TRY(window->set_main_widget<ChessWidget>());
|
||||
|
||||
TRY(Core::System::unveil("/sys/kernel/processes", "r"));
|
||||
TRY(Core::System::unveil("/res", "r"));
|
||||
|
|
|
@ -48,7 +48,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->resize(436, 481);
|
||||
window->set_resizable(false);
|
||||
|
||||
auto game = TRY(window->try_set_main_widget<ColorLines>(app_name));
|
||||
auto game = TRY(window->set_main_widget<ColorLines>(app_name));
|
||||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->set_title("Flappy Bug");
|
||||
window->set_double_buffering_enabled(false);
|
||||
window->set_resizable(false);
|
||||
auto widget = TRY(window->try_set_main_widget<FlappyBug::Game>(TRY(FlappyBug::Game::Bug::construct()), TRY(FlappyBug::Game::Cloud::construct())));
|
||||
auto widget = TRY(window->set_main_widget<FlappyBug::Game>(TRY(FlappyBug::Game::Bug::construct()), TRY(FlappyBug::Game::Cloud::construct())));
|
||||
|
||||
widget->on_game_end = [&](u32 score) {
|
||||
if (score <= high_score)
|
||||
|
|
|
@ -27,30 +27,30 @@ SettingsDialog::SettingsDialog(GUI::Window* parent, size_t board_rows, size_t bo
|
|||
set_icon(parent->icon());
|
||||
set_resizable(false);
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(settings_dialog_gml))
|
||||
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
if (!main_widget->load_from_gml(settings_dialog_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto board_rows_spinbox = main_widget.find_descendant_of_type_named<GUI::SpinBox>("board_rows_spinbox");
|
||||
auto board_rows_spinbox = main_widget->find_descendant_of_type_named<GUI::SpinBox>("board_rows_spinbox");
|
||||
board_rows_spinbox->set_value(m_board_rows);
|
||||
|
||||
board_rows_spinbox->on_change = [&](auto value) {
|
||||
m_board_rows = value;
|
||||
};
|
||||
|
||||
auto board_columns_spinbox = main_widget.find_descendant_of_type_named<GUI::SpinBox>("board_columns_spinbox");
|
||||
auto board_columns_spinbox = main_widget->find_descendant_of_type_named<GUI::SpinBox>("board_columns_spinbox");
|
||||
board_columns_spinbox->set_value(m_board_columns);
|
||||
|
||||
board_columns_spinbox->on_change = [&](auto value) {
|
||||
m_board_columns = value;
|
||||
};
|
||||
|
||||
auto cancel_button = main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
auto cancel_button = main_widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
cancel_button->on_click = [this](auto) {
|
||||
done(ExecResult::Cancel);
|
||||
};
|
||||
|
||||
auto ok_button = main_widget.find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
auto ok_button = main_widget->find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
ok_button->on_click = [this](auto) {
|
||||
done(ExecResult::OK);
|
||||
};
|
||||
|
|
|
@ -82,16 +82,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->set_title("Flood");
|
||||
window->resize(304, 325);
|
||||
|
||||
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(flood_window_gml))
|
||||
auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
if (!main_widget->load_from_gml(flood_window_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto board_widget = TRY(main_widget.find_descendant_of_type_named<GUI::Widget>("board_widget_container")->try_add<BoardWidget>(board_rows, board_columns));
|
||||
auto board_widget = TRY(main_widget->find_descendant_of_type_named<GUI::Widget>("board_widget_container")->try_add<BoardWidget>(board_rows, board_columns));
|
||||
board_widget->board()->randomize();
|
||||
int ai_moves = get_number_of_moves_from_ai(*board_widget->board());
|
||||
int moves_made = 0;
|
||||
|
||||
auto statusbar = main_widget.find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||
auto statusbar = main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||
|
||||
app->on_action_enter = [&](GUI::Action& action) {
|
||||
auto text = action.status_tip();
|
||||
|
|
|
@ -52,7 +52,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->set_double_buffering_enabled(false);
|
||||
window->set_title("Game Of Life");
|
||||
|
||||
auto main_widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
main_widget->load_from_gml(game_of_life_gml);
|
||||
main_widget->set_fill_with_background_color(true);
|
||||
|
||||
|
|
|
@ -122,16 +122,16 @@ void Game::show_score_card(bool game_over)
|
|||
score_dialog->set_resizable(false);
|
||||
score_dialog->set_icon(window()->icon());
|
||||
|
||||
auto& score_widget = score_dialog->set_main_widget<GUI::Widget>();
|
||||
score_widget.set_fill_with_background_color(true);
|
||||
auto& layout = score_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
auto score_widget = score_dialog->set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
score_widget->set_fill_with_background_color(true);
|
||||
auto& layout = score_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
layout.set_margins(10);
|
||||
layout.set_spacing(15);
|
||||
|
||||
auto& card_container = score_widget.add<GUI::Widget>();
|
||||
auto& card_container = score_widget->add<GUI::Widget>();
|
||||
auto& score_card = card_container.add<ScoreCard>(m_players, game_over);
|
||||
|
||||
auto& button_container = score_widget.add<GUI::Widget>();
|
||||
auto& button_container = score_widget->add<GUI::Widget>();
|
||||
button_container.set_shrink_to_fit(true);
|
||||
button_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@ SettingsDialog::SettingsDialog(GUI::Window* parent, DeprecatedString player_name
|
|||
set_icon(parent->icon());
|
||||
set_resizable(false);
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
main_widget->set_fill_with_background_color(true);
|
||||
|
||||
auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
auto& layout = main_widget->set_layout<GUI::VerticalBoxLayout>();
|
||||
layout.set_margins(4);
|
||||
|
||||
auto& name_box = main_widget.add<GUI::Widget>();
|
||||
auto& name_box = main_widget->add<GUI::Widget>();
|
||||
auto& input_layout = name_box.set_layout<GUI::HorizontalBoxLayout>();
|
||||
input_layout.set_spacing(4);
|
||||
|
||||
|
@ -38,7 +38,7 @@ SettingsDialog::SettingsDialog(GUI::Window* parent, DeprecatedString player_name
|
|||
m_player_name = textbox.text();
|
||||
};
|
||||
|
||||
auto& button_box = main_widget.add<GUI::Widget>();
|
||||
auto& button_box = main_widget->add<GUI::Widget>();
|
||||
auto& button_layout = button_box.set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_layout.set_spacing(10);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto window = TRY(GUI::Window::try_create());
|
||||
window->set_title("Hearts");
|
||||
|
||||
auto widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
auto widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
widget->load_from_gml(hearts_gml);
|
||||
|
||||
auto& game = *widget->find_descendant_of_type_named<Hearts::Game>("game");
|
||||
|
|
|
@ -46,7 +46,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->set_title("MasterWord");
|
||||
window->set_resizable(false);
|
||||
|
||||
auto main_widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
main_widget->load_from_gml(master_word_gml);
|
||||
auto& game = *main_widget->find_descendant_of_type_named<MasterWord::WordGame>("word_game");
|
||||
auto& statusbar = *main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||
|
|
|
@ -45,15 +45,15 @@ CustomGameDialog::CustomGameDialog(Window* parent_window)
|
|||
set_resizable(false);
|
||||
set_title("Custom game");
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(minesweeper_custom_game_window_gml))
|
||||
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
if (!main_widget->load_from_gml(minesweeper_custom_game_window_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
m_columns_spinbox = *main_widget.find_descendant_of_type_named<GUI::SpinBox>("columns_spinbox");
|
||||
m_rows_spinbox = *main_widget.find_descendant_of_type_named<GUI::SpinBox>("rows_spinbox");
|
||||
m_mines_spinbox = *main_widget.find_descendant_of_type_named<GUI::SpinBox>("mines_spinbox");
|
||||
m_ok_button = *main_widget.find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
m_cancel_button = *main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
m_columns_spinbox = *main_widget->find_descendant_of_type_named<GUI::SpinBox>("columns_spinbox");
|
||||
m_rows_spinbox = *main_widget->find_descendant_of_type_named<GUI::SpinBox>("rows_spinbox");
|
||||
m_mines_spinbox = *main_widget->find_descendant_of_type_named<GUI::SpinBox>("mines_spinbox");
|
||||
m_ok_button = *main_widget->find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
m_cancel_button = *main_widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
|
||||
m_columns_spinbox->on_change = [this](auto) {
|
||||
set_max_mines();
|
||||
|
|
|
@ -49,7 +49,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->set_title("Minesweeper");
|
||||
window->resize(139, 177);
|
||||
|
||||
auto widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
auto widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
widget->load_from_gml(minesweeper_window_gml);
|
||||
|
||||
auto& separator = *widget->find_descendant_of_type_named<GUI::HorizontalSeparator>("separator");
|
||||
|
|
|
@ -48,7 +48,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->set_title("Snake");
|
||||
window->resize(324, 345);
|
||||
|
||||
auto widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
auto widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
TRY(widget->try_load_from_gml(snake_gml));
|
||||
|
||||
auto& game = *widget->find_descendant_of_type_named<Snake::Game>("game");
|
||||
|
|
|
@ -83,7 +83,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (mode >= Solitaire::Mode::__Count)
|
||||
update_mode(Solitaire::Mode::SingleCardDraw);
|
||||
|
||||
auto widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
auto widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
TRY(widget->try_load_from_gml(solitaire_gml));
|
||||
|
||||
auto& game = *widget->find_descendant_of_type_named<Solitaire::Game>("game");
|
||||
|
|
|
@ -117,7 +117,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (statistic_display >= StatisticDisplay::__Count)
|
||||
update_statistic_display(StatisticDisplay::HighScore);
|
||||
|
||||
auto widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
auto widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
TRY(widget->try_load_from_gml(spider_gml));
|
||||
|
||||
auto& game = *widget->find_descendant_of_type_named<Spider::Game>("game");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue