summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpbrw <borowski.pb1@gmail.com>2021-11-25 02:56:13 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-25 08:49:31 +0100
commit162c271eb60f94f0d82dc2e56fda9272ffb5c632 (patch)
treecdac8e8b05cbbb47ccbe3f353722fda66880752b
parent601de466cb0f0b394195ac89364a9c4963697a03 (diff)
downloadserenity-162c271eb60f94f0d82dc2e56fda9272ffb5c632.zip
ModelGallery: Use TRY() a lot more :^)
-rw-r--r--Userland/Demos/ModelGallery/CMakeLists.txt2
-rw-r--r--Userland/Demos/ModelGallery/GalleryWidget.cpp24
-rw-r--r--Userland/Demos/ModelGallery/GalleryWidget.h2
-rw-r--r--Userland/Demos/ModelGallery/main.cpp20
4 files changed, 23 insertions, 25 deletions
diff --git a/Userland/Demos/ModelGallery/CMakeLists.txt b/Userland/Demos/ModelGallery/CMakeLists.txt
index cf9f7f9c96..70a7dd10cb 100644
--- a/Userland/Demos/ModelGallery/CMakeLists.txt
+++ b/Userland/Demos/ModelGallery/CMakeLists.txt
@@ -14,4 +14,4 @@ set(SOURCES
serenity_app(ModelGallery ICON app-model-gallery)
-target_link_libraries(ModelGallery LibGUI LibGfx)
+target_link_libraries(ModelGallery LibGUI LibGfx LibMain)
diff --git a/Userland/Demos/ModelGallery/GalleryWidget.cpp b/Userland/Demos/ModelGallery/GalleryWidget.cpp
index a24face5bc..a3a971dd6e 100644
--- a/Userland/Demos/ModelGallery/GalleryWidget.cpp
+++ b/Userland/Demos/ModelGallery/GalleryWidget.cpp
@@ -13,23 +13,23 @@ GalleryWidget::GalleryWidget()
set_layout<GUI::VerticalBoxLayout>();
auto& inner_widget = add<GUI::Widget>();
- auto& inner_layout = inner_widget.set_layout<GUI::VerticalBoxLayout>();
- inner_layout.set_margins({ 4 });
+ auto inner_layout = inner_widget.try_set_layout<GUI::VerticalBoxLayout>().release_value_but_fixme_should_propagate_errors();
+ inner_layout->set_margins({ 4 });
- m_tab_widget = inner_widget.add<GUI::TabWidget>();
+ m_tab_widget = inner_widget.try_add<GUI::TabWidget>().release_value_but_fixme_should_propagate_errors();
m_statusbar = add<GUI::Statusbar>();
- load_basic_model_tab();
+ (void)load_basic_model_tab();
load_sorting_filtering_tab();
}
-void GalleryWidget::load_basic_model_tab()
+ErrorOr<void> GalleryWidget::load_basic_model_tab()
{
- auto& tab = m_tab_widget->add_tab<GUI::Widget>("Basic Model");
- tab.load_from_gml(basic_model_tab_gml);
+ auto tab = TRY(m_tab_widget->try_add_tab<GUI::Widget>("Basic Model"));
+ 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 = [&] {
@@ -43,9 +43,9 @@ 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::try_load_from_file("/res/icons/16x16/plus.png").release_value_but_fixme_should_propagate_errors());
m_remove_selected_item->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/minus.png").release_value_but_fixme_should_propagate_errors());
@@ -59,6 +59,8 @@ void GalleryWidget::load_basic_model_tab()
m_basic_model->remove_item(index);
}
};
+
+ return {};
}
void GalleryWidget::load_sorting_filtering_tab()
diff --git a/Userland/Demos/ModelGallery/GalleryWidget.h b/Userland/Demos/ModelGallery/GalleryWidget.h
index ddb7a3c0b6..d1ac6c359f 100644
--- a/Userland/Demos/ModelGallery/GalleryWidget.h
+++ b/Userland/Demos/ModelGallery/GalleryWidget.h
@@ -21,7 +21,7 @@ class GalleryWidget final : public GUI::Widget {
private:
GalleryWidget();
- void load_basic_model_tab();
+ ErrorOr<void> load_basic_model_tab();
void load_sorting_filtering_tab();
void add_textbox_contents_to_basic_model();
diff --git a/Userland/Demos/ModelGallery/main.cpp b/Userland/Demos/ModelGallery/main.cpp
index acdf0c5876..228c89d971 100644
--- a/Userland/Demos/ModelGallery/main.cpp
+++ b/Userland/Demos/ModelGallery/main.cpp
@@ -5,34 +5,30 @@
*/
#include "GalleryWidget.h"
+#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/Frame.h>
#include <LibGUI/MessageBox.h>
+#include <LibMain/Main.h>
#include <unistd.h>
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio recvfd sendfd rpath wpath cpath unix", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath unix", nullptr));
- auto app = GUI::Application::construct(argc, argv);
+ auto app = TRY(GUI::Application::try_create(arguments));
- if (pledge("stdio recvfd sendfd rpath", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio recvfd sendfd rpath", nullptr));
auto app_icon = GUI::Icon::default_icon("app-model-gallery");
- auto window = GUI::Window::construct();
+ auto window = TRY(GUI::Window::try_create());
window->set_title("Model Gallery");
window->set_icon(app_icon.bitmap_for_size(16));
window->resize(430, 480);
- window->set_main_widget<GalleryWidget>();
+ TRY(window->try_set_main_widget<GalleryWidget>());
window->show();
return app->exec();