1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:17:34 +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:
Sam Atkins 2023-01-06 16:48:37 +00:00 committed by Andrew Kaster
parent d223477bc6
commit 0c24522635
121 changed files with 441 additions and 449 deletions

View file

@ -84,14 +84,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16));
window->resize(800, 600);
auto splitter = TRY(window->try_set_main_widget<GUI::HorizontalSplitter>());
auto splitter = TRY(window->set_main_widget<GUI::HorizontalSplitter>());
auto editor = TRY(splitter->try_add<GUI::TextEditor>());
auto preview_frame_widget = TRY(splitter->try_add<GUI::Frame>());
auto preview_window = TRY(GUI::Window::try_create());
preview_window->set_title("Preview - GML Playground");
preview_window->set_icon(app_icon.bitmap_for_size(16));
auto preview_window_widget = TRY(preview_window->try_set_main_widget<GUI::Widget>());
auto preview_window_widget = TRY(preview_window->set_main_widget<GUI::Widget>());
preview_window_widget->set_fill_with_background_color(true);
GUI::Widget* preview = preview_frame_widget;

View file

@ -17,13 +17,13 @@ GitCommitDialog::GitCommitDialog(GUI::Window* parent)
set_title("Commit");
set_icon(parent->icon());
auto& widget = set_main_widget<GUI::Widget>();
widget.load_from_gml(git_commit_dialog_gml);
auto widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
widget->load_from_gml(git_commit_dialog_gml);
m_message_editor = widget.find_descendant_of_type_named<GUI::TextEditor>("message_editor");
m_cancel_button = widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
m_commit_button = widget.find_descendant_of_type_named<GUI::Button>("commit_button");
m_line_and_col_label = widget.find_descendant_of_type_named<GUI::Label>("line_and_col_label");
m_message_editor = widget->find_descendant_of_type_named<GUI::TextEditor>("message_editor");
m_cancel_button = widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
m_commit_button = widget->find_descendant_of_type_named<GUI::Button>("commit_button");
m_line_and_col_label = widget->find_descendant_of_type_named<GUI::Label>("line_and_col_label");
m_message_editor->on_change = [this]() {
m_commit_button->set_enabled(!m_message_editor->text().is_empty() && on_commit);

View file

@ -49,10 +49,10 @@ NewProjectDialog::NewProjectDialog(GUI::Window* parent)
set_resizable(false);
set_title("New project");
auto& main_widget = set_main_widget<GUI::Widget>();
main_widget.load_from_gml(new_project_dialog_gml);
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
main_widget->load_from_gml(new_project_dialog_gml);
m_icon_view_container = *main_widget.find_descendant_of_type_named<GUI::Widget>("icon_view_container");
m_icon_view_container = *main_widget->find_descendant_of_type_named<GUI::Widget>("icon_view_container");
m_icon_view = m_icon_view_container->add<GUI::IconView>();
m_icon_view->set_always_wrap_item_labels(true);
m_icon_view->set_model(m_model);
@ -65,24 +65,24 @@ NewProjectDialog::NewProjectDialog(GUI::Window* parent)
do_create_project();
};
m_description_label = *main_widget.find_descendant_of_type_named<GUI::Label>("description_label");
m_name_input = *main_widget.find_descendant_of_type_named<GUI::TextBox>("name_input");
m_description_label = *main_widget->find_descendant_of_type_named<GUI::Label>("description_label");
m_name_input = *main_widget->find_descendant_of_type_named<GUI::TextBox>("name_input");
m_name_input->on_change = [&]() {
update_dialog();
};
m_create_in_input = *main_widget.find_descendant_of_type_named<GUI::TextBox>("create_in_input");
m_create_in_input = *main_widget->find_descendant_of_type_named<GUI::TextBox>("create_in_input");
m_create_in_input->on_change = [&]() {
update_dialog();
};
m_full_path_label = *main_widget.find_descendant_of_type_named<GUI::Label>("full_path_label");
m_full_path_label = *main_widget->find_descendant_of_type_named<GUI::Label>("full_path_label");
m_ok_button = *main_widget.find_descendant_of_type_named<GUI::Button>("ok_button");
m_ok_button = *main_widget->find_descendant_of_type_named<GUI::Button>("ok_button");
m_ok_button->set_default(true);
m_ok_button->on_click = [this](auto) {
do_create_project();
};
m_cancel_button = *main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
m_cancel_button = *main_widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
m_cancel_button->on_click = [this](auto) {
done(ExecResult::Cancel);
};

View file

@ -94,7 +94,7 @@ ErrorOr<void> Editor::initialize_tooltip_window()
s_tooltip_window->set_window_type(GUI::WindowType::Tooltip);
}
if (s_tooltip_page_view.is_null()) {
s_tooltip_page_view = TRY(s_tooltip_window->try_set_main_widget<WebView::OutOfProcessWebView>());
s_tooltip_page_view = TRY(s_tooltip_window->set_main_widget<WebView::OutOfProcessWebView>());
}
return {};
}

View file

@ -149,7 +149,7 @@ Locator::Locator(Core::Object* parent)
m_popup_window->set_window_type(GUI::WindowType::Popup);
m_popup_window->set_rect(0, 0, 500, 200);
m_suggestion_view = m_popup_window->set_main_widget<GUI::TableView>();
m_suggestion_view = m_popup_window->set_main_widget<GUI::TableView>().release_value_but_fixme_should_propagate_errors();
m_suggestion_view->set_column_headers_visible(false);
m_suggestion_view->on_activation = [this](auto& index) {

View file

@ -99,7 +99,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}));
help_menu.add_action(GUI::CommonActions::make_about_action("Inspector", app_icon, window));
auto widget = TRY(window->try_set_main_widget<GUI::Widget>());
auto widget = TRY(window->set_main_widget<GUI::Widget>());
widget->set_fill_with_background_color(true);
widget->set_layout<GUI::VerticalBoxLayout>();

View file

@ -86,7 +86,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16));
window->resize(800, 600);
auto main_widget = TRY(window->try_set_main_widget<GUI::Widget>());
auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
main_widget->set_fill_with_background_color(true);
main_widget->set_layout<GUI::VerticalBoxLayout>();
@ -318,19 +318,19 @@ static bool prompt_to_stop_profiling(pid_t pid, DeprecatedString const& process_
window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-profiler.png"sv).release_value_but_fixme_should_propagate_errors());
window->center_on_screen();
auto& widget = window->set_main_widget<GUI::Widget>();
widget.set_fill_with_background_color(true);
auto& layout = widget.set_layout<GUI::VerticalBoxLayout>();
auto widget = window->set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
widget->set_fill_with_background_color(true);
auto& layout = widget->set_layout<GUI::VerticalBoxLayout>();
layout.set_margins({ 0, 0, 16 });
auto& timer_label = widget.add<GUI::Label>("...");
auto& timer_label = widget->add<GUI::Label>("...");
Core::ElapsedTimer clock;
clock.start();
auto update_timer = Core::Timer::construct(100, [&] {
timer_label.set_text(DeprecatedString::formatted("{:.1} seconds", clock.elapsed() / 1000.0f));
});
auto& stop_button = widget.add<GUI::Button>("Stop");
auto& stop_button = widget->add<GUI::Button>("Stop");
stop_button.set_fixed_size(140, 22);
stop_button.on_click = [&](auto) {
GUI::Application::the()->quit();

View file

@ -30,7 +30,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16));
window->set_title("SQL Studio");
auto main_widget = TRY(window->try_set_main_widget<MainWidget>());
auto main_widget = TRY(window->set_main_widget<MainWidget>());
main_widget->initialize_menu(window);
window->on_close_request = [&] {