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 :)
This commit is contained in:
Baitinq 2022-12-16 02:00:56 +01:00 committed by Andreas Kling
parent 55a903911b
commit 4c732abed5
4 changed files with 29 additions and 13 deletions

View file

@ -22,21 +22,21 @@
namespace HackStudio {
void DebugInfoWidget::init_toolbar()
ErrorOr<void> 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<NonnullRefPtr<DebugInfoWidget>> DebugInfoWidget::create()
{
auto debuginfo_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DebugInfoWidget));
auto& toolbar_container = debuginfo_widget->add<GUI::ToolbarContainer>();
debuginfo_widget->m_toolbar = toolbar_container.add<GUI::Toolbar>();
TRY(debuginfo_widget->init_toolbar());
return debuginfo_widget;
}
DebugInfoWidget::DebugInfoWidget()
{
set_layout<GUI::VerticalBoxLayout>();
auto& toolbar_container = add<GUI::ToolbarContainer>();
m_toolbar = toolbar_container.add<GUI::Toolbar>();
init_toolbar();
auto& bottom_box = add<GUI::Widget>();
bottom_box.set_layout<GUI::HorizontalBoxLayout>();

View file

@ -24,6 +24,7 @@ namespace HackStudio {
class DebugInfoWidget final : public GUI::Widget {
C_OBJECT(DebugInfoWidget)
public:
static ErrorOr<NonnullRefPtr<DebugInfoWidget>> create();
virtual ~DebugInfoWidget() override { }
void update_state(Debug::ProcessInspector&, PtraceRegisters const&);
@ -34,7 +35,7 @@ public:
private:
explicit DebugInfoWidget();
void init_toolbar();
ErrorOr<void> init_toolbar();
NonnullRefPtr<GUI::Widget> build_variables_tab();
NonnullRefPtr<GUI::Widget> build_registers_tab();

View file

@ -125,7 +125,7 @@ ErrorOr<NonnullRefPtr<HackStudioWidget>> 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<GUI::Action> HackStudioWidget::create_run_action()
});
}
void HackStudioWidget::create_action_tab(GUI::Widget& parent)
ErrorOr<void> HackStudioWidget::create_action_tab(GUI::Widget& parent)
{
m_action_tab_widget = parent.add<GUI::TabWidget>();
@ -1317,7 +1317,9 @@ void HackStudioWidget::create_action_tab(GUI::Widget& parent)
m_find_in_files_widget = m_action_tab_widget->add_tab<FindInFilesWidget>("Find in files");
m_todo_entries_widget = m_action_tab_widget->add_tab<ToDoEntriesWidget>("TODO");
m_terminal_wrapper = m_action_tab_widget->add_tab<TerminalWrapper>("Console", false);
m_debug_info_widget = m_action_tab_widget->add_tab<DebugInfoWidget>("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)

View file

@ -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<void> create_action_tab(GUI::Widget& parent);
void create_file_menu(GUI::Window&);
void update_recent_projects_submenu();
void create_edit_menu(GUI::Window&);