mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 11:07:46 +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
|
@ -27,31 +27,31 @@ CreateNewImageDialog::CreateNewImageDialog(GUI::Window* parent_window)
|
|||
set_icon(parent_window->icon());
|
||||
resize(200, 220);
|
||||
|
||||
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_label = main_widget.add<GUI::Label>("Name:");
|
||||
auto& name_label = main_widget->add<GUI::Label>("Name:");
|
||||
name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
m_name_textbox = main_widget.add<GUI::TextBox>();
|
||||
m_name_textbox = main_widget->add<GUI::TextBox>();
|
||||
m_name_textbox->on_change = [this] {
|
||||
m_image_name = m_name_textbox->text();
|
||||
};
|
||||
auto default_name = Config::read_string("PixelPaint"sv, "NewImage"sv, "Name"sv);
|
||||
m_name_textbox->set_text(default_name);
|
||||
|
||||
auto& width_label = main_widget.add<GUI::Label>("Width:");
|
||||
auto& width_label = main_widget->add<GUI::Label>("Width:");
|
||||
width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
auto& width_spinbox = main_widget.add<GUI::SpinBox>();
|
||||
auto& width_spinbox = main_widget->add<GUI::SpinBox>();
|
||||
|
||||
auto& height_label = main_widget.add<GUI::Label>("Height:");
|
||||
auto& height_label = main_widget->add<GUI::Label>("Height:");
|
||||
height_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
auto& height_spinbox = main_widget.add<GUI::SpinBox>();
|
||||
auto& height_spinbox = main_widget->add<GUI::SpinBox>();
|
||||
|
||||
enum class BackgroundIndex {
|
||||
Transparent = 0,
|
||||
|
@ -81,10 +81,10 @@ CreateNewImageDialog::CreateNewImageDialog(GUI::Window* parent_window)
|
|||
return BackgroundIndex::Custom;
|
||||
}();
|
||||
|
||||
auto& background_label = main_widget.add<GUI::Label>("Background:");
|
||||
auto& background_label = main_widget->add<GUI::Label>("Background:");
|
||||
background_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
auto& background_color_combo = main_widget.add<GUI::ComboBox>();
|
||||
auto& background_color_input = main_widget.add<GUI::ColorInput>();
|
||||
auto& background_color_combo = main_widget->add<GUI::ComboBox>();
|
||||
auto& background_color_input = main_widget->add<GUI::ColorInput>();
|
||||
background_color_input.set_visible(false);
|
||||
background_color_combo.set_only_allow_values_from_model(true);
|
||||
background_color_combo.set_model(*GUI::ItemListModel<StringView, decltype(suggested_backgrounds)>::create(suggested_backgrounds));
|
||||
|
@ -110,10 +110,10 @@ CreateNewImageDialog::CreateNewImageDialog(GUI::Window* parent_window)
|
|||
m_background_color = background_color_input.color();
|
||||
};
|
||||
|
||||
auto& set_defaults_checkbox = main_widget.add<GUI::CheckBox>();
|
||||
auto& set_defaults_checkbox = main_widget->add<GUI::CheckBox>();
|
||||
set_defaults_checkbox.set_text("Use these settings as default");
|
||||
|
||||
auto& button_container = main_widget.add<GUI::Widget>();
|
||||
auto& button_container = main_widget->add<GUI::Widget>();
|
||||
button_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
auto& ok_button = button_container.add<GUI::Button>("OK");
|
||||
|
|
|
@ -20,33 +20,33 @@ CreateNewLayerDialog::CreateNewLayerDialog(Gfx::IntSize suggested_size, GUI::Win
|
|||
set_icon(parent_window->icon());
|
||||
resize(200, 200);
|
||||
|
||||
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_label = main_widget.add<GUI::Label>("Name:");
|
||||
auto& name_label = main_widget->add<GUI::Label>("Name:");
|
||||
name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
m_name_textbox = main_widget.add<GUI::TextBox>();
|
||||
m_name_textbox = main_widget->add<GUI::TextBox>();
|
||||
m_name_textbox->set_text("Layer"sv);
|
||||
m_name_textbox->select_all();
|
||||
m_name_textbox->on_change = [this] {
|
||||
m_layer_name = m_name_textbox->text();
|
||||
};
|
||||
|
||||
auto& width_label = main_widget.add<GUI::Label>("Width:");
|
||||
auto& width_label = main_widget->add<GUI::Label>("Width:");
|
||||
width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
auto& width_spinbox = main_widget.add<GUI::SpinBox>();
|
||||
auto& width_spinbox = main_widget->add<GUI::SpinBox>();
|
||||
|
||||
auto& height_label = main_widget.add<GUI::Label>("Height:");
|
||||
auto& height_label = main_widget->add<GUI::Label>("Height:");
|
||||
height_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
auto& height_spinbox = main_widget.add<GUI::SpinBox>();
|
||||
auto& height_spinbox = main_widget->add<GUI::SpinBox>();
|
||||
|
||||
auto& button_container = main_widget.add<GUI::Widget>();
|
||||
auto& button_container = main_widget->add<GUI::Widget>();
|
||||
button_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
auto& ok_button = button_container.add<GUI::Button>("OK");
|
||||
|
|
|
@ -23,15 +23,15 @@ EditGuideDialog::EditGuideDialog(GUI::Window* parent_window, DeprecatedString co
|
|||
resize(200, 130);
|
||||
set_resizable(false);
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(edit_guide_dialog_gml))
|
||||
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
if (!main_widget->load_from_gml(edit_guide_dialog_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto horizontal_radio = main_widget.find_descendant_of_type_named<GUI::RadioButton>("orientation_horizontal_radio");
|
||||
auto vertical_radio = main_widget.find_descendant_of_type_named<GUI::RadioButton>("orientation_vertical_radio");
|
||||
auto ok_button = main_widget.find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
auto cancel_button = main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
m_offset_text_box = main_widget.find_descendant_of_type_named<GUI::TextBox>("offset_text_box");
|
||||
auto horizontal_radio = main_widget->find_descendant_of_type_named<GUI::RadioButton>("orientation_horizontal_radio");
|
||||
auto vertical_radio = main_widget->find_descendant_of_type_named<GUI::RadioButton>("orientation_vertical_radio");
|
||||
auto ok_button = main_widget->find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
auto cancel_button = main_widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
m_offset_text_box = main_widget->find_descendant_of_type_named<GUI::TextBox>("offset_text_box");
|
||||
|
||||
VERIFY(horizontal_radio);
|
||||
VERIFY(ok_button);
|
||||
|
|
|
@ -21,15 +21,15 @@ FilterGallery::FilterGallery(GUI::Window* parent_window, ImageEditor* editor)
|
|||
resize(400, 250);
|
||||
set_resizable(true);
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(filter_gallery_gml))
|
||||
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
if (!main_widget->load_from_gml(filter_gallery_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
m_filter_tree = main_widget.find_descendant_of_type_named<GUI::TreeView>("tree_view");
|
||||
auto apply_button = main_widget.find_descendant_of_type_named<GUI::Button>("apply_button");
|
||||
auto cancel_button = main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
m_config_widget = main_widget.find_descendant_of_type_named<GUI::Widget>("config_widget");
|
||||
m_preview_widget = main_widget.find_descendant_of_type_named<FilterPreviewWidget>("preview_widget");
|
||||
m_filter_tree = main_widget->find_descendant_of_type_named<GUI::TreeView>("tree_view");
|
||||
auto apply_button = main_widget->find_descendant_of_type_named<GUI::Button>("apply_button");
|
||||
auto cancel_button = main_widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
m_config_widget = main_widget->find_descendant_of_type_named<GUI::Widget>("config_widget");
|
||||
m_preview_widget = main_widget->find_descendant_of_type_named<FilterPreviewWidget>("preview_widget");
|
||||
|
||||
VERIFY(m_filter_tree);
|
||||
VERIFY(apply_button);
|
||||
|
|
|
@ -48,11 +48,11 @@ private:
|
|||
set_title(builder.string_view());
|
||||
|
||||
resize(200, 250);
|
||||
auto& main_widget = set_main_widget<GUI::Frame>();
|
||||
main_widget.set_frame_shape(Gfx::FrameShape::Container);
|
||||
main_widget.set_frame_shadow(Gfx::FrameShadow::Raised);
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
auto& layout = main_widget.template set_layout<GUI::VerticalBoxLayout>();
|
||||
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_frame_shadow(Gfx::FrameShadow::Raised);
|
||||
main_widget->set_fill_with_background_color(true);
|
||||
auto& layout = main_widget->template set_layout<GUI::VerticalBoxLayout>();
|
||||
layout.set_margins(4);
|
||||
|
||||
size_t index = 0;
|
||||
|
@ -60,7 +60,7 @@ private:
|
|||
size_t rows = N;
|
||||
|
||||
for (size_t row = 0; row < rows; ++row) {
|
||||
auto& horizontal_container = main_widget.template add<GUI::Widget>();
|
||||
auto& horizontal_container = main_widget->template add<GUI::Widget>();
|
||||
horizontal_container.template set_layout<GUI::HorizontalBoxLayout>();
|
||||
for (size_t column = 0; column < columns; ++column) {
|
||||
if (index < columns * rows) {
|
||||
|
@ -81,13 +81,13 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
auto& norm_checkbox = main_widget.template add<GUI::CheckBox>("Normalize");
|
||||
auto& norm_checkbox = main_widget->template add<GUI::CheckBox>("Normalize");
|
||||
norm_checkbox.set_checked(false);
|
||||
|
||||
auto& wrap_checkbox = main_widget.template add<GUI::CheckBox>("Wrap");
|
||||
auto& wrap_checkbox = main_widget->template add<GUI::CheckBox>("Wrap");
|
||||
wrap_checkbox.set_checked(m_should_wrap);
|
||||
|
||||
auto& button = main_widget.template add<GUI::Button>("Done");
|
||||
auto& button = main_widget->template add<GUI::Button>("Done");
|
||||
button.on_click = [&](auto) {
|
||||
m_should_wrap = wrap_checkbox.is_checked();
|
||||
if (norm_checkbox.is_checked())
|
||||
|
|
|
@ -18,8 +18,8 @@ LevelsDialog::LevelsDialog(GUI::Window* parent_window, ImageEditor* editor)
|
|||
set_title("Levels");
|
||||
set_icon(parent_window->icon());
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(levels_dialog_gml))
|
||||
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
if (!main_widget->load_from_gml(levels_dialog_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
resize(305, 202);
|
||||
|
@ -27,12 +27,12 @@ LevelsDialog::LevelsDialog(GUI::Window* parent_window, ImageEditor* editor)
|
|||
|
||||
m_editor = editor;
|
||||
|
||||
m_brightness_slider = main_widget.find_descendant_of_type_named<GUI::ValueSlider>("brightness_slider");
|
||||
m_contrast_slider = main_widget.find_descendant_of_type_named<GUI::ValueSlider>("contrast_slider");
|
||||
m_gamma_slider = main_widget.find_descendant_of_type_named<GUI::ValueSlider>("gamma_slider");
|
||||
auto context_label = main_widget.find_descendant_of_type_named<GUI::Label>("context_label");
|
||||
auto apply_button = main_widget.find_descendant_of_type_named<GUI::Button>("apply_button");
|
||||
auto cancel_button = main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
m_brightness_slider = main_widget->find_descendant_of_type_named<GUI::ValueSlider>("brightness_slider");
|
||||
m_contrast_slider = main_widget->find_descendant_of_type_named<GUI::ValueSlider>("contrast_slider");
|
||||
m_gamma_slider = main_widget->find_descendant_of_type_named<GUI::ValueSlider>("gamma_slider");
|
||||
auto context_label = main_widget->find_descendant_of_type_named<GUI::Label>("context_label");
|
||||
auto apply_button = main_widget->find_descendant_of_type_named<GUI::Button>("apply_button");
|
||||
auto cancel_button = main_widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
|
||||
VERIFY(m_brightness_slider);
|
||||
VERIFY(m_contrast_slider);
|
||||
|
|
|
@ -27,13 +27,13 @@ ResizeImageDialog::ResizeImageDialog(Gfx::IntSize suggested_size, GUI::Window* p
|
|||
resize(260, 228);
|
||||
set_icon(parent_window->icon());
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(resize_image_dialog_gml))
|
||||
auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
if (!main_widget->load_from_gml(resize_image_dialog_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto width_spinbox = main_widget.find_descendant_of_type_named<GUI::SpinBox>("width_spinbox");
|
||||
auto height_spinbox = main_widget.find_descendant_of_type_named<GUI::SpinBox>("height_spinbox");
|
||||
auto keep_aspect_ratio_checkbox = main_widget.find_descendant_of_type_named<GUI::CheckBox>("keep_aspect_ratio_checkbox");
|
||||
auto width_spinbox = main_widget->find_descendant_of_type_named<GUI::SpinBox>("width_spinbox");
|
||||
auto height_spinbox = main_widget->find_descendant_of_type_named<GUI::SpinBox>("height_spinbox");
|
||||
auto keep_aspect_ratio_checkbox = main_widget->find_descendant_of_type_named<GUI::CheckBox>("keep_aspect_ratio_checkbox");
|
||||
|
||||
VERIFY(width_spinbox);
|
||||
VERIFY(height_spinbox);
|
||||
|
@ -67,10 +67,10 @@ ResizeImageDialog::ResizeImageDialog(Gfx::IntSize suggested_size, GUI::Window* p
|
|||
}
|
||||
};
|
||||
|
||||
auto nearest_neighbor_radio = main_widget.find_descendant_of_type_named<GUI::RadioButton>("nearest_neighbor_radio");
|
||||
auto smooth_pixels_radio = main_widget.find_descendant_of_type_named<GUI::RadioButton>("smooth_pixels_radio");
|
||||
auto bilinear_radio = main_widget.find_descendant_of_type_named<GUI::RadioButton>("bilinear_radio");
|
||||
auto resize_canvas_radio = main_widget.find_descendant_of_type_named<GUI::RadioButton>("resize_canvas");
|
||||
auto nearest_neighbor_radio = main_widget->find_descendant_of_type_named<GUI::RadioButton>("nearest_neighbor_radio");
|
||||
auto smooth_pixels_radio = main_widget->find_descendant_of_type_named<GUI::RadioButton>("smooth_pixels_radio");
|
||||
auto bilinear_radio = main_widget->find_descendant_of_type_named<GUI::RadioButton>("bilinear_radio");
|
||||
auto resize_canvas_radio = main_widget->find_descendant_of_type_named<GUI::RadioButton>("resize_canvas");
|
||||
|
||||
VERIFY(nearest_neighbor_radio);
|
||||
VERIFY(smooth_pixels_radio);
|
||||
|
@ -99,8 +99,8 @@ ResizeImageDialog::ResizeImageDialog(Gfx::IntSize suggested_size, GUI::Window* p
|
|||
m_scaling_mode = Gfx::Painter::ScalingMode::None;
|
||||
};
|
||||
|
||||
auto ok_button = main_widget.find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
auto cancel_button = main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
auto ok_button = main_widget->find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
auto cancel_button = main_widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
|
||||
VERIFY(ok_button);
|
||||
VERIFY(cancel_button);
|
||||
|
|
|
@ -48,7 +48,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->resize(800, 510);
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
||||
auto main_widget = TRY(window->try_set_main_widget<PixelPaint::MainWidget>());
|
||||
auto main_widget = TRY(window->set_main_widget<PixelPaint::MainWidget>());
|
||||
|
||||
TRY(main_widget->initialize_menubar(*window));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue