diff options
author | Cameron Youell <cameronyouell@gmail.com> | 2023-04-17 16:01:00 +1000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-24 09:21:51 +0200 |
commit | ba38984a6031aa1dd6fa6bfe931c346a8971ce92 (patch) | |
tree | 7a83375c380772d2f7b377adac3efdb92c1f168c | |
parent | e9ad7b8eed79f4aabb29e68d4ea469b7431cf1fb (diff) | |
download | serenity-ba38984a6031aa1dd6fa6bfe931c346a8971ce92.zip |
SQLStudio: Convert `MainWidget` to a failable constructor
-rw-r--r-- | Userland/DevTools/SQLStudio/MainWidget.cpp | 25 | ||||
-rw-r--r-- | Userland/DevTools/SQLStudio/MainWidget.h | 5 | ||||
-rw-r--r-- | Userland/DevTools/SQLStudio/main.cpp | 3 |
3 files changed, 23 insertions, 10 deletions
diff --git a/Userland/DevTools/SQLStudio/MainWidget.cpp b/Userland/DevTools/SQLStudio/MainWidget.cpp index cc4abf2456..63bea6e1bb 100644 --- a/Userland/DevTools/SQLStudio/MainWidget.cpp +++ b/Userland/DevTools/SQLStudio/MainWidget.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2022, Dylan Katz <dykatz@uw.edu> * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> + * Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -59,11 +60,19 @@ static Vector<DeprecatedString> lookup_database_names() return database_names; } -MainWidget::MainWidget() +ErrorOr<NonnullRefPtr<MainWidget>> MainWidget::create() { - load_from_gml(sql_studio_gml).release_value_but_fixme_should_propagate_errors(); + auto widget = TRY(try_make_ref_counted<MainWidget>()); - m_new_action = GUI::Action::create("&New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { + TRY(widget->load_from_gml(sql_studio_gml)); + TRY(widget->setup()); + + return widget; +} + +ErrorOr<void> MainWidget::setup() +{ + m_new_action = GUI::Action::create("&New", { Mod_Ctrl, Key_N }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"sv)), [this](auto&) { open_new_script(); }); @@ -149,7 +158,7 @@ MainWidget::MainWidget() update_editor_actions(editor); }); - m_connect_to_database_action = GUI::Action::create("Connect to Database"sv, { Mod_Alt, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { + m_connect_to_database_action = GUI::Action::create("Connect to Database"sv, { Mod_Alt, Key_C }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv)), [this](auto&) { auto database_name = m_databases_combo_box->text().trim_whitespace(); if (database_name.is_empty()) return; @@ -171,7 +180,7 @@ MainWidget::MainWidget() } }); - m_run_script_action = GUI::Action::create("Run script", { Mod_Alt, Key_F9 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/play.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) { + m_run_script_action = GUI::Action::create("Run script", { Mod_Alt, Key_F9 }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/play.png"sv)), [&](auto&) { m_results.clear(); m_current_line_for_parsing = 0; read_next_sql_statement_of_editor(); @@ -251,7 +260,7 @@ MainWidget::MainWidget() m_statusbar->set_override_text({}); }; - m_sql_client = SQL::SQLClient::try_create().release_value_but_fixme_should_propagate_errors(); + m_sql_client = TRY(SQL::SQLClient::try_create()); m_sql_client->on_execution_success = [this](auto result) { m_result_column_names = move(result.column_names); read_next_sql_statement_of_editor(); @@ -285,10 +294,12 @@ MainWidget::MainWidget() Vector<JsonValue> individual_result_as_json; for (auto& result_row_column : result_row) individual_result_as_json.append(result_row_column); - query_results_model->add(move(individual_result_as_json)); + MUST(query_results_model->add(move(individual_result_as_json))); } m_action_tab_widget->set_visible(true); }; + + return {}; } ErrorOr<void> MainWidget::initialize_menu(GUI::Window* window) diff --git a/Userland/DevTools/SQLStudio/MainWidget.h b/Userland/DevTools/SQLStudio/MainWidget.h index 017923b5eb..76058555a5 100644 --- a/Userland/DevTools/SQLStudio/MainWidget.h +++ b/Userland/DevTools/SQLStudio/MainWidget.h @@ -17,10 +17,11 @@ namespace SQLStudio { class ScriptEditor; class MainWidget : public GUI::Widget { - C_OBJECT(MainWidget) + C_OBJECT_ABSTRACT(MainWidget) public: virtual ~MainWidget() = default; + static ErrorOr<NonnullRefPtr<MainWidget>> create(); ErrorOr<void> initialize_menu(GUI::Window*); void open_new_script(); @@ -29,7 +30,7 @@ public: bool request_close(); private: - MainWidget(); + ErrorOr<void> setup(); ScriptEditor* active_editor(); diff --git a/Userland/DevTools/SQLStudio/main.cpp b/Userland/DevTools/SQLStudio/main.cpp index 5689a33509..e855d3ee20 100644 --- a/Userland/DevTools/SQLStudio/main.cpp +++ b/Userland/DevTools/SQLStudio/main.cpp @@ -30,7 +30,8 @@ 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->set_main_widget<MainWidget>()); + auto main_widget = TRY(MainWidget::create()); + window->set_main_widget(main_widget); TRY(main_widget->initialize_menu(window)); window->on_close_request = [&] { |