1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:37: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:
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

@ -30,15 +30,15 @@ AboutDialog::AboutDialog(StringView name, StringView version, Gfx::Bitmap const*
if (parent_window)
set_icon(parent_window->icon());
auto& widget = set_main_widget<Widget>();
widget.set_fill_with_background_color(true);
widget.set_layout<VerticalBoxLayout>();
widget.layout()->set_spacing(0);
auto widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
widget->set_fill_with_background_color(true);
widget->set_layout<VerticalBoxLayout>();
widget->layout()->set_spacing(0);
auto& banner_image = widget.add<GUI::ImageWidget>();
auto& banner_image = widget->add<GUI::ImageWidget>();
banner_image.load_from_file("/res/graphics/brand-banner.png"sv);
auto& content_container = widget.add<Widget>();
auto& content_container = widget->add<Widget>();
content_container.set_layout<HorizontalBoxLayout>();
auto& left_container = content_container.add<Widget>();

View file

@ -44,7 +44,7 @@ private:
{
set_window_type(WindowType::Tooltip);
set_obey_widget_min_size(false);
m_label = set_main_widget<Label>();
m_label = set_main_widget<Label>().release_value_but_fixme_should_propagate_errors();
m_label->set_background_role(Gfx::ColorRole::Tooltip);
m_label->set_foreground_role(Gfx::ColorRole::TooltipText);
m_label->set_fill_with_background_color(true);

View file

@ -92,11 +92,11 @@ AutocompleteBox::AutocompleteBox(TextEditor& editor)
m_popup_window->set_obey_widget_min_size(false);
m_popup_window->set_rect(0, 0, 175, 25);
auto& main_widget = m_popup_window->set_main_widget<GUI::Widget>();
main_widget.set_fill_with_background_color(true);
main_widget.set_layout<GUI::VerticalBoxLayout>();
auto main_widget = m_popup_window->set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
main_widget->set_fill_with_background_color(true);
main_widget->set_layout<GUI::VerticalBoxLayout>();
m_suggestion_view = main_widget.add<GUI::TableView>();
m_suggestion_view = main_widget->add<GUI::TableView>();
m_suggestion_view->set_frame_shadow(Gfx::FrameShadow::Plain);
m_suggestion_view->set_frame_thickness(1);
m_suggestion_view->set_column_headers_visible(false);
@ -109,7 +109,7 @@ AutocompleteBox::AutocompleteBox(TextEditor& editor)
apply_suggestion();
};
m_no_suggestions_view = main_widget.add<GUI::Label>("No suggestions");
m_no_suggestions_view = main_widget->add<GUI::Label>("No suggestions");
}
void AutocompleteBox::update_suggestions(Vector<CodeComprehension::AutocompleteResultEntry>&& suggestions)

View file

@ -206,12 +206,12 @@ void ColorPicker::set_color_has_alpha_channel(bool has_alpha)
void ColorPicker::build_ui()
{
auto& root_container = set_main_widget<Widget>();
root_container.set_layout<VerticalBoxLayout>();
root_container.layout()->set_margins(4);
root_container.set_fill_with_background_color(true);
auto root_container = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
root_container->set_layout<VerticalBoxLayout>();
root_container->layout()->set_margins(4);
root_container->set_fill_with_background_color(true);
auto& tab_widget = root_container.add<GUI::TabWidget>();
auto& tab_widget = root_container->add<GUI::TabWidget>();
auto& tab_palette = tab_widget.add_tab<Widget>("Palette");
tab_palette.set_layout<VerticalBoxLayout>();
@ -227,7 +227,7 @@ void ColorPicker::build_ui()
build_ui_custom(tab_custom_color);
auto& button_container = root_container.add<Widget>();
auto& button_container = root_container->add<Widget>();
button_container.set_preferred_height(GUI::SpecialDimension::Fit);
button_container.set_layout<HorizontalBoxLayout>();
button_container.layout()->set_spacing(4);

View file

@ -116,7 +116,7 @@ ComboBox::ComboBox()
m_list_window = add<Window>(window());
m_list_window->set_window_type(GUI::WindowType::Popup);
m_list_view = m_list_window->set_main_widget<ListView>();
m_list_view = m_list_window->set_main_widget<ListView>().release_value_but_fixme_should_propagate_errors();
m_list_view->set_should_hide_unnecessary_scrollbars(true);
m_list_view->set_alternating_row_colors(false);
m_list_view->set_hover_highlighting(true);

View file

@ -182,15 +182,15 @@ CommandPalette::CommandPalette(GUI::Window& parent_window, ScreenPosition screen
collect_actions(parent_window);
auto& main_widget = set_main_widget<GUI::Frame>();
main_widget.set_frame_shape(Gfx::FrameShape::Window);
main_widget.set_fill_with_background_color(true);
auto main_widget = set_main_widget<GUI::Frame>().release_value_but_fixme_should_propagate_errors();
main_widget->set_frame_shape(Gfx::FrameShape::Window);
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);
m_text_box = main_widget.add<GUI::TextBox>();
m_table_view = main_widget.add<GUI::TableView>();
m_text_box = main_widget->add<GUI::TextBox>();
m_table_view = main_widget->add<GUI::TableView>();
m_model = adopt_ref(*new ActionModel(m_actions));
m_table_view->set_column_headers_visible(false);

View file

@ -92,8 +92,8 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
: Dialog(parent_window)
, m_category_action_group(make<ActionGroup>())
{
auto& main_widget = set_main_widget<Frame>();
if (!main_widget.load_from_gml(emoji_input_dialog_gml))
auto main_widget = set_main_widget<Frame>().release_value_but_fixme_should_propagate_errors();
if (!main_widget->load_from_gml(emoji_input_dialog_gml))
VERIFY_NOT_REACHED();
set_window_type(GUI::WindowType::Popup);
@ -101,10 +101,10 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
set_blocks_emoji_input(true);
resize(400, 300);
auto& scrollable_container = *main_widget.find_descendant_of_type_named<GUI::ScrollableContainerWidget>("scrollable_container"sv);
m_search_box = main_widget.find_descendant_of_type_named<GUI::TextBox>("search_box"sv);
m_toolbar = main_widget.find_descendant_of_type_named<GUI::Toolbar>("toolbar"sv);
m_emojis_widget = main_widget.find_descendant_of_type_named<GUI::Widget>("emojis"sv);
auto& scrollable_container = *main_widget->find_descendant_of_type_named<GUI::ScrollableContainerWidget>("scrollable_container"sv);
m_search_box = main_widget->find_descendant_of_type_named<GUI::TextBox>("search_box"sv);
m_toolbar = main_widget->find_descendant_of_type_named<GUI::Toolbar>("toolbar"sv);
m_emojis_widget = main_widget->find_descendant_of_type_named<GUI::Widget>("emojis"sv);
m_emojis = supported_emoji();
m_category_action_group->set_exclusive(true);

View file

@ -84,16 +84,16 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
}
resize(560, 320);
auto& widget = set_main_widget<GUI::Widget>();
if (!widget.load_from_gml(file_picker_dialog_gml))
auto widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
if (!widget->load_from_gml(file_picker_dialog_gml))
VERIFY_NOT_REACHED();
auto& toolbar = *widget.find_descendant_of_type_named<GUI::Toolbar>("toolbar");
auto& toolbar = *widget->find_descendant_of_type_named<GUI::Toolbar>("toolbar");
m_location_textbox = *widget.find_descendant_of_type_named<GUI::TextBox>("location_textbox");
m_location_textbox = *widget->find_descendant_of_type_named<GUI::TextBox>("location_textbox");
m_location_textbox->set_text(path);
m_view = *widget.find_descendant_of_type_named<GUI::MultiView>("view");
m_view = *widget->find_descendant_of_type_named<GUI::MultiView>("view");
m_view->set_selection_mode(m_mode == Mode::OpenMultiple ? GUI::AbstractView::SelectionMode::MultiSelection : GUI::AbstractView::SelectionMode::SingleSelection);
m_view->set_model(MUST(SortingProxyModel::create(*m_model)));
m_view->set_model_column(FileSystemModel::Column::Name);
@ -150,7 +150,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
toolbar.add_action(m_view->view_as_table_action());
toolbar.add_action(m_view->view_as_columns_action());
m_filename_textbox = *widget.find_descendant_of_type_named<GUI::TextBox>("filename_textbox");
m_filename_textbox = *widget->find_descendant_of_type_named<GUI::TextBox>("filename_textbox");
m_filename_textbox->set_focus(true);
if (m_mode == Mode::Save) {
LexicalPath lexical_filename { filename };
@ -183,14 +183,14 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
}
};
auto& ok_button = *widget.find_descendant_of_type_named<GUI::Button>("ok_button");
auto& ok_button = *widget->find_descendant_of_type_named<GUI::Button>("ok_button");
ok_button.set_text(ok_button_name(m_mode));
ok_button.on_click = [this](auto) {
on_file_return();
};
ok_button.set_enabled(m_mode == Mode::OpenFolder || !m_filename_textbox->text().is_empty());
auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
auto& cancel_button = *widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button.set_text("Cancel");
cancel_button.on_click = [this](auto) {
done(ExecResult::Cancel);
@ -237,7 +237,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
m_view->view_as_columns_action().set_enabled(false);
};
auto& common_locations_tray = *widget.find_descendant_of_type_named<GUI::Tray>("common_locations_tray");
auto& common_locations_tray = *widget->find_descendant_of_type_named<GUI::Tray>("common_locations_tray");
m_model->on_complete = [&] {
m_view->set_active_widget(&m_view->current_view());
for (auto& location_button : m_common_location_buttons)

View file

@ -26,26 +26,26 @@ FontPicker::FontPicker(Window* parent_window, Gfx::Font const* current_font, boo
resize(430, 280);
set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png"sv).release_value_but_fixme_should_propagate_errors());
auto& widget = set_main_widget<GUI::Widget>();
if (!widget.load_from_gml(font_picker_dialog_gml))
auto widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
if (!widget->load_from_gml(font_picker_dialog_gml))
VERIFY_NOT_REACHED();
m_family_list_view = *widget.find_descendant_of_type_named<ListView>("family_list_view");
m_family_list_view = *widget->find_descendant_of_type_named<ListView>("family_list_view");
m_family_list_view->set_model(ItemListModel<DeprecatedString>::create(m_families));
m_family_list_view->horizontal_scrollbar().set_visible(false);
m_variant_list_view = *widget.find_descendant_of_type_named<ListView>("variant_list_view");
m_variant_list_view = *widget->find_descendant_of_type_named<ListView>("variant_list_view");
m_variant_list_view->set_model(ItemListModel<DeprecatedString>::create(m_variants));
m_variant_list_view->horizontal_scrollbar().set_visible(false);
m_size_spin_box = *widget.find_descendant_of_type_named<SpinBox>("size_spin_box");
m_size_spin_box = *widget->find_descendant_of_type_named<SpinBox>("size_spin_box");
m_size_spin_box->set_range(1, 255);
m_size_list_view = *widget.find_descendant_of_type_named<ListView>("size_list_view");
m_size_list_view = *widget->find_descendant_of_type_named<ListView>("size_list_view");
m_size_list_view->set_model(ItemListModel<int>::create(m_sizes));
m_size_list_view->horizontal_scrollbar().set_visible(false);
m_sample_text_label = *widget.find_descendant_of_type_named<Label>("sample_text_label");
m_sample_text_label = *widget->find_descendant_of_type_named<Label>("sample_text_label");
m_families.clear();
Gfx::FontDatabase::the().for_each_typeface([&](auto& typeface) {
@ -157,13 +157,13 @@ FontPicker::FontPicker(Window* parent_window, Gfx::Font const* current_font, boo
update_font();
};
auto& ok_button = *widget.find_descendant_of_type_named<GUI::Button>("ok_button");
auto& ok_button = *widget->find_descendant_of_type_named<GUI::Button>("ok_button");
ok_button.on_click = [this](auto) {
done(ExecResult::OK);
};
ok_button.set_default(true);
auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
auto& cancel_button = *widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button.on_click = [this](auto) {
done(ExecResult::Cancel);
};

View file

@ -49,20 +49,20 @@ void InputBox::on_done(ExecResult result)
void InputBox::build(InputType input_type)
{
auto& widget = set_main_widget<Widget>();
auto widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
int text_width = widget.font().width(m_prompt);
int title_width = widget.font().width(title()) + 24 /* icon, plus a little padding -- not perfect */;
int text_width = widget->font().width(m_prompt);
int title_width = widget->font().width(title()) + 24 /* icon, plus a little padding -- not perfect */;
int max_width = max(text_width, title_width);
widget.set_layout<VerticalBoxLayout>();
widget.set_fill_with_background_color(true);
widget.set_preferred_height(SpecialDimension::Fit);
widget->set_layout<VerticalBoxLayout>();
widget->set_fill_with_background_color(true);
widget->set_preferred_height(SpecialDimension::Fit);
widget.layout()->set_margins(6);
widget.layout()->set_spacing(6);
widget->layout()->set_margins(6);
widget->layout()->set_spacing(6);
auto& label_editor_container = widget.add<Widget>();
auto& label_editor_container = widget->add<Widget>();
label_editor_container.set_layout<HorizontalBoxLayout>();
label_editor_container.set_preferred_height(SpecialDimension::Fit);
@ -83,7 +83,7 @@ void InputBox::build(InputType input_type)
if (!m_placeholder.is_null())
m_text_editor->set_placeholder(m_placeholder);
auto& button_container_outer = widget.add<Widget>();
auto& button_container_outer = widget->add<Widget>();
button_container_outer.set_preferred_height(SpecialDimension::Fit);
button_container_outer.set_layout<VerticalBoxLayout>();
@ -113,7 +113,7 @@ void InputBox::build(InputType input_type)
};
m_text_editor->set_focus(true);
set_rect(x(), y(), max_width + 140, widget.effective_preferred_size().height().as_int());
set_rect(x(), y(), max_width + 140, widget->effective_preferred_size().height().as_int());
}
}

View file

@ -110,21 +110,21 @@ bool MessageBox::should_include_no_button() const
void MessageBox::build()
{
auto& widget = set_main_widget<Widget>();
auto widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
int text_width = widget.font().width(m_text);
int text_width = widget->font().width(m_text);
auto number_of_lines = m_text.split('\n').size();
int padded_text_height = widget.font().glyph_height() * 1.6;
int padded_text_height = widget->font().glyph_height() * 1.6;
int total_text_height = number_of_lines * padded_text_height;
int icon_width = 0;
widget.set_layout<VerticalBoxLayout>();
widget.set_fill_with_background_color(true);
widget->set_layout<VerticalBoxLayout>();
widget->set_fill_with_background_color(true);
widget.layout()->set_margins(8);
widget.layout()->set_spacing(6);
widget->layout()->set_margins(8);
widget->layout()->set_spacing(6);
auto& message_container = widget.add<Widget>();
auto& message_container = widget->add<Widget>();
message_container.set_layout<HorizontalBoxLayout>();
message_container.layout()->set_spacing(8);
@ -143,7 +143,7 @@ void MessageBox::build()
if (m_type != Type::None)
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
auto& button_container = widget.add<Widget>();
auto& button_container = widget->add<Widget>();
button_container.set_layout<HorizontalBoxLayout>();
button_container.set_fixed_height(24);
button_container.layout()->set_spacing(8);

View file

@ -22,30 +22,30 @@ PasswordInputDialog::PasswordInputDialog(Window* parent_window, DeprecatedString
resize(340, 122);
set_title(move(title));
auto& widget = set_main_widget<Widget>();
auto widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
widget.load_from_gml(password_input_dialog_gml);
widget->load_from_gml(password_input_dialog_gml);
auto& key_icon_label = *widget.find_descendant_of_type_named<GUI::Label>("key_icon_label");
auto& key_icon_label = *widget->find_descendant_of_type_named<GUI::Label>("key_icon_label");
key_icon_label.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/key.png"sv).release_value_but_fixme_should_propagate_errors());
auto& server_label = *widget.find_descendant_of_type_named<GUI::Label>("server_label");
auto& server_label = *widget->find_descendant_of_type_named<GUI::Label>("server_label");
server_label.set_text(move(server));
auto& username_label = *widget.find_descendant_of_type_named<GUI::Label>("username_label");
auto& username_label = *widget->find_descendant_of_type_named<GUI::Label>("username_label");
username_label.set_text(move(username));
auto& password_box = *widget.find_descendant_of_type_named<GUI::PasswordBox>("password_box");
auto& password_box = *widget->find_descendant_of_type_named<GUI::PasswordBox>("password_box");
auto& ok_button = *widget.find_descendant_of_type_named<GUI::Button>("ok_button");
auto& ok_button = *widget->find_descendant_of_type_named<GUI::Button>("ok_button");
ok_button.on_click = [&](auto) {
dbgln("GUI::PasswordInputDialog: OK button clicked");
m_password = password_box.text();
done(ExecResult::OK);
};
auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
auto& cancel_button = *widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button.on_click = [this](auto) {
dbgln("GUI::PasswordInputDialog: Cancel button clicked");
done(ExecResult::Cancel);

View file

@ -31,11 +31,11 @@ ProcessChooser::ProcessChooser(StringView window_title, StringView button_label,
resize(300, 340);
center_on_screen();
auto& widget = set_main_widget<GUI::Widget>();
widget.set_fill_with_background_color(true);
widget.set_layout<GUI::VerticalBoxLayout>();
auto widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
widget->set_fill_with_background_color(true);
widget->set_layout<GUI::VerticalBoxLayout>();
m_table_view = widget.add<GUI::TableView>();
m_table_view = widget->add<GUI::TableView>();
auto process_model = RunningProcessesModel::create();
auto sorting_model = MUST(GUI::SortingProxyModel::create(process_model));
sorting_model->set_sort_role(GUI::ModelRole::Display);
@ -46,7 +46,7 @@ ProcessChooser::ProcessChooser(StringView window_title, StringView button_label,
m_table_view->on_activation = [this](ModelIndex const& index) { set_pid_from_index_and_close(index); };
auto& button_container = widget.add<GUI::Widget>();
auto& button_container = widget->add<GUI::Widget>();
button_container.set_fixed_height(30);
button_container.set_layout<GUI::HorizontalBoxLayout>();
button_container.layout()->set_margins({ 0, 4, 0 });

View file

@ -32,7 +32,7 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(DeprecatedString t
window->set_resizable(false);
window->set_minimizable(false);
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);
(void)TRY(main_widget->try_set_layout<GUI::VerticalBoxLayout>());
main_widget->layout()->set_margins(4);

View file

@ -143,21 +143,13 @@ public:
void set_main_widget(Widget*);
template<class T, class... Args>
inline ErrorOr<NonnullRefPtr<T>> try_set_main_widget(Args&&... args)
inline ErrorOr<NonnullRefPtr<T>> set_main_widget(Args&&... args)
{
auto widget = TRY(T::try_create(forward<Args>(args)...));
set_main_widget(widget.ptr());
return widget;
}
template<class T, class... Args>
inline T& set_main_widget(Args&&... args)
{
auto widget = T::construct(forward<Args>(args)...);
set_main_widget(widget.ptr());
return *widget;
}
Widget* default_return_key_widget() { return m_default_return_key_widget; }
Widget const* default_return_key_widget() const { return m_default_return_key_widget; }
void set_default_return_key_widget(Widget*);

View file

@ -27,19 +27,19 @@ WizardDialog::WizardDialog(Window* parent_window)
if (parent_window)
set_icon(parent_window->icon());
auto& main_widget = set_main_widget<Widget>();
main_widget.set_fill_with_background_color(true);
main_widget.set_layout<VerticalBoxLayout>();
main_widget.layout()->set_spacing(0);
auto main_widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
main_widget->set_fill_with_background_color(true);
main_widget->set_layout<VerticalBoxLayout>();
main_widget->layout()->set_spacing(0);
m_page_container_widget = main_widget.add<Widget>();
m_page_container_widget = main_widget->add<Widget>();
m_page_container_widget->set_fixed_size(500, 315);
m_page_container_widget->set_layout<VerticalBoxLayout>();
auto& separator = main_widget.add<SeparatorWidget>(Gfx::Orientation::Horizontal);
auto& separator = main_widget->add<SeparatorWidget>(Gfx::Orientation::Horizontal);
separator.set_fixed_height(2);
auto& nav_container_widget = main_widget.add<Widget>();
auto& nav_container_widget = main_widget->add<Widget>();
nav_container_widget.set_layout<HorizontalBoxLayout>();
nav_container_widget.set_fixed_height(42);
nav_container_widget.layout()->set_margins({ 0, 10 });