From 4c732abed52535071d9b47d0e70dcda63fe28e42 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Fri, 16 Dec 2022 02:00:56 +0100 Subject: [PATCH] HackStudio: Add a factory function for DebugInfoWidget Thanks to this patch we now do error propagation in the DebugInfoWidget creation and as a result we get rid of 4 FIXMEs :) --- .../HackStudio/Debugger/DebugInfoWidget.cpp | 27 +++++++++++++------ .../HackStudio/Debugger/DebugInfoWidget.h | 3 ++- .../DevTools/HackStudio/HackStudioWidget.cpp | 10 ++++--- .../DevTools/HackStudio/HackStudioWidget.h | 2 +- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp index d31261a050f..ad9abd77f39 100644 --- a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp +++ b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp @@ -22,21 +22,21 @@ namespace HackStudio { -void DebugInfoWidget::init_toolbar() +ErrorOr DebugInfoWidget::init_toolbar() { - m_continue_action = GUI::Action::create("Continue", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-continue.png"sv).release_value_but_fixme_should_propagate_errors(), [](auto&) { + m_continue_action = GUI::Action::create("Continue", TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-continue.png"sv)), [](auto&) { Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::Continue); }); - m_singlestep_action = GUI::Action::create("Step Over", { Mod_None, Key_F10 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-over.png"sv).release_value_but_fixme_should_propagate_errors(), [](auto&) { + m_singlestep_action = GUI::Action::create("Step Over", { Mod_None, Key_F10 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-over.png"sv)), [](auto&) { Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::SourceStepOver); }); - m_step_in_action = GUI::Action::create("Step In", { Mod_None, Key_F11 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-in.png"sv).release_value_but_fixme_should_propagate_errors(), [](auto&) { + m_step_in_action = GUI::Action::create("Step In", { Mod_None, Key_F11 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-in.png"sv)), [](auto&) { Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::SourceSingleStep); }); - m_step_out_action = GUI::Action::create("Step Out", { Mod_Shift, Key_F11 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-out.png"sv).release_value_but_fixme_should_propagate_errors(), [](auto&) { + m_step_out_action = GUI::Action::create("Step Out", { Mod_Shift, Key_F11 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-step-out.png"sv)), [](auto&) { Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::SourceStepOut); }); @@ -46,14 +46,25 @@ void DebugInfoWidget::init_toolbar() m_toolbar->add_action(*m_step_out_action); set_debug_actions_enabled(false); + + return {}; +} + +ErrorOr> DebugInfoWidget::create() +{ + auto debuginfo_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DebugInfoWidget)); + + auto& toolbar_container = debuginfo_widget->add(); + debuginfo_widget->m_toolbar = toolbar_container.add(); + + TRY(debuginfo_widget->init_toolbar()); + + return debuginfo_widget; } DebugInfoWidget::DebugInfoWidget() { set_layout(); - auto& toolbar_container = add(); - m_toolbar = toolbar_container.add(); - init_toolbar(); auto& bottom_box = add(); bottom_box.set_layout(); diff --git a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h index 2f72f4c285b..d881cf0166e 100644 --- a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h +++ b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h @@ -24,6 +24,7 @@ namespace HackStudio { class DebugInfoWidget final : public GUI::Widget { C_OBJECT(DebugInfoWidget) public: + static ErrorOr> create(); virtual ~DebugInfoWidget() override { } void update_state(Debug::ProcessInspector&, PtraceRegisters const&); @@ -34,7 +35,7 @@ public: private: explicit DebugInfoWidget(); - void init_toolbar(); + ErrorOr init_toolbar(); NonnullRefPtr build_variables_tab(); NonnullRefPtr build_registers_tab(); diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index d168c3caf74..2487ca351b3 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -125,7 +125,7 @@ ErrorOr> HackStudioWidget::create(DeprecatedStri widget->m_save_as_action = widget->create_save_as_action(); widget->m_new_project_action = widget->create_new_project_action(); - widget->create_action_tab(*widget->m_right_hand_splitter); + TRY(widget->create_action_tab(*widget->m_right_hand_splitter)); widget->m_add_editor_tab_widget_action = widget->create_add_editor_tab_widget_action(); widget->m_add_editor_action = widget->create_add_editor_action(); @@ -1300,7 +1300,7 @@ NonnullRefPtr HackStudioWidget::create_run_action() }); } -void HackStudioWidget::create_action_tab(GUI::Widget& parent) +ErrorOr HackStudioWidget::create_action_tab(GUI::Widget& parent) { m_action_tab_widget = parent.add(); @@ -1317,7 +1317,9 @@ void HackStudioWidget::create_action_tab(GUI::Widget& parent) m_find_in_files_widget = m_action_tab_widget->add_tab("Find in files"); m_todo_entries_widget = m_action_tab_widget->add_tab("TODO"); m_terminal_wrapper = m_action_tab_widget->add_tab("Console", false); - m_debug_info_widget = m_action_tab_widget->add_tab("Debug"); + auto debug_info_widget = TRY(DebugInfoWidget::create()); + TRY(m_action_tab_widget->add_tab(debug_info_widget, "Debug")); + m_debug_info_widget = debug_info_widget; m_debug_info_widget->on_backtrace_frame_selection = [this](Debug::DebugInfo::SourcePosition const& source_position) { open_file(get_absolute_path(source_position.file_path), source_position.line_number - 1); @@ -1334,6 +1336,8 @@ void HackStudioWidget::create_action_tab(GUI::Widget& parent) ToDoEntries::the().on_update = [this]() { m_todo_entries_widget->refresh(); }; + + return {}; } void HackStudioWidget::create_project_tab(GUI::Widget& parent) diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h index b387aa4f8dc..290e11de31d 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.h +++ b/Userland/DevTools/HackStudio/HackStudioWidget.h @@ -145,7 +145,7 @@ private: void create_open_files_view(GUI::Widget& parent); void create_toolbar(GUI::Widget& parent); - void create_action_tab(GUI::Widget& parent); + ErrorOr create_action_tab(GUI::Widget& parent); void create_file_menu(GUI::Window&); void update_recent_projects_submenu(); void create_edit_menu(GUI::Window&);