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

Applications: Make creation of tabs non-fallible

This commit is contained in:
Tim Ledbetter 2023-09-14 08:01:53 +01:00 committed by Andreas Kling
parent 3c9dee5d5a
commit ffda0785c0
7 changed files with 161 additions and 161 deletions

View file

@ -24,11 +24,11 @@ GalleryWidget::GalleryWidget()
ErrorOr<void> GalleryWidget::load_basic_model_tab()
{
auto tab = TRY(m_tab_widget->try_add_tab<GUI::Widget>("Basic Model"_string));
TRY(tab->load_from_gml(basic_model_tab_gml));
auto& tab = m_tab_widget->add_tab<GUI::Widget>("Basic Model"_string);
TRY(tab.load_from_gml(basic_model_tab_gml));
m_basic_model = BasicModel::create();
m_basic_model_table = *tab->find_descendant_of_type_named<GUI::TableView>("model_table");
m_basic_model_table = *tab.find_descendant_of_type_named<GUI::TableView>("model_table");
m_basic_model_table->set_model(m_basic_model);
m_basic_model->on_invalidate = [&] {
@ -42,9 +42,9 @@ ErrorOr<void> GalleryWidget::load_basic_model_tab()
m_basic_model->add_item("...hello...");
m_basic_model->add_item("...friends! :^)");
m_new_item_name = *tab->find_descendant_of_type_named<GUI::TextBox>("new_item_name");
m_add_new_item = *tab->find_descendant_of_type_named<GUI::Button>("add_new_item");
m_remove_selected_item = *tab->find_descendant_of_type_named<GUI::Button>("remove_selected_item");
m_new_item_name = *tab.find_descendant_of_type_named<GUI::TextBox>("new_item_name");
m_add_new_item = *tab.find_descendant_of_type_named<GUI::Button>("add_new_item");
m_remove_selected_item = *tab.find_descendant_of_type_named<GUI::Button>("remove_selected_item");
m_add_new_item->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/plus.png"sv).release_value_but_fixme_should_propagate_errors());
m_remove_selected_item->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/minus.png"sv).release_value_but_fixme_should_propagate_errors());

View file

@ -36,11 +36,11 @@ GalleryWidget::GalleryWidget()
auto& tab_widget = *find_descendant_of_type_named<GUI::TabWidget>("tab_widget");
auto basics_tab = tab_widget.try_add_tab<GUI::Widget>("Basics"_string).release_value_but_fixme_should_propagate_errors();
basics_tab->load_from_gml(basics_tab_gml).release_value_but_fixme_should_propagate_errors();
auto& basics_tab = tab_widget.add_tab<GUI::Widget>("Basics"_string);
basics_tab.load_from_gml(basics_tab_gml).release_value_but_fixme_should_propagate_errors();
m_enabled_label = basics_tab->find_descendant_of_type_named<GUI::Label>("enabled_label");
m_label_frame = basics_tab->find_descendant_of_type_named<GUI::Frame>("label_frame");
m_enabled_label = basics_tab.find_descendant_of_type_named<GUI::Label>("enabled_label");
m_label_frame = basics_tab.find_descendant_of_type_named<GUI::Frame>("label_frame");
m_frame_shapes.append("No Frame");
m_frame_shapes.append("Window");
@ -52,7 +52,7 @@ GalleryWidget::GalleryWidget()
m_frame_shapes.append("Raised Panel");
m_frame_shapes.append("Sunken Panel");
m_frame_shape_combobox = basics_tab->find_descendant_of_type_named<GUI::ComboBox>("frame_style_combobox");
m_frame_shape_combobox = basics_tab.find_descendant_of_type_named<GUI::ComboBox>("frame_style_combobox");
m_frame_shape_combobox->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_frame_shapes));
m_frame_shape_combobox->on_change = [&](auto&, auto const& index) {
@ -68,10 +68,10 @@ GalleryWidget::GalleryWidget()
m_button_icons.append(Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"sv).release_value_but_fixme_should_propagate_errors());
m_button_icons.append(Gfx::Bitmap::load_from_file("/res/icons/16x16/ladybug.png"sv).release_value_but_fixme_should_propagate_errors());
m_icon_button = basics_tab->find_descendant_of_type_named<GUI::Button>("icon_button");
m_icon_button = basics_tab.find_descendant_of_type_named<GUI::Button>("icon_button");
m_icon_button->set_icon(*m_button_icons[2]);
m_disabled_icon_button = basics_tab->find_descendant_of_type_named<GUI::Button>("disabled_icon_button");
m_disabled_icon_button = basics_tab.find_descendant_of_type_named<GUI::Button>("disabled_icon_button");
m_disabled_icon_button->set_icon(*m_button_icons[2]);
m_icon_button->on_click = [&](auto) {
@ -83,9 +83,9 @@ GalleryWidget::GalleryWidget()
i++;
};
m_text_editor = basics_tab->find_descendant_of_type_named<GUI::TextEditor>("text_editor");
m_text_editor = basics_tab.find_descendant_of_type_named<GUI::TextEditor>("text_editor");
m_font_button = basics_tab->find_descendant_of_type_named<GUI::Button>("font_button");
m_font_button = basics_tab.find_descendant_of_type_named<GUI::Button>("font_button");
m_font_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png"sv).release_value_but_fixme_should_propagate_errors());
m_font_button->on_click = [&](auto) {
@ -95,7 +95,7 @@ GalleryWidget::GalleryWidget()
}
};
m_file_button = basics_tab->find_descendant_of_type_named<GUI::Button>("file_button");
m_file_button = basics_tab.find_descendant_of_type_named<GUI::Button>("file_button");
m_file_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors());
m_file_button->on_click = [&](auto) {
@ -105,7 +105,7 @@ GalleryWidget::GalleryWidget()
m_text_editor->set_text(response.release_value().filename());
};
m_input_button = basics_tab->find_descendant_of_type_named<GUI::Button>("input_button");
m_input_button = basics_tab.find_descendant_of_type_named<GUI::Button>("input_button");
m_input_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"sv).release_value_but_fixme_should_propagate_errors());
m_input_button->on_click = [&](auto) {
@ -114,7 +114,7 @@ GalleryWidget::GalleryWidget()
m_text_editor->set_text(value);
};
m_font_colorinput = basics_tab->find_descendant_of_type_named<GUI::ColorInput>("font_colorinput");
m_font_colorinput = basics_tab.find_descendant_of_type_named<GUI::ColorInput>("font_colorinput");
m_font_colorinput->on_change = [&]() {
auto palette = m_text_editor->palette();
@ -123,7 +123,7 @@ GalleryWidget::GalleryWidget()
m_text_editor->update();
};
m_msgbox_button = basics_tab->find_descendant_of_type_named<GUI::Button>("msgbox_button");
m_msgbox_button = basics_tab.find_descendant_of_type_named<GUI::Button>("msgbox_button");
m_msgbox_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-browser.png"sv).release_value_but_fixme_should_propagate_errors());
m_msgbox_type = GUI::MessageBox::Type::None;
@ -140,7 +140,7 @@ GalleryWidget::GalleryWidget()
m_msgbox_buttons.append("Yes No");
m_msgbox_buttons.append("Yes No Cancel");
m_msgbox_icon_combobox = basics_tab->find_descendant_of_type_named<GUI::ComboBox>("msgbox_icon_combobox");
m_msgbox_icon_combobox = basics_tab.find_descendant_of_type_named<GUI::ComboBox>("msgbox_icon_combobox");
m_msgbox_icon_combobox->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_msgbox_icons));
m_msgbox_icon_combobox->set_selected_index(0);
@ -148,7 +148,7 @@ GalleryWidget::GalleryWidget()
m_msgbox_type = static_cast<GUI::MessageBox::Type>(index.row());
};
m_msgbox_buttons_combobox = basics_tab->find_descendant_of_type_named<GUI::ComboBox>("msgbox_buttons_combobox");
m_msgbox_buttons_combobox = basics_tab.find_descendant_of_type_named<GUI::ComboBox>("msgbox_buttons_combobox");
m_msgbox_buttons_combobox->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_msgbox_buttons));
m_msgbox_buttons_combobox->set_selected_index(0);
@ -160,17 +160,17 @@ GalleryWidget::GalleryWidget()
GUI::MessageBox::show(window(), m_text_editor->text(), "Message"sv, m_msgbox_type, m_msgbox_input_type);
};
auto sliders_tab = tab_widget.try_add_tab<GUI::Widget>("Sliders"_string).release_value_but_fixme_should_propagate_errors();
sliders_tab->load_from_gml(sliders_tab_gml).release_value_but_fixme_should_propagate_errors();
auto& sliders_tab = tab_widget.add_tab<GUI::Widget>("Sliders"_string);
sliders_tab.load_from_gml(sliders_tab_gml).release_value_but_fixme_should_propagate_errors();
m_vertical_progressbar_left = sliders_tab->find_descendant_of_type_named<GUI::VerticalProgressbar>("vertical_progressbar_left");
m_vertical_progressbar_left = sliders_tab.find_descendant_of_type_named<GUI::VerticalProgressbar>("vertical_progressbar_left");
m_vertical_progressbar_left->set_value(0);
m_vertical_progressbar_right = sliders_tab->find_descendant_of_type_named<GUI::VerticalProgressbar>("vertical_progressbar_right");
m_vertical_progressbar_right = sliders_tab.find_descendant_of_type_named<GUI::VerticalProgressbar>("vertical_progressbar_right");
m_vertical_progressbar_right->set_value(100);
m_vertical_slider_left = sliders_tab->find_descendant_of_type_named<GUI::VerticalSlider>("vertical_slider_left");
m_vertical_slider_right = sliders_tab->find_descendant_of_type_named<GUI::VerticalSlider>("vertical_slider_right");
m_vertical_slider_left = sliders_tab.find_descendant_of_type_named<GUI::VerticalSlider>("vertical_slider_left");
m_vertical_slider_right = sliders_tab.find_descendant_of_type_named<GUI::VerticalSlider>("vertical_slider_right");
m_vertical_slider_left->on_change = [&](auto value) {
m_vertical_progressbar_left->set_value(m_vertical_slider_left->max() - value);
@ -180,11 +180,11 @@ GalleryWidget::GalleryWidget()
m_vertical_progressbar_right->set_value((100 / m_vertical_slider_right->max()) * (m_vertical_slider_right->max() - value));
};
m_horizontal_progressbar = sliders_tab->find_descendant_of_type_named<GUI::HorizontalProgressbar>("horizontal_progressbar");
m_horizontal_progressbar = sliders_tab.find_descendant_of_type_named<GUI::HorizontalProgressbar>("horizontal_progressbar");
m_horizontal_progressbar->set_value(0);
m_horizontal_slider_left = sliders_tab->find_descendant_of_type_named<GUI::HorizontalSlider>("horizontal_slider_left");
m_horizontal_slider_right = sliders_tab->find_descendant_of_type_named<GUI::HorizontalSlider>("horizontal_slider_right");
m_horizontal_slider_left = sliders_tab.find_descendant_of_type_named<GUI::HorizontalSlider>("horizontal_slider_left");
m_horizontal_slider_right = sliders_tab.find_descendant_of_type_named<GUI::HorizontalSlider>("horizontal_slider_right");
m_horizontal_slider_left->on_change = [&](auto value) {
m_horizontal_progressbar->set_value(value);
@ -197,23 +197,23 @@ GalleryWidget::GalleryWidget()
m_horizontal_slider_left->set_value((value * 100) / m_horizontal_slider_right->max());
};
m_enabled_scrollbar = sliders_tab->find_descendant_of_type_named<GUI::Scrollbar>("enabled_scrollbar");
m_enabled_scrollbar = sliders_tab.find_descendant_of_type_named<GUI::Scrollbar>("enabled_scrollbar");
m_enabled_scrollbar->set_orientation(Orientation::Horizontal);
m_disabled_scrollbar = sliders_tab->find_descendant_of_type_named<GUI::Scrollbar>("disabled_scrollbar");
m_disabled_scrollbar = sliders_tab.find_descendant_of_type_named<GUI::Scrollbar>("disabled_scrollbar");
m_disabled_scrollbar->set_orientation(Orientation::Horizontal);
m_opacity_imagewidget = sliders_tab->find_descendant_of_type_named<GUI::ImageWidget>("opacity_imagewidget");
m_opacity_imagewidget = sliders_tab.find_descendant_of_type_named<GUI::ImageWidget>("opacity_imagewidget");
m_opacity_imagewidget->load_from_file("/res/graphics/brand-banner.png"sv);
m_opacity_slider = sliders_tab->find_descendant_of_type_named<GUI::HorizontalOpacitySlider>("opacity_slider");
m_opacity_slider = sliders_tab.find_descendant_of_type_named<GUI::HorizontalOpacitySlider>("opacity_slider");
m_opacity_slider->on_change = [&](auto percent) {
m_opacity_imagewidget->set_opacity_percent(percent);
m_opacity_value_slider->set_value(percent);
};
m_opacity_value_slider = sliders_tab->find_descendant_of_type_named<GUI::ValueSlider>("opacity_value_slider");
m_opacity_value_slider = sliders_tab.find_descendant_of_type_named<GUI::ValueSlider>("opacity_value_slider");
m_opacity_value_slider->set_range(0, 100);
m_opacity_value_slider->on_change = [&](auto percent) {
@ -221,11 +221,11 @@ GalleryWidget::GalleryWidget()
m_opacity_slider->set_value(percent);
};
auto wizards_tab = tab_widget.try_add_tab<GUI::Widget>("Wizards"_string).release_value_but_fixme_should_propagate_errors();
wizards_tab->load_from_gml(wizards_tab_gml).release_value_but_fixme_should_propagate_errors();
auto& wizards_tab = tab_widget.add_tab<GUI::Widget>("Wizards"_string);
wizards_tab.load_from_gml(wizards_tab_gml).release_value_but_fixme_should_propagate_errors();
m_wizard_button = wizards_tab->find_descendant_of_type_named<GUI::Button>("wizard_button");
m_wizard_output = wizards_tab->find_descendant_of_type_named<GUI::TextEditor>("wizard_output");
m_wizard_button = wizards_tab.find_descendant_of_type_named<GUI::Button>("wizard_button");
m_wizard_output = wizards_tab.find_descendant_of_type_named<GUI::TextEditor>("wizard_output");
m_wizard_output->set_should_hide_unnecessary_scrollbars(true);
char const* serenityos_ascii = {
@ -277,10 +277,10 @@ GalleryWidget::GalleryWidget()
m_wizard_output->set_text(sb.string_view());
};
auto cursors_tab = tab_widget.try_add_tab<GUI::Widget>("Cursors"_string).release_value_but_fixme_should_propagate_errors();
cursors_tab->load_from_gml(cursors_tab_gml).release_value_but_fixme_should_propagate_errors();
auto& cursors_tab = tab_widget.add_tab<GUI::Widget>("Cursors"_string);
cursors_tab.load_from_gml(cursors_tab_gml).release_value_but_fixme_should_propagate_errors();
m_cursors_tableview = cursors_tab->find_descendant_of_type_named<GUI::TableView>("cursors_tableview");
m_cursors_tableview = cursors_tab.find_descendant_of_type_named<GUI::TableView>("cursors_tableview");
m_cursors_tableview->set_highlight_selected_rows(true);
m_cursors_tableview->set_alternating_row_colors(false);
m_cursors_tableview->set_vertical_padding(16);
@ -300,10 +300,10 @@ GalleryWidget::GalleryWidget()
m_cursors_tableview->set_override_cursor(NonnullRefPtr<Gfx::Bitmap const>(icon_index.data().as_bitmap()));
};
auto icons_tab = tab_widget.try_add_tab<GUI::Widget>("Icons"_string).release_value_but_fixme_should_propagate_errors();
icons_tab->load_from_gml(icons_tab_gml).release_value_but_fixme_should_propagate_errors();
auto& icons_tab = tab_widget.add_tab<GUI::Widget>("Icons"_string);
icons_tab.load_from_gml(icons_tab_gml).release_value_but_fixme_should_propagate_errors();
m_icons_tableview = icons_tab->find_descendant_of_type_named<GUI::TableView>("icons_tableview");
m_icons_tableview = icons_tab.find_descendant_of_type_named<GUI::TableView>("icons_tableview");
m_icons_tableview->set_highlight_selected_rows(true);
m_icons_tableview->set_alternating_row_colors(false);
m_icons_tableview->set_vertical_padding(24);